X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FIO%2FMeshReader.cxx;h=8dce5610aa72221d108b4f991b8b6767227c18dc;hb=bf1c5140976e42a53f0860b2e8691d72ef70ff49;hp=60bb57d4dfe4eb9c9f8dd95fa96ac0f7734e7b82;hpb=c3a83f9e38129c9efd40de5ab09aca14c731f371;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 60bb57d..8dce561 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -1,8 +1,11 @@ #include "MeshReader.h" #include +#include + #include #include +#include // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: @@ -67,16 +70,41 @@ _GD1( ) // Get filename std::string fname = this->m_Parameters->GetOpenFileName( "FileName" ); - vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); - pdr->SetFileName( fname.c_str( ) ); - pdr->Update( ); + // Get file extension + std::istringstream fname_str( fname ); + std::string token, ext; + while( std::getline( fname_str, token, '.' ) ) + ext = token; + std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower ); + + // Real read + if( ext == "stl" ) + { + vtkSTLReader* stlr = this->_CreateVTK< vtkSTLReader >( ); + stlr->SetFileName( fname.c_str( ) ); + stlr->Update( ); + + auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + if( out != NULL ) + out->SetVTK( stlr->GetOutput( ) ); + else + return( "MeshReader: output not correctly created." ); + return( "" ); + } + else if( ext == "vtk" ) + { + vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); + pdr->SetFileName( fname.c_str( ) ); + pdr->Update( ); + + auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); + if( out != NULL ) + out->SetVTK( pdr->GetOutput( ) ); + else + return( "MeshReader: output not correctly created." ); + return( "" ); - auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); - if( out != NULL ) - out->SetVTK( pdr->GetOutput( ) ); - else - return( "MeshReader: output not correctly created." ); - return( "" ); + } // fi } // eof - $RCSfile$