]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/MeshReader.cxx
Garbage collector added
[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   this->m_DefaultParameters[ "FileName" ] =
23     TParameter( "string", "no_file_name" );
24   this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "float" );
25   this->m_DefaultParameters[ "MeshDimension" ] = TParameter( "int", "3" );
26 }
27
28 // -------------------------------------------------------------------------
29 cpPlugins::Plugins::MeshReader::
30 ~MeshReader( )
31 {
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_RealProcessObject.GetPointer( ) );
89   if( reader == NULL )
90   {
91     this->m_RealProcessObject = _TReader::New( );
92     reader =
93       dynamic_cast< _TReader* >( this->m_RealProcessObject.GetPointer( ) );
94
95   } // fi
96   reader->SetFileName( fIt->second.second );
97   try
98   {
99     reader->Update( );
100   }
101   catch( itk::ExceptionObject& err )
102   {
103     return( err.GetDescription( ) );
104
105   } // yrt
106   this->_SetOutput( 0, reader->GetOutput( ) );
107
108   return( "" );
109 }
110
111 // eof - $RCSfile$