]> Creatis software - cpPlugins.git/blob - plugins/IO/MeshWriter.cxx
8bb075ea75dea28c4cd1a37b7c954db182a2c7cb
[cpPlugins.git] / plugins / IO / MeshWriter.cxx
1 #include <IO/MeshWriter.h>
2 #include <cpPlugins/DataObjects/Mesh.h>
3 #include <cpPlugins/QT/SaveFileDialog.h>
4
5 #include <vtkPolyData.h>
6 #include <vtkPolyDataWriter.h>
7
8 #ifdef cpPlugins_QT4
9 #  include <QApplication>
10 #endif // cpPlugins_QT4
11
12 // -------------------------------------------------------------------------
13 QDialog* cpPluginsIO::MeshWriter::
14 CreateQDialog( )
15 {
16 #ifdef cpPlugins_QT4
17   cpPlugins::QT::SaveFileDialog* dlg = NULL;
18   if( QApplication::instance( ) != NULL )
19   {
20     dlg = new cpPlugins::QT::SaveFileDialog( );
21     dlg->SetParameters( &( this->m_Parameters ), "FileName" );
22
23   } // fi
24   return( dlg );
25 #else // cpPlugins_QT4
26   return( NULL );
27 #endif // cpPlugins_QT4
28 }
29
30 // -------------------------------------------------------------------------
31 cpPluginsIO::MeshWriter::
32 MeshWriter( )
33   : Superclass( )
34 {
35   typedef cpPlugins::DataObjects::Mesh _TMesh;
36
37   this->_ConfigureInput< _TMesh >( "Input", true, false );
38   this->m_Parameters.Clear( );
39   this->m_Parameters.ConfigureAsSaveFileName( "FileName", "" );
40   this->m_Parameters.SetAcceptedFileExtensions(
41     "FileName",
42     "Mesh files (*.vtk)"
43     );
44 }
45
46 // -------------------------------------------------------------------------
47 cpPluginsIO::MeshWriter::
48 ~MeshWriter( )
49 {
50 }
51
52 // -------------------------------------------------------------------------
53 void cpPluginsIO::MeshWriter::
54 _GenerateData( )
55 {
56   auto mesh = this->GetInputData< vtkPolyData >( "Input" );
57   if( mesh == NULL )
58     this->_Error( "Invalid input image." );
59
60   auto f = this->_CreateVTK< vtkPolyDataWriter >( );
61   f->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ).c_str( ) );
62   f->SetInputData( mesh );
63   f->SetFileTypeToBinary( );
64   f->Update( );
65 }
66
67 // eof - $RCSfile$