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