]> Creatis software - cpPlugins.git/commitdiff
Examples with meshes (read and render, with and without plugins) added.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 10 Dec 2014 17:45:47 +0000 (18:45 +0100)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 10 Dec 2014 17:45:47 +0000 (18:45 +0100)
appli/examples/CMakeLists.txt
appli/examples/example_ReadQuadEdgeMesh.cxx [new file with mode: 0644]
appli/examples/example_RenderQuadEdgeMesh.cxx [new file with mode: 0644]
appli/examples/example_RenderQuadEdgeMeshWithoutPlugins.cxx [new file with mode: 0644]
lib/cpPlugins/Extensions/OpenGLMeshMapper.hxx
lib/cpPlugins/Interface/Mesh.cxx
lib/cpPlugins/Plugins/Host.cxx
lib/cpPlugins/Plugins/ImageReader.h
lib/cpPlugins/Plugins/MeshReader.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/MeshReader.h [new file with mode: 0644]

index ff76b4d6a39f64a67a7b6f072d4a279d4204e295..2a29508ba3c3735abf43fc9e602e6daba2751263 100644 (file)
@@ -8,7 +8,10 @@ SET(
   example_LoadPlugins
   example_ReadWriteImage
   example_ReadImageSeriesWriteImage
+  example_ReadQuadEdgeMesh
   example_ReadQuadEdgeMeshWithoutPlugins
+  example_RenderQuadEdgeMesh
+  example_RenderQuadEdgeMeshWithoutPlugins
   )
 
 FOREACH(prog ${EXAMPLES_PROGRAMS}) 
diff --git a/appli/examples/example_ReadQuadEdgeMesh.cxx b/appli/examples/example_ReadQuadEdgeMesh.cxx
new file mode 100644 (file)
index 0000000..655acad
--- /dev/null
@@ -0,0 +1,67 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <cpPlugins/Interface/Interface.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+
+int main( int argc, char* argv[] )
+{
+  if( argc < 5 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " plugins_file"
+      << " input_mesh"
+      << " dimensions pixel_type" << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string plugins_file = argv[ 1 ];
+  std::string input_mesh_file = argv[ 2 ];
+  std::string dimensions = argv[ 3 ];
+  std::string pixel_type = argv[ 4 ];
+
+  // Create interface
+  typedef cpPlugins::Interface::Interface TInterface;
+  typedef TInterface::TClasses            TClasses;
+
+  TInterface plugins;
+  plugins.Load( plugins_file );
+
+  // Create objects
+  typedef cpPlugins::Interface::ProcessObject TProcessObject;
+  typedef TProcessObject::TParameters         TParameters;
+  cpPlugins::Interface::ProcessObject* reader;
+
+  reader =
+    dynamic_cast< TProcessObject* >(
+      plugins.CreateObject( "cpPlugins::Plugins::MeshReader" )
+      );
+  if( reader == NULL )
+  {
+    std::cerr << "No suitable reader found in plugins." << std::endl;
+    return( 1 );
+
+  } // fi
+
+  // Configure reader
+  TParameters reader_params = reader->GetDefaultParameters( );
+  reader_params[ "FileName" ].second = input_mesh_file;
+  reader_params[ "PixelType" ].second = pixel_type;
+  reader_params[ "MeshDimension" ].second = dimensions;
+  reader->SetParameters( reader_params );
+
+  // Execute reader
+  std::string msg = reader->Update( );
+
+  if( msg != "" )
+    std::cerr << "ERROR: " << msg << std::endl;
+
+  // Free memory
+  delete reader;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$
diff --git a/appli/examples/example_RenderQuadEdgeMesh.cxx b/appli/examples/example_RenderQuadEdgeMesh.cxx
new file mode 100644 (file)
index 0000000..db1e1ab
--- /dev/null
@@ -0,0 +1,108 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <cpPlugins/Interface/Interface.h>
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Mesh.h>
+
+#include <vtkActor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
+
+int main( int argc, char* argv[] )
+{
+  if( argc < 5 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " plugins_file"
+      << " input_mesh"
+      << " dimensions pixel_type" << std::endl;
+    return( 1 );
+
+  } // fi
+  std::string plugins_file = argv[ 1 ];
+  std::string input_mesh_file = argv[ 2 ];
+  std::string dimensions = argv[ 3 ];
+  std::string pixel_type = argv[ 4 ];
+
+  // Create interface
+  typedef cpPlugins::Interface::Interface TInterface;
+  typedef TInterface::TClasses            TClasses;
+
+  TInterface plugins;
+  plugins.Load( plugins_file );
+
+  // Create objects
+  typedef cpPlugins::Interface::ProcessObject TProcessObject;
+  typedef TProcessObject::TParameters         TParameters;
+  cpPlugins::Interface::ProcessObject* reader;
+
+  reader =
+    dynamic_cast< TProcessObject* >(
+      plugins.CreateObject( "cpPlugins::Plugins::MeshReader" )
+      );
+  if( reader == NULL )
+  {
+    std::cerr << "No suitable reader found in plugins." << std::endl;
+    return( 1 );
+
+  } // fi
+
+  // Configure reader
+  TParameters reader_params = reader->GetDefaultParameters( );
+  reader_params[ "FileName" ].second = input_mesh_file;
+  reader_params[ "PixelType" ].second = pixel_type;
+  reader_params[ "MeshDimension" ].second = dimensions;
+  reader->SetParameters( reader_params );
+
+  // Execute reader
+  std::string msg = reader->Update( );
+
+  if( msg != "" )
+    std::cerr << "ERROR: " << msg << std::endl;
+
+  // Create actor
+  vtkSmartPointer< vtkActor > actor =
+    vtkSmartPointer< vtkActor >::New( );
+  actor->SetMapper(
+    dynamic_cast< cpPlugins::Interface::Mesh* >( reader->GetOutput( 0 ) )->
+    GetVTKMapper( )
+    );
+  actor->GetProperty( )->SetColor( 1, 1, 0 );
+  actor->GetProperty( )->SetOpacity( 0.5 );
+
+  // Configure visualization objects
+  vtkSmartPointer< vtkRenderer > renderer =
+    vtkSmartPointer< vtkRenderer >::New( );
+  renderer->SetBackground( 0.1, 0.3, 0.5 );
+
+  vtkSmartPointer< vtkRenderWindow > window =
+    vtkSmartPointer< vtkRenderWindow >::New( );
+  window->AddRenderer( renderer );
+  window->SetSize( 800, 800 );
+
+  // Set up the interaction
+  vtkSmartPointer< vtkRenderWindowInteractor > interactor =
+    vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+  window->SetInteractor( interactor );
+
+  // Associate actors
+  renderer->AddActor( actor );
+
+  // Begin interaction
+  window->Render( );
+  interactor->Start( );
+
+  // Free memory
+  delete reader;
+
+  return( 0 );
+}
+
+// eof - $RCSfile$
diff --git a/appli/examples/example_RenderQuadEdgeMeshWithoutPlugins.cxx b/appli/examples/example_RenderQuadEdgeMeshWithoutPlugins.cxx
new file mode 100644 (file)
index 0000000..35d9ab6
--- /dev/null
@@ -0,0 +1,78 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <cpPlugins/Extensions/QuadEdgeMesh.h>
+#include <cpPlugins/Extensions/MeshReader.h>
+#include <cpPlugins/Extensions/OpenGLMeshMapper.h>
+
+#include <vtkActor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+const unsigned int Dimension = 3;
+typedef float TScalar;
+typedef cpPlugins::Extensions::QuadEdgeMesh< TScalar, Dimension > TMesh;
+typedef cpPlugins::Extensions::OpenGLMeshMapper< TMesh > TMeshMapper;
+
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  if( argc < 2 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " input_mesh"
+      << std::endl;
+    return( 1 );
+
+  } // fi
+
+  typedef cpPlugins::Extensions::MeshReader< TMesh > TReader;
+  TReader::Pointer reader = TReader::New( );
+  reader->SetFileName( argv[ 1 ] );
+  reader->Update( );
+
+  // Map mesh
+  vtkSmartPointer< TMeshMapper > mapper =
+    vtkSmartPointer< TMeshMapper >::New( );
+  mapper->SetInputData( reader->GetOutput( ) );
+
+  // Create actor
+  vtkSmartPointer< vtkActor > actor =
+    vtkSmartPointer< vtkActor >::New( );
+  actor->SetMapper( mapper );
+  actor->GetProperty( )->SetColor( 1, 1, 0 );
+  actor->GetProperty( )->SetOpacity( 0.5 );
+
+  // Configure visualization objects
+  vtkSmartPointer< vtkRenderer > renderer =
+    vtkSmartPointer< vtkRenderer >::New( );
+  renderer->SetBackground( 0.1, 0.3, 0.5 );
+
+  vtkSmartPointer< vtkRenderWindow > window =
+    vtkSmartPointer< vtkRenderWindow >::New( );
+  window->AddRenderer( renderer );
+  window->SetSize( 800, 800 );
+
+  // Set up the interaction
+  vtkSmartPointer< vtkRenderWindowInteractor > interactor =
+    vtkSmartPointer< vtkRenderWindowInteractor >::New( );
+  window->SetInteractor( interactor );
+
+  // Associate actors
+  renderer->AddActor( actor );
+
+  // Begin interaction
+  window->Render( );
+  interactor->Start( );
+
+  return( 0 );
+}
+
+// eof - $RCSfile$
index 903cfc73cfd452c83765c821e5ca5fbcf449a5b2..3610b43353cfe77da830c49b3668efcfc057d6bc 100644 (file)
@@ -575,15 +575,13 @@ _ConfigureOpenGL( )
     unsigned int indId = 0;
     for( cIt = cells->Begin( ); cIt != cells->End( ); cIt++ )
     {
-      /* TODO
-         const typename M::TQuadEdgeCell* cell =
-         dynamic_cast< const typename M::TQuadEdgeCell* >( cIt.Value( ) );
-         const typename M::TPrimalEdge* edge =
-         cell->GetEntryPrimalEdge( );
-         typename M::TPrimalEdge::ConstIterator iIt = edge->BeginLnext( );
-         for( ; iIt != edge->EndLnext( ); ++iIt )
-         this->Indices[ indId++ ] = ( *iIt )->GetOrigin( );
-      */
+      const typename M::TQuadEdgeCell* cell =
+        dynamic_cast< const typename M::TQuadEdgeCell* >( cIt.Value( ) );
+      const typename M::TPrimalEdge* edge =
+        cell->GetEntryPrimalEdge( );
+      typename M::TPrimalEdge::ConstIterator iIt = edge->BeginLnext( );
+      for( ; iIt != edge->EndLnext( ); ++iIt )
+        this->Indices[ indId++ ] = ( *iIt )->GetOrigin( );
 
     } // fi
 
index 07bd28d434f87f9ae791e0e9c1877dbcb3b740b1..3bcb5afaa043e06f650bd07746055cad3578b101 100644 (file)
@@ -63,56 +63,7 @@ _Map( )
   M* mesh = dynamic_cast< M* >( this->Superclass::GetDataObject( ) );
   _TMapper* mapper = _TMapper::New( );
   mapper->SetInputData( mesh );
-  mapper->Update( );
   this->m_Mapper = mapper;
 }
 
-// -------------------------------------------------------------------------
-/* TODO
-template< unsigned int D >
-void cpPlugins::Interface::Mesh::
-_ConnectToVTK_0( )
-{
-  itk::DataObject* dobj = this->Superclass::GetDataObject( );
-
-  cpPlugins_Interface_Mesh_Pixel( char, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( short, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( int, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( long, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( unsigned char, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( unsigned short, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( unsigned int, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( unsigned long, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( float, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_Pixel( double, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( char, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( short, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( int, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( long, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( unsigned char, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( unsigned short, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( unsigned int, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( unsigned long, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( float, D, dobj, _ConnectToVTK_1 );
-  else cpPlugins_Interface_Mesh_RGB( double, D, dobj, _ConnectToVTK_1 );
-}
-
-// -------------------------------------------------------------------------
-template< class P, unsigned int D >
-void cpPlugins::Interface::Mesh::
-_ConnectToVTK_1( )
-{
-  typedef itk::Mesh< P, D > _TMesh;
-  typedef itk::MeshToVTKMeshFilter< _TMesh > _TFilter;
-
-  _TMesh* img =
-    dynamic_cast< _TMesh* >( this->Superclass::GetDataObject( ) );
-  typename _TFilter::Pointer filter = _TFilter::New( );
-  filter->SetInput( img );
-  filter->Update( );
-  this->m_VTKMeshData = filter->GetOutput( );
-  this->m_Mesh2VTKMeshData = filter;
-}
-*/
-
 // eof - $RCSfile$
index 37e48b095912ab324aaaff35462e0ae4da002b8a..aab20638a20e6a5c16c284939bbf7a03e7edf2c9 100644 (file)
@@ -3,6 +3,7 @@
 #include <cpPlugins/Plugins/ImageSeriesReader.h>
 #include <cpPlugins/Plugins/ImageWriter.h>
 #include <cpPlugins/Plugins/MarchingCubes.h>
+#include <cpPlugins/Plugins/MeshReader.h>
 
 /// TODO: doc
 PLUMA_CONNECTOR
@@ -12,6 +13,7 @@ bool connect( pluma::Host& host )
   host.add( new cpPlugins::Plugins::ImageSeriesReaderProvider( ) );
   host.add( new cpPlugins::Plugins::ImageWriterProvider( ) );
   host.add( new cpPlugins::Plugins::MarchingCubesProvider( ) );
+  host.add( new cpPlugins::Plugins::MeshReaderProvider( ) );
   return( true );
 }
 
index ce0055fd8566bcfb1a7c62081a4179379dac9682..39d243b4ae8a7aa1fc816d0f5dcda4a099b2e490 100644 (file)
@@ -28,7 +28,6 @@ namespace cpPlugins
       virtual std::string GetClassName( ) const;
 
     protected:
-
       virtual std::string _GenerateData( );
 
       template< unsigned int D >
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$
diff --git a/lib/cpPlugins/Plugins/MeshReader.h b/lib/cpPlugins/Plugins/MeshReader.h
new file mode 100644 (file)
index 0000000..968c4ac
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef __CPPLUGINS__PLUGINS__MESHREADER__H__
+#define __CPPLUGINS__PLUGINS__MESHREADER__H__
+
+#include <cpPlugins/Plugins/cpPlugins_Export.h>
+#include <cpPlugins/Interface/SourceObject.h>
+#include <itkProcessObject.h>
+
+namespace cpPlugins
+{
+  namespace Plugins
+  {
+    /**
+     */
+    class cpPlugins_EXPORT MeshReader
+      : public cpPlugins::Interface::SourceObject
+    {
+    public:
+      typedef MeshReader                         Self;
+      typedef cpPlugins::Interface::SourceObject Superclass;
+
+      typedef Superclass::TParameter  TParameter;
+      typedef Superclass::TParameters TParameters;
+
+    public:
+      MeshReader( );
+      virtual ~MeshReader( );
+
+      virtual std::string GetClassName( ) const;
+
+    protected:
+      virtual std::string _GenerateData( );
+
+      template< unsigned int D >
+        std::string _GD0( );
+
+      template< class P, unsigned int D >
+        std::string _GD1( );
+
+    protected:
+      itk::ProcessObject::Pointer m_Reader;
+    };
+
+    // ---------------------------------------------------------------------
+    PLUMA_INHERIT_PROVIDER( MeshReader, cpPlugins::Interface::Object );
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__MESHREADER__H__
+
+// eof - $RCSfile$