]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/MeshReader.cxx
322e49c350fec9432404770150280b33b569d360
[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 cpPlugins::Plugins::MeshReader::
9 MeshReader( )
10   : Superclass( )
11 {
12   this->SetNumberOfOutputs( 1 );
13   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
14
15   this->m_DefaultParameters[ "FileName" ] =
16     TParameter( "string", "no_file_name" );
17   this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "float" );
18   this->m_DefaultParameters[ "MeshDimension" ] = TParameter( "int", "3" );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::Plugins::MeshReader::
23 ~MeshReader( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::Plugins::MeshReader::
29 GetClassName( ) const
30 {
31   return( "cpPlugins::Plugins::MeshReader" );
32 }
33
34 // -------------------------------------------------------------------------
35 std::string cpPlugins::Plugins::MeshReader::
36 _GenerateData( )
37 {
38   TParameters::const_iterator dIt;
39
40   // Get image dimension
41   dIt = this->m_Parameters.find( "MeshDimension" );
42   if( dIt == this->m_Parameters.end( ) )
43     dIt = this->m_DefaultParameters.find( "MeshDimension" );
44
45   std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh dimension not supported.";
46   if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
47
48   return( r );
49 }
50
51 // -------------------------------------------------------------------------
52 template< unsigned int D >
53 std::string cpPlugins::Plugins::MeshReader::
54 _GD0( )
55 {
56   TParameters::const_iterator tIt, cIt;
57
58   // Get image pixel type
59   tIt = this->m_Parameters.find( "PixelType" );
60   if( tIt == this->m_Parameters.end( ) )
61     tIt = this->m_DefaultParameters.find( "PixelType" );
62
63   std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh pixel type not supported";
64   if( tIt->second.second == "float" )
65     r = this->_GD1< float, D >( );
66   else if( tIt->second.second == "double" )
67     r = this->_GD1< double, D >( );
68   return( r );
69 }
70
71 // -------------------------------------------------------------------------
72 template< class P, unsigned int D >
73 std::string cpPlugins::Plugins::MeshReader::
74 _GD1( )
75 {
76   TParameters::const_iterator fIt;
77
78   // Get filename
79   fIt = this->m_Parameters.find( "FileName" );
80   if( fIt == this->m_Parameters.end( ) )
81     fIt = this->m_DefaultParameters.find( "FileName" );
82
83   using namespace cpPlugins::Extensions;
84   typedef DataStructures::QuadEdgeMesh< P, D > _TMesh;
85   typedef IO::MeshReader< _TMesh > _TReader;
86
87   _TReader* reader =
88     dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
89   if( reader == NULL )
90   {
91     this->m_Reader = _TReader::New( );
92     reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
93
94   } // fi
95   reader->SetFileName( fIt->second.second );
96   try
97   {
98     reader->Update( );
99   }
100   catch( itk::ExceptionObject& err )
101   {
102     return( err.GetDescription( ) );
103
104   } // yrt
105   this->_SetOutput( 0, reader->GetOutput( ) );
106
107   return( "" );
108 }
109
110 // eof - $RCSfile$