ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkBYUMeshIO.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 
00019 #ifndef __itkBYUMeshIO_h
00020 #define __itkBYUMeshIO_h
00021 
00022 #include "itkMeshIOBase.h"
00023 
00024 #include <fstream>
00025 
00026 namespace itk
00027 {
00035 class ITK_EXPORT BYUMeshIO:public MeshIOBase
00036 {
00037 public:
00039   typedef BYUMeshIO                  Self;
00040   typedef MeshIOBase                 Superclass;
00041   typedef SmartPointer< const Self > ConstPointer;
00042   typedef SmartPointer< Self >       Pointer;
00043 
00044   typedef Superclass::StreamOffsetType StreamOffsetType;
00045   typedef Superclass::SizeValueType    SizeValueType;
00046 
00048   itkNewMacro(Self);
00049 
00051   itkTypeMacro(BYUMeshIO, MeshIOBase);
00052 
00053   /*-------- This part of the interfaces deals with reading data. ----- */
00054 
00060   virtual bool CanReadFile(const char *FileNameToRead);
00061 
00063   virtual void ReadMeshInformation();
00064 
00066   virtual void ReadPoints(void *buffer);
00067 
00068   virtual void ReadCells(void *buffer);
00069 
00070   virtual void ReadPointData(void *buffer);
00071 
00072   virtual void ReadCellData(void *buffer);
00073 
00074   /*-------- This part of the interfaces deals with writing data. ----- */
00075 
00081   virtual bool CanWriteFile(const char *FileNameToWrite);
00082 
00084   virtual void WriteMeshInformation();
00085 
00087   virtual void WritePoints(void *buffer);
00088 
00089   virtual void WriteCells(void *buffer);
00090 
00091   virtual void WritePointData(void *buffer);
00092 
00093   virtual void WriteCellData(void *buffer);
00094 
00095   virtual void Write();
00096 
00097 protected:
00099   template< typename T >
00100   void WritePoints(T *buffer, std::ofstream & outputFile)
00101     {
00102     Indent indent(1);
00103     SizeValueType index = itk::NumericTraits< SizeValueType >::Zero;
00105 
00106     for( SizeValueType ii = 0; ii < this->m_NumberOfPoints; ii++ )
00107       {
00108       outputFile << indent;
00109       for( unsigned int jj = 0; jj < this->m_PointDimension; jj++ )
00110         {
00111         outputFile << std::scientific << buffer[index++] << " ";
00112         }
00113       outputFile << '\n';
00114       }
00115     }
00116 
00117   template< typename T >
00118   void WriteCells(T *buffer, std::ofstream & outputFile)
00119     {
00120     Indent        indent(7);
00121     SizeValueType index = itk::NumericTraits< SizeValueType >::Zero;
00122 
00123     for( SizeValueType ii = 0; ii < this->m_NumberOfCells; ii++ )
00124       {
00125       unsigned int numberOfCellPoints = static_cast< unsigned int >( buffer[++index] );
00126       index++;
00127       for ( unsigned int jj = 0; jj < numberOfCellPoints - 1; jj++ )
00128         {
00129         outputFile << indent << buffer[index++] + 1;
00130         }
00131 
00132       outputFile << indent << -( buffer[index++] + 1 ) << '\n';
00133       }
00134     }
00135 
00136 protected:
00137   BYUMeshIO();
00138   virtual ~BYUMeshIO(){}
00139 
00140   void PrintSelf(std::ostream & os, Indent indent) const;
00141 
00142 private:
00143   BYUMeshIO(const Self &);      // purposely not implemented
00144   void operator=(const Self &); // purposely not implemented
00145 
00146   StreamOffsetType m_FilePosition;
00147   SizeValueType    m_PartId;
00148   SizeValueType    m_FirstCellId;
00149   SizeValueType    m_LastCellId;
00150 };
00151 } // end namespace itk
00152 
00153 #endif
00154