ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkMetaArrayReader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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:
33 
39 
41  itkNewMacro(Self);
42 
44  itkTypeMacro(MetaArrayReader, LightProcessObject);
45 
47  itkSetStringMacro(FileName);
48 
50  itkGetStringMacro(FileName);
51 
54  MetaArray * GetMetaArrayPointer();
55 
57  void SetBuffer(void *_buffer);
58 
60  void Update();
61 
63  MET_ValueEnumType GetDataType(void) const
64  {
65  return m_MetaArray.ElementType();
66  }
67 
69  int Size(void) const
70  {
71  return m_MetaArray.Length();
72  }
73 
75  int GetNumberOfElements(void) const
76  {
77  return m_MetaArray.Length();
78  }
79 
81  int GetVectorDimension(void) const
82  {
83  return m_MetaArray.Length();
84  }
85 
87  int GetNumberOfComponents(void) const
88  {
89  return m_MetaArray.Length();
90  }
91 
94  {
95  return m_MetaArray.Length();
96  }
97 
99  template< typename TValue >
100  inline void GetElement(TValue & value, unsigned int i,
101  unsigned int channel = 0) const
102  {
103  value = static_cast< TValue >( m_MetaArray.ElementData(
104  i * m_MetaArray.ElementNumberOfChannels() + channel) );
105  }
106 
115  template< typename TValue >
116  void GetOutput(MET_ValueEnumType _metaElementType,
117  Array< TValue > *_array,
118  bool _letArrayManageData = true)
119  {
120  if ( m_MetaArray.ElementType() != _metaElementType )
121  {
122  m_MetaArray.ConvertElementDataTo(_metaElementType);
123  }
124  _array->SetData( (TValue *)( m_MetaArray.ElementData() ),
125  m_MetaArray.Length(),
126  _letArrayManageData );
127  if ( _letArrayManageData )
128  {
129  m_MetaArray.AutoFreeElementData(false);
130  }
131  }
133 
135  template< typename TValue, unsigned int VLength >
136  bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
138  {
139  if ( static_cast< int >( VLength ) <= m_MetaArray.Length() )
140  {
141  unsigned int i;
142  for ( i = 0; i < VLength; i++ )
143  {
144  this->GetElement( ( *_array )[i], i );
145  }
146  return true;
147  }
148  return false;
149  }
151 
155  template< typename TValue, unsigned int VLength >
156  bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
157  Vector< TValue, VLength > *_vector)
158  {
159  if ( static_cast< int >( VLength ) <= m_MetaArray.Length() )
160  {
161  unsigned int i;
162  for ( i = 0; i < VLength; i++ )
163  {
164  this->GetElement( ( *_vector )[i], i );
165  }
166  return true;
167  }
168  return false;
169  }
171 
176  template< typename TValue, unsigned int VLength >
177  bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
179  {
180  if ( static_cast< int >( VLength ) <= m_MetaArray.Length() )
181  {
182  unsigned int i;
183  for ( i = 0; i < VLength; i++ )
184  {
185  this->GetElement( ( *_vector )[i], i );
186  }
187  return true;
188  }
189  return false;
190  }
192 
202  template< typename TValue >
203  void GetOutput(MET_ValueEnumType _metaElementType,
205  bool _letVectorManageData = true)
206  {
207  if ( m_MetaArray.ElementType() != _metaElementType )
208  {
209  m_MetaArray.ConvertElementDataTo(_metaElementType);
210  }
211  _vector->SetData( (TValue *)( m_MetaArray.ElementData() ),
212  m_MetaArray.Length(),
213  _letVectorManageData );
214  if ( _letVectorManageData )
215  {
216  m_MetaArray.AutoFreeElementData(false);
217  }
218  }
220 
226  template< typename TValue >
227  void GetMultiChannelOutput(MET_ValueEnumType _metaElementType,
228  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 >
243  ( m_MetaArray.ElementData(i * cols + j) );
244  }
245  }
246  }
248 
249 protected:
250 
251  MetaArrayReader();
252  virtual ~MetaArrayReader() ITK_OVERRIDE;
253  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
254 
255 private:
256 
257  MetaArray m_MetaArray;
258 
259  std::string m_FileName;
260 
261  void *m_Buffer;
262 };
263 } // namespace itk
264 
265 #endif // itkMetaArrayReader_h
Array class with size defined at construction time.
Definition: itkArray.h:50
LightProcessObject Superclass
Light weight base class for most itk classes.
void GetOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array, bool _letArrayManageData=true)
bool GetOutput(MET_ValueEnumType, FixedArray< TValue, VLength > *_array)
bool GetOutput(MET_ValueEnumType, Vector< TValue, VLength > *_vector)
int Size(void) const
void GetOutput(MET_ValueEnumType _metaElementType, VariableLengthVector< TValue > *_vector, bool _letVectorManageData=true)
void GetElement(TValue &value, unsigned int i, unsigned int channel=0) const
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
Represents an array whose length can be defined at run-time.
bool GetOutput(MET_ValueEnumType, CovariantVector< TValue, VLength > *_vector)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
void SetSize(SizeValueType sz)
int GetVectorDimension(void) const
int GetCovariantVectorDimension(void) const
MET_ValueEnumType GetDataType(void) const
void SetData(TValue *data, SizeValueType sz, bool LetArrayManageMemory=false)
int GetNumberOfElements(void) const
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetData(TValue *data, bool LetArrayManageMemory=false)
void GetMultiChannelOutput(MET_ValueEnumType _metaElementType, Array< TValue > *_array)
A templated class holding a n-Dimensional covariant vector.
SmartPointer< Self > Pointer
SmartPointer< const Self > ConstPointer
int GetNumberOfComponents(void) const