]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Plugins/MeshReader.cxx
Examples with meshes (read and render, with and without plugins) added.
[cpPlugins.git] / lib / cpPlugins / Plugins / MeshReader.cxx
diff --git a/lib/cpPlugins/Plugins/MeshReader.cxx b/lib/cpPlugins/Plugins/MeshReader.cxx
new file mode 100644 (file)
index 0000000..17d668c
--- /dev/null
@@ -0,0 +1,109 @@
+#include <cpPlugins/Plugins/MeshReader.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+#include <cpPlugins/Extensions/QuadEdgeMesh.h>
+#include <cpPlugins/Extensions/MeshReader.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::MeshReader::
+MeshReader( )
+  : Superclass( )
+{
+  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" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Plugins::MeshReader::
+~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 >( );
+
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+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 >( );
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+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( ) );
+
+  return( "" );
+}
+
+// eof - $RCSfile$