#include "MeshReader.h" #include #include #include #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 ); } // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: MeshReader( ) : Superclass( ) { this->_MakeOutput< 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->ConfigureAsChoices( "PixelType", valid_types ); this->m_Parameters->ConfigureAsUint( "Dimension" ); this->m_Parameters->SetUint( "Dimension", 3 ); } // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: ~MeshReader( ) { } // ------------------------------------------------------------------------- std::string cpPlugins::IO::MeshReader:: _GenerateData( ) { using namespace cpPlugins::Interface; Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" ); std::string r = "MeshReader: Mesh dimension not supported."; if( dim == 2 ) r = this->_GD0< 2 >( ); else if( dim == 3 ) r = this->_GD0< 3 >( ); return( r ); } // ------------------------------------------------------------------------- template< unsigned int D > std::string cpPlugins::IO::MeshReader:: _GD0( ) { using namespace cpPlugins::Interface; 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 >( ); return( r ); } // ------------------------------------------------------------------------- template< class P, unsigned int D > std::string cpPlugins::IO::MeshReader:: _GD1( ) { // Get filename std::string fname = this->m_Parameters->GetString( "FileName" ); vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); pdr->SetFileName( fname.c_str( ) ); pdr->Update( ); cpPlugins::Interface::Mesh* out = this->GetOutput< cpPlugins::Interface::Mesh >( "Output" ); if( out != NULL ) out->SetVTK( pdr->GetOutput( ) ); else return( "MeshReader: output not correctly created." ); return( "" ); } // eof - $RCSfile$