ITK  4.2.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:
49 
51  MeshFileReaderException(const char *file, unsigned int line,
52  const char *message = "Error in IO",
53  const char *loc = "Unknown"):
54  ExceptionObject(file, line, message, loc)
55  {}
56 
58  MeshFileReaderException(const std::string & file, unsigned int line,
59  const char *message = "Error in IO",
60  const char *loc = "Unknown"):
61  ExceptionObject(file, line, message, loc)
62  {}
63 };
65 
97 template< class TOutputMesh,
98  class ConvertPointPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::PixelType >,
99  class ConvertCellPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::CellPixelType > >
100 class ITK_EXPORT MeshFileReader:public MeshSource< TOutputMesh >
101 {
102 public:
108 
110  itkNewMacro(Self);
111 
113  itkTypeMacro(MeshFileReader, MeshSource);
114 
116  typedef TOutputMesh OutputMeshType;
117  typedef typename OutputMeshType::CoordRepType OutputCoordRepType;
118  typedef typename OutputMeshType::PixelType OutputPointPixelType;
119  typedef typename OutputMeshType::CellPixelType OutputCellPixelType;
120  typedef typename OutputMeshType::PointType OutputPointType;
121  typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
122  typedef typename OutputMeshType::CellIdentifier OutputCellIdentifier;
123  typedef typename OutputMeshType::CellAutoPointer OutputCellAutoPointer;
124  typedef typename OutputMeshType::CellType OutputCellType;
126 
136 
138  itkStaticConstMacro(OutputPointDimension, unsigned int, OutputMeshType::PointDimension);
139 
141  itkSetStringMacro(FileName);
142  itkGetStringMacro(FileName);
144 
151  void SetMeshIO(MeshIOBase *meshIO);
152 
153  itkGetObjectMacro(MeshIO, MeshIOBase);
154 
157  virtual void GenerateOutputInformation();
158 
159  template< typename T >
160  void ReadPoints(T *buffer);
161 
162  template< typename T >
163  void ReadCells(T *buffer);
164 
165  void ReadPointData();
166 
167  void ReadCellData();
168 
169 protected:
170  MeshFileReader();
172  void PrintSelf(std::ostream & os, Indent indent) const;
173 
175  template< typename T >
176  void ConvertPointPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
177 
178  template< typename T >
179  void ConvertCellPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
180 
186  void TestFileExistanceAndReadability();
187 
189  virtual void GenerateData();
190 
192  bool m_UserSpecifiedMeshIO; // keep track whether the MeshIO is
193  // user specified
194  std::string m_FileName; // The file to be read
195 private:
196  MeshFileReader(const Self &); // purposely not implemented
197  void operator=(const Self &); // purposely not implemented
198 
199  std::string m_ExceptionMessage;
200 };
201 } // namespace ITK
202 
203 #ifndef ITK_MANUAL_INSTANTIATION
204 #include "itkMeshFileReader.hxx"
205 #endif
206 
207 #endif
208