ITK  4.6.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 #include "ITKIOMeshExport.h"
21 
22 #include "itkMacro.h"
23 #include "itkHexahedronCell.h"
24 #include "itkLineCell.h"
25 #include "itkMeshIOBase.h"
26 #include "itkMeshSource.h"
27 #include "itkPolygonCell.h"
28 #include "itkQuadrilateralCell.h"
29 #include "itkQuadraticEdgeCell.h"
31 #include "itkTetrahedronCell.h"
32 #include "itkTriangleCell.h"
33 #include "itkVertexCell.h"
34 
37 
38 namespace itk
39 {
45 class ITKIOMesh_HIDDEN MeshFileReaderException:public ExceptionObject
46 {
47 public:
49  virtual ~MeshFileReaderException() throw() {};
50 
53 
55  MeshFileReaderException(const char *file, unsigned int line,
56  const char *message = "Error in IO",
57  const char *loc = "Unknown"):
58  ExceptionObject(file, line, message, loc)
59  {}
60 
62  MeshFileReaderException(const std::string & file, unsigned int line,
63  const char *message = "Error in IO",
64  const char *loc = "Unknown"):
65  ExceptionObject(file, line, message, loc)
66  {}
67 
68 };
69 
101 template< typename TOutputMesh,
102  typename ConvertPointPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::PixelType >,
103  class ConvertCellPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::CellPixelType > >
104 class ITKIOMesh_HIDDEN MeshFileReader:public MeshSource< TOutputMesh >
105 {
106 public:
112 
114  itkNewMacro(Self);
115 
117  itkTypeMacro(MeshFileReader, MeshSource);
118 
120  typedef TOutputMesh OutputMeshType;
121  typedef typename OutputMeshType::CoordRepType OutputCoordRepType;
122  typedef typename OutputMeshType::PixelType OutputPointPixelType;
123  typedef typename OutputMeshType::CellPixelType OutputCellPixelType;
124  typedef typename OutputMeshType::PointType OutputPointType;
125  typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
126  typedef typename OutputMeshType::CellIdentifier OutputCellIdentifier;
127  typedef typename OutputMeshType::CellAutoPointer OutputCellAutoPointer;
128  typedef typename OutputMeshType::CellType OutputCellType;
130 
140 
142  itkStaticConstMacro(OutputPointDimension, unsigned int, OutputMeshType::PointDimension);
143 
145  itkSetStringMacro(FileName);
146  itkGetStringMacro(FileName);
148 
155  void SetMeshIO(MeshIOBase *meshIO);
156  itkGetModifiableObjectMacro(MeshIO, MeshIOBase);
158 
161  virtual void GenerateOutputInformation();
162 
163  template< typename T >
164  void ReadPoints(T *buffer);
165 
166  template< typename T >
167  void ReadCells(T *buffer);
168 
169  void ReadPointData();
170 
171  void ReadCellData();
172 
173 protected:
174  MeshFileReader();
176  void PrintSelf(std::ostream & os, Indent indent) const;
177 
179  template< typename T >
180  void ConvertPointPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
181 
182  template< typename T >
183  void ConvertCellPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
184 
190  void TestFileExistanceAndReadability();
191 
193  virtual void GenerateData();
194 
196  bool m_UserSpecifiedMeshIO; // keep track whether the MeshIO is
197  // user specified
198  std::string m_FileName; // The file to be read
199 
200 private:
201  MeshFileReader(const Self &); // purposely not implemented
202  void operator=(const Self &); // purposely not implemented
203 
204  std::string m_ExceptionMessage;
205 };
206 } // namespace ITK
207 
208 #ifndef ITK_MANUAL_INSTANTIATION
209 #include "itkMeshFileReader.hxx"
210 #endif
211 
212 #endif
MeshIOBase::SizeValueType SizeValueType
MeshFileReaderException(const char *file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
Represents a line segment for a Mesh.
Definition: itkLineCell.h:42
Light weight base class for most itk classes.
OutputMeshType::CellIdentifier OutputCellIdentifier
TriangleCell< OutputCellType > OutputTriangleCellType
SmartPointer< const Self > ConstPointer
IdentifierType SizeValueType
Definition: itkMeshIOBase.h:84
OutputMeshType::CellPixelType OutputCellPixelType
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
MeshSource< TOutputMesh > Superclass
TetrahedronCell< OutputCellType > OutputTetrahedronCellType
std::string m_ExceptionMessage
QuadraticTriangleCell< OutputCellType > OutputQuadraticTriangleCellType
PolygonCell< OutputCellType > OutputPolygonCellType
Represents a second order triangular patch for a Mesh.
Represents a hexahedron for a Mesh.
OutputMeshType::CellAutoPointer OutputCellAutoPointer
Represents a second order line segment for a Mesh.
Standard exception handling object.
OutputMeshType::PointIdentifier OutputPointIdentifier
SmartPointer< Self > Pointer
OutputMeshType::PointType OutputPointType
QuadrilateralCell< OutputCellType > OutputQuadrilateralCellType
LineCell< OutputCellType > OutputLineCellType
VertexCell< OutputCellType > OutputVertexCellType
Represents a polygon in a Mesh.
TetrahedronCell represents a tetrahedron for a Mesh.
MeshFileReaderException(const std::string &file, unsigned int line, const char *message="Error in IO", const char *loc="Unknown")
OutputMeshType::PixelType OutputPointPixelType
MeshIOBase::Pointer m_MeshIO
OutputMeshType::CoordRepType OutputCoordRepType
Represents a single vertex for a Mesh.
Definition: itkVertexCell.h:39
QuadraticEdgeCell< OutputCellType > OutputQuadraticEdgeCellType
HexahedronCell< OutputCellType > OutputHexahedronCellType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract superclass defines mesh IO interface.
Definition: itkMeshIOBase.h:69
Represents a quadrilateral for a Mesh.
OutputMeshType::CellType OutputCellType
Mesh source that reads mesh data from a single file.
Base exception class for IO conflicts.