]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/MeshReader.cxx
e658d8611b0fa69d998a85fd2c83fb79dca11210
[cpPlugins.git] / lib / cpPlugins / Plugins / MeshReader.cxx
1 #include <cpPlugins/Plugins/MeshReader.h>
2 #include <cpPlugins/Interface/Mesh.h>
3
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataReader.h>
6
7 // -------------------------------------------------------------------------
8 cpPlugins::Plugins::MeshReader::
9 MeshReader( )
10   : Superclass( )
11 {
12   this->m_ClassName = "cpPlugins::MeshReader";
13   this->m_ClassCategory = "MeshReader";
14
15   this->SetNumberOfOutputs( 1 );
16   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
17
18   using namespace cpPlugins::Interface;
19   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
20   this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
21   this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
22   this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
23   this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
24   this->m_Parameters = this->m_DefaultParameters;
25 }
26
27 // -------------------------------------------------------------------------
28 cpPlugins::Plugins::MeshReader::
29 ~MeshReader( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 std::string cpPlugins::Plugins::MeshReader::
35 _GenerateData( )
36 {
37   using namespace cpPlugins::Interface;
38   Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
39   std::string r = "MeshReader: Mesh dimension not supported.";
40   if( dim == 2 )
41     r = this->_GD0< 2 >( );
42   else if( dim == 3 )
43     r = this->_GD0< 3 >( );
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< unsigned int D >
49 std::string cpPlugins::Plugins::MeshReader::
50 _GD0( )
51 {
52   using namespace cpPlugins::Interface;
53   Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
54   std::string r = "MeshReader: Mesh pixel type not supported";
55   if( pt == "float" )       r = this->_GD1< float, D >( );
56   else if( pt == "double" ) r = this->_GD1< double, D >( );
57   return( r );
58 }
59
60 // -------------------------------------------------------------------------
61 template< class P, unsigned int D >
62 std::string cpPlugins::Plugins::MeshReader::
63 _GD1( )
64 {
65   // Get filename
66   using namespace cpPlugins::Interface;
67   Parameters::TString fname =
68     this->m_Parameters.GetValueAsString( "FileName" );
69
70   if( this->m_Reader != NULL )
71     this->m_Reader->Delete( );
72
73   vtkPolyDataReader* pdr = vtkPolyDataReader::New( );
74   this->m_Reader = pdr;
75   pdr->SetFileName( fname.c_str( ) );
76   pdr->Update( );
77
78   cpPlugins::Interface::Mesh* out =
79     this->_Output< cpPlugins::Interface::Mesh >( 0 );
80   if( out != NULL )
81     out->SetVTKMesh( pdr->GetOutput( ) );
82   else
83     return( "MeshReader: output not correctly created." );
84   return( "" );
85 }
86
87 // eof - $RCSfile$