ITK  5.2.0
Insight Toolkit
itkMetaArrayWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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:
36 
39 
41  itkNewMacro(Self);
42 
44  itkTypeMacro(MetaArrayWriter, LightProcessObject);
45 
47  itkSetStringMacro(FileName);
48  itkGetStringMacro(FileName);
50 
53  itkSetStringMacro(DataFileName);
54  itkGetStringMacro(DataFileName);
56 
61  itkBooleanMacro(Binary);
62  itkSetMacro(Binary, bool);
63  itkGetConstMacro(Binary, bool);
65 
67  template <typename TValue>
68  void
69  SetInput(MET_ValueEnumType _metaElementType, const Array<TValue> * _array)
70  {
71  m_Buffer = (const void *)(_array->data_block());
72  m_MetaArray.InitializeEssential(_array->Size(), _metaElementType);
73  }
75 
77  template <typename TValue, unsigned int VLength>
78  void
79  SetInput(MET_ValueEnumType _metaElementType, const FixedArray<TValue, VLength> * _array)
80  {
81  m_Buffer = (const void *)(_array->GetDataPointer());
82  m_MetaArray.InitializeEssential(VLength, _metaElementType);
83  }
85 
87  template <typename TValue, unsigned int VLength>
88  void
89  SetInput(MET_ValueEnumType _metaElementType, const Vector<TValue, VLength> * _vector)
90  {
91  m_Buffer = (const void *)(_vector->GetDataPointer());
92  m_MetaArray.InitializeEssential(VLength, _metaElementType);
93  }
95 
97  template <typename TValue, unsigned int VLength>
98  void
99  SetInput(MET_ValueEnumType _metaElementType, const CovariantVector<TValue, VLength> * _vector)
100  {
101  m_Buffer = (const void *)(_vector->GetDataPointer());
102  m_MetaArray.InitializeEssential(VLength, _metaElementType);
103  }
105 
107  template <typename TValue>
108  void
109  SetInput(MET_ValueEnumType _metaElementType, const VariableLengthVector<TValue> * _vector)
110  {
111  m_Buffer = (const void *)(_vector->GetDataPointer());
112  m_MetaArray.InitializeEssential(_vector->Size(), _metaElementType);
113  }
115 
123  template <typename TValue>
124  void
125  SetMultiChannelInput(MET_ValueEnumType _metaElementType, int, const Array<TValue> * _array)
126  {
127  int rows = _array->GetSize();
128  int cols = (*_array)[0].GetSize();
130 
131  m_MetaArray.InitializeEssential(rows, _metaElementType, cols, nullptr, true, true);
132  m_Buffer = m_MetaArray.ElementData();
133  for (int i = 0; i < rows; i++)
134  {
135  for (int j = 0; j < cols; j++)
136  {
137  m_MetaArray.ElementData(i * cols + j, (double)((*_array)[i][j]));
138  }
139  }
140  }
141 
143  itkSetMacro(Precision, unsigned int);
144  itkGetConstMacro(Precision, unsigned int);
146 
148  void
149  ConvertTo(MET_ValueEnumType _metaElementType);
150 
152  void
153  Update();
154 
155 protected:
156  MetaArrayWriter();
157  ~MetaArrayWriter() override;
158  void
159  PrintSelf(std::ostream & os, Indent indent) const override;
160 
161 private:
162  bool m_Binary{ false };
163 
164  unsigned int m_Precision{ 6 };
165 
166  std::string m_FileName;
167  std::string m_DataFileName;
168 
169  MetaArray m_MetaArray;
170 
171  const void * m_Buffer{ nullptr };
172 };
173 } // namespace itk
174 
175 #endif // itkMetaArrayWriter_h
itk::VariableLengthVector::GetDataPointer
const TValue * GetDataPointer() const
Definition: itkVariableLengthVector.h:767
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
itkCovariantVector.h
itk::MetaArrayWriter::m_MetaArray
MetaArray m_MetaArray
Definition: itkMetaArrayWriter.h:169
itkLightProcessObject.h
itkVariableLengthVector.h
itk::MetaArrayWriter::SetInput
void SetInput(MET_ValueEnumType _metaElementType, const FixedArray< TValue, VLength > *_array)
Definition: itkMetaArrayWriter.h:79
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::MetaArrayWriter::m_DataFileName
std::string m_DataFileName
Definition: itkMetaArrayWriter.h:167
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::FixedArray::GetDataPointer
ValueType * GetDataPointer()
Definition: itkFixedArray.h:313
itk::MetaArrayWriter::SetInput
void SetInput(MET_ValueEnumType _metaElementType, const CovariantVector< TValue, VLength > *_vector)
Definition: itkMetaArrayWriter.h:99
itk::MetaArrayWriter::SetInput
void SetInput(MET_ValueEnumType _metaElementType, const Vector< TValue, VLength > *_vector)
Definition: itkMetaArrayWriter.h:89
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Array::GetSize
SizeValueType GetSize() const
Definition: itkArray.h:161
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:592
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itkArray.h
itk::MetaArrayWriter::SetMultiChannelInput
void SetMultiChannelInput(MET_ValueEnumType _metaElementType, int, const Array< TValue > *_array)
Definition: itkMetaArrayWriter.h:125
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::MetaArrayWriter
Definition: itkMetaArrayWriter.h:30
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::MetaArrayWriter::SetInput
void SetInput(MET_ValueEnumType _metaElementType, const Array< TValue > *_array)
Definition: itkMetaArrayWriter.h:69
itk::Array::Size
SizeValueType Size() const
Definition: itkArray.h:131
itk::MetaArrayWriter::m_FileName
std::string m_FileName
Definition: itkMetaArrayWriter.h:166
itk::MetaArrayWriter::SetInput
void SetInput(MET_ValueEnumType _metaElementType, const VariableLengthVector< TValue > *_vector)
Definition: itkMetaArrayWriter.h:109