ITK  5.4.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
23#include "itkArray.h"
24#include "itkCovariantVector.h"
26#include "metaArray.h"
27
28namespace itk
29{
30class ITKIOMeta_EXPORT MetaArrayReader : public LightProcessObject
31{
32public:
38
40 itkNewMacro(Self);
41
43 itkOverrideGetNameOfClassMacro(MetaArrayReader);
44
46 itkSetStringMacro(FileName);
47
49 itkGetStringMacro(FileName);
50
53 MetaArray *
55
57 void
58 SetBuffer(void * _buffer);
59
61 void
63
65 MET_ValueEnumType
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 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 }
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 }
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 }
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 }
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 }
251protected:
254 void
255 PrintSelf(std::ostream & os, Indent indent) const override;
256
257private:
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
Array class with size defined at construction time.
Definition: itkArray.h:48
void SetData(TValue *datain, SizeValueType sz, bool LetArrayManageMemory=false)
void SetSize(SizeValueType sz)
A templated class holding a n-Dimensional covariant vector.
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
void GetOutput(MET_ValueEnumType _metaElementType, VariableLengthVector< TValue > *_vector, bool _letVectorManageData=true)
bool GetOutput(MET_ValueEnumType, CovariantVector< TValue, VLength > *_vector)
bool GetOutput(MET_ValueEnumType, FixedArray< TValue, VLength > *_array)
void GetElement(TValue &value, unsigned int i, unsigned int channel=0) const
int GetNumberOfElements() const
int GetCovariantVectorDimension() const
void SetBuffer(void *_buffer)
void GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array)
bool GetOutput(MET_ValueEnumType, Vector< TValue, VLength > *_vector)
void GetOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array, bool _letArrayManageData=true)
~MetaArrayReader() override
MetaArray * GetMetaArrayPointer()
int GetVectorDimension() const
void PrintSelf(std::ostream &os, Indent indent) const override
int GetNumberOfComponents() const
MET_ValueEnumType GetDataType() const
Base class for most ITK classes.
Definition: itkObject.h:62
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....