ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkMetaArrayWriter.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 __itkMetaArrayWriter_h
19 #define __itkMetaArrayWriter_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 MetaArrayWriter:public LightProcessObject
31 {
32 public:
33 
37 
40 
42  itkNewMacro(Self);
43 
45  itkTypeMacro(MetaArrayWriter, LightProcessObject);
46 
48  itkSetStringMacro(FileName);
49 
51  itkGetStringMacro(FileName);
52 
56  itkSetStringMacro(DataFileName);
57 
59  itkGetStringMacro(DataFileName);
60 
62  itkSetMacro(Binary, bool);
63 
66  itkGetConstMacro(Binary, bool);
67 
69  template< typename TValue >
70  void SetInput(MET_ValueEnumType _metaElementType,
71  const Array< TValue > *_array)
72  {
73  m_Buffer = (const void *)( _array->data_block() );
74  m_MetaArray.InitializeEssential(_array->Size(),
75  _metaElementType);
76  }
78 
80  template< typename TValue, unsigned int VLength >
81  void SetInput(MET_ValueEnumType _metaElementType,
82  const FixedArray< TValue, VLength > *_array)
83  {
84  m_Buffer = (const void *)( _array->GetDataPointer() );
85  m_MetaArray.InitializeEssential(VLength,
86  _metaElementType);
87  }
89 
91  template< typename TValue, unsigned int VLength >
92  void SetInput(MET_ValueEnumType _metaElementType,
93  const Vector< TValue, VLength > *_vector)
94  {
95  m_Buffer = (const void *)( _vector->GetDataPointer() );
96  m_MetaArray.InitializeEssential(VLength,
97  _metaElementType);
98  }
100 
102  template< typename TValue, unsigned int VLength >
103  void SetInput(MET_ValueEnumType _metaElementType,
104  const CovariantVector< TValue, VLength > *_vector)
105  {
106  m_Buffer = (const void *)( _vector->GetDataPointer() );
107  m_MetaArray.InitializeEssential(VLength,
108  _metaElementType);
109  }
111 
113  template< typename TValue >
114  void SetInput(MET_ValueEnumType _metaElementType,
115  const VariableLengthVector< TValue > *_vector)
116  {
117  m_Buffer = (const void *)( _vector->GetDataPointer() );
118  m_MetaArray.InitializeEssential(_vector->Size(),
119  _metaElementType);
120  }
122 
130  template< typename TValue >
131  void SetMultiChannelInput(MET_ValueEnumType _metaElementType,
132  int ,
133  const Array< TValue > *_array)
134  {
135  int rows = _array->GetSize();
136  int cols = ( *_array )[0].GetSize();
138 
139  m_MetaArray.InitializeEssential(rows,
140  _metaElementType,
141  cols,
142  ITK_NULLPTR,
143  true,
144  true);
145  m_Buffer = m_MetaArray.ElementData();
146  for ( int i = 0; i < rows; i++ )
147  {
148  for ( int j = 0; j < cols; j++ )
149  {
150  m_MetaArray.ElementData( i * cols + j, (double)( ( *_array )[i][j] ) );
151  }
152  }
153  }
154 
156  itkSetMacro(Precision, unsigned int);
157  itkGetConstMacro(Precision, unsigned int);
159 
161  void ConvertTo(MET_ValueEnumType _metaElementType);
162 
164  void Update();
165 
166 protected:
167 
168  MetaArrayWriter();
169  virtual ~MetaArrayWriter();
170  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
171 
172 private:
173 
174  bool m_Binary;
175 
176  unsigned int m_Precision;
177 
178  std::string m_FileName;
179  std::string m_DataFileName;
180 
181  MetaArray m_MetaArray;
182 
183  const void *m_Buffer;
184 };
185 } // namespace itk
186 
187 #endif // __itkMetaArrayWriter_h
Array class with size defined at construction time.
Definition: itkArray.h:50
void SetInput(MET_ValueEnumType _metaElementType, const Array< TValue > *_array)
Light weight base class for most itk classes.
unsigned int Size(void) const
void SetInput(MET_ValueEnumType _metaElementType, const CovariantVector< TValue, VLength > *_vector)
const TValue * GetDataPointer() const
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
void SetInput(MET_ValueEnumType _metaElementType, const FixedArray< TValue, VLength > *_array)
Represents an array whose length can be defined at run-time.
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
void SetInput(MET_ValueEnumType _metaElementType, const Vector< TValue, VLength > *_vector)
void SetMultiChannelInput(MET_ValueEnumType _metaElementType, int, const Array< TValue > *_array)
SizeValueType GetSize(void) const
Definition: itkArray.h:141
LightProcessObject Superclass
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
void SetInput(MET_ValueEnumType _metaElementType, const VariableLengthVector< TValue > *_vector)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
SizeValueType Size(void) const
Definition: itkArray.h:124
ValueType * GetDataPointer()
SmartPointer< const Self > ConstPointer
A templated class holding a n-Dimensional covariant vector.
SmartPointer< Self > Pointer