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
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 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 }
248protected:
251 void
252 PrintSelf(std::ostream & os, Indent indent) const override;
253
254private:
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
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....