1 #include "MeshReader.h"
2 #include <cpPlugins/Interface/Mesh.h>
4 #include <vtkPolyData.h>
5 #include <vtkPolyDataReader.h>
8 #ifdef cpPlugins_Interface_QT4
10 #endif // cpPlugins_Interface_QT4
12 // -------------------------------------------------------------------------
13 cpPlugins::IO::MeshReader::
14 DialogResult cpPlugins::IO::MeshReader::
15 ExecConfigurationDialog( QWidget* parent )
17 DialogResult r = Self::DialogResult_Cancel;
19 #ifdef cpPlugins_Interface_QT4
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 (*)" ) );
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 );
33 r = Self::DialogResult_NoModal;
37 #endif // cpPlugins_Interface_QT4
43 // -------------------------------------------------------------------------
44 cpPlugins::IO::MeshReader::
48 this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
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" );
57 this->m_Parameters->SetUint( "Dimension", 3 );
60 // -------------------------------------------------------------------------
61 cpPlugins::IO::MeshReader::
66 // -------------------------------------------------------------------------
67 std::string cpPlugins::IO::MeshReader::
70 using namespace cpPlugins::Interface;
71 Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
72 std::string r = "MeshReader: Mesh dimension not supported.";
74 r = this->_GD0< 2 >( );
76 r = this->_GD0< 3 >( );
80 // -------------------------------------------------------------------------
81 template< unsigned int D >
82 std::string cpPlugins::IO::MeshReader::
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 >( );
94 // -------------------------------------------------------------------------
95 template< class P, unsigned int D >
96 std::string cpPlugins::IO::MeshReader::
100 std::string fname = this->m_Parameters->GetOpenFileName( "FileName" );
102 vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
103 pdr->SetFileName( fname.c_str( ) );
106 auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
108 out->SetVTK( pdr->GetOutput( ) );
110 return( "MeshReader: output not correctly created." );