ITK  6.0.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 
30 namespace itk
31 {
43 class ITKIOMeta_EXPORT MetaImageIO : public ImageIOBase
44 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(MetaImageIO);
47 
49  using Self = MetaImageIO;
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
79  ReadImageInformation() override;
80 
82  void
83  Read(void * buffer) override;
84 
85  MetaImage *
86  GetMetaImagePointer();
87 
88  /*-------- This part of the interfaces deals with writing data. ----- */
89 
92  bool
93  CanWriteFile(const char *) override;
94 
96  void
97  WriteImageInformation() override;
98 
101  void
102  Write(const void * buffer) override;
103 
107  virtual void
108  SetDataFileName(const char * filename);
109 
112  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
186  GetDefaultDoublePrecision();
189 protected:
190  MetaImageIO();
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,
197  const MetaDataDictionary & metaDict,
198  const std::string & metaString) const;
199 
200 private:
202  itkGetGlobalDeclarationMacro(unsigned int, DefaultDoublePrecision);
203 
204  MetaImage m_MetaImage{};
205 
206  unsigned int m_SubSamplingFactor{};
207 
208  static unsigned int * m_DefaultDoublePrecision;
209 };
210 
211 template <unsigned int VNRows, unsigned int VNColumns>
212 bool
213 MetaImageIO::WriteMatrixInMetaData(std::ostringstream & strs,
214  const MetaDataDictionary & metaDict,
215  const std::string & metaString) const
216 {
218  if (ExposeMetaData<itk::Matrix<double, VNRows, VNColumns>>(metaDict, metaString, mval))
219  {
220  for (unsigned int i = 0; i < VNRows; ++i)
221  {
222  for (unsigned int j = 0; j < VNColumns; ++j)
223  {
224  strs << mval[i][j];
225  if (i != VNRows - 1 || j != VNColumns - 1)
226  {
227  strs << ' ';
228  }
229  }
230  }
231  return true;
232  }
233  return false;
234 }
235 
236 } // end namespace itk
237 
238 #endif // itkMetaImageIO_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:77
itk::MetaImageIO::m_DefaultDoublePrecision
static unsigned int * m_DefaultDoublePrecision
Definition: itkMetaImageIO.h:208
itk::MetaImageIO::SetDoublePrecision
void SetDoublePrecision(unsigned int precision)
Definition: itkMetaImageIO.h:113
itk::MetaImageIO::SupportsDimension
bool SupportsDimension(unsigned long) override
Definition: itkMetaImageIO.h:65
itkSingletonMacro.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::MetaImageIO::WriteMatrixInMetaData
bool WriteMatrixInMetaData(std::ostringstream &strs, const MetaDataDictionary &metaDict, const std::string &metaString) const
Definition: itkMetaImageIO.h:213
itk::ImageIORegion
An ImageIORegion represents a structured region of data.
Definition: itkImageIORegion.h:52
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:54
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MetaImageIO::CanStreamWrite
bool CanStreamWrite() override
Definition: itkMetaImageIO.h:156
itk::ExposeMetaData
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
Definition: itkMetaDataObject.h:244
itk::MetaImageIO
Read MetaImage file format.
Definition: itkMetaImageIO.h:43
itkImageIOBase.h
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:52
itkMetaDataObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:34
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::MetaImageIO::CanStreamRead
bool CanStreamRead() override
Definition: itkMetaImageIO.h:140