1 #include "MeshReader.h"
2 #include <cpPlugins/Interface/Mesh.h>
6 #include <vtkPolyData.h>
7 #include <vtkPolyDataReader.h>
8 #include <vtkSTLReader.h>
10 // -------------------------------------------------------------------------
11 cpPlugins::IO::MeshReader::
15 this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
17 std::vector< TParameters::TString > valid_types;
18 valid_types.push_back( "float" );
19 valid_types.push_back( "double" );
20 this->m_Parameters->ConfigureAsOpenFileName( "FileName" );
21 this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types );
22 this->m_Parameters->ConfigureAsUint( "Dimension" );
24 this->m_Parameters->SetUint( "Dimension", 3 );
25 this->m_Parameters->SetAcceptedFileExtensions(
27 "Mesh files (*.vtk *.stl *.obj)"
31 // -------------------------------------------------------------------------
32 cpPlugins::IO::MeshReader::
37 // -------------------------------------------------------------------------
38 std::string cpPlugins::IO::MeshReader::
41 using namespace cpPlugins::Interface;
42 Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
43 std::string r = "MeshReader: Mesh dimension not supported.";
45 r = this->_GD0< 2 >( );
47 r = this->_GD0< 3 >( );
51 // -------------------------------------------------------------------------
52 template< unsigned int D >
53 std::string cpPlugins::IO::MeshReader::
56 using namespace cpPlugins::Interface;
57 Parameters::TString pt =
58 this->m_Parameters->GetSelectedChoice( "PixelType" );
59 std::string r = "MeshReader: Mesh pixel type not supported";
60 if( pt == "float" ) r = this->_GD1< float, D >( );
61 else if( pt == "double" ) r = this->_GD1< double, D >( );
65 // -------------------------------------------------------------------------
66 template< class P, unsigned int D >
67 std::string cpPlugins::IO::MeshReader::
71 std::string fname = this->m_Parameters->GetOpenFileName( "FileName" );
74 std::istringstream fname_str( fname );
75 std::string token, ext;
76 while( std::getline( fname_str, token, '.' ) )
78 std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
83 vtkSTLReader* stlr = this->_CreateVTK< vtkSTLReader >( );
84 stlr->SetFileName( fname.c_str( ) );
87 auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
88 out->SetVTK( stlr->GetOutput( ) );
91 else if( ext == "obj" )
95 else if( ext == "vtk" )
97 vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
98 pdr->SetFileName( fname.c_str( ) );
101 auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
102 out->SetVTK( pdr->GetOutput( ) );