ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkBYUMeshIO.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 
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 {
37 class ITKIOMeshBYU_EXPORT BYUMeshIO:public MeshIOBase
38 {
39 public:
40  ITK_DISALLOW_COPY_AND_ASSIGN(BYUMeshIO);
41 
43  using Self = BYUMeshIO;
47 
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(BYUMeshIO, MeshIOBase);
56 
57  /*-------- This part of the interfaces deals with reading data. ----- */
58 
64  bool CanReadFile(const char *FileNameToRead) override;
65 
67  void ReadMeshInformation() override;
68 
70  void ReadPoints(void *buffer) override;
71 
72  void ReadCells(void *buffer) override;
73 
74  void ReadPointData(void *buffer) override;
75 
76  void ReadCellData(void *buffer) override;
77 
78  /*-------- This part of the interfaces deals with writing data. ----- */
79 
85  bool CanWriteFile(const char *FileNameToWrite) override;
86 
88  void WriteMeshInformation() override;
89 
91  void WritePoints(void *buffer) override;
92 
93  void WriteCells(void *buffer) override;
94 
95  void WritePointData(void *buffer) override;
96 
97  void WriteCellData(void *buffer) override;
98 
99  void Write() override;
100 
101 protected:
103  template< typename T >
104  void WritePoints(T *buffer, std::ofstream & outputFile)
105  {
106  NumberToString<T> convert;
107  Indent indent(1);
108  SizeValueType index = itk::NumericTraits< SizeValueType >::ZeroValue();
110 
111  for( SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
112  {
113  outputFile << indent;
114  for( unsigned int jj = 0; jj < this->m_PointDimension; jj++ )
115  {
116  outputFile << convert(buffer[index++]) << " ";
117  }
118  outputFile << '\n';
119  }
120  }
121 
122  template< typename T >
123  void WriteCells(T *buffer, std::ofstream & outputFile)
124  {
125  Indent indent(7);
126  SizeValueType index = itk::NumericTraits< SizeValueType >::ZeroValue();
127 
128  for( SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
129  {
130  auto numberOfCellPoints = static_cast< unsigned int >( buffer[++index] );
131  index++;
132  for ( unsigned int jj = 0; jj < numberOfCellPoints - 1; jj++ )
133  {
134  outputFile << indent << buffer[index++] + 1;
135  }
136 
137  outputFile << indent << -static_cast<long long>( buffer[index++] + 1 ) << '\n';
138  }
139  }
140 
141 protected:
142  BYUMeshIO();
143  ~BYUMeshIO() override;
144 
145  void PrintSelf(std::ostream & os, Indent indent) const override;
146 
147 private:
148  StreamOffsetType m_FilePosition{0};
152 };
153 } // end namespace itk
154 
155 #endif
void WriteCells(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:123
Light weight base class for most itk classes.
SizeValueType m_LastCellId
Definition: itkBYUMeshIO.h:151
void WritePoints(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:104
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:86
unsigned long SizeValueType
Definition: itkIntTypes.h:83
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:84
Convert floating and fixed point numbers to strings.
SizeValueType m_PartId
Definition: itkBYUMeshIO.h:149
SizeValueType m_FirstCellId
Definition: itkBYUMeshIO.h:150
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
This class defines how to read and write BYU Geometry File Format.
Definition: itkBYUMeshIO.h:37