]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshWriter.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / MeshWriter.cxx
1 #include "MeshWriter.h"
2 #include <cpPlugins/Interface/Mesh.h>
3
4 #include <vtkSmartPointer.h>
5 #include <vtkPolyData.h>
6 #include <vtkPolyDataWriter.h>
7
8 // -------------------------------------------------------------------------
9 cpPlugins::IO::MeshWriter::
10 MeshWriter( )
11   : Superclass( )
12 {
13   this->_AddInput( "Input" );
14   this->m_Parameters->ConfigureAsSaveFileName( "FileName" );
15   this->m_Parameters->SetAcceptedFileExtensions(
16     "FileName",
17     "Mesh files (*.vtk *.stl *.obj)"
18     );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPlugins::IO::MeshWriter::
23 ~MeshWriter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 std::string cpPlugins::IO::MeshWriter::
29 _GenerateData( )
30 {
31   auto mesh = this->GetInputData( "Input" );
32   vtkPolyData* i = mesh->GetVTK< vtkPolyData >( );
33   if( i == NULL )
34     return( "MeshWriter: No suitable input." );
35   std::string fname = this->m_Parameters->GetSaveFileName( "FileName" );
36
37   vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
38   pdw->SetInputData( i );
39   pdw->SetFileName( fname.c_str( ) );
40   pdw->SetFileTypeToBinary( );
41   pdw->Update( );
42   if( pdw->GetErrorCode( ) != 0 )
43     return( "MeshWriter: someting wrong happened." );
44   return( "" );
45 }
46
47 // eof - $RCSfile$