Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkQuadEdgeMeshScalarDataVTKPolyDataWriter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkQuadEdgeMeshScalarDataVTKPolyDataWriter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-10-10 22:22:05 $
00007   Version:   $Revision: 1.3 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkQuadEdgeMeshScalarDataVTKPolyDataWriter_h
00019 #define __itkQuadEdgeMeshScalarDataVTKPolyDataWriter_h
00020 
00021 #include <itkVTKPolyDataWriter.h>
00022 #include <fstream>
00023 
00024 namespace itk
00025 {
00030 template< class TMesh >
00031 class QuadEdgeMeshScalarDataVTKPolyDataWriter : public VTKPolyDataWriter< TMesh >
00032 {
00033 public:
00034   typedef QuadEdgeMeshScalarDataVTKPolyDataWriter         Self;
00035   typedef SmartPointer< Self >                            Pointer;
00036   typedef SmartPointer< const Self >                      ConstPointer;
00037   typedef VTKPolyDataWriter< TMesh >                      Superclass;
00038 
00040   itkTypeMacro( QuadEdgeMeshScalarDataVTKPolyDataWriter, VTKPolyDataWriter );
00041 
00043   itkNewMacro( Self );
00044 
00045   typedef TMesh                                           MeshType;
00046   typedef typename MeshType::Pointer                      MeshPointer;
00047   typedef typename MeshType::CellType                     CellType;
00048 
00049   typedef typename MeshType::PointsContainerPointer       PointsContainerPointer;
00050   typedef typename MeshType::PointsContainerIterator      PointsContainerIterator;
00051 
00052   typedef typename MeshType::PointDataContainerPointer          PointDataContainerPointer;
00053   typedef typename MeshType::PointDataContainerConstPointer     PointDataContainerConstPointer;
00054   typedef typename MeshType::PointDataContainerIterator         PointDataContainerIterator;
00055 
00056   typedef typename MeshType::CellsContainerPointer        CellsContainerPointer;
00057   typedef typename MeshType::CellsContainerIterator       CellsContainerIterator;
00058 
00059   typedef typename MeshType::CellDataContainerPointer     CellDataContainerPointer;
00060   typedef typename MeshType::CellDataContainerIterator    CellDataContainerIterator;
00061   
00063   itkSetStringMacro(CellDataName);
00064   itkGetStringMacro(CellDataName);
00066 
00068   itkSetStringMacro(PointDataName);
00069   itkGetStringMacro(PointDataName);
00071 
00072 protected:
00073   QuadEdgeMeshScalarDataVTKPolyDataWriter() 
00074     {
00075     m_CellDataName = "";
00076     m_PointDataName = "";
00077     }
00078   ~QuadEdgeMeshScalarDataVTKPolyDataWriter() {}
00079 
00080   std::string     m_CellDataName;
00081   std::string     m_PointDataName;
00082 
00083   void GenerateData()
00084     {
00085     Superclass::GenerateData();
00086     this->WriteCellData();
00087     this->WritePointData();
00088     }
00089 
00090   void WriteCellData()
00091     {
00092     CellDataContainerPointer celldata = this->m_Input->GetCellData();
00093 
00094     if( celldata )
00095       {
00096       if( celldata->Size() != 0 )
00097         {
00098         std::ofstream outputFile( this->m_FileName.c_str(), std::ios_base::app );
00099 
00100         outputFile <<"CELL_DATA " <<this->m_Input->GetNumberOfFaces() <<std::endl;
00101         outputFile <<"SCALARS ";
00102 
00103         if( m_CellDataName != "" )
00104           {
00105           outputFile <<m_CellDataName <<" " <<m_CellDataName <<std::endl;
00106           }
00107         else
00108           {
00109           outputFile <<"double double" <<std::endl;
00110           }
00111         
00112         outputFile <<"LOOKUP_TABLE default" <<std::endl;
00113 
00114         unsigned long k(0);
00115 
00116         CellsContainerPointer cells = this->m_Input->GetCells();
00117         CellsContainerIterator it = cells->Begin();
00118 
00119         for( CellDataContainerIterator c_it = celldata->Begin();
00120             c_it != celldata->End();
00121             ++c_it, ++it )
00122           {
00123           CellType* cellPointer = it.Value();
00124           if( cellPointer->GetType() != 1 )
00125             {
00126             outputFile <<c_it.Value();
00127             if( k++ % 3 == 0 )
00128               {
00129               outputFile <<std::endl;
00130               }
00131             }
00132           }
00133         outputFile <<std::endl;
00134         outputFile.close();
00135         }
00136       }
00137     }
00138 
00139   void WritePointData()
00140     {
00141     PointDataContainerConstPointer pointdata = this->m_Input->GetPointData();
00142 
00143     if( pointdata )
00144       {
00145       std::ofstream outputFile( this->m_FileName.c_str(), std::ios_base::app );
00146       outputFile <<"POINT_DATA " <<this->m_Input->GetNumberOfPoints()
00147         <<std::endl;
00148       outputFile <<"SCALARS ";
00149       if( m_PointDataName != "" )
00150         outputFile <<m_PointDataName <<" " <<m_PointDataName <<std::endl;
00151       else
00152         outputFile <<"double double"<<std::endl;
00153 
00154       outputFile <<"LOOKUP_TABLE default" <<std::endl; 
00155       unsigned long k(0);
00156 
00157       for( PointDataContainerIterator c_it = pointdata->Begin();
00158           c_it != pointdata->End();
00159           ++c_it, ++k )
00160         {
00161         outputFile <<c_it.Value() <<" ";
00162         if( k % 3 == 0 )
00163           {
00164           outputFile <<std::endl;
00165           }
00166         }
00167       outputFile <<std::endl;
00168       outputFile.close();
00169       }
00170     }
00171 
00172 private:
00173   QuadEdgeMeshScalarDataVTKPolyDataWriter( const Self& );
00174   void operator = ( const Self& );
00175   
00176 };
00177 
00178 }
00179 
00180 #endif
00181 

Generated at Wed Nov 5 23:45:26 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000