#include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpPluginsIO::MeshReader:: MeshReader( ) : Superclass( ) { this->_AddOutput< cpPlugins::Mesh >( "Output" ); this->m_Parameters.Clear( ); this->m_Parameters.ConfigureAsOpenFileName( "FileName" ); this->m_Parameters.ConfigureAsUint( "Dimension" ); std::vector< std::string > valid_types; valid_types.push_back( "float" ); valid_types.push_back( "double" ); this->m_Parameters.ConfigureAsChoices( "ScalarType", valid_types ); this->m_Parameters.SetSelectedChoice( "ScalarType", "float" ); this->m_Parameters.SetUint( "Dimension", 3 ); this->m_Parameters.SetAcceptedFileExtensions( "FileName", "Mesh files (*.obj *.stl *.vtk)" ); } // ------------------------------------------------------------------------- cpPluginsIO::MeshReader:: ~MeshReader( ) { } // ------------------------------------------------------------------------- void cpPluginsIO::MeshReader:: _GenerateData( ) { auto d = this->m_Parameters.GetUint( "Dimension" ); if ( d == 2 ) this->_GD0< 2 >( ); else if( d == 3 ) this->_GD0< 3 >( ); else this->_Error( "Mesh dimension not supported." ); } // ------------------------------------------------------------------------- template< unsigned int _Dim > void cpPluginsIO::MeshReader:: _GD0( ) { auto s = this->m_Parameters.GetSelectedChoice( "ScalarType" ); if ( s == "float" ) this->_GD1< float, _Dim >( ); else if( s == "double" ) this->_GD1< double, _Dim >( ); else this->_Error( "Mesh type not supported." ); } // ------------------------------------------------------------------------- template< class _TScalar, unsigned int _Dim > void cpPluginsIO::MeshReader:: _GD1( ) { auto 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( ); this->GetOutputData( "Output" )->SetVTK( stlr->GetOutput( ) ); } else if( ext == "obj" ) { vtkOBJReader* objr = this->_CreateVTK< vtkOBJReader >( ); objr->SetFileName( fname.c_str( ) ); objr->Update( ); this->GetOutputData( "Output" )->SetVTK( objr->GetOutput( ) ); } else if( ext == "vtk" ) { vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( ); pdr->SetFileName( fname.c_str( ) ); pdr->Update( ); this->GetOutputData( "Output" )->SetVTK( pdr->GetOutput( ) ); } else this->_Error( "Input file format not recognized." ); } // eof - $RCSfile$