ITK  5.2.0
Insight Toolkit
itkMetaArrayReader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMetaArrayReader_h
19 #define itkMetaArrayReader_h
20 #include "ITKIOMetaExport.h"
21 
22 #include "itkLightProcessObject.h"
23 #include "itkArray.h"
24 #include "itkCovariantVector.h"
26 #include "metaArray.h"
27 
28 namespace itk
29 {
30 class ITKIOMeta_EXPORT MetaArrayReader : public LightProcessObject
31 {
32 public:
38 
40  itkNewMacro(Self);
41 
43  itkTypeMacro(MetaArrayReader, LightProcessObject);
44 
46  itkSetStringMacro(FileName);
47 
49  itkGetStringMacro(FileName);
50 
53  MetaArray *
54  GetMetaArrayPointer();
55 
57  void
58  SetBuffer(void * _buffer);
59 
61  void
62  Update();
63 
65  MET_ValueEnumType
66  GetDataType() const
67  {
68  return m_MetaArray.ElementType();
69  }
70 
72  int
73  Size() const
74  {
75  return m_MetaArray.Length();
76  }
77 
79  int
81  {
82  return m_MetaArray.Length();
83  }
84 
86  int
88  {
89  return m_MetaArray.Length();
90  }
91 
93  int
95  {
96  return m_MetaArray.Length();
97  }
98 
100  int
102  {
103  return m_MetaArray.Length();
104  }
105 
107  template <typename TValue>
108  inline void
109  GetElement(TValue & value, unsigned int i, unsigned int channel = 0) const
110  {
111  value = static_cast<TValue>(m_MetaArray.ElementData(i * m_MetaArray.ElementNumberOfChannels() + channel));
112  }
113 
122  template <typename TValue>
123  void
124  GetOutput(MET_ValueEnumType _metaElementType, Array<TValue> * _array, bool _letArrayManageData = true)
125  {
126  if (m_MetaArray.ElementType() != _metaElementType)
127  {
128  m_MetaArray.ConvertElementDataTo(_metaElementType);
129  }
130  _array->SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letArrayManageData);
131  if (_letArrayManageData)
132  {
133  m_MetaArray.AutoFreeElementData(false);
134  }
135  }
137 
139  template <typename TValue, unsigned int VLength>
140  bool
141  GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType), FixedArray<TValue, VLength> * _array)
142  {
143  if (static_cast<int>(VLength) <= m_MetaArray.Length())
144  {
145  unsigned int i;
146  for (i = 0; i < VLength; i++)
147  {
148  this->GetElement((*_array)[i], i);
149  }
150  return true;
151  }
152  return false;
153  }
155 
159  template <typename TValue, unsigned int VLength>
160  bool
161  GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType), Vector<TValue, VLength> * _vector)
162  {
163  if (static_cast<int>(VLength) <= m_MetaArray.Length())
164  {
165  unsigned int i;
166  for (i = 0; i < VLength; i++)
167  {
168  this->GetElement((*_vector)[i], i);
169  }
170  return true;
171  }
172  return false;
173  }
175 
180  template <typename TValue, unsigned int VLength>
181  bool
182  GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType), CovariantVector<TValue, VLength> * _vector)
183  {
184  if (static_cast<int>(VLength) <= m_MetaArray.Length())
185  {
186  unsigned int i;
187  for (i = 0; i < VLength; i++)
188  {
189  this->GetElement((*_vector)[i], i);
190  }
191  return true;
192  }
193  return false;
194  }
196 
206  template <typename TValue>
207  void
208  GetOutput(MET_ValueEnumType _metaElementType,
210  bool _letVectorManageData = true)
211  {
212  if (m_MetaArray.ElementType() != _metaElementType)
213  {
214  m_MetaArray.ConvertElementDataTo(_metaElementType);
215  }
216  _vector->SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letVectorManageData);
217  if (_letVectorManageData)
218  {
219  m_MetaArray.AutoFreeElementData(false);
220  }
221  }
223 
229  template <typename TValue>
230  void
231  GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array<TValue> * _array)
232  {
233  if (m_MetaArray.ElementType() != _metaElementType)
234  {
235  m_MetaArray.ConvertElementDataTo(_metaElementType);
236  }
237  int rows = m_MetaArray.Length();
238  int cols = m_MetaArray.ElementNumberOfChannels();
239  _array->SetSize(rows);
240  for (int i = 0; i < rows; i++)
241  {
242  (*_array)[i].SetSize(cols);
243  for (int j = 0; j < cols; j++)
244  {
245  (*_array)[i][j] = static_cast<typename TValue::ValueType>(m_MetaArray.ElementData(i * cols + j));
246  }
247  }
248  }
250 
251 protected:
252  MetaArrayReader();
253  ~MetaArrayReader() override;
254  void
255  PrintSelf(std::ostream & os, Indent indent) const override;
256 
257 private:
258  MetaArray m_MetaArray;
259 
260  std::string m_FileName;
261 
262  void * m_Buffer{ nullptr };
263 };
264 } // namespace itk
265 
266 #endif // itkMetaArrayReader_h
itk::MetaArrayReader::GetOutput
void GetOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array, bool _letArrayManageData=true)
Definition: itkMetaArrayReader.h:124
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
itkCovariantVector.h
itk::MetaArrayReader
Definition: itkMetaArrayReader.h:30
itkLightProcessObject.h
itkVariableLengthVector.h
itk::MetaArrayReader::GetOutput
bool GetOutput(MET_ValueEnumType, Vector< TValue, VLength > *_vector)
Definition: itkMetaArrayReader.h:161
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::MetaArrayReader::GetOutput
void GetOutput(MET_ValueEnumType _metaElementType, VariableLengthVector< TValue > *_vector, bool _letVectorManageData=true)
Definition: itkMetaArrayReader.h:208
itk::MetaArrayReader::GetNumberOfComponents
int GetNumberOfComponents() const
Definition: itkMetaArrayReader.h:94
itk::MetaArrayReader::GetVectorDimension
int GetVectorDimension() const
Definition: itkMetaArrayReader.h:87
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::MetaArrayReader::GetOutput
bool GetOutput(MET_ValueEnumType, FixedArray< TValue, VLength > *_array)
Definition: itkMetaArrayReader.h:141
itk::VariableLengthVector::SetData
void SetData(TValue *datain, bool LetArrayManageMemory=false)
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::MetaArrayReader::m_MetaArray
MetaArray m_MetaArray
Definition: itkMetaArrayReader.h:258
itk::MetaArrayReader::GetOutput
bool GetOutput(MET_ValueEnumType, CovariantVector< TValue, VLength > *_vector)
Definition: itkMetaArrayReader.h:182
itk::MetaArrayReader::GetElement
void GetElement(TValue &value, unsigned int i, unsigned int channel=0) const
Definition: itkMetaArrayReader.h:109
itk::MetaArrayReader::GetDataType
MET_ValueEnumType GetDataType() const
Definition: itkMetaArrayReader.h:66
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::Array::SetData
void SetData(TValue *datain, SizeValueType sz, bool LetArrayManageMemory=false)
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::MetaArrayReader::GetNumberOfElements
int GetNumberOfElements() const
Definition: itkMetaArrayReader.h:80
itkArray.h
itk::MetaArrayReader::GetCovariantVectorDimension
int GetCovariantVectorDimension() const
Definition: itkMetaArrayReader.h:101
itk::MetaArrayReader::m_FileName
std::string m_FileName
Definition: itkMetaArrayReader.h:260
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::MetaArrayReader::GetMultiChannelOutput
void GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array)
Definition: itkMetaArrayReader.h:231
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::MetaArrayReader::Size
int Size() const
Definition: itkMetaArrayReader.h:73
itk::Array::SetSize
void SetSize(SizeValueType sz)