From: Leonardo Florez-Valencia Date: Wed, 10 Dec 2014 17:45:47 +0000 (+0100) Subject: Examples with meshes (read and render, with and without plugins) added. X-Git-Tag: v0.1~443 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d97da4c5884307e660b0ed9135f87cffff174b93;p=cpPlugins.git Examples with meshes (read and render, with and without plugins) added. --- diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index ff76b4d..2a29508 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -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 index 0000000..655acad --- /dev/null +++ b/appli/examples/example_ReadQuadEdgeMesh.cxx @@ -0,0 +1,67 @@ +#include +#include +#include + +#include +#include + +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 index 0000000..db1e1ab --- /dev/null +++ b/appli/examples/example_RenderQuadEdgeMesh.cxx @@ -0,0 +1,108 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +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 index 0000000..35d9ab6 --- /dev/null +++ b/appli/examples/example_RenderQuadEdgeMeshWithoutPlugins.cxx @@ -0,0 +1,78 @@ +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +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$ diff --git a/lib/cpPlugins/Extensions/OpenGLMeshMapper.hxx b/lib/cpPlugins/Extensions/OpenGLMeshMapper.hxx index 903cfc7..3610b43 100644 --- a/lib/cpPlugins/Extensions/OpenGLMeshMapper.hxx +++ b/lib/cpPlugins/Extensions/OpenGLMeshMapper.hxx @@ -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 diff --git a/lib/cpPlugins/Interface/Mesh.cxx b/lib/cpPlugins/Interface/Mesh.cxx index 07bd28d..3bcb5af 100644 --- a/lib/cpPlugins/Interface/Mesh.cxx +++ b/lib/cpPlugins/Interface/Mesh.cxx @@ -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$ diff --git a/lib/cpPlugins/Plugins/Host.cxx b/lib/cpPlugins/Plugins/Host.cxx index 37e48b0..aab2063 100644 --- a/lib/cpPlugins/Plugins/Host.cxx +++ b/lib/cpPlugins/Plugins/Host.cxx @@ -3,6 +3,7 @@ #include #include #include +#include /// 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 ); } diff --git a/lib/cpPlugins/Plugins/ImageReader.h b/lib/cpPlugins/Plugins/ImageReader.h index ce0055f..39d243b 100644 --- a/lib/cpPlugins/Plugins/ImageReader.h +++ b/lib/cpPlugins/Plugins/ImageReader.h @@ -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 index 0000000..17d668c --- /dev/null +++ b/lib/cpPlugins/Plugins/MeshReader.cxx @@ -0,0 +1,109 @@ +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +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 index 0000000..968c4ac --- /dev/null +++ b/lib/cpPlugins/Plugins/MeshReader.h @@ -0,0 +1,52 @@ +#ifndef __CPPLUGINS__PLUGINS__MESHREADER__H__ +#define __CPPLUGINS__PLUGINS__MESHREADER__H__ + +#include +#include +#include + +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$