#include "MeshReader.h"
#include <cpPlugins/Interface/Mesh.h>
+#include <cstring>
+
#include <vtkPolyData.h>
#include <vtkPolyDataReader.h>
-
-#ifdef cpPlugins_Interface_QT4
-#include <QFileDialog>
-#endif // cpPlugins_Interface_QT4
-
-// -------------------------------------------------------------------------
-cpPlugins::IO::MeshReader::
-DialogResult cpPlugins::IO::MeshReader::
-ExecConfigurationDialog( QWidget* parent )
-{
- DialogResult r = Self::DialogResult_Cancel;
-
-#ifdef cpPlugins_Interface_QT4
-
- // Show dialog and check if it was accepted
- QFileDialog dialog( parent );
- dialog.setFileMode( QFileDialog::ExistingFile );
- dialog.setDirectory( QFileDialog::tr( "." ) );
- dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) );
- if( dialog.exec( ) )
- {
- QStringList names = dialog.selectedFiles( );
- this->m_Parameters->SetString( "FileName", names[ 0 ].toStdString( ) );
- this->m_Parameters->SetSelectedChoice( "PixelType", "float" );
- this->m_Parameters->SetUint( "Dimension", 3 );
-
- r = Self::DialogResult_NoModal;
-
- } // fi
-
-#endif // cpPlugins_Interface_QT4
-
- return( r );
-}
+#include <vtkSTLReader.h>
// -------------------------------------------------------------------------
cpPlugins::IO::MeshReader::
MeshReader( )
: Superclass( )
{
- this->_MakeOutput< cpPlugins::Interface::Mesh >( "Output" );
+ this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
std::vector< TParameters::TString > valid_types;
valid_types.push_back( "float" );
valid_types.push_back( "double" );
- this->m_Parameters->ConfigureAsString( "FileName", "" );
+ this->m_Parameters->ConfigureAsOpenFileName( "FileName" );
this->m_Parameters->ConfigureAsChoices( "PixelType", valid_types );
- this->m_Parameters->ConfigureAsUint( "Dimension", 3 );
+ this->m_Parameters->ConfigureAsUint( "Dimension" );
+
+ this->m_Parameters->SetUint( "Dimension", 3 );
+ this->m_Parameters->SetAcceptedFileExtensions(
+ "FileName",
+ "Mesh files (*.vtk *.stl *.obj)"
+ );
}
// -------------------------------------------------------------------------
_GD1( )
{
// Get filename
- std::string fname = this->m_Parameters->GetString( "FileName" );
+ std::string fname = this->m_Parameters->GetOpenFileName( "FileName" );
- vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
- pdr->SetFileName( fname.c_str( ) );
- pdr->Update( );
+ // Get file extension
+ std::istringstream fname_str( fname );
+ std::string token, ext;
+ while( std::getline( fname_str, token, '.' ) )
+ ext = token;
+ std::transform( ext.begin( ), ext.end( ), ext.begin( ), tolower );
- cpPlugins::Interface::Mesh* out =
- this->GetOutput< cpPlugins::Interface::Mesh >( "Output" );
- if( out != NULL )
- out->SetVTK( pdr->GetOutput( ) );
- else
- return( "MeshReader: output not correctly created." );
- return( "" );
+ // Real read
+ if( ext == "stl" )
+ {
+ vtkSTLReader* stlr = this->_CreateVTK< vtkSTLReader >( );
+ stlr->SetFileName( fname.c_str( ) );
+ stlr->Update( );
+
+ auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
+ if( out != NULL )
+ out->SetVTK( stlr->GetOutput( ) );
+ else
+ return( "MeshReader: output not correctly created." );
+ return( "" );
+ }
+ else if( ext == "obj" )
+ {
+ // TODO
+ }
+ else if( ext == "vtk" )
+ {
+ vtkPolyDataReader* pdr = this->_CreateVTK< vtkPolyDataReader >( );
+ pdr->SetFileName( fname.c_str( ) );
+ pdr->Update( );
+
+ auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
+ if( out != NULL )
+ out->SetVTK( pdr->GetOutput( ) );
+ else
+ return( "MeshReader: output not correctly created." );
+ return( "" );
+
+ } // fi
}
// eof - $RCSfile$