]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshReader.cxx
Widget integration (step 3/6). WARNING: IT DOES NOT COMPILE YET
[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.AddValueToStringList(
29       "FileNames", 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->m_ClassName = "cpPlugins::IO::MeshReader";
52   this->m_ClassCategory = "MeshReader";
53
54   this->SetNumberOfOutputs( 1 );
55   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
56
57   using namespace cpPlugins::Interface;
58   this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
59   this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
60   this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
61   this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
62   this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
63   this->m_Parameters = this->m_DefaultParameters;
64 }
65
66 // -------------------------------------------------------------------------
67 cpPlugins::IO::MeshReader::
68 ~MeshReader( )
69 {
70 }
71
72 // -------------------------------------------------------------------------
73 std::string cpPlugins::IO::MeshReader::
74 _GenerateData( )
75 {
76   using namespace cpPlugins::Interface;
77   Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
78   std::string r = "MeshReader: Mesh dimension not supported.";
79   if( dim == 2 )
80     r = this->_GD0< 2 >( );
81   else if( dim == 3 )
82     r = this->_GD0< 3 >( );
83   return( r );
84 }
85
86 // -------------------------------------------------------------------------
87 template< unsigned int D >
88 std::string cpPlugins::IO::MeshReader::
89 _GD0( )
90 {
91   using namespace cpPlugins::Interface;
92   Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
93   std::string r = "MeshReader: Mesh pixel type not supported";
94   if( pt == "float" )       r = this->_GD1< float, D >( );
95   else if( pt == "double" ) r = this->_GD1< double, D >( );
96   return( r );
97 }
98
99 // -------------------------------------------------------------------------
100 template< class P, unsigned int D >
101 std::string cpPlugins::IO::MeshReader::
102 _GD1( )
103 {
104   // Get filename
105   using namespace cpPlugins::Interface;
106   Parameters::TString fname =
107     this->m_Parameters.GetValueAsString( "FileName" );
108
109   vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
110   pdr->SetFileName( fname.c_str( ) );
111   pdr->Update( );
112
113   cpPlugins::Interface::Mesh* out =
114     this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
115   if( out != NULL )
116     out->SetVTK( pdr->GetOutput( ) );
117   else
118     return( "MeshReader: output not correctly created." );
119   return( "" );
120 }
121
122 // eof - $RCSfile$