X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=plugins%2FcpPluginsIO%2FMeshReader.cxx;fp=plugins%2FcpPluginsIO%2FMeshReader.cxx;h=49b76a2406840e98f5a5c62ec323b2a3ad110cd4;hb=eccc88f770fd53f8ef8d578127a8788315573c52;hp=0000000000000000000000000000000000000000;hpb=7989665e222981539e3c354e9d50bf142e777a2c;p=cpPlugins.git diff --git a/plugins/cpPluginsIO/MeshReader.cxx b/plugins/cpPluginsIO/MeshReader.cxx new file mode 100644 index 0000000..49b76a2 --- /dev/null +++ b/plugins/cpPluginsIO/MeshReader.cxx @@ -0,0 +1,106 @@ +#include +#include + +#include + +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsIO::MeshReader:: +MeshReader( ) + : Superclass( ) +{ + this->_AddOutput< cpPlugins::Mesh >( "Output" ); + this->m_Parameters.Clear( ); + this->m_Parameters.ConfigureAsOpenFileName( "FileName" ); + this->m_Parameters.ConfigureAsUint( "Dimension" ); + + std::vector< std::string > valid_types; + valid_types.push_back( "float" ); + valid_types.push_back( "double" ); + this->m_Parameters.ConfigureAsChoices( "ScalarType", valid_types ); + this->m_Parameters.SetSelectedChoice( "ScalarType", "float" ); + + this->m_Parameters.SetUint( "Dimension", 3 ); + this->m_Parameters.SetAcceptedFileExtensions( + "FileName", + "Mesh files (*.obj *.stl *.vtk)" + ); +} + +// ------------------------------------------------------------------------- +cpPluginsIO::MeshReader:: +~MeshReader( ) +{ +} + +// ------------------------------------------------------------------------- +std::string cpPluginsIO::MeshReader:: +_GenerateData( ) +{ + auto dim = this->m_Parameters.GetUint( "Dimension" ); + if ( dim == 2 ) return( this->_GD0< 2 >( ) ); + else if( dim == 3 ) return( this->_GD0< 3 >( ) ); + else return( "MeshReader: Mesh dimension not supported." ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _Dim > +std::string cpPluginsIO::MeshReader:: +_GD0( ) +{ + auto st = this->m_Parameters.GetSelectedChoice( "ScalarType" ); + if ( st == "float" ) return( this->_GD1< float, _Dim >( ) ); + else if( st == "double" ) return( this->_GD1< double, _Dim >( ) ); + else return( "MeshReader: Mesh type not supported." ); +} + +// ------------------------------------------------------------------------- +template< class _TScalar, unsigned int _Dim > +std::string cpPluginsIO::MeshReader:: +_GD1( ) +{ + auto fname = this->m_Parameters.GetOpenFileName( "FileName" ); + + // 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( ); + + this->GetOutputData( "Output" )->SetVTK( stlr->GetOutput( ) ); + return( "" ); + } + else if( ext == "obj" ) + { + vtkOBJReader* objr = this->_CreateVTK< vtkOBJReader >( ); + objr->SetFileName( fname.c_str( ) ); + objr->Update( ); + + this->GetOutputData( "Output" )->SetVTK( objr->GetOutput( ) ); + return( "" ); + } + else if( ext == "vtk" ) + { + vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); + pdr->SetFileName( fname.c_str( ) ); + pdr->Update( ); + + this->GetOutputData( "Output" )->SetVTK( pdr->GetOutput( ) ); + return( "" ); + } + else + return( "MeshReader: Input file format not recognized." ); +} + +// eof - $RCSfile$