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