X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=lib%2FcpPlugins%2FPlugins%2FMeshReader.cxx;fp=lib%2FcpPlugins%2FPlugins%2FMeshReader.cxx;h=17d668c5594fe6b9eae73f7012675315196a760c;hb=d97da4c5884307e660b0ed9135f87cffff174b93;hp=0000000000000000000000000000000000000000;hpb=2d96cce7bcab0bdcd9e93e44ed413c47388151d9;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/MeshReader.cxx b/lib/cpPlugins/Plugins/MeshReader.cxx new file mode 100644 index 0000000..17d668c --- /dev/null +++ b/lib/cpPlugins/Plugins/MeshReader.cxx @@ -0,0 +1,109 @@ +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::MeshReader:: +MeshReader( ) + : Superclass( ) +{ + this->SetNumberOfOutputs( 1 ); + this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); + + this->m_DefaultParameters[ "FileName" ] = + TParameter( "string", "no_file_name" ); + this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "float" ); + this->m_DefaultParameters[ "MeshDimension" ] = TParameter( "int", "3" ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Plugins::MeshReader:: +~MeshReader( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::MeshReader:: +GetClassName( ) const +{ + return( "cpPlugins::Plugins::MeshReader" ); +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::Plugins::MeshReader:: +_GenerateData( ) +{ + TParameters::const_iterator dIt; + + // Get image dimension + dIt = this->m_Parameters.find( "MeshDimension" ); + if( dIt == this->m_Parameters.end( ) ) + dIt = this->m_DefaultParameters.find( "MeshDimension" ); + + std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh dimension not supported."; + if( dIt->second.second == "3" ) r = this->_GD0< 3 >( ); + + return( r ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +std::string cpPlugins::Plugins::MeshReader:: +_GD0( ) +{ + TParameters::const_iterator tIt, cIt; + + // Get image pixel type + tIt = this->m_Parameters.find( "PixelType" ); + if( tIt == this->m_Parameters.end( ) ) + tIt = this->m_DefaultParameters.find( "PixelType" ); + + std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh pixel type not supported"; + if( tIt->second.second == "float" ) + r = this->_GD1< float, D >( ); + else if( tIt->second.second == "double" ) + r = this->_GD1< double, D >( ); + return( r ); +} + +// ------------------------------------------------------------------------- +template< class P, unsigned int D > +std::string cpPlugins::Plugins::MeshReader:: +_GD1( ) +{ + TParameters::const_iterator fIt; + + // Get filename + fIt = this->m_Parameters.find( "FileName" ); + if( fIt == this->m_Parameters.end( ) ) + fIt = this->m_DefaultParameters.find( "FileName" ); + + typedef cpPlugins::Extensions::QuadEdgeMesh< P, D > _TMesh; + typedef cpPlugins::Extensions::MeshReader< _TMesh > _TReader; + + _TReader* reader = + dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) ); + if( reader == NULL ) + { + this->m_Reader = _TReader::New( ); + reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) ); + + } // fi + reader->SetFileName( fIt->second.second ); + try + { + reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + return( err.GetDescription( ) ); + + } // yrt + this->_SetOutput( 0, reader->GetOutput( ) ); + + return( "" ); +} + +// eof - $RCSfile$