1 #include <cpPluginsIO/MeshWriter.h>
2 #include <cpPlugins/Mesh.h>
7 #include <vtkPolyDataWriter.h>
8 #include <vtkSTLWriter.h>
10 // -------------------------------------------------------------------------
11 cpPluginsIO::MeshWriter::
15 this->_AddInput( "Input" );
16 this->m_Parameters.Clear( );
17 this->m_Parameters.ConfigureAsSaveFileName( "FileName" );
18 this->m_Parameters.SetAcceptedFileExtensions(
20 "Mesh files (*.stl *.vtk)"
24 // -------------------------------------------------------------------------
25 cpPluginsIO::MeshWriter::
30 // -------------------------------------------------------------------------
31 void cpPluginsIO::MeshWriter::
34 auto mesh = this->GetInputData( "Input" )->GetVTK< vtkPolyData >( );
36 this->_Error( "No suitable input." );
39 auto fname = this->m_Parameters.GetSaveFileName( "FileName" );
40 std::istringstream fname_str( fname );
41 std::string token, ext;
42 while( std::getline( fname_str, token, '.' ) )
44 std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
49 vtkSTLWriter* stlw = this->_CreateVTK< vtkSTLWriter >( );
50 stlw->SetInputData( mesh );
51 stlw->SetFileName( fname.c_str( ) );
53 if( stlw->GetErrorCode( ) != 0 )
54 this->_Error( "Someting wrong happened." );
56 else if( ext == "vtk" )
58 vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
59 pdw->SetInputData( mesh );
60 pdw->SetFileName( fname.c_str( ) );
62 if( pdw->GetErrorCode( ) != 0 )
63 this->_Error( "Someting wrong happened." );
66 this->_Error( "Input file format not recognized." );