1 #include "MeshReader.h"
2 #include <cpPlugins/Interface/Mesh.h>
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataReader.h>
7 #ifdef cpPlugins_Interface_QT4
9 #endif // cpPlugins_Interface_QT4
11 // -------------------------------------------------------------------------
12 cpPlugins::IO::MeshReader::
13 DialogResult cpPlugins::IO::MeshReader::
14 ExecConfigurationDialog( QWidget* parent )
16 DialogResult r = Self::DialogResult_Cancel;
18 #ifdef cpPlugins_Interface_QT4
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 (*)" ) );
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 );
32 r = Self::DialogResult_NoModal;
36 #endif // cpPlugins_Interface_QT4
41 // -------------------------------------------------------------------------
42 cpPlugins::IO::MeshReader::
46 this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
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", 3 );
56 // -------------------------------------------------------------------------
57 cpPlugins::IO::MeshReader::
62 // -------------------------------------------------------------------------
63 std::string cpPlugins::IO::MeshReader::
66 using namespace cpPlugins::Interface;
67 Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
68 std::string r = "MeshReader: Mesh dimension not supported.";
70 r = this->_GD0< 2 >( );
72 r = this->_GD0< 3 >( );
76 // -------------------------------------------------------------------------
77 template< unsigned int D >
78 std::string cpPlugins::IO::MeshReader::
81 using namespace cpPlugins::Interface;
82 Parameters::TString pt =
83 this->m_Parameters->GetSelectedChoice( "PixelType" );
84 std::string r = "MeshReader: Mesh pixel type not supported";
85 if( pt == "float" ) r = this->_GD1< float, D >( );
86 else if( pt == "double" ) r = this->_GD1< double, D >( );
90 // -------------------------------------------------------------------------
91 template< class P, unsigned int D >
92 std::string cpPlugins::IO::MeshReader::
96 std::string fname = this->m_Parameters->GetString( "FileName" );
98 vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
99 pdr->SetFileName( fname.c_str( ) );
102 cpPlugins::Interface::Mesh* out =
103 this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
105 out->SetVTK( pdr->GetOutput( ) );
107 return( "MeshReader: output not correctly created." );