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