ITK  4.13.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  itkGetStringMacro(FileName);
51 
54  itkSetStringMacro(DataFileName);
55  itkGetStringMacro(DataFileName);
57 
62  itkBooleanMacro(Binary);
63  itkSetMacro(Binary, bool);
64  itkGetConstMacro(Binary, bool);
66 
68  template< typename TValue >
69  void SetInput(MET_ValueEnumType _metaElementType,
70  const Array< TValue > *_array)
71  {
72  m_Buffer = (const void *)( _array->data_block() );
73  m_MetaArray.InitializeEssential(_array->Size(),
74  _metaElementType);
75  }
77 
79  template< typename TValue, unsigned int VLength >
80  void SetInput(MET_ValueEnumType _metaElementType,
81  const FixedArray< TValue, VLength > *_array)
82  {
83  m_Buffer = (const void *)( _array->GetDataPointer() );
84  m_MetaArray.InitializeEssential(VLength,
85  _metaElementType);
86  }
88 
90  template< typename TValue, unsigned int VLength >
91  void SetInput(MET_ValueEnumType _metaElementType,
92  const Vector< TValue, VLength > *_vector)
93  {
94  m_Buffer = (const void *)( _vector->GetDataPointer() );
95  m_MetaArray.InitializeEssential(VLength,
96  _metaElementType);
97  }
99 
101  template< typename TValue, unsigned int VLength >
102  void SetInput(MET_ValueEnumType _metaElementType,
103  const CovariantVector< TValue, VLength > *_vector)
104  {
105  m_Buffer = (const void *)( _vector->GetDataPointer() );
106  m_MetaArray.InitializeEssential(VLength,
107  _metaElementType);
108  }
110 
112  template< typename TValue >
113  void SetInput(MET_ValueEnumType _metaElementType,
114  const VariableLengthVector< TValue > *_vector)
115  {
116  m_Buffer = (const void *)( _vector->GetDataPointer() );
117  m_MetaArray.InitializeEssential(_vector->Size(),
118  _metaElementType);
119  }
121 
129  template< typename TValue >
130  void SetMultiChannelInput(MET_ValueEnumType _metaElementType,
131  int ,
132  const Array< TValue > *_array)
133  {
134  int rows = _array->GetSize();
135  int cols = ( *_array )[0].GetSize();
137 
138  m_MetaArray.InitializeEssential(rows,
139  _metaElementType,
140  cols,
141  ITK_NULLPTR,
142  true,
143  true);
144  m_Buffer = m_MetaArray.ElementData();
145  for ( int i = 0; i < rows; i++ )
146  {
147  for ( int j = 0; j < cols; j++ )
148  {
149  m_MetaArray.ElementData( i * cols + j, (double)( ( *_array )[i][j] ) );
150  }
151  }
152  }
153 
155  itkSetMacro(Precision, unsigned int);
156  itkGetConstMacro(Precision, unsigned int);
158 
160  void ConvertTo(MET_ValueEnumType _metaElementType);
161 
163  void Update();
164 
165 protected:
166 
167  MetaArrayWriter();
168  virtual ~MetaArrayWriter() ITK_OVERRIDE;
169  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
170 
171 private:
172 
173  bool m_Binary;
174 
175  unsigned int m_Precision;
176 
177  std::string m_FileName;
178  std::string m_DataFileName;
179 
180  MetaArray m_MetaArray;
181 
182  const void *m_Buffer;
183 };
184 } // namespace itk
185 
186 #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