]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshReader.cxx
fe61d707532d52b9b91f5ab724f6330d39ac026a
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / MeshReader.cxx
1 #include "MeshReader.h"
2 #include <cpPlugins/Interface/Mesh.h>
3
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataReader.h>
6
7 #ifdef cpPlugins_Interface_QT4
8 #include <QFileDialog>
9 #endif // cpPlugins_Interface_QT4
10
11 // -------------------------------------------------------------------------
12 bool cpPlugins::IO::MeshReader::
13 ExecConfigurationDialog( QWidget* parent )
14 {
15   bool r = false;
16
17 #ifdef cpPlugins_Interface_QT4
18
19   // Show dialog and check if it was accepted
20   QFileDialog dialog( parent );
21   dialog.setFileMode( QFileDialog::ExistingFile );
22   dialog.setDirectory( QFileDialog::tr( "." ) );
23   dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
24   if( dialog.exec( ) )
25   {
26     this->m_Parameters = this->m_DefaultParameters;
27     QStringList names = dialog.selectedFiles( );
28     this->m_Parameters.SetValueAsString(
29       "FileName", names[ 0 ].toStdString( )
30       );
31
32     /* TODO
33        this->m_Parameters.SetValueAsString( "PixelType", "float" );
34        this->m_Parameters.SetValueAsUint( "Dimension", 3 );
35     */
36
37     r = true;
38
39   } // fi
40
41 #endif // cpPlugins_Interface_QT4
42
43   return( r );
44 }
45
46 // -------------------------------------------------------------------------
47 cpPlugins::IO::MeshReader::
48 MeshReader( )
49   : Superclass( )
50 {
51   this->SetNumberOfOutputs( 1 );
52   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
53
54   using namespace cpPlugins::Interface;
55   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
56   this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
57   this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
58   this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
59   this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
60   this->m_Parameters = this->m_DefaultParameters;
61 }
62
63 // -------------------------------------------------------------------------
64 cpPlugins::IO::MeshReader::
65 ~MeshReader( )
66 {
67 }
68
69 // -------------------------------------------------------------------------
70 std::string cpPlugins::IO::MeshReader::
71 _GenerateData( )
72 {
73   using namespace cpPlugins::Interface;
74   Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
75   std::string r = "MeshReader: Mesh dimension not supported.";
76   if( dim == 2 )
77     r = this->_GD0< 2 >( );
78   else if( dim == 3 )
79     r = this->_GD0< 3 >( );
80   return( r );
81 }
82
83 // -------------------------------------------------------------------------
84 template< unsigned int D >
85 std::string cpPlugins::IO::MeshReader::
86 _GD0( )
87 {
88   using namespace cpPlugins::Interface;
89   Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
90   std::string r = "MeshReader: Mesh pixel type not supported";
91   if( pt == "float" )       r = this->_GD1< float, D >( );
92   else if( pt == "double" ) r = this->_GD1< double, D >( );
93   return( r );
94 }
95
96 // -------------------------------------------------------------------------
97 template< class P, unsigned int D >
98 std::string cpPlugins::IO::MeshReader::
99 _GD1( )
100 {
101   // Get filename
102   using namespace cpPlugins::Interface;
103   Parameters::TString fname =
104     this->m_Parameters.GetValueAsString( "FileName" );
105
106   vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
107   pdr->SetFileName( fname.c_str( ) );
108   pdr->Update( );
109
110   cpPlugins::Interface::Mesh* out =
111     this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
112   if( out != NULL )
113     out->SetVTK( pdr->GetOutput( ) );
114   else
115     return( "MeshReader: output not correctly created." );
116   return( "" );
117 }
118
119 // eof - $RCSfile$