ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkFreeSurferAsciiMeshIO.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
19#ifndef itkFreeSurferAsciiMeshIO_h
20#define itkFreeSurferAsciiMeshIO_h
21#include "ITKIOMeshFreeSurferExport.h"
22
23#include "itkMeshIOBase.h"
25
26#include <fstream>
27#include "itkNumberToString.h"
28
29namespace itk
30{
37
38class ITKIOMeshFreeSurfer_EXPORT FreeSurferAsciiMeshIO : public MeshIOBase
39{
40public:
41 ITK_DISALLOW_COPY_AND_MOVE(FreeSurferAsciiMeshIO);
42
48
50
52 itkNewMacro(Self);
53
55 itkOverrideGetNameOfClassMacro(FreeSurferAsciiMeshIO);
56
57 /*-------- This part of the interfaces deals with reading data. ----- */
58
64 bool
65 CanReadFile(const char * fileName) override;
66
68 void
70
72 void
73 ReadPoints(void * buffer) override;
74
75 void
76 ReadCells(void * buffer) override;
77
78 void
79 ReadPointData(void * buffer) override;
80
81 void
82 ReadCellData(void * buffer) override;
83
84 /*-------- This part of the interfaces deals with writing data. ----- */
85
91 bool
92 CanWriteFile(const char * fileName) override;
93
95 void
97
100 void
101 WritePoints(void * buffer) override;
102
103 void
104 WriteCells(void * buffer) override;
105
106 void
107 WritePointData(void * buffer) override;
108
109 void
110 WriteCellData(void * buffer) override;
111
112 void
113 Write() override;
114
115protected:
117 template <typename T>
118 void
119 WritePoints(T * buffer, std::ofstream & outputFile, T label = T{})
120 {
121 SizeValueType index = 0;
122 for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
123 {
124 for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
125 {
126 outputFile << ConvertNumberToString(buffer[index++]) << " ";
127 }
128 outputFile << label << '\n';
129 }
130 }
131
133 template <typename T>
134 void
135 WriteCells(T * buffer, std::ofstream & outputFile, T label = T{})
136 {
137 constexpr unsigned int numberOfCellPoints{ 3 };
138 SizeValueType index = 0;
139
140 const auto data = make_unique_for_overwrite<T[]>(this->m_NumberOfCells * numberOfCellPoints);
141
142 ReadCellsBuffer(buffer, data.get());
143
144 for (SizeValueType ii = 0; ii < this->m_NumberOfCells; ++ii)
145 {
146 for (unsigned int jj = 0; jj < numberOfCellPoints; ++jj)
147 {
148 outputFile << data[index++] << " ";
149 }
150 outputFile << label << '\n';
151 }
152 }
153
155 template <typename TInput, typename TOutput>
156 void
157 ReadCellsBuffer(TInput * input, TOutput * output)
158 {
159 if (input && output)
160 {
161 for (SizeValueType ii = 0; ii < this->m_NumberOfCells; ++ii)
162 {
163 for (unsigned int jj = 0; jj < 3; ++jj)
164 {
165
168 output[ii * 3 + jj] = static_cast<TOutput>(input[5 * ii + jj + 2]);
169 }
170 }
171 }
172 }
173
174protected:
177 void
178 PrintSelf(std::ostream & os, Indent indent) const override;
179
180 void
182
183 void
185
186private:
187 std::ifstream m_InputFile{};
188};
189} // end namespace itk
190
191#endif
void ReadCells(void *buffer) override
void WriteMeshInformation() override
SmartPointer< const Self > ConstPointer
void ReadPoints(void *buffer) override
bool CanReadFile(const char *fileName) override
void WritePoints(T *buffer, std::ofstream &outputFile, T label=T{})
void ReadPointData(void *buffer) override
void WriteCells(void *buffer) override
void ReadCellsBuffer(TInput *input, TOutput *output)
bool CanWriteFile(const char *fileName) override
void PrintSelf(std::ostream &os, Indent indent) const override
void WritePoints(void *buffer) override
Superclass::SizeValueType SizeValueType
void WriteCellData(void *buffer) override
void WriteCells(T *buffer, std::ofstream &outputFile, T label=T{})
void WritePointData(void *buffer) override
void ReadCellData(void *buffer) override
void ReadMeshInformation() override
Control indentation during Print() invocation.
Definition itkIndent.h:51
IdentifierType SizeValueType
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
std::string ConvertNumberToString(const TValue val)