1 #include "MeshReader.h"
2 #include <cpPlugins/Interface/Mesh.h>
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataReader.h>
7 // -------------------------------------------------------------------------
8 cpPlugins::IO::MeshReader::
13 this->m_ClassName = "cpPlugins::IO::MeshReader";
14 this->m_ClassCategory = "MeshReader";
16 this->SetNumberOfOutputs( 1 );
17 this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
19 using namespace cpPlugins::Interface;
20 this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
21 this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
22 this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
23 this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
24 this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
25 this->m_Parameters = this->m_DefaultParameters;
28 // -------------------------------------------------------------------------
29 cpPlugins::IO::MeshReader::
32 if( this->m_Reader != NULL )
33 this->m_Reader = NULL;
36 // -------------------------------------------------------------------------
37 std::string cpPlugins::IO::MeshReader::
40 using namespace cpPlugins::Interface;
41 Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
42 std::string r = "MeshReader: Mesh dimension not supported.";
44 r = this->_GD0< 2 >( );
46 r = this->_GD0< 3 >( );
50 // -------------------------------------------------------------------------
51 template< unsigned int D >
52 std::string cpPlugins::IO::MeshReader::
55 using namespace cpPlugins::Interface;
56 Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
57 std::string r = "MeshReader: Mesh pixel type not supported";
58 if( pt == "float" ) r = this->_GD1< float, D >( );
59 else if( pt == "double" ) r = this->_GD1< double, D >( );
63 // -------------------------------------------------------------------------
64 template< class P, unsigned int D >
65 std::string cpPlugins::IO::MeshReader::
69 using namespace cpPlugins::Interface;
70 Parameters::TString fname =
71 this->m_Parameters.GetValueAsString( "FileName" );
73 if( this->m_Reader != NULL )
74 this->m_Reader->Delete( );
76 vtkPolyDataReader* pdr = vtkPolyDataReader::New( );
78 pdr->SetFileName( fname.c_str( ) );
81 cpPlugins::Interface::Mesh* out =
82 this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
84 out->SetVTKMesh( pdr->GetOutput( ) );
86 return( "MeshReader: output not correctly created." );