ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkMeshFileReader.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 #ifndef __itkMeshFileReader_h
19 #define __itkMeshFileReader_h
20 
21 #include "itkMacro.h"
22 #include "itkHexahedronCell.h"
23 #include "itkLineCell.h"
24 #include "itkMeshIOBase.h"
25 #include "itkMeshSource.h"
26 #include "itkPolygonCell.h"
27 #include "itkQuadrilateralCell.h"
28 #include "itkQuadraticEdgeCell.h"
30 #include "itkTetrahedronCell.h"
31 #include "itkTriangleCell.h"
32 #include "itkVertexCell.h"
33 
36 
37 namespace itk
38 {
44 class ITK_ABI_EXPORT MeshFileReaderException:public ExceptionObject
45 {
46 public:
48  virtual ~MeshFileReaderException() throw() {};
49 
52 
54  MeshFileReaderException(const char *file, unsigned int line,
55  const char *message = "Error in IO",
56  const char *loc = "Unknown"):
57  ExceptionObject(file, line, message, loc)
58  {}
59 
61  MeshFileReaderException(const std::string & file, unsigned int line,
62  const char *message = "Error in IO",
63  const char *loc = "Unknown"):
64  ExceptionObject(file, line, message, loc)
65  {}
66 
67 };
68 
100 template< class TOutputMesh,
101  class ConvertPointPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::PixelType >,
102  class ConvertCellPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::CellPixelType > >
103 class ITK_EXPORT MeshFileReader:public MeshSource< TOutputMesh >
104 {
105 public:
111 
113  itkNewMacro(Self);
114 
116  itkTypeMacro(MeshFileReader, MeshSource);
117 
119  typedef TOutputMesh OutputMeshType;
120  typedef typename OutputMeshType::CoordRepType OutputCoordRepType;
121  typedef typename OutputMeshType::PixelType OutputPointPixelType;
122  typedef typename OutputMeshType::CellPixelType OutputCellPixelType;
123  typedef typename OutputMeshType::PointType OutputPointType;
124  typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
125  typedef typename OutputMeshType::CellIdentifier OutputCellIdentifier;
126  typedef typename OutputMeshType::CellAutoPointer OutputCellAutoPointer;
127  typedef typename OutputMeshType::CellType OutputCellType;
129 
139 
141  itkStaticConstMacro(OutputPointDimension, unsigned int, OutputMeshType::PointDimension);
142 
144  itkSetStringMacro(FileName);
145  itkGetStringMacro(FileName);
147 
154  void SetMeshIO(MeshIOBase *meshIO);
155 
156  itkGetObjectMacro(MeshIO, MeshIOBase);
157 
160  virtual void GenerateOutputInformation();
161 
162  template< typename T >
163  void ReadPoints(T *buffer);
164 
165  template< typename T >
166  void ReadCells(T *buffer);
167 
168  void ReadPointData();
169 
170  void ReadCellData();
171 
172 protected:
173  MeshFileReader();
175  void PrintSelf(std::ostream & os, Indent indent) const;
176 
178  template< typename T >
179  void ConvertPointPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
180 
181  template< typename T >
182  void ConvertCellPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
183 
189  void TestFileExistanceAndReadability();
190 
192  virtual void GenerateData();
193 
195  bool m_UserSpecifiedMeshIO; // keep track whether the MeshIO is
196  // user specified
197  std::string m_FileName; // The file to be read
198 
199 private:
200  MeshFileReader(const Self &); // purposely not implemented
201  void operator=(const Self &); // purposely not implemented
202 
203  std::string m_ExceptionMessage;
204 };
205 } // namespace ITK
206 
207 #ifndef ITK_MANUAL_INSTANTIATION
208 #include "itkMeshFileReader.hxx"
209 #endif
210 
211 #endif
212