#include "MeshReader.h" #include #include #include #include #include // ------------------------------------------------------------------------- cpPlugins::IO::MeshReader:: MeshReader( ) : Superclass( ) { 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)" ); } // ------------------------------------------------------------------------- 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->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( ); 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$