]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshWriter.cxx
ee8b6668d904bb2402036b89bf80d06406df4baa
[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->m_ClassName = "cpPlugins::IO::MeshWriter";
14   this->m_ClassCategory = "MeshWriter";
15   this->SetNumberOfInputs( 1 );
16
17   using namespace cpPlugins::Interface;
18   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
19   this->m_Parameters = this->m_DefaultParameters;
20 }
21
22 // -------------------------------------------------------------------------
23 cpPlugins::IO::MeshWriter::
24 ~MeshWriter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 std::string cpPlugins::IO::MeshWriter::
30 _GenerateData( )
31 {
32   cpPlugins::Interface::Mesh* mesh =
33     this->GetInput< cpPlugins::Interface::Mesh >( 0 );
34   if( mesh == NULL )
35     return( "MeshWriter: No input mesh." );
36   vtkPolyData* i = mesh->GetVTK< vtkPolyData >( );
37   if( i == NULL )
38     return( "MeshWriter: No suitable input." );
39   std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
40
41   vtkPolyDataWriter* pdw = this->_CreateVTK< vtkPolyDataWriter >( );
42   pdw->SetInputData( i );
43   pdw->SetFileName( fname.c_str( ) );
44   pdw->Update( );
45   if( pdw->GetErrorCode( ) != 0 )
46     return( "MeshWriter: someting wrong happened." );
47   return( "" );
48 }
49
50 // eof - $RCSfile$