ITK  6.0.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 * https://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
23#include "itkArray.h"
24#include "itkCovariantVector.h"
26#include "metaArray.h"
27
28namespace itk
29{
30class ITKIOMeta_EXPORT MetaArrayWriter : public LightProcessObject
31{
32public:
36
39
41 itkNewMacro(Self);
42
44 itkOverrideGetNameOfClassMacro(MetaArrayWriter);
45
47 itkSetStringMacro(FileName);
48 itkGetStringMacro(FileName);
53 itkSetStringMacro(DataFileName);
54 itkGetStringMacro(DataFileName);
61 itkBooleanMacro(Binary);
62 itkSetMacro(Binary, bool);
63 itkGetConstMacro(Binary, bool);
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 }
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 }
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 }
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 }
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 }
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();
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, static_cast<double>((*_array)[i][j]));
138 }
139 }
140 }
141
143 itkSetMacro(Precision, unsigned int);
144 itkGetConstMacro(Precision, unsigned int);
148 void
149 ConvertTo(MET_ValueEnumType _metaElementType);
150
152 void
154
155protected:
158 void
159 PrintSelf(std::ostream & os, Indent indent) const override;
160
161private:
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
Array class with size defined at construction time.
Definition: itkArray.h:48
SizeValueType Size() const
Definition: itkArray.h:128
SizeValueType GetSize() const
Definition: itkArray.h:158
A templated class holding a n-Dimensional covariant vector.
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
ValueType * GetDataPointer()
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
void PrintSelf(std::ostream &os, Indent indent) const override
void SetInput(MET_ValueEnumType _metaElementType, const VariableLengthVector< TValue > *_vector)
void SetInput(MET_ValueEnumType _metaElementType, const Array< TValue > *_array)
~MetaArrayWriter() override
void SetInput(MET_ValueEnumType _metaElementType, const FixedArray< TValue, VLength > *_array)
void SetInput(MET_ValueEnumType _metaElementType, const Vector< TValue, VLength > *_vector)
void SetInput(MET_ValueEnumType _metaElementType, const CovariantVector< TValue, VLength > *_vector)
void ConvertTo(MET_ValueEnumType _metaElementType)
void SetMultiChannelInput(MET_ValueEnumType _metaElementType, int, const Array< TValue > *_array)
Base class for most ITK classes.
Definition: itkObject.h:62
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....