ITK  5.3.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  * 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 
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  itkTypeMacro(BYUMeshIO, MeshIOBase);
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  NumberToString<T> convert;
122  Indent indent(1);
125 
126  for (SizeValueType ii = 0; ii < this->m_NumberOfPoints; ++ii)
127  {
128  outputFile << indent;
129  for (unsigned int jj = 0; jj < this->m_PointDimension; ++jj)
130  {
131  outputFile << convert(buffer[index++]) << " ";
132  }
133  outputFile << '\n';
134  }
135  }
136 
137  template <typename T>
138  void
139  WriteCells(T * buffer, std::ofstream & outputFile)
140  {
141  Indent indent(7);
143 
144  for (SizeValueType ii = 0; ii < this->m_NumberOfCells; ++ii)
145  {
146  auto numberOfCellPoints = static_cast<unsigned int>(buffer[++index]);
147  index++;
148  for (unsigned int jj = 0; jj < numberOfCellPoints - 1; ++jj)
149  {
150  outputFile << indent << buffer[index++] + 1;
151  }
152 
153  outputFile << indent << -static_cast<long long>(buffer[index++] + 1) << '\n';
154  }
155  }
156 
157 protected:
158  BYUMeshIO();
159  ~BYUMeshIO() override;
160 
161  void
162  PrintSelf(std::ostream & os, Indent indent) const override;
163 
164 private:
165  StreamOffsetType m_FilePosition{ 0 };
169 };
170 } // end namespace itk
171 
172 #endif
itk::NumberToString
Convert floating and fixed point numbers to strings.
Definition: itkNumberToString.h:42
itk::MeshIOBase::SizeValueType
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:88
itk::BYUMeshIO::m_FirstCellId
SizeValueType m_FirstCellId
Definition: itkBYUMeshIO.h:167
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:71
itk::SmartPointer< const Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::BYUMeshIO::m_PartId
SizeValueType m_PartId
Definition: itkBYUMeshIO.h:166
itk::BYUMeshIO::m_LastCellId
SizeValueType m_LastCellId
Definition: itkBYUMeshIO.h:168
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itkNumberToString.h
itk::BYUMeshIO::WriteCells
void WriteCells(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:139
itk::BYUMeshIO::WritePoints
void WritePoints(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:119
itkMeshIOBase.h
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::MeshIOBase::StreamOffsetType
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:86
fileName
std::string fileName
Definition: itkTestDriverInclude.h:118