]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/MeshReader.cxx
b7ce4ba88e3d5667232cef35c237d82a95854295
[cpPlugins.git] / lib / cpPlugins / Plugins / MeshReader.cxx
1 #include <cpPlugins/Plugins/MeshReader.h>
2 #include <cpPlugins/Interface/Mesh.h>
3
4 #include <cpPlugins/Extensions/DataStructures/QuadEdgeMesh.h>
5 #include <cpPlugins/Extensions/IO/MeshReader.h>
6
7 // -------------------------------------------------------------------------
8 std::string cpPlugins::Plugins::MeshReader::
9 GetClassName( ) const
10 {
11   return( "cpPlugins::Plugins::MeshReader" );
12 }
13
14 // -------------------------------------------------------------------------
15 cpPlugins::Plugins::MeshReader::
16 MeshReader( )
17   : Superclass( )
18 {
19   this->SetNumberOfOutputs( 1 );
20   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
21
22   using namespace cpPlugins::Interface;
23   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
24   this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
25   this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
26   this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
27   this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
28   this->m_Parameters = this->m_DefaultParameters;
29 }
30
31 // -------------------------------------------------------------------------
32 cpPlugins::Plugins::MeshReader::
33 ~MeshReader( )
34 {
35 }
36
37 // -------------------------------------------------------------------------
38 std::string cpPlugins::Plugins::MeshReader::
39 _GenerateData( )
40 {
41   using namespace cpPlugins::Interface;
42   Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
43   std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh dimension not supported.";
44   if( dim == 3 )
45     r = this->_GD0< 3 >( );
46   return( r );
47 }
48
49 // -------------------------------------------------------------------------
50 template< unsigned int D >
51 std::string cpPlugins::Plugins::MeshReader::
52 _GD0( )
53 {
54   using namespace cpPlugins::Interface;
55   Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
56   std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh pixel type not supported";
57   if( pt == "float" )       r = this->_GD1< float, D >( );
58   else if( pt == "double" ) r = this->_GD1< double, D >( );
59   return( r );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class P, unsigned int D >
64 std::string cpPlugins::Plugins::MeshReader::
65 _GD1( )
66 {
67   // Get filename
68   using namespace cpPlugins::Interface;
69   Parameters::TString fname =
70     this->m_Parameters.GetValueAsString( "FileName" );
71
72   using namespace cpPlugins::Extensions;
73   typedef DataStructures::QuadEdgeMesh< P, D > _TMesh;
74   typedef IO::MeshReader< _TMesh > _TReader;
75
76   _TReader* reader =
77     dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
78   if( reader == NULL )
79   {
80     this->m_RealProcessObject = _TReader::New( );
81     reader =
82       dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
83
84   } // fi
85   reader->SetFileName( fname );
86   try
87   {
88     reader->Update( );
89   }
90   catch( itk::ExceptionObject& err )
91   {
92     return( err.GetDescription( ) );
93
94   } // yrt
95   this->_SetOutput( 0, reader->GetOutput( ) );
96
97   return( "" );
98 }
99
100 // eof - $RCSfile$