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