ITK  5.3.0
Insight Toolkit
itkGiftiMeshIO.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 itkGiftiMeshIO_h
19 #define itkGiftiMeshIO_h
20 #include "ITKIOMeshGiftiExport.h"
21 
22 #include <memory>
23 #include "itkMapContainer.h"
24 #include "itkMatrix.h"
25 #include "itkMeshIOBase.h"
26 #include "itkRGBAPixel.h"
27 
28 #include <fstream>
29 #include <string>
30 
31 namespace itk
32 {
39 class ITKIOMeshGifti_EXPORT GiftiMeshIO : public MeshIOBase
40 {
41 public:
42  ITK_DISALLOW_COPY_AND_MOVE(GiftiMeshIO);
43 
45  using Self = GiftiMeshIO;
49 
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(GiftiMeshIO, MeshIOBase);
63 
64  itkGetConstMacro(ReadPointData, bool);
65  itkSetMacro(ReadPointData, bool);
66  itkBooleanMacro(ReadPointData);
67 
68  void
69  SetDirection(const DirectionType & direction);
70 
71  itkGetConstReferenceMacro(Direction, DirectionType);
72 
74  GetLabelColorTable();
76  GetLabelNameTable();
77  void
78  SetLabelColorTable(const LabelColorContainer * colorMap);
79  void
80  SetLabelNameTable(const LabelNameContainer * labelMap);
81 
82  /*-------- This part of the interfaces deals with reading data. ----- */
83 
89  bool
90  CanReadFile(const char * fileName) override;
91 
93  void
94  ReadMeshInformation() override;
95 
97  void
98  ReadPoints(void * buffer) override;
99 
100  void
101  ReadCells(void * buffer) override;
102 
103  void
104  ReadPointData(void * buffer) override;
105 
106  void
107  ReadCellData(void * buffer) override;
108 
109  /*-------- This part of the interfaces deals with writing data. ----- */
110 
116  bool
117  CanWriteFile(const char * fileName) override;
118 
120  void
121  WriteMeshInformation() override;
122 
125  void
126  WritePoints(void * buffer) override;
127 
128  void
129  WriteCells(void * buffer) override;
130 
131  void
132  WritePointData(void * buffer) override;
133 
134  void
135  WriteCellData(void * buffer) override;
136 
137  void
138  Write() override;
139 
140 protected:
141  GiftiMeshIO();
142  ~GiftiMeshIO() override;
143 
144  void
145  PrintSelf(std::ostream & os, Indent indent) const override;
146 
147  template <typename TInput, typename TOutput>
148  void
149  ConvertBuffer(TInput * input, TOutput * output, SizeValueType numberOfElements)
150  {
151  if (input && output)
152  {
153  for (SizeValueType ii = 0; ii < numberOfElements; ii++)
154  {
155  output[ii] = static_cast<TOutput>(input[ii]);
156  }
157  }
158  }
159 
160 private:
161  // This proxy class provides a gifti_image pointer interface to the internal implementation
162  // of itk::GiftiImageIO, while hiding the gifticlib interface from the external ITK interface.
163  class GiftiImageProxy;
164 
165  // Note that it is essential that m_GiftiImageHolder is defined before m_GiftiImage, to ensure that
166  // m_GiftiImage can directly get a proxy from m_GiftiImageHolder during GiftiImageIO construction.
167  const std::unique_ptr<GiftiImageProxy> m_GiftiImageHolder;
168 
169  GiftiImageProxy & m_GiftiImage;
170 
173 
174  // Translate (G|N)ifti datatypes to IOComponentEnum
176  GetComponentTypeFromGifti(int datatype);
177 
178  // Translate (G|N)ifti datatypes to IOPixelEnum
180  GetPixelTypeFromGifti(int datatype);
181 
182  int
183  GetNumberOfPixelComponentsFromGifti(int datatype);
184 };
185 } // end namespace itk
186 
187 #endif
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:88
itkMatrix.h
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:71
itk::GiftiMeshIO::m_GiftiImage
GiftiImageProxy & m_GiftiImage
Definition: itkGiftiMeshIO.h:169
itkRGBAPixel.h
itk::SmartPointer< const Self >
itk::CommonEnums::IOComponent
IOComponent
Definition: itkCommonEnums.h:76
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CommonEnums::IOPixel
IOPixel
Definition: itkCommonEnums.h:49
itk::MapContainer
A wrapper of the STL "map" container.
Definition: itkMapContainer.h:45
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GiftiMeshIO
This class defines how to read and write Gifti file format.
Definition: itkGiftiMeshIO.h:39
itk::Matrix< double, 4, 4 >
itkMeshIOBase.h
itk::RGBAPixel
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::GiftiMeshIO::m_GiftiImageHolder
const std::unique_ptr< GiftiImageProxy > m_GiftiImageHolder
Definition: itkGiftiMeshIO.h:163
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::GiftiMeshIO::m_ReadPointData
bool m_ReadPointData
Definition: itkGiftiMeshIO.h:171
itk::GiftiMeshIO::m_Direction
DirectionType m_Direction
Definition: itkGiftiMeshIO.h:172
itk::GiftiMeshIO::ConvertBuffer
void ConvertBuffer(TInput *input, TOutput *output, SizeValueType numberOfElements)
Definition: itkGiftiMeshIO.h:149
itkMapContainer.h
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
fileName
std::string fileName
Definition: itkTestDriverInclude.h:118