1 #include <cpPluginsIO/MeshWriter.h>
2 #include <cpPlugins/Mesh.h>
6 #include <vtkPolyDataWriter.h>
7 #include <vtkSTLWriter.h>
9 // -------------------------------------------------------------------------
10 cpPluginsIO::MeshWriter::
14 this->_AddInput( "Input" );
15 this->m_Parameters.Clear( );
16 this->m_Parameters.ConfigureAsSaveFileName( "FileName" );
17 this->m_Parameters.SetAcceptedFileExtensions(
19 "Mesh files (*.stl *.vtk)"
23 // -------------------------------------------------------------------------
24 cpPluginsIO::MeshWriter::
29 // -------------------------------------------------------------------------
30 void cpPluginsIO::MeshWriter::
33 auto mesh = this->GetInputData( "Input" )->GetVTK< vtkPolyData >( );
35 this->_Error( "No suitable input." );
38 auto fname = this->m_Parameters.GetSaveFileName( "FileName" );
39 std::istringstream fname_str( fname );
40 std::string token, ext;
41 while( std::getline( fname_str, token, '.' ) )
43 std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
48 vtkSTLWriter* stlw = this->_CreateVTK< vtkSTLWriter >( );
49 stlw->SetInputData( mesh );
50 stlw->SetFileName( fname.c_str( ) );
52 if( stlw->GetErrorCode( ) != 0 )
53 this->_Error( "Someting wrong happened." );
55 else if( ext == "vtk" )
57 vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
58 pdw->SetInputData( mesh );
59 pdw->SetFileName( fname.c_str( ) );
61 if( pdw->GetErrorCode( ) != 0 )
62 this->_Error( "Someting wrong happened." );
65 this->_Error( "Input file format not recognized." );