]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/MeshWriter.cxx
beaee046be3338f090c5d494286695bb04e2014b
[cpPlugins.git] / lib / cpPlugins / Plugins / MeshWriter.cxx
1 #include <cpPlugins/Plugins/MeshWriter.h>
2
3 #include <vtkSmartPointer.h>
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataWriter.h>
6
7 // -------------------------------------------------------------------------
8 cpPlugins::Plugins::MeshWriter::
9 MeshWriter( )
10   : Superclass( ),
11     m_Writer( NULL )
12 {
13   this->m_ClassName = "cpPlugins::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::Plugins::MeshWriter::
24 ~MeshWriter( )
25 {
26   if( this->m_Writer != NULL )
27     this->m_Writer->Delete( );
28 }
29
30 // -------------------------------------------------------------------------
31 std::string cpPlugins::Plugins::MeshWriter::
32 _GenerateData( )
33 {
34   vtkPolyData* i =
35     dynamic_cast< vtkPolyData* >(
36       this->m_Inputs[ 0 ]->GetVTKDataObject( )
37       );
38   if( i == NULL )
39     return( "MeshWriter: No suitable input." );
40   std::string fname = this->m_Parameters.GetValueAsString( "FileName" );
41
42   if( this->m_Writer != NULL )
43     this->m_Writer->Delete( );
44
45   vtkPolyDataWriter* pdw = vtkPolyDataWriter::New( );
46   this->m_Writer = pdw;
47   pdw->SetInputData( i );
48   pdw->SetFileName( fname.c_str( ) );
49   pdw->Update( );
50   if( pdw->GetErrorCode( ) != 0 )
51     return( "MeshWriter: someting wrong happened." );
52   return( "" );
53 }
54
55 // eof - $RCSfile$