ITK  6.0.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 
28 namespace itk
29 {
38 class ITKIOMeshBYU_EXPORT BYUMeshIO : public MeshIOBase
39 {
40 public:
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
70  ReadMeshInformation() override;
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
97  WriteMeshInformation() override;
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 
115 protected:
117  template <typename T>
118  void
119  WritePoints(T * buffer, std::ofstream & outputFile)
120  {
121  const 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  const 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 
156 protected:
157  BYUMeshIO();
158  ~BYUMeshIO() override;
159 
160  void
161  PrintSelf(std::ostream & os, Indent indent) const override;
162 
163 private:
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
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:89
itk::BYUMeshIO
This class defines how to read and write BYU Geometry File Format.
Definition: itkBYUMeshIO.h:38
itk::MeshIOBase
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:72
itk::SmartPointer< const Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkNumberToString.h
itk::BYUMeshIO::WriteCells
void WriteCells(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:138
itk::BYUMeshIO::WritePoints
void WritePoints(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:119
itk::ConvertNumberToString
std::string ConvertNumberToString(const TValue val)
Definition: itkNumberToString.h:83
itkMeshIOBase.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::MeshIOBase::StreamOffsetType
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:87