ITK  4.4.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 
21 #include "itkLightProcessObject.h"
22 #include "itkArray.h"
23 #include "itkCovariantVector.h"
25 #include "metaArray.h"
26 
27 namespace itk
28 {
29 class ITK_EXPORT MetaArrayWriter:public LightProcessObject
30 {
31 public:
32 
36 
39 
41  itkNewMacro(Self);
42 
44  itkTypeMacro(MetaArrayWriter, LightProcessObject);
45 
47  itkSetStringMacro(FileName);
48 
50  itkGetStringMacro(FileName);
51 
55  itkSetStringMacro(DataFileName);
56 
58  itkGetStringMacro(DataFileName);
59 
61  itkSetMacro(Binary, bool);
62 
65  itkGetConstMacro(Binary, bool);
66 
68  template< typename TValueType >
69  void SetInput(MET_ValueEnumType _metaElementType,
70  const Array< TValueType > *_array)
71  {
72  m_Buffer = (const void *)( _array->data_block() );
73  m_MetaArray.InitializeEssential(_array->Size(),
74  _metaElementType);
75  }
77 
79  template< typename TValueType, unsigned int VLength >
80  void SetInput(MET_ValueEnumType _metaElementType,
82  {
83  m_Buffer = (const void *)( _array->GetDataPointer() );
84  m_MetaArray.InitializeEssential(VLength,
85  _metaElementType);
86  }
88 
90  template< typename TValueType, unsigned int VLength >
91  void SetInput(MET_ValueEnumType _metaElementType,
92  const Vector< TValueType, VLength > *_vector)
93  {
94  m_Buffer = (const void *)( _vector->GetDataPointer() );
95  m_MetaArray.InitializeEssential(VLength,
96  _metaElementType);
97  }
99 
101  template< typename TValueType, unsigned int VLength >
102  void SetInput(MET_ValueEnumType _metaElementType,
104  {
105  m_Buffer = (const void *)( _vector->GetDataPointer() );
106  m_MetaArray.InitializeEssential(VLength,
107  _metaElementType);
108  }
110 
112  template< typename TValueType >
113  void SetInput(MET_ValueEnumType _metaElementType,
114  const VariableLengthVector< TValueType > *_vector)
115  {
116  m_Buffer = (const void *)( _vector->GetDataPointer() );
117  m_MetaArray.InitializeEssential(_vector->Size(),
118  _metaElementType);
119  }
121 
129  template< typename TValueType >
130  void SetMultiChannelInput(MET_ValueEnumType _metaElementType,
131  int ,
132  const Array< TValueType > *_array)
133  {
134  int rows = _array->GetSize();
135  int cols = ( *_array )[0].GetSize();
137 
138  m_MetaArray.InitializeEssential(rows,
139  _metaElementType,
140  cols,
141  NULL,
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();
169  void PrintSelf(std::ostream & os, Indent indent) const;
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
187