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=fe61d707532d52b9b91f5ab724f6330d39ac026a;hpb=dba64a6906e88d6023b2e6c9632da9fd41bfeb53;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index fe61d70..943d3ac 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -1,63 +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( ) ) - { - this->m_Parameters = this->m_DefaultParameters; - QStringList names = dialog.selectedFiles( ); - this->m_Parameters.SetValueAsString( - "FileName", names[ 0 ].toStdString( ) - ); - - /* TODO - this->m_Parameters.SetValueAsString( "PixelType", "float" ); - this->m_Parameters.SetValueAsUint( "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 ); - - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::String, "FileName" ); - this->m_DefaultParameters.Configure( Parameters::String, "PixelType" ); - this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" ); - this->m_DefaultParameters.SetValueAsString( "PixelType", "float" ); - this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 ); - this->m_Parameters = this->m_DefaultParameters; + 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->ConfigureAsOpenFileName( "FileName" ); + this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types ); + this->m_Parameters->ConfigureAsUint( "Dimension" ); + + this->m_Parameters->SetUint( "Dimension", 3 ); + this->m_Parameters->SetAcceptedFileExtensions( + "FileName", + "Mesh files (*.vtk *.stl *.obj)" + ); } // ------------------------------------------------------------------------- @@ -71,7 +39,7 @@ std::string cpPlugins::IO::MeshReader:: _GenerateData( ) { using namespace cpPlugins::Interface; - Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" ); + Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" ); std::string r = "MeshReader: Mesh dimension not supported."; if( dim == 2 ) r = this->_GD0< 2 >( ); @@ -86,7 +54,8 @@ std::string cpPlugins::IO::MeshReader:: _GD0( ) { using namespace cpPlugins::Interface; - Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" ); + Parameters::TString pt = + this->m_Parameters->GetSelectedChoice( "PixelType" ); std::string r = "MeshReader: Mesh pixel type not supported"; if( pt == "float" ) r = this->_GD1< float, D >( ); else if( pt == "double" ) r = this->_GD1< double, D >( ); @@ -99,21 +68,41 @@ std::string cpPlugins::IO::MeshReader:: _GD1( ) { // Get filename - using namespace cpPlugins::Interface; - Parameters::TString fname = - this->m_Parameters.GetValueAsString( "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 ) + // 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$