ITK  4.6.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 "ITKIOMeshExport.h"
22 
23 #include "itkMeshIOBase.h"
24 #include "itkNumberToString.h"
25 
26 #include <fstream>
27 
28 namespace itk
29 {
37 class ITKIOMesh_EXPORT BYUMeshIO:public MeshIOBase
38 {
39 public:
41  typedef BYUMeshIO Self;
45 
48 
50  itkNewMacro(Self);
51 
53  itkTypeMacro(BYUMeshIO, MeshIOBase);
54 
55  /*-------- This part of the interfaces deals with reading data. ----- */
56 
62  virtual bool CanReadFile(const char *FileNameToRead) ITK_OVERRIDE;
63 
65  virtual void ReadMeshInformation() ITK_OVERRIDE;
66 
68  virtual void ReadPoints(void *buffer) ITK_OVERRIDE;
69 
70  virtual void ReadCells(void *buffer) ITK_OVERRIDE;
71 
72  virtual void ReadPointData(void *buffer) ITK_OVERRIDE;
73 
74  virtual void ReadCellData(void *buffer) ITK_OVERRIDE;
75 
76  /*-------- This part of the interfaces deals with writing data. ----- */
77 
83  virtual bool CanWriteFile(const char *FileNameToWrite) ITK_OVERRIDE;
84 
86  virtual void WriteMeshInformation() ITK_OVERRIDE;
87 
89  virtual void WritePoints(void *buffer) ITK_OVERRIDE;
90 
91  virtual void WriteCells(void *buffer) ITK_OVERRIDE;
92 
93  virtual void WritePointData(void *buffer) ITK_OVERRIDE;
94 
95  virtual void WriteCellData(void *buffer) ITK_OVERRIDE;
96 
97  virtual void Write() ITK_OVERRIDE;
98 
99 protected:
101  template< typename T >
102  void WritePoints(T *buffer, std::ofstream & outputFile)
103  {
104  NumberToString<T> convert;
105  Indent indent(1);
108 
109  for( SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
110  {
111  outputFile << indent;
112  for( unsigned int jj = 0; jj < this->m_PointDimension; jj++ )
113  {
114  outputFile << convert(buffer[index++]) << " ";
115  }
116  outputFile << '\n';
117  }
118  }
119 
120  template< typename T >
121  void WriteCells(T *buffer, std::ofstream & outputFile)
122  {
123  Indent indent(7);
125 
126  for( SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
127  {
128  unsigned int numberOfCellPoints = static_cast< unsigned int >( buffer[++index] );
129  index++;
130  for ( unsigned int jj = 0; jj < numberOfCellPoints - 1; jj++ )
131  {
132  outputFile << indent << buffer[index++] + 1;
133  }
134 
135  outputFile << indent << -static_cast<long long>( buffer[index++] + 1 ) << '\n';
136  }
137  }
138 
139 protected:
140  BYUMeshIO();
141  virtual ~BYUMeshIO(){}
142 
143  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
144 
145 private:
146  BYUMeshIO(const Self &); // purposely not implemented
147  void operator=(const Self &); // purposely not implemented
148 
153 };
154 } // end namespace itk
155 
156 #endif
void WriteCells(T *buffer, std::ofstream &outputFile)
Definition: itkBYUMeshIO.h:121
Light weight base class for most itk classes.
SizeValueType m_LastCellId
Definition: itkBYUMeshIO.h:152
std::streamoff StreamOffsetType
Definition: itkMeshIOBase.h:82
Superclass::StreamOffsetType StreamOffsetType
Definition: itkBYUMeshIO.h:46
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:84
MeshIOBase Superclass
Definition: itkBYUMeshIO.h:42
Convert floating and fixed point numbers to strings.
SmartPointer< Self > Pointer
Definition: itkBYUMeshIO.h:44
SizeValueType m_PartId
Definition: itkBYUMeshIO.h:150
Superclass::SizeValueType SizeValueType
Definition: itkBYUMeshIO.h:47
SizeValueType m_FirstCellId
Definition: itkBYUMeshIO.h:151
BYUMeshIO Self
Definition: itkBYUMeshIO.h:41
SmartPointer< const Self > ConstPointer
Definition: itkBYUMeshIO.h:43
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:69
StreamOffsetType m_FilePosition
Definition: itkBYUMeshIO.h:149
Define additional traits for native types such as int or float.
This class defines how to read and write BYU Geometry File Format.
Definition: itkBYUMeshIO.h:37
virtual ~BYUMeshIO()
Definition: itkBYUMeshIO.h:141