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())
145 for (
unsigned int i = 0; i < VLength; ++i)
147 this->GetElement((*_array)[i], i);
158 template <
typename TValue,
unsigned int VLength>
162 if (static_cast<int>(VLength) <= m_MetaArray.Length())
164 for (
unsigned int i = 0; i < VLength; ++i)
166 this->GetElement((*_vector)[i], i);
178 template <
typename TValue,
unsigned int VLength>
182 if (static_cast<int>(VLength) <= m_MetaArray.Length())
184 for (
unsigned int i = 0; i < VLength; ++i)
186 this->GetElement((*_vector)[i], i);
203 template <
typename TValue>
207 bool _letVectorManageData =
true)
209 if (m_MetaArray.ElementType() != _metaElementType)
211 m_MetaArray.ConvertElementDataTo(_metaElementType);
213 _vector->
SetData((TValue *)(m_MetaArray.ElementData()), m_MetaArray.Length(), _letVectorManageData);
214 if (_letVectorManageData)
216 m_MetaArray.AutoFreeElementData(
false);
226 template <
typename TValue>
230 if (m_MetaArray.ElementType() != _metaElementType)
232 m_MetaArray.ConvertElementDataTo(_metaElementType);
234 int rows = m_MetaArray.Length();
235 int cols = m_MetaArray.ElementNumberOfChannels();
237 for (
int i = 0; i < rows; ++i)
239 (*_array)[i].SetSize(cols);
240 for (
int j = 0; j < cols; ++j)
242 (*_array)[i][j] = static_cast<typename TValue::ValueType>(m_MetaArray.ElementData(i * cols + j));
252 PrintSelf(std::ostream & os,
Indent indent)
const override;
255 MetaArray m_MetaArray{};
257 std::string m_FileName{};
259 void * m_Buffer{
nullptr };
263 #endif // itkMetaArrayReader_h