ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMeshFileReader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMeshFileReader_h
00019 #define __itkMeshFileReader_h
00020 
00021 #include "itkMacro.h"
00022 #include "itkHexahedronCell.h"
00023 #include "itkLineCell.h"
00024 #include "itkMeshIOBase.h"
00025 #include "itkMeshSource.h"
00026 #include "itkPolygonCell.h"
00027 #include "itkQuadrilateralCell.h"
00028 #include "itkQuadraticEdgeCell.h"
00029 #include "itkQuadraticTriangleCell.h"
00030 #include "itkTetrahedronCell.h"
00031 #include "itkTriangleCell.h"
00032 #include "itkVertexCell.h"
00033 
00034 #include "itkDefaultConvertPixelTraits.h"
00035 #include "itkMeshConvertPixelTraits.h"
00036 
00037 namespace itk
00038 {
00044 class ITK_ABI_EXPORT MeshFileReaderException:public ExceptionObject
00045 {
00046 public:
00048   itkTypeMacro(MeshFileReaderException, ExceptionObject);
00049 
00051   MeshFileReaderException(const char *file, unsigned int line,
00052                           const char *message = "Error in IO",
00053                           const char *loc = "Unknown"):
00054     ExceptionObject(file, line, message, loc)
00055   {}
00056 
00058   MeshFileReaderException(const std::string & file, unsigned int line,
00059                           const char *message = "Error in IO",
00060                           const char *loc = "Unknown"):
00061     ExceptionObject(file, line, message, loc)
00062   {}
00063 };
00065 
00097 template< class TOutputMesh,
00098           class ConvertPointPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::PixelType >,
00099           class ConvertCellPixelTraits = MeshConvertPixelTraits< typename TOutputMesh::CellPixelType > >
00100 class ITK_EXPORT MeshFileReader:public MeshSource< TOutputMesh >
00101 {
00102 public:
00104   typedef MeshFileReader             Self;
00105   typedef MeshSource< TOutputMesh >  Superclass;
00106   typedef SmartPointer< const Self > ConstPointer;
00107   typedef SmartPointer< Self >       Pointer;
00108 
00110   itkNewMacro(Self);
00111 
00113   itkTypeMacro(MeshFileReader, MeshSource);
00114 
00116   typedef TOutputMesh                              OutputMeshType;
00117   typedef typename OutputMeshType::CoordRepType    OutputCoordRepType;
00118   typedef typename OutputMeshType::PixelType       OutputPointPixelType;
00119   typedef typename OutputMeshType::CellPixelType   OutputCellPixelType;
00120   typedef typename OutputMeshType::PointType       OutputPointType;
00121   typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
00122   typedef typename OutputMeshType::CellIdentifier  OutputCellIdentifier;
00123   typedef typename OutputMeshType::CellAutoPointer OutputCellAutoPointer;
00124   typedef typename OutputMeshType::CellType        OutputCellType;
00125   typedef typename MeshIOBase::SizeValueType       SizeValueType;
00126 
00127   typedef VertexCell< OutputCellType >            OutputVertexCellType;
00128   typedef LineCell< OutputCellType >              OutputLineCellType;
00129   typedef TriangleCell< OutputCellType >          OutputTriangleCellType;
00130   typedef PolygonCell< OutputCellType >           OutputPolygonCellType;
00131   typedef TetrahedronCell< OutputCellType >       OutputTetrahedronCellType;
00132   typedef HexahedronCell< OutputCellType >        OutputHexahedronCellType;
00133   typedef QuadrilateralCell< OutputCellType >     OutputQuadrilateralCellType;
00134   typedef QuadraticEdgeCell< OutputCellType >     OutputQuadraticEdgeCellType;
00135   typedef QuadraticTriangleCell< OutputCellType > OutputQuadraticTriangleCellType;
00136 
00138   itkStaticConstMacro(OutputPointDimension, unsigned int, OutputMeshType::PointDimension);
00139 
00141   itkSetStringMacro(FileName);
00142   itkGetStringMacro(FileName);
00144 
00151   void  SetMeshIO(MeshIOBase *meshIO);
00152 
00153   itkGetObjectMacro(MeshIO, MeshIOBase);
00154 
00157   virtual void GenerateOutputInformation();
00158 
00159   template< typename T >
00160   void ReadPoints(T *buffer);
00161 
00162   template< typename T >
00163   void ReadCells(T *buffer);
00164 
00165   void ReadPointData();
00166 
00167   void ReadCellData();
00168 
00169 protected:
00170   MeshFileReader();
00171   ~MeshFileReader(){}
00172   void PrintSelf(std::ostream & os, Indent indent) const;
00173 
00175   template< typename T >
00176   void ConvertPointPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
00177 
00178   template< typename T >
00179   void ConvertCellPixelBuffer(void *inputData, T *outputData, size_t numberOfPixels);
00180 
00186   void TestFileExistanceAndReadability();
00187 
00189   virtual void GenerateData();
00190 
00191   MeshIOBase::Pointer m_MeshIO;
00192   bool                m_UserSpecifiedMeshIO; // keep track whether the MeshIO is
00193                                              // user specified
00194   std::string m_FileName;                    // The file to be read
00195 private:
00196   MeshFileReader(const Self &); // purposely not implemented
00197   void operator=(const Self &); // purposely not implemented
00198 
00199   std::string m_ExceptionMessage;
00200 };
00201 } // namespace ITK
00202 
00203 #ifndef ITK_MANUAL_INSTANTIATION
00204 #include "itkMeshFileReader.hxx"
00205 #endif
00206 
00207 #endif
00208