]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/MeshReader.cxx
...
[cpPlugins.git] / lib / cpPlugins / Plugins / MeshReader.cxx
index 17d668c5594fe6b9eae73f7012675315196a760c..e658d8611b0fa69d998a85fd2c83fb79dca11210 100644 (file)
@@ -1,21 +1,27 @@
 #include <cpPlugins/Plugins/MeshReader.h>
 #include <cpPlugins/Interface/Mesh.h>
 
-#include <cpPlugins/Extensions/QuadEdgeMesh.h>
-#include <cpPlugins/Extensions/MeshReader.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataReader.h>
 
 // -------------------------------------------------------------------------
 cpPlugins::Plugins::MeshReader::
 MeshReader( )
   : Superclass( )
 {
+  this->m_ClassName = "cpPlugins::MeshReader";
+  this->m_ClassCategory = "MeshReader";
+
   this->SetNumberOfOutputs( 1 );
   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
 
-  this->m_DefaultParameters[ "FileName" ] =
-    TParameter( "string", "no_file_name" );
-  this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "float" );
-  this->m_DefaultParameters[ "MeshDimension" ] = TParameter( "int", "3" );
+  using namespace cpPlugins::Interface;
+  this->m_DefaultParameters.Configure( Parameters::String, "FileName" );
+  this->m_DefaultParameters.Configure( Parameters::String, "PixelType" );
+  this->m_DefaultParameters.Configure( Parameters::Uint, "Dimension" );
+  this->m_DefaultParameters.SetValueAsString( "PixelType", "float" );
+  this->m_DefaultParameters.SetValueAsUint( "Dimension", 3 );
+  this->m_Parameters = this->m_DefaultParameters;
 }
 
 // -------------------------------------------------------------------------
@@ -24,27 +30,17 @@ cpPlugins::Plugins::MeshReader::
 {
 }
 
-// -------------------------------------------------------------------------
-std::string cpPlugins::Plugins::MeshReader::
-GetClassName( ) const
-{
-  return( "cpPlugins::Plugins::MeshReader" );
-}
-
 // -------------------------------------------------------------------------
 std::string cpPlugins::Plugins::MeshReader::
 _GenerateData( )
 {
-  TParameters::const_iterator dIt;
-
-  // Get image dimension
-  dIt = this->m_Parameters.find( "MeshDimension" );
-  if( dIt == this->m_Parameters.end( ) )
-    dIt = this->m_DefaultParameters.find( "MeshDimension" );
-
-  std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh dimension not supported.";
-  if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
-
+  using namespace cpPlugins::Interface;
+  Parameters::TUint dim = this->m_Parameters.GetValueAsUint( "Dimension" );
+  std::string r = "MeshReader: Mesh dimension not supported.";
+  if( dim == 2 )
+    r = this->_GD0< 2 >( );
+  else if( dim == 3 )
+    r = this->_GD0< 3 >( );
   return( r );
 }
 
@@ -53,18 +49,11 @@ template< unsigned int D >
 std::string cpPlugins::Plugins::MeshReader::
 _GD0( )
 {
-  TParameters::const_iterator tIt, cIt;
-
-  // Get image pixel type
-  tIt = this->m_Parameters.find( "PixelType" );
-  if( tIt == this->m_Parameters.end( ) )
-    tIt = this->m_DefaultParameters.find( "PixelType" );
-
-  std::string r = "cpPlugins::Plugins::MeshReader: itk::Mesh pixel type not supported";
-  if( tIt->second.second == "float" )
-    r = this->_GD1< float, D >( );
-  else if( tIt->second.second == "double" )
-    r = this->_GD1< double, D >( );
+  using namespace cpPlugins::Interface;
+  Parameters::TString pt = this->m_Parameters.GetValueAsString( "PixelType" );
+  std::string r = "MeshReader: Mesh pixel type not supported";
+  if( pt == "float" )       r = this->_GD1< float, D >( );
+  else if( pt == "double" ) r = this->_GD1< double, D >( );
   return( r );
 }
 
@@ -73,36 +62,25 @@ template< class P, unsigned int D >
 std::string cpPlugins::Plugins::MeshReader::
 _GD1( )
 {
-  TParameters::const_iterator fIt;
-
   // Get filename
-  fIt = this->m_Parameters.find( "FileName" );
-  if( fIt == this->m_Parameters.end( ) )
-    fIt = this->m_DefaultParameters.find( "FileName" );
-
-  typedef cpPlugins::Extensions::QuadEdgeMesh< P, D > _TMesh;
-  typedef cpPlugins::Extensions::MeshReader< _TMesh > _TReader;
-
-  _TReader* reader =
-    dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
-  if( reader == NULL )
-  {
-    this->m_Reader = _TReader::New( );
-    reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
-
-  } // fi
-  reader->SetFileName( fIt->second.second );
-  try
-  {
-    reader->Update( );
-  }
-  catch( itk::ExceptionObject& err )
-  {
-    return( err.GetDescription( ) );
-
-  } // yrt
-  this->_SetOutput( 0, reader->GetOutput( ) );
-
+  using namespace cpPlugins::Interface;
+  Parameters::TString fname =
+    this->m_Parameters.GetValueAsString( "FileName" );
+
+  if( this->m_Reader != NULL )
+    this->m_Reader->Delete( );
+
+  vtkPolyDataReader* pdr = vtkPolyDataReader::New( );
+  this->m_Reader = pdr;
+  pdr->SetFileName( fname.c_str( ) );
+  pdr->Update( );
+
+  cpPlugins::Interface::Mesh* out =
+    this->_Output< cpPlugins::Interface::Mesh >( 0 );
+  if( out != NULL )
+    out->SetVTKMesh( pdr->GetOutput( ) );
+  else
+    return( "MeshReader: output not correctly created." );
   return( "" );
 }