]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/IO/MeshReader.cxx
More tree visualization
[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     QStringList names = dialog.selectedFiles( );
27     this->m_Parameters->SetString( "FileName", names[ 0 ].toStdString( ) );
28     this->m_Parameters->SetSelectedChoice( "PixelType", "float" );
29     this->m_Parameters->SetUint( "Dimension", 3 );
30
31     r = true;
32
33   } // fi
34
35 #endif // cpPlugins_Interface_QT4
36
37   return( r );
38 }
39
40 // -------------------------------------------------------------------------
41 cpPlugins::IO::MeshReader::
42 MeshReader( )
43   : Superclass( )
44 {
45   this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
46
47   std::vector< TParameters::TString > valid_types;
48   valid_types.push_back( "float" );
49   valid_types.push_back( "double" );
50   this->m_Parameters->ConfigureAsString( "FileName", "" );
51   this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types );
52   this->m_Parameters->ConfigureAsUint( "Dimension", 3 );
53 }
54
55 // -------------------------------------------------------------------------
56 cpPlugins::IO::MeshReader::
57 ~MeshReader( )
58 {
59 }
60
61 // -------------------------------------------------------------------------
62 std::string cpPlugins::IO::MeshReader::
63 _GenerateData( )
64 {
65   using namespace cpPlugins::Interface;
66   Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
67   std::string r = "MeshReader: Mesh dimension not supported.";
68   if( dim == 2 )
69     r = this->_GD0< 2 >( );
70   else if( dim == 3 )
71     r = this->_GD0< 3 >( );
72   return( r );
73 }
74
75 // -------------------------------------------------------------------------
76 template< unsigned int D >
77 std::string cpPlugins::IO::MeshReader::
78 _GD0( )
79 {
80   using namespace cpPlugins::Interface;
81   Parameters::TString pt =
82     this->m_Parameters->GetSelectedChoice( "PixelType" );
83   std::string r = "MeshReader: Mesh pixel type not supported";
84   if( pt == "float" )       r = this->_GD1< float, D >( );
85   else if( pt == "double" ) r = this->_GD1< double, D >( );
86   return( r );
87 }
88
89 // -------------------------------------------------------------------------
90 template< class P, unsigned int D >
91 std::string cpPlugins::IO::MeshReader::
92 _GD1( )
93 {
94   // Get filename
95   std::string fname = this->m_Parameters->GetString( "FileName" );
96
97   vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
98   pdr->SetFileName( fname.c_str( ) );
99   pdr->Update( );
100
101   cpPlugins::Interface::Mesh* out =
102     this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
103   if( out != NULL )
104     out->SetVTK( pdr->GetOutput( ) );
105   else
106     return( "MeshReader: output not correctly created." );
107   return( "" );
108 }
109
110 // eof - $RCSfile$