ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGiftiMeshIO.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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_ASSIGN(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 SetDirection(const DirectionType & direction);
69 
70  itkGetConstReferenceMacro(Direction, DirectionType);
71 
72  LabelColorContainerPointer GetLabelColorTable();
73  LabelNameContainerPointer GetLabelNameTable();
74  void SetLabelColorTable(const LabelColorContainer * colorMap);
75  void SetLabelNameTable(const LabelNameContainer * labelMap);
76 
77  /*-------- This part of the interfaces deals with reading data. ----- */
78 
84  bool CanReadFile(const char *FileNameToRead) override;
85 
87  void ReadMeshInformation() override;
88 
90  void ReadPoints(void *buffer) override;
91 
92  void ReadCells(void *buffer) override;
93 
94  void ReadPointData(void *buffer) override;
95 
96  void ReadCellData(void *buffer) override;
97 
98  /*-------- This part of the interfaces deals with writing data. ----- */
99 
105  bool CanWriteFile(const char *FileNameToWrite) override;
106 
108  void WriteMeshInformation() override;
109 
112  void WritePoints(void *buffer) override;
113 
114  void WriteCells(void *buffer) override;
115 
116  void WritePointData(void *buffer) override;
117 
118  void WriteCellData(void *buffer) override;
119 
120  void Write() override;
121 
122 protected:
123  GiftiMeshIO();
124  ~GiftiMeshIO() override;
125 
126  void PrintSelf(std::ostream & os, Indent indent) const override;
127 
128  template< typename TInput, typename TOutput >
129  void ConvertBuffer(TInput *input, TOutput *output, SizeValueType numberOfElements)
130  {
131  if ( input && output )
132  {
133  for ( SizeValueType ii = 0; ii < numberOfElements; ii++ )
134  {
135  output[ii] = static_cast< TOutput >( input[ii] );
136  }
137  }
138  }
139 
140 private:
141  //This proxy class provides a gifti_image pointer interface to the internal implementation
142  //of itk::GiftiImageIO, while hiding the gifticlib interface from the external ITK interface.
143  class GiftiImageProxy;
144 
145  //Note that it is essential that m_GiftiImageHolder is defined before m_GiftiImage, to ensure that
146  //m_GiftiImage can directly get a proxy from m_GiftiImageHolder during GiftiImageIO construction.
147  const std::unique_ptr<GiftiImageProxy> m_GiftiImageHolder;
148 
149  GiftiImageProxy& m_GiftiImage;
150 
153 };
154 } // end namespace itk
155 
156 #endif
Light weight base class for most itk classes.
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:86
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
unsigned long SizeValueType
Definition: itkIntTypes.h:83
A wrapper of the STL &quot;map&quot; container.
void ConvertBuffer(TInput *input, TOutput *output, SizeValueType numberOfElements)
This class defines how to read and write Gifti file format.
DirectionType m_Direction
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:69
Base class for most ITK classes.
Definition: itkObject.h:60
const std::unique_ptr< GiftiImageProxy > m_GiftiImageHolder
GiftiImageProxy & m_GiftiImage