X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FIO%2FMeshReader.cxx;h=c820c68a9620fdca76405c5c260c81aa544fa9a7;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=397b644ef10b402d267a5e0fadd98a7571e239fd;hpb=e9143845b476fc8b86c1706fb140ebee770a650b;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 397b644..c820c68 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -1,56 +1,31 @@ #include "MeshReader.h" #include +#include + #include #include - -#ifdef cpPlugins_Interface_QT4 -#include -#endif // cpPlugins_Interface_QT4 - -// ------------------------------------------------------------------------- -bool cpPlugins::IO::MeshReader:: -ExecConfigurationDialog( QWidget* parent ) -{ - bool r = false; - -#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 = true; - - } // fi - -#endif // cpPlugins_Interface_QT4 - - return( r ); -} +#include // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: MeshReader( ) : Superclass( ) { - this->SetNumberOfOutputs( 1 ); - this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); + this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" ); std::vector< TParameters::TString > valid_types; valid_types.push_back( "float" ); valid_types.push_back( "double" ); - this->m_Parameters->ConfigureAsString( "FileName", "" ); + this->m_Parameters->ConfigureAsOpenFileName( "FileName" ); this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types ); - this->m_Parameters->ConfigureAsUint( "Dimension", 3 ); + this->m_Parameters->ConfigureAsUint( "Dimension" ); + + this->m_Parameters->SetUint( "Dimension", 3 ); + this->m_Parameters->SetAcceptedFileExtensions( + "FileName", + "Mesh files (*.vtk *.stl *.obj)" + ); } // ------------------------------------------------------------------------- @@ -93,19 +68,47 @@ std::string cpPlugins::IO::MeshReader:: _GD1( ) { // Get filename - std::string fname = this->m_Parameters->GetString( "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 >( 0 ); - if( out != NULL ) - out->SetVTK( pdr->GetOutput( ) ); - else - return( "MeshReader: output not correctly created." ); - return( "" ); + // 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 == "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" ); + if( out != NULL ) + out->SetVTK( pdr->GetOutput( ) ); + else + return( "MeshReader: output not correctly created." ); + return( "" ); + + } // fi } // eof - $RCSfile$