]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/IO/MeshReader.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / IO / MeshReader.cxx
index f8c3b84483a96a6b79be61bf9a11eb056fddcd48..943d3ac6badb87b07d77833a75dc30ac72274212 100644 (file)
@@ -1,56 +1,31 @@
 #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)"
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -93,19 +68,41 @@ std::string cpPlugins::IO::MeshReader::
 _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 )
+  // 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" );
+    out->SetVTK( stlr->GetOutput( ) );
+    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" );
     out->SetVTK( pdr->GetOutput( ) );
-  else
-    return( "MeshReader: output not correctly created." );
-  return( "" );
+    return( "" );
+
+  } // fi
 }
 
 // eof - $RCSfile$