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" );
55 this->m_Parameters->SetUint( "Dimension", 3 );
58 // -------------------------------------------------------------------------
59 cpPlugins::IO::MeshReader::
64 // -------------------------------------------------------------------------
65 std::string cpPlugins::IO::MeshReader::
68 using namespace cpPlugins::Interface;
69 Parameters::TUint dim = this->m_Parameters->GetUint( "Dimension" );
70 std::string r = "MeshReader: Mesh dimension not supported.";
72 r = this->_GD0< 2 >( );
74 r = this->_GD0< 3 >( );
78 // -------------------------------------------------------------------------
79 template< unsigned int D >
80 std::string cpPlugins::IO::MeshReader::
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 >( );
92 // -------------------------------------------------------------------------
93 template< class P, unsigned int D >
94 std::string cpPlugins::IO::MeshReader::
98 std::string fname = this->m_Parameters->GetString( "FileName" );
100 vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
101 pdr->SetFileName( fname.c_str( ) );
104 cpPlugins::Interface::Mesh* out =
105 this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
107 out->SetVTK( pdr->GetOutput( ) );
109 return( "MeshReader: output not correctly created." );