18 #ifndef itkMetaArrayReader_h
19 #define itkMetaArrayReader_h
20 #include "ITKIOMetaExport.h"
26 #include "metaArray.h"
46 itkSetStringMacro(FileName);
49 itkGetStringMacro(FileName);
54 GetMetaArrayPointer();
58 SetBuffer(
void * _buffer);
68 return m_MetaArray.ElementType();
75 return m_MetaArray.Length();
82 return m_MetaArray.Length();
89 return m_MetaArray.Length();
96 return m_MetaArray.Length();
103 return m_MetaArray.Length();
107 template <
typename TValue>
109 GetElement(TValue & value,
unsigned int i,
unsigned int channel = 0)
const
111 value = static_cast<TValue>(m_MetaArray.ElementData(i * m_MetaArray.ElementNumberOfChannels() + channel));
122 template <
typename TValue>
126 if (m_MetaArray.ElementType() != _metaElementType)
128 m_MetaArray.ConvertElementDataTo(_metaElementType);
130 _array->
SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letArrayManageData);
131 if (_letArrayManageData)
133 m_MetaArray.AutoFreeElementData(
false);
139 template <
typename TValue,
unsigned int VLength>
143 if (static_cast<int>(VLength) <= m_MetaArray.Length())
146 for (i = 0; i < VLength; ++i)
148 this->GetElement((*_array)[i], i);
159 template <
typename TValue,
unsigned int VLength>
163 if (static_cast<int>(VLength) <= m_MetaArray.Length())
166 for (i = 0; i < VLength; ++i)
168 this->GetElement((*_vector)[i], i);
180 template <
typename TValue,
unsigned int VLength>
184 if (static_cast<int>(VLength) <= m_MetaArray.Length())
187 for (i = 0; i < VLength; ++i)
189 this->GetElement((*_vector)[i], i);
206 template <
typename TValue>
210 bool _letVectorManageData =
true)
212 if (m_MetaArray.ElementType() != _metaElementType)
214 m_MetaArray.ConvertElementDataTo(_metaElementType);
216 _vector->
SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letVectorManageData);
217 if (_letVectorManageData)
219 m_MetaArray.AutoFreeElementData(
false);
229 template <
typename TValue>
233 if (m_MetaArray.ElementType() != _metaElementType)
235 m_MetaArray.ConvertElementDataTo(_metaElementType);
237 int rows = m_MetaArray.Length();
238 int cols = m_MetaArray.ElementNumberOfChannels();
240 for (
int i = 0; i < rows; ++i)
242 (*_array)[i].SetSize(cols);
243 for (
int j = 0; j < cols; ++j)
245 (*_array)[i][j] = static_cast<typename TValue::ValueType>(m_MetaArray.ElementData(i * cols + j));
255 PrintSelf(std::ostream & os,
Indent indent)
const override;
258 MetaArray m_MetaArray{};
260 std::string m_FileName{};
262 void * m_Buffer{
nullptr };
266 #endif // itkMetaArrayReader_h