X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FIO%2FMeshReader.cxx;h=943d3ac6badb87b07d77833a75dc30ac72274212;hb=a89305e04527ebe2e81d0d1a62bbe34e0d35a141;hp=473686dc0b0a3da14862eec846f157b7a92f0fdc;hpb=de874ea850042e77a99a456188f423c8df2e374f;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 473686d..943d3ac 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -1,51 +1,18 @@ #include "MeshReader.h" #include +#include + #include #include - -/* TODO -#ifdef cpPlugins_Interface_QT4 -#include -#endif // cpPlugins_Interface_QT4 - -// ------------------------------------------------------------------------- -cpPlugins::IO::MeshReader:: -DialogResult cpPlugins::IO::MeshReader:: -ExecConfigurationDialog( QWidget* parent ) -{ - DialogResult r = Self::DialogResult_Cancel; - -#ifdef cpPlugins_Interface_QT4 - - // Show dialog and check if it was accepted - QFileDialog dialog( parent ); - dialog.setFileMode( QFileDialog::ExistingFile ); - dialog.setDirectory( QFileDialog::tr( "." ) ); - dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) ); - if( dialog.exec( ) ) - { - QStringList names = dialog.selectedFiles( ); - this->m_Parameters->SetString( "FileName", names[ 0 ].toStdString( ) ); - this->m_Parameters->SetSelectedChoice( "PixelType", "float" ); - this->m_Parameters->SetUint( "Dimension", 3 ); - - r = Self::DialogResult_NoModal; - - } // fi - -#endif // cpPlugins_Interface_QT4 - - return( r ); -} -*/ +#include // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: MeshReader( ) : Superclass( ) { - this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" ); + this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" ); std::vector< TParameters::TString > valid_types; valid_types.push_back( "float" ); @@ -55,6 +22,10 @@ MeshReader( ) this->m_Parameters->ConfigureAsUint( "Dimension" ); this->m_Parameters->SetUint( "Dimension", 3 ); + this->m_Parameters->SetAcceptedFileExtensions( + "FileName", + "Mesh files (*.vtk *.stl *.obj)" + ); } // ------------------------------------------------------------------------- @@ -99,17 +70,39 @@ _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 ); - cpPlugins::Interface::Mesh* out = - this->GetOutput< cpPlugins::Interface::Mesh >( "Output" ); - if( out != NULL ) + // 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" ); + out->SetVTK( stlr->GetOutput( ) ); + return( "" ); + } + else if( ext == "obj" ) + { + // TODO + } + else if( ext == "vtk" ) + { + vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); + pdr->SetFileName( fname.c_str( ) ); + pdr->Update( ); + + auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" ); out->SetVTK( pdr->GetOutput( ) ); - else - return( "MeshReader: output not correctly created." ); - return( "" ); + return( "" ); + + } // fi } // eof - $RCSfile$