ITK  4.2.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 
24 #include <fstream>
25 
26 namespace itk
27 {
35 class ITK_EXPORT BYUMeshIO:public MeshIOBase
36 {
37 public:
39  typedef BYUMeshIO Self;
43 
46 
48  itkNewMacro(Self);
49 
51  itkTypeMacro(BYUMeshIO, MeshIOBase);
52 
53  /*-------- This part of the interfaces deals with reading data. ----- */
54 
60  virtual bool CanReadFile(const char *FileNameToRead);
61 
63  virtual void ReadMeshInformation();
64 
66  virtual void ReadPoints(void *buffer);
67 
68  virtual void ReadCells(void *buffer);
69 
70  virtual void ReadPointData(void *buffer);
71 
72  virtual void ReadCellData(void *buffer);
73 
74  /*-------- This part of the interfaces deals with writing data. ----- */
75 
81  virtual bool CanWriteFile(const char *FileNameToWrite);
82 
84  virtual void WriteMeshInformation();
85 
87  virtual void WritePoints(void *buffer);
88 
89  virtual void WriteCells(void *buffer);
90 
91  virtual void WritePointData(void *buffer);
92 
93  virtual void WriteCellData(void *buffer);
94 
95  virtual void Write();
96 
97 protected:
99  template< typename T >
100  void WritePoints(T *buffer, std::ofstream & outputFile)
101  {
102  Indent indent(1);
105 
106  for( SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
107  {
108  outputFile << indent;
109  for( unsigned int jj = 0; jj < this->m_PointDimension; jj++ )
110  {
111  outputFile << std::scientific << buffer[index++] << " ";
112  }
113  outputFile << '\n';
114  }
115  }
116 
117  template< typename T >
118  void WriteCells(T *buffer, std::ofstream & outputFile)
119  {
120  Indent indent(7);
122 
123  for( SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
124  {
125  unsigned int numberOfCellPoints = static_cast< unsigned int >( buffer[++index] );
126  index++;
127  for ( unsigned int jj = 0; jj < numberOfCellPoints - 1; jj++ )
128  {
129  outputFile << indent << buffer[index++] + 1;
130  }
131 
132  outputFile << indent << -static_cast<long long>( buffer[index++] + 1 ) << '\n';
133  }
134  }
135 
136 protected:
137  BYUMeshIO();
138  virtual ~BYUMeshIO(){}
139 
140  void PrintSelf(std::ostream & os, Indent indent) const;
141 
142 private:
143  BYUMeshIO(const Self &); // purposely not implemented
144  void operator=(const Self &); // purposely not implemented
145 
150 };
151 } // end namespace itk
152 
153 #endif
154