1 #include <cpPluginsIO/MeshReader.h>
2 #include <cpPlugins/Mesh.h>
7 #include <vtkPolyDataReader.h>
8 #include <vtkOBJReader.h>
9 #include <vtkSTLReader.h>
11 // -------------------------------------------------------------------------
12 cpPluginsIO::MeshReader::
16 this->_AddOutput< cpPlugins::Mesh >( "Output" );
17 this->m_Parameters.Clear( );
18 this->m_Parameters.ConfigureAsOpenFileName( "FileName" );
19 this->m_Parameters.ConfigureAsUint( "Dimension" );
21 std::vector< std::string > valid_types;
22 valid_types.push_back( "float" );
23 valid_types.push_back( "double" );
24 this->m_Parameters.ConfigureAsChoices( "ScalarType", valid_types );
25 this->m_Parameters.SetSelectedChoice( "ScalarType", "float" );
27 this->m_Parameters.SetUint( "Dimension", 3 );
28 this->m_Parameters.SetAcceptedFileExtensions(
30 "Mesh files (*.obj *.stl *.vtk)"
34 // -------------------------------------------------------------------------
35 cpPluginsIO::MeshReader::
40 // -------------------------------------------------------------------------
41 void cpPluginsIO::MeshReader::
44 auto d = this->m_Parameters.GetUint( "Dimension" );
45 if ( d == 2 ) this->_GD0< 2 >( );
46 else if( d == 3 ) this->_GD0< 3 >( );
47 else this->_Error( "Mesh dimension not supported." );
50 // -------------------------------------------------------------------------
51 template< unsigned int _Dim >
52 void cpPluginsIO::MeshReader::
55 auto s = this->m_Parameters.GetSelectedChoice( "ScalarType" );
56 if ( s == "float" ) this->_GD1< float, _Dim >( );
57 else if( s == "double" ) this->_GD1< double, _Dim >( );
58 else this->_Error( "Mesh type not supported." );
61 // -------------------------------------------------------------------------
62 template< class _TScalar, unsigned int _Dim >
63 void cpPluginsIO::MeshReader::
66 auto fname = this->m_Parameters.GetOpenFileName( "FileName" );
69 std::istringstream fname_str( fname );
70 std::string token, ext;
71 while( std::getline( fname_str, token, '.' ) )
73 std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
78 vtkSTLReader* stlr = this->_CreateVTK< vtkSTLReader >( );
79 stlr->SetFileName( fname.c_str( ) );
82 this->GetOutputData( "Output" )->SetVTK( stlr->GetOutput( ) );
84 else if( ext == "obj" )
86 vtkOBJReader* objr = this->_CreateVTK< vtkOBJReader >( );
87 objr->SetFileName( fname.c_str( ) );
90 this->GetOutputData( "Output" )->SetVTK( objr->GetOutput( ) );
92 else if( ext == "vtk" )
94 vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
95 pdr->SetFileName( fname.c_str( ) );
98 this->GetOutputData( "Output" )->SetVTK( pdr->GetOutput( ) );
101 this->_Error( "Input file format not recognized." );