Orfeo Toolbox  3.16
itkMetaArrayReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMetaArrayReader.h,v $
5  Language: C++
6  Date: $Date: 2007-03-22 14:28:51 $
7  Version: $Revision: 1.6 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMetaArrayReader_h
18 #define __itkMetaArrayReader_h
19 
20 #include "itkLightProcessObject.h"
21 #include "itkArray.h"
22 #include "itkFixedArray.h"
23 #include "itkVector.h"
24 #include "itkCovariantVector.h"
26 #include "metaArray.h"
27 
28 namespace itk
29 {
30 
32 {
33 public:
34 
40 
42  itkNewMacro(Self);
43 
45  itkTypeMacro(MetaArrayReader, LightProcessObject);
46 
48  itkSetStringMacro(FileName);
49 
51  itkGetStringMacro(FileName);
52 
55  MetaArray * GetMetaArrayPointer(void);
56 
58  void SetBuffer(void * _buffer);
59 
61  void Update();
62 
64  MET_ValueEnumType GetDataType(void) const
65  {
66  return m_MetaArray.ElementType();
67  }
68 
70  int Size(void) const
71  {
72  return m_MetaArray.Length();
73  }
74 
76  int GetNumberOfElements(void) const
77  {
78  return m_MetaArray.Length();
79  }
80 
82  int GetVectorDimension(void) const
83  {
84  return m_MetaArray.Length();
85  }
86 
88  int GetNumberOfComponents(void) const
89  {
90  return m_MetaArray.Length();
91  }
92 
95  {
96  return m_MetaArray.Length();
97  }
98 
100  template <typename TValueType>
101  inline void GetElement( TValueType & value, unsigned int i,
102  unsigned int channel=0 ) const
103  {
104  value = static_cast<TValueType>(m_MetaArray.ElementData(
105  i * m_MetaArray.ElementNumberOfChannels() + channel));
106  }
107 
116  template <typename TValueType>
117  void GetOutput(MET_ValueEnumType _metaElementType,
118  Array<TValueType> * _array,
119  bool _letArrayManageData = true)
120  {
121  if(m_MetaArray.ElementType() != _metaElementType)
122  {
123  m_MetaArray.ConvertElementDataTo(_metaElementType);
124  }
125  _array->SetData((TValueType *)(m_MetaArray.ElementData()),
126  m_MetaArray.Length(),
127  _letArrayManageData);
128  if(_letArrayManageData)
129  {
130  m_MetaArray.AutoFreeElementData(false);
131  }
132  }
133 
135  template <typename TValueType, 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  }
150 
154  template <typename TValueType, unsigned int VLength>
155  bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
156  Vector<TValueType, VLength> * _vector)
157  {
158  if(static_cast<int>(VLength) <= m_MetaArray.Length())
159  {
160  unsigned int i;
161  for(i = 0; i<VLength; i++)
162  {
163  this->GetElement( (*_vector)[i], i );
164  }
165  return true;
166  }
167  return false;
168  }
169 
170 
175  template <typename TValueType, unsigned int VLength>
176  bool GetOutput(MET_ValueEnumType itkNotUsed(_metaElementType),
178  {
179  if(static_cast<int>(VLength) <= m_MetaArray.Length())
180  {
181  unsigned int i;
182  for(i = 0; i<VLength; i++)
183  {
184  this->GetElement( (*_vector)[i], i );
185  }
186  return true;
187  }
188  return false;
189  }
190 
200  template <typename TValueType>
201  void GetOutput(MET_ValueEnumType _metaElementType,
203  bool _letVectorManageData = true)
204  {
205  if(m_MetaArray.ElementType() != _metaElementType)
206  {
207  m_MetaArray.ConvertElementDataTo(_metaElementType);
208  }
209  _vector->SetData((TValueType *)(m_MetaArray.ElementData()),
210  m_MetaArray.Length(),
211  _letVectorManageData);
212  if(_letVectorManageData)
213  {
214  m_MetaArray.AutoFreeElementData(false);
215  }
216  }
217 
223  template <typename TValueType>
224  void GetMultiChannelOutput(MET_ValueEnumType _metaElementType,
225  Array<TValueType> * _array)
226  {
227  if(m_MetaArray.ElementType() != _metaElementType)
228  {
229  m_MetaArray.ConvertElementDataTo(_metaElementType);
230  }
231  int rows = m_MetaArray.Length();
232  int cols = m_MetaArray.ElementNumberOfChannels();
233  _array->SetSize(rows);
234  for(int i=0; i<rows; i++)
235  {
236  (*_array)[i].SetSize(cols);
237  for(int j=0; j<cols; j++)
238  {
239  (*_array)[i][j] = static_cast<typename TValueType::ValueType>
240  (m_MetaArray.ElementData(i*cols+j));
241  }
242  }
243  }
244 
245 protected:
246 
247  MetaArrayReader();
248  virtual ~MetaArrayReader();
249 
250 private:
251 
252  MetaArray m_MetaArray;
253 
254  std::string m_FileName;
255 
256  void * m_Buffer;
257 
258 };
259 
260 } // namespace itk
261 
262 
263 #endif // __itkTransformFileReader_h

Generated at Sat Feb 2 2013 23:52:43 for Orfeo Toolbox with doxygen 1.8.1.1