ITK  6.0.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  * https://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  itkOverrideGetNameOfClassMacro(MetaArrayReader);
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  }
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  for (unsigned int i = 0; i < VLength; ++i)
146  {
147  this->GetElement((*_array)[i], i);
148  }
149  return true;
150  }
151  return false;
152  }
158  template <typename TValue, unsigned int VLength>
159  bool
160  GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType), Vector<TValue, VLength> * _vector)
161  {
162  if (static_cast<int>(VLength) <= m_MetaArray.Length())
163  {
164  for (unsigned int i = 0; i < VLength; ++i)
165  {
166  this->GetElement((*_vector)[i], i);
167  }
168  return true;
169  }
170  return false;
171  }
178  template <typename TValue, unsigned int VLength>
179  bool
180  GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType), CovariantVector<TValue, VLength> * _vector)
181  {
182  if (static_cast<int>(VLength) <= m_MetaArray.Length())
183  {
184  for (unsigned int i = 0; i < VLength; ++i)
185  {
186  this->GetElement((*_vector)[i], i);
187  }
188  return true;
189  }
190  return false;
191  }
203  template <typename TValue>
204  void
205  GetOutput(MET_ValueEnumType _metaElementType,
207  bool _letVectorManageData = true)
208  {
209  if (m_MetaArray.ElementType() != _metaElementType)
210  {
211  m_MetaArray.ConvertElementDataTo(_metaElementType);
212  }
213  _vector->SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letVectorManageData);
214  if (_letVectorManageData)
215  {
216  m_MetaArray.AutoFreeElementData(false);
217  }
218  }
226  template <typename TValue>
227  void
228  GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array<TValue> * _array)
229  {
230  if (m_MetaArray.ElementType() != _metaElementType)
231  {
232  m_MetaArray.ConvertElementDataTo(_metaElementType);
233  }
234  int rows = m_MetaArray.Length();
235  int cols = m_MetaArray.ElementNumberOfChannels();
236  _array->SetSize(rows);
237  for (int i = 0; i < rows; ++i)
238  {
239  (*_array)[i].SetSize(cols);
240  for (int j = 0; j < cols; ++j)
241  {
242  (*_array)[i][j] = static_cast<typename TValue::ValueType>(m_MetaArray.ElementData(i * cols + j));
243  }
244  }
245  }
248 protected:
249  MetaArrayReader();
250  ~MetaArrayReader() override;
251  void
252  PrintSelf(std::ostream & os, Indent indent) const override;
253 
254 private:
255  MetaArray m_MetaArray{};
256 
257  std::string m_FileName{};
258 
259  void * m_Buffer{ nullptr };
260 };
261 } // namespace itk
262 
263 #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:160
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:205
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:55
itk::MetaArrayReader::GetOutput
bool GetOutput(MET_ValueEnumType, CovariantVector< TValue, VLength > *_vector)
Definition: itkMetaArrayReader.h:180
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:53
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
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::MetaArrayReader::GetMultiChannelOutput
void GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array)
Definition: itkMetaArrayReader.h:228
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:61
itk::MetaArrayReader::Size
int Size() const
Definition: itkMetaArrayReader.h:73
itk::Array::SetSize
void SetSize(SizeValueType sz)