ITK  5.4.0
Insight Toolkit
itkBYUMeshIO.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 itkBYUMeshIO_h
20#define itkBYUMeshIO_h
21#include "ITKIOMeshBYUExport.h"
22
23#include "itkMeshIOBase.h"
24#include "itkNumberToString.h"
25
26#include <fstream>
27
28namespace itk
29{
38class ITKIOMeshBYU_EXPORT BYUMeshIO : public MeshIOBase
39{
40public:
41 ITK_DISALLOW_COPY_AND_MOVE(BYUMeshIO);
42
44 using Self = BYUMeshIO;
48
51
53 itkNewMacro(Self);
54
56 itkOverrideGetNameOfClassMacro(BYUMeshIO);
57
58 /*-------- This part of the interfaces deals with reading data. ----- */
59
65 bool
66 CanReadFile(const char * fileName) override;
67
69 void
71
73 void
74 ReadPoints(void * buffer) override;
75
76 void
77 ReadCells(void * buffer) override;
78
79 void
80 ReadPointData(void * buffer) override;
81
82 void
83 ReadCellData(void * buffer) override;
84
85 /*-------- This part of the interfaces deals with writing data. ----- */
86
92 bool
93 CanWriteFile(const char * fileName) override;
94
96 void
98
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)
120 {
121 Indent indent(1);
122 SizeValueType index{};
125 for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
126 {
127 outputFile << indent;
128 for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
129 {
130 outputFile << ConvertNumberToString(buffer[index++]) << ' ';
131 }
132 outputFile << '\n';
133 }
134 }
135
136 template <typename T>
137 void
138 WriteCells(T * buffer, std::ofstream & outputFile)
139 {
140 Indent indent(7);
141 SizeValueType index{};
142
143 for (SizeValueType ii = 0; ii < this->m_NumberOfCells; ++ii)
144 {
145 auto numberOfCellPoints = static_cast<unsigned int>(buffer[++index]);
146 ++index;
147 for (unsigned int jj = 0; jj < numberOfCellPoints - 1; ++jj)
148 {
149 outputFile << indent << buffer[index++] + 1;
150 }
151
152 outputFile << indent << -static_cast<long long>(buffer[index++] + 1) << '\n';
153 }
154 }
155
156protected:
158 ~BYUMeshIO() override;
159
160 void
161 PrintSelf(std::ostream & os, Indent indent) const override;
162
163private:
164 StreamOffsetType m_FilePosition{ 0 };
165 SizeValueType m_PartId{};
166 SizeValueType m_FirstCellId{};
167 SizeValueType m_LastCellId{};
168};
169} // end namespace itk
170
171#endif
This class defines how to read and write BYU Geometry File Format.
Definition: itkBYUMeshIO.h:39
void WritePointData(void *buffer) override
bool CanReadFile(const char *fileName) override
void WritePoints(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:119
void WriteCells(void *buffer) override
bool CanWriteFile(const char *fileName) override
void WriteMeshInformation() override
void ReadCellData(void *buffer) override
void WriteCells(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:138
void Write() override
void ReadPoints(void *buffer) override
void WritePoints(void *buffer) override
void ReadCells(void *buffer) override
void ReadMeshInformation() override
void WriteCellData(void *buffer) override
~BYUMeshIO() override
void PrintSelf(std::ostream &os, Indent indent) const override
void ReadPointData(void *buffer) override
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:73
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:87
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
std::string ConvertNumberToString(const TValue val)
unsigned long SizeValueType
Definition: itkIntTypes.h:83