ITK  4.4.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 
22 #include "itkMeshIOBase.h"
23 #include "itkNumberToString.h"
24 
25 #include <fstream>
26 
27 namespace itk
28 {
36 class ITK_EXPORT BYUMeshIO:public MeshIOBase
37 {
38 public:
40  typedef BYUMeshIO Self;
44 
47 
49  itkNewMacro(Self);
50 
52  itkTypeMacro(BYUMeshIO, MeshIOBase);
53 
54  /*-------- This part of the interfaces deals with reading data. ----- */
55 
61  virtual bool CanReadFile(const char *FileNameToRead);
62 
64  virtual void ReadMeshInformation();
65 
67  virtual void ReadPoints(void *buffer);
68 
69  virtual void ReadCells(void *buffer);
70 
71  virtual void ReadPointData(void *buffer);
72 
73  virtual void ReadCellData(void *buffer);
74 
75  /*-------- This part of the interfaces deals with writing data. ----- */
76 
82  virtual bool CanWriteFile(const char *FileNameToWrite);
83 
85  virtual void WriteMeshInformation();
86 
88  virtual void WritePoints(void *buffer);
89 
90  virtual void WriteCells(void *buffer);
91 
92  virtual void WritePointData(void *buffer);
93 
94  virtual void WriteCellData(void *buffer);
95 
96  virtual void Write();
97 
98 protected:
100  template< typename T >
101  void WritePoints(T *buffer, std::ofstream & outputFile)
102  {
103  NumberToString<T> convert;
104  Indent indent(1);
107 
108  for( SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
109  {
110  outputFile << indent;
111  for( unsigned int jj = 0; jj < this->m_PointDimension; jj++ )
112  {
113  outputFile << convert(buffer[index++]) << " ";
114  }
115  outputFile << '\n';
116  }
117  }
118 
119  template< typename T >
120  void WriteCells(T *buffer, std::ofstream & outputFile)
121  {
122  Indent indent(7);
124 
125  for( SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
126  {
127  unsigned int numberOfCellPoints = static_cast< unsigned int >( buffer[++index] );
128  index++;
129  for ( unsigned int jj = 0; jj < numberOfCellPoints - 1; jj++ )
130  {
131  outputFile << indent << buffer[index++] + 1;
132  }
133 
134  outputFile << indent << -static_cast<long long>( buffer[index++] + 1 ) << '\n';
135  }
136  }
137 
138 protected:
139  BYUMeshIO();
140  virtual ~BYUMeshIO(){}
141 
142  void PrintSelf(std::ostream & os, Indent indent) const;
143 
144 private:
145  BYUMeshIO(const Self &); // purposely not implemented
146  void operator=(const Self &); // purposely not implemented
147 
152 };
153 } // end namespace itk
154 
155 #endif
156