ITK  5.4.0
Insight Toolkit
itkMetaImageIO.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 itkMetaImageIO_h
19#define itkMetaImageIO_h
20#include "ITKIOMetaExport.h"
21
22
23#include <fstream>
24#include "itkImageIOBase.h"
25#include "itkSingletonMacro.h"
26#include "itkMetaDataObject.h"
27#include "metaObject.h"
28#include "metaImage.h"
29
30namespace itk
31{
43class ITKIOMeta_EXPORT MetaImageIO : public ImageIOBase
44{
45public:
46 ITK_DISALLOW_COPY_AND_MOVE(MetaImageIO);
47
52
54 itkNewMacro(Self);
55
57 itkOverrideGetNameOfClassMacro(MetaImageIO);
58
64 bool
65 SupportsDimension(unsigned long) override
66 {
67 return true;
68 }
69
70 /*-------- This part of the interfaces deals with reading data. ----- */
71
74 bool
75 CanReadFile(const char *) override;
76
78 void
80
82 void
83 Read(void * buffer) override;
84
85 MetaImage *
87
88 /*-------- This part of the interfaces deals with writing data. ----- */
89
92 bool
93 CanWriteFile(const char *) override;
94
96 void
98
101 void
102 Write(const void * buffer) override;
103
107 virtual void
108 SetDataFileName(const char * filename);
109
112 virtual void
113 SetDoublePrecision(unsigned int precision)
114 {
115 m_MetaImage.SetDoublePrecision(precision);
116 }
117
123 GenerateStreamableReadRegionFromRequestedRegion(const ImageIORegion & requestedRegion) const override;
124
125 unsigned int
126 GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits,
127 const ImageIORegion & pasteRegion,
128 const ImageIORegion & largestPossibleRegion) override;
129
131 GetSplitRegionForWriting(unsigned int ithPiece,
132 unsigned int numberOfActualSplits,
133 const ImageIORegion & pasteRegion,
134 const ImageIORegion & largestPossibleRegion) override;
135
139 bool
140 CanStreamRead() override
141 {
142 if (m_MetaImage.CompressedData())
143 {
144 return false;
145 }
146 return true;
147 }
155 bool
156 CanStreamWrite() override
157 {
158 if (this->GetUseCompression())
159 {
160 return false;
161 }
162 return true;
163 }
169 itkSetMacro(SubSamplingFactor, unsigned int);
170 itkGetConstMacro(SubSamplingFactor, unsigned int);
183 static void
184 SetDefaultDoublePrecision(unsigned int precision);
185 static unsigned int
189protected:
191 ~MetaImageIO() override;
192 void
193 PrintSelf(std::ostream & os, Indent indent) const override;
194 template <unsigned int VNRows, unsigned int VNColumns = VNRows>
195 bool
196 WriteMatrixInMetaData(std::ostringstream & strs, const MetaDataDictionary & metaDict, const std::string & metaString);
197
198private:
200 itkGetGlobalDeclarationMacro(unsigned int, DefaultDoublePrecision);
201
202 MetaImage m_MetaImage{};
203
204 unsigned int m_SubSamplingFactor{};
205
206 static unsigned int * m_DefaultDoublePrecision;
207};
208
209template <unsigned int VNRows, unsigned int VNColumns>
210bool
211MetaImageIO::WriteMatrixInMetaData(std::ostringstream & strs,
212 const MetaDataDictionary & metaDict,
213 const std::string & metaString)
214{
216 if (ExposeMetaData<itk::Matrix<double, VNRows, VNColumns>>(metaDict, metaString, mval))
217 {
218 for (unsigned int i = 0; i < VNRows; ++i)
219 {
220 for (unsigned int j = 0; j < VNColumns; ++j)
221 {
222 strs << mval[i][j];
223 if (i != VNRows - 1 || j != VNColumns - 1)
224 {
225 strs << ' ';
226 }
227 }
228 }
229 return true;
230 }
231 return false;
232}
233
234} // end namespace itk
235
236#endif // itkMetaImageIO_h
Abstract superclass defines image IO interface.
An ImageIORegion represents a structured region of data.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:53
Provides a mechanism for storing a collection of arbitrary data types.
Read MetaImage file format.
itkGetGlobalDeclarationMacro(unsigned int, DefaultDoublePrecision)
~MetaImageIO() override
void PrintSelf(std::ostream &os, Indent indent) const override
static unsigned int GetDefaultDoublePrecision()
bool CanWriteFile(const char *) override
ImageIORegion GetSplitRegionForWriting(unsigned int ithPiece, unsigned int numberOfActualSplits, const ImageIORegion &pasteRegion, const ImageIORegion &largestPossibleRegion) override
void Write(const void *buffer) override
static unsigned int * m_DefaultDoublePrecision
ImageIORegion GenerateStreamableReadRegionFromRequestedRegion(const ImageIORegion &requestedRegion) const override
void WriteImageInformation() override
bool WriteMatrixInMetaData(std::ostringstream &strs, const MetaDataDictionary &metaDict, const std::string &metaString)
bool CanStreamWrite() override
bool SupportsDimension(unsigned long) override
virtual void SetDoublePrecision(unsigned int precision)
unsigned int GetActualNumberOfSplitsForWriting(unsigned int numberOfRequestedSplits, const ImageIORegion &pasteRegion, const ImageIORegion &largestPossibleRegion) override
MetaImage * GetMetaImagePointer()
void ReadImageInformation() override
virtual void SetDataFileName(const char *filename)
void Read(void *buffer) override
bool CanReadFile(const char *) override
bool CanStreamRead() override
static void SetDefaultDoublePrecision(unsigned int precision)
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)