From 4f6c47b5d9994cd1bbb601bfe8bc087a0a619e72 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Fri, 2 Oct 2015 18:41:14 -0500 Subject: [PATCH] Widget integration (step 2/6). WARNING: IT DOES NOT COMPILE YETgit shortlog ! --- appli/ImageMPR/ImageMPR.cxx | 123 +++++++++++++----- appli/ImageMPR/ImageMPR.h | 28 ++-- .../Visualization/ImageSliceActors.cxx | 54 +++++++- .../Visualization/ImageSliceActors.h | 8 ++ lib/cpExtensions/Visualization/MPRObjects.cxx | 16 +++ lib/cpExtensions/Visualization/MPRObjects.h | 3 + lib/cpPlugins/Interface/CMakeLists.txt | 3 + lib/cpPlugins/Interface/DataObject.cxx | 5 +- lib/cpPlugins/Interface/DataObject.h | 8 +- lib/cpPlugins/Interface/ImplicitFunction.cxx | 95 ++++++++++++++ lib/cpPlugins/Interface/ImplicitFunction.h | 85 ++++++++++++ lib/cpPlugins/Interface/ImplicitFunction.hxx | 38 ++++++ lib/cpPlugins/Interface/ProcessObject.h | 7 + lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx | 76 +++++++++++ lib/cpPlugins/Plugins/BasicFilters/Cutter.h | 57 ++++++++ .../Plugins/BasicFilters/MarchingCubes.cxx | 1 + 16 files changed, 553 insertions(+), 54 deletions(-) create mode 100644 lib/cpPlugins/Interface/ImplicitFunction.cxx create mode 100644 lib/cpPlugins/Interface/ImplicitFunction.h create mode 100644 lib/cpPlugins/Interface/ImplicitFunction.hxx create mode 100644 lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx create mode 100644 lib/cpPlugins/Plugins/BasicFilters/Cutter.h diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 6cc4ed1..7fffc27 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -23,7 +23,10 @@ ImageMPR::ImageMPR( QWidget* parent ) m_UI( new Ui::ImageMPR ), m_ImageReaderClass( "" ), m_ImageWriterClass( "" ), - m_InputImage( NULL ) + m_MeshReaderClass( "" ), + m_MeshWriterClass( "" ), + m_MeshCutterClass( "" ), + m_Image( NULL ) { this->m_UI->setupUi( this ); @@ -60,6 +63,11 @@ ImageMPR::ImageMPR( QWidget* parent ) std::string( "cpPluginsIO." ) + std::string( PLUGIN_EXT ) ); + this->_LoadPlugins( + std::string( PLUGIN_PREFIX ) + + std::string( "cpPluginsBasicFilters." ) + + std::string( PLUGIN_EXT ) + ); } // ------------------------------------------------------------------------- @@ -84,6 +92,7 @@ _LoadPlugins( const std::string& filename ) this->m_ImageWriterClass = ""; this->m_MeshReaderClass = ""; this->m_MeshWriterClass = ""; + this->m_MeshCutterClass = ""; this->m_UI->MenuImageToImage->clear( ); this->m_UI->MenuImageToMesh->clear( ); @@ -106,6 +115,11 @@ _LoadPlugins( const std::string& filename ) this->m_MeshReaderClass = name; else if( category == "MeshWriter" ) this->m_MeshWriterClass = name; + else if( category == "MeshToMeshFilter" ) + { + if( name.find_last_of( "Cutter" ) != std::string::npos ) + this->m_MeshCutterClass = name; + } else if( category == "ImageToImageFilter" ) { QAction* action = @@ -174,6 +188,51 @@ _LoadImage( TPluginImage::Pointer& image ) return( ret ); } +// ------------------------------------------------------------------------- +std::string ImageMPR:: +_ConfigureMeshActors( ) +{ + if( this->m_Mesh.IsNull( ) ) + return( "Valid mesh not found." ); + + vtkActor* vtk_actor = this->m_Mesh->GetVTKActor( ); + if( vtk_actor != NULL ) + { + this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor ); + this->m_MPRObjects->Render( 4 ); + + } // fi + + TMPRObjects::TMPRActors* mprActors = this->m_MPRObjects->GetMPRActors( ); + + std::string err = ""; + for( unsigned int i = 0; i < 3; ++i ) + { + this->m_Cutters[ i ] = this->m_Plugins.CreateProcessObject( this->m_MeshCutterClass ); + this->m_Planes[ i ] = TPluginImplicitFunction::New( ); + this->m_Planes[ i ]->SetFunction( mprActors->GetSliceActors( i )->GetPlaneFunction( ) ); + this->m_Cutters[ i ]->SetInput( 0, this->m_Mesh ); + this->m_Cutters[ i ]->SetInput( 1, this->m_Planes[ i ] ); + std::string lerr = this->m_Cutters[ i ]->Update( ); + if( lerr == "" ) + { + vtkActor* actor = this->m_Cutters[ i ]->GetOutput< TPluginMesh >( 0 )->GetVTKActor( ); + mprActors->GetSliceActors( i )->AddActor( this->m_Cutters[ i ]->GetVTKAlgorithm( ), actor ); + if( i == 0 ) + this->m_MPRObjects->GetXRenderer( )->AddActor( actor ); + else if( i == 1 ) + this->m_MPRObjects->GetYRenderer( )->AddActor( actor ); + else if( i == 2 ) + this->m_MPRObjects->GetZRenderer( )->AddActor( actor ); + + } // fi + err += lerr; + + } // rof + this->m_MPRObjects->RenderAll( ); + return( err ); +} + // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionOpenPlugins( ) @@ -201,10 +260,10 @@ void ImageMPR:: _triggered_actionOpenInputImage( ) { // Read image - std::string err = this->_LoadImage( this->m_InputImage ); + std::string err = this->_LoadImage( this->m_Image ); if( err == "" ) { - vtkImageData* vtk_id = this->m_InputImage->GetVTKImageData( ); + vtkImageData* vtk_id = this->m_Image->GetVTKImageData( ); if( vtk_id != NULL ) { this->m_MPRObjects->SetImage( vtk_id ); @@ -231,7 +290,7 @@ _triggered_actionOpenInputImage( ) void ImageMPR:: _triggered_actionOpenSegmentation( ) { - if( this->m_InputImage.IsNull( ) ) + if( this->m_Image.IsNull( ) ) { QMessageBox::critical( this, @@ -243,10 +302,10 @@ _triggered_actionOpenSegmentation( ) } // fi // Read image - std::string err = this->_LoadImage( this->m_InputSegmentation ); + std::string err = this->_LoadImage( this->m_Segmentation ); if( err == "" ) { - vtkImageData* vtk_id = this->m_InputSegmentation->GetVTKImageData( ); + vtkImageData* vtk_id = this->m_Segmentation->GetVTKImageData( ); if( vtk_id != NULL ) { this->m_MPRObjects->AddAuxiliaryImage( vtk_id ); @@ -271,7 +330,7 @@ _triggered_actionOpenSegmentation( ) void ImageMPR:: _triggered_actionOpenInputPolyData( ) { - this->m_InputMesh = NULL; + this->m_Mesh = NULL; // Get a reader from plugins TPluginFilter::Pointer reader = @@ -292,24 +351,15 @@ _triggered_actionOpenInputPolyData( ) // Assign fresh mesh, if any if( err == "" ) { - this->m_InputMesh = reader->GetOutput< TPluginMesh >( 0 ); + this->m_Mesh = reader->GetOutput< TPluginMesh >( 0 ); reader->DisconnectOutputs( ); - if( this->m_InputMesh.IsNotNull( ) ) - { - vtkActor* vtk_actor = this->m_InputMesh->GetVTKActor( ); - if( vtk_actor != NULL ) - { - this->m_MPRObjects->Get3DRenderer( )->AddActor( vtk_actor ); - this->m_MPRObjects->Render( 4 ); - } - else - QMessageBox::critical( - this, - tr( "Error message" ), - tr( "Read mesh does not have a valid vtkActor." ) - ); - - } // fi + err = this->_ConfigureMeshActors( ); + if( err != "" ) + QMessageBox::critical( + this, + tr( "Error message" ), + tr( err.c_str( ) ) + ); } else QMessageBox::critical( @@ -332,7 +382,7 @@ _triggered_actionOpenInputPolyData( ) void ImageMPR:: _triggered_actionImageToImage( ) { - if( this->m_InputImage.IsNull( ) ) + if( this->m_Image.IsNull( ) ) return; // Get filter name @@ -351,7 +401,7 @@ _triggered_actionImageToImage( ) // Execute filter QApplication::setOverrideCursor( Qt::WaitCursor ); this->setEnabled( false ); - filter->SetInput( 0, this->m_InputImage ); + filter->SetInput( 0, this->m_Image ); std::string err = filter->Update( ); QApplication::restoreOverrideCursor( ); this->setEnabled( true ); @@ -361,9 +411,9 @@ _triggered_actionImageToImage( ) { TPluginImage* result = filter->GetOutput< TPluginImage >( 0 ); result->DisconnectPipeline( ); - this->m_InputImage = result; - if( this->m_InputImage.IsNotNull( ) ) - this->m_MPRObjects->SetImage( this->m_InputImage->GetVTKImageData( ) ); + this->m_Image = result; + if( this->m_Image.IsNotNull( ) ) + this->m_MPRObjects->SetImage( this->m_Image->GetVTKImageData( ) ); } else QMessageBox::critical( @@ -377,7 +427,7 @@ _triggered_actionImageToImage( ) void ImageMPR:: _triggered_actionImageToMesh( ) { - if( this->m_InputImage.IsNull( ) ) + if( this->m_Image.IsNull( ) ) return; // Get filter name @@ -396,7 +446,7 @@ _triggered_actionImageToMesh( ) // Execute filter QApplication::setOverrideCursor( Qt::WaitCursor ); this->setEnabled( false ); - filter->SetInput( 0, this->m_InputImage ); + filter->SetInput( 0, this->m_Image ); std::string err = filter->Update( ); QApplication::restoreOverrideCursor( ); this->setEnabled( true ); @@ -406,10 +456,13 @@ _triggered_actionImageToMesh( ) { TPluginMesh* result = filter->GetOutput< TPluginMesh >( 0 ); result->DisconnectPipeline( ); - this->m_InputMesh = result; - if( this->m_InputMesh.IsNotNull( ) ) - this->m_MPRObjects->Get3DRenderer( )->AddActor( - this->m_InputMesh->GetVTKActor( ) + this->m_Mesh = result; + err = this->_ConfigureMeshActors( ); + if( err != "" ) + QMessageBox::critical( + this, + tr( "Error message" ), + tr( err.c_str( ) ) ); } else diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index d82f026..82e2e19 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -14,6 +14,7 @@ #include #include #include +#include #include // ------------------------------------------------------------------------- @@ -32,13 +33,14 @@ class ImageMPR public: // Plugins types - typedef cpPlugins::Interface::Interface TPluginsInterface; - typedef cpPlugins::Interface::Object TPluginObject; - typedef cpPlugins::Interface::DataObject TPluginData; - typedef cpPlugins::Interface::Image TPluginImage; - typedef cpPlugins::Interface::Mesh TPluginMesh; - typedef cpPlugins::Interface::ProcessObject TPluginFilter; - typedef cpPlugins::Interface::Parameters TParameters; + typedef cpPlugins::Interface::Interface TPluginsInterface; + typedef cpPlugins::Interface::Object TPluginObject; + typedef cpPlugins::Interface::DataObject TPluginData; + typedef cpPlugins::Interface::Image TPluginImage; + typedef cpPlugins::Interface::ImplicitFunction TPluginImplicitFunction; + typedef cpPlugins::Interface::Mesh TPluginMesh; + typedef cpPlugins::Interface::ProcessObject TPluginFilter; + typedef cpPlugins::Interface::Parameters TParameters; typedef cpExtensions::Visualization::MPRObjects TMPRObjects; @@ -49,6 +51,7 @@ public: protected: bool _LoadPlugins( const std::string& filename ); std::string _LoadImage( TPluginImage::Pointer& image ); + std::string _ConfigureMeshActors( ); private slots: void _triggered_actionOpenPlugins( ); @@ -69,11 +72,16 @@ private: std::string m_ImageWriterClass; std::string m_MeshReaderClass; std::string m_MeshWriterClass; + std::string m_MeshCutterClass; // Real data - TPluginImage::Pointer m_InputImage; - TPluginImage::Pointer m_InputSegmentation; - TPluginMesh::Pointer m_InputMesh; + TPluginImage::Pointer m_Image; + TPluginImage::Pointer m_Segmentation; + TPluginMesh::Pointer m_Mesh; + + // Cutters + TPluginFilter::Pointer m_Cutters[ 3 ]; + TPluginImplicitFunction::Pointer m_Planes[ 3 ]; // Visualization stuff vtkSmartPointer< TMPRObjects > m_MPRObjects; diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index ef55f54..31787e5 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -50,12 +50,14 @@ Clear( ) // Delete all images this->SliceMappers.clear( ); this->ImageActors.clear( ); + this->OtherActors.clear( ); // Reconfigure unique objects - this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); - this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); - this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); + this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( ); + this->PlaneSource = vtkSmartPointer< vtkPolyData >::New( ); + this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); + this->TextActor = vtkSmartPointer< vtkTextActor >::New( ); + this->PlaneActor = vtkSmartPointer< vtkActor >::New( ); this->TextBuffer[ 0 ] = '\0'; // Unique objects configuration @@ -150,6 +152,28 @@ GetPlaneActor( ) const return( this->PlaneActor ); } +// ------------------------------------------------------------------------- +vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) +{ + return( this->PlaneFunction ); +} + +// ------------------------------------------------------------------------- +const vtkPlane* cpExtensions::Visualization::ImageSliceActors:: +GetPlaneFunction( ) const +{ + return( this->PlaneFunction ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AddActor( vtkAlgorithm* algorithm, vtkActor* actor ) +{ + this->OtherActors.push_back( std::pair< vtkSmartPointer< vtkAlgorithm >, vtkSmartPointer< vtkActor > >( algorithm, actor ) ); + this->AddItem( actor ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: SetInterpolate( bool v ) @@ -308,12 +332,17 @@ SetSliceNumber( const int& slice ) } // fi + // Plane function origin + this->PlaneFunction->SetOrigin( pos ); + + // Configure visualization and implicit plane orientation int axis = this->SliceMappers[ 0 ]->GetOrientation( ); this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( ); this->PlaneActor->GetProperty( )->SetLineWidth( 2 ); vtkPoints* plane_points = this->PlaneSource->GetPoints( ); if( axis == 0 ) // YZ, x-normal { + this->PlaneFunction->SetNormal( 1, 0, 0 ); plane_points->SetPoint( 0, pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ] ); plane_points->SetPoint( 1, pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] ); plane_points->SetPoint( 2, pos[ 0 ], ybnds[ 1 ], zbnds[ 1 ] ); @@ -322,6 +351,7 @@ SetSliceNumber( const int& slice ) } else if( axis == 1 ) // ZX, y-normal { + this->PlaneFunction->SetNormal( 0, 1, 0 ); plane_points->SetPoint( 0, xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] ); plane_points->SetPoint( 1, xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] ); plane_points->SetPoint( 2, xbnds[ 1 ], pos[ 1 ], zbnds[ 1 ] ); @@ -330,6 +360,7 @@ SetSliceNumber( const int& slice ) } else // XY, z-normal { + this->PlaneFunction->SetNormal( 0, 0, 1 ); plane_points->SetPoint( 0, xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] ); plane_points->SetPoint( 1, xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] ); plane_points->SetPoint( 2, xbnds[ 1 ], ybnds[ 1 ], pos[ 2 ] ); @@ -337,9 +368,24 @@ SetSliceNumber( const int& slice ) this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 ); } // fi + this->PlaneFunction->Modified( ); this->PlaneSource->Modified( ); this->PlaneMapper->Modified( ); this->PlaneActor->Modified( ); + + // Prepare other actors to update + for( unsigned int i = 0; i < this->OtherActors.size( ); ++i ) + { +#error CLEAN UP CODING STYLE AND NULL POINTER CHECK + + this->OtherActors[ i ].first->Modified( ); + this->OtherActors[ i ].first->Update( ); + this->OtherActors[ i ].second->GetMapper( )->Modified( ); + this->OtherActors[ i ].second->Modified( ); + + } // rof + + // Update text this->UpdateText( ); } diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 90b9ff0..091b7bc 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -3,11 +3,13 @@ #include +#include #include #include #include #include +#include #include #include #include @@ -49,6 +51,10 @@ namespace cpExtensions const vtkTextActor* GetTextActor( ) const; vtkActor* GetPlaneActor( ); const vtkActor* GetPlaneActor( ) const; + vtkPlane* GetPlaneFunction( ); + const vtkPlane* GetPlaneFunction( ) const; + + void AddActor( vtkAlgorithm* algorithm, vtkActor* actor ); void SetInterpolate( bool v ); void InterpolateOn( ); @@ -80,9 +86,11 @@ namespace cpExtensions // Multiple actors std::vector< vtkSmartPointer< vtkImageSliceMapper > > SliceMappers; std::vector< vtkSmartPointer< vtkImageActor > > ImageActors; + std::vector< std::pair< vtkSmartPointer< vtkAlgorithm >, vtkSmartPointer< vtkActor > > > OtherActors; bool Interpolate; // Unique objects + vtkSmartPointer< vtkPlane > PlaneFunction; vtkSmartPointer< vtkPolyData > PlaneSource; vtkSmartPointer< vtkPolyDataMapper > PlaneMapper; char TextBuffer[ 1024 ]; diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index 914c46d..a32824c 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -236,6 +236,22 @@ Get3DRenderer( ) const return( this->m_Renderers[ 3 ] ); } +// ------------------------------------------------------------------------- +cpExtensions::Visualization::MPRObjects:: +TMPRActors* cpExtensions::Visualization::MPRObjects:: +GetMPRActors( ) +{ + return( this->m_MPRActors ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::Visualization::MPRObjects:: +TMPRActors* cpExtensions::Visualization::MPRObjects:: +GetMPRActors( ) const +{ + return( this->m_MPRActors ); +} + // ------------------------------------------------------------------------- cpExtensions::Visualization::MPRObjects:: MPRObjects( ) diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index 1a81350..cbec46f 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -51,6 +51,9 @@ namespace cpExtensions const vtkRenderer* GetZRenderer( ) const; const vtkRenderer* Get3DRenderer( ) const; + TMPRActors* GetMPRActors( ); + const TMPRActors* GetMPRActors( ) const; + protected: MPRObjects( ); virtual ~MPRObjects( ); diff --git a/lib/cpPlugins/Interface/CMakeLists.txt b/lib/cpPlugins/Interface/CMakeLists.txt index a3990cc..8ee6221 100644 --- a/lib/cpPlugins/Interface/CMakeLists.txt +++ b/lib/cpPlugins/Interface/CMakeLists.txt @@ -15,6 +15,7 @@ SET( BaseProcessObjects.h DataObject.h Image.h + ImplicitFunction.h Interface.h Macros.h Mesh.h @@ -30,6 +31,7 @@ SET( SET( LIB_HEADERS_HXX Image.hxx + ImplicitFunction.hxx Mesh.hxx Parameters.hxx ProcessObject.hxx @@ -50,6 +52,7 @@ SET( BaseProcessObjects.cxx DataObject.cxx Image.cxx + ImplicitFunction.cxx Interface.cxx Mesh.cxx Object.cxx diff --git a/lib/cpPlugins/Interface/DataObject.cxx b/lib/cpPlugins/Interface/DataObject.cxx index 09df979..d68d2b7 100644 --- a/lib/cpPlugins/Interface/DataObject.cxx +++ b/lib/cpPlugins/Interface/DataObject.cxx @@ -65,7 +65,10 @@ DisconnectPipeline( ) // ------------------------------------------------------------------------- cpPlugins::Interface::DataObject:: DataObject( ) - : Superclass( ) + : Superclass( ), + m_ITKObject( NULL ), + m_VTKObject( NULL ), + m_Source( NULL ) { this->m_ClassName = "cpPlugins::Interface::DataObject"; this->m_ClassCategory = "BasicObject"; diff --git a/lib/cpPlugins/Interface/DataObject.h b/lib/cpPlugins/Interface/DataObject.h index c08b3a3..aad9977 100644 --- a/lib/cpPlugins/Interface/DataObject.h +++ b/lib/cpPlugins/Interface/DataObject.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include @@ -45,9 +45,9 @@ namespace cpPlugins Self& operator=( const Self& ); protected: - itk::DataObject::Pointer m_ITKObject; - vtkSmartPointer< vtkDataObject > m_VTKObject; - Object::Pointer m_Source; + itk::DataObject::Pointer m_ITKObject; + vtkSmartPointer< vtkObject > m_VTKObject; + Object::Pointer m_Source; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/ImplicitFunction.cxx b/lib/cpPlugins/Interface/ImplicitFunction.cxx new file mode 100644 index 0000000..1ffc516 --- /dev/null +++ b/lib/cpPlugins/Interface/ImplicitFunction.cxx @@ -0,0 +1,95 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_ImplicitFunction_DEF( T ) \ + void cpPlugins::Interface::ImplicitFunction::SetFunctionTo##T( ) \ + { \ + this->m_VTKObject = vtkSmartPointer< vtk##T >::New( ); \ + this->Modified( ); \ + } + +// ------------------------------------------------------------------------- +cpPlugins_Interface_ImplicitFunction_DEF( Box ); +cpPlugins_Interface_ImplicitFunction_DEF( Cone ); +cpPlugins_Interface_ImplicitFunction_DEF( Cylinder ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitBoolean ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitDataSet ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitHalo ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitPolyDataDistance ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitSelectionLoop ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitSum ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitVolume ); +cpPlugins_Interface_ImplicitFunction_DEF( ImplicitWindowFunction ); +cpPlugins_Interface_ImplicitFunction_DEF( PerlinNoise ); +cpPlugins_Interface_ImplicitFunction_DEF( Plane ); +cpPlugins_Interface_ImplicitFunction_DEF( Planes ); +cpPlugins_Interface_ImplicitFunction_DEF( PlanesIntersection ); +cpPlugins_Interface_ImplicitFunction_DEF( PolyPlane ); +cpPlugins_Interface_ImplicitFunction_DEF( Quadric ); +cpPlugins_Interface_ImplicitFunction_DEF( Sphere ); +cpPlugins_Interface_ImplicitFunction_DEF( Superquadric ); + +// ------------------------------------------------------------------------- +vtkImplicitFunction* cpPlugins::Interface::ImplicitFunction:: +GetVTKImplicitFunction( ) +{ + return( + dynamic_cast< vtkImplicitFunction* >( + this->m_VTKObject.GetPointer( ) + ) + ); +} + +// ------------------------------------------------------------------------- +const vtkImplicitFunction* cpPlugins::Interface::ImplicitFunction:: +GetVTKImplicitFunction( ) const +{ + return( + dynamic_cast< const vtkImplicitFunction* >( + this->m_VTKObject.GetPointer( ) + ) + ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ImplicitFunction:: +SetFunction( vtkImplicitFunction* function ) +{ + this->m_VTKObject = function; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ImplicitFunction:: +ImplicitFunction( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ImplicitFunction:: +~ImplicitFunction( ) +{ +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ImplicitFunction.h b/lib/cpPlugins/Interface/ImplicitFunction.h new file mode 100644 index 0000000..6b9c7ee --- /dev/null +++ b/lib/cpPlugins/Interface/ImplicitFunction.h @@ -0,0 +1,85 @@ +#ifndef __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__H__ +#define __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__H__ + +#include +#include + +#include + +#include +#include + +namespace cpPlugins +{ + namespace Interface + { + /** + */ + class cpPlugins_Interface_EXPORT ImplicitFunction + : public DataObject + { + public: + typedef ImplicitFunction Self; + typedef DataObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( ImplicitFunction, DataObject ); + + public: + template< class F > + inline F* GetITKImplicitFunction( ); + + template< class F > + inline const F* GetITKImplicitFunction( ) const; + + template< class F > + inline F* GetVTKImplicitFunction( ); + + template< class F > + inline const F* GetVTKImplicitFunction( ) const; + + virtual vtkImplicitFunction* GetVTKImplicitFunction( ); + virtual const vtkImplicitFunction* GetVTKImplicitFunction( ) const; + + void SetFunction( vtkImplicitFunction* function ); + + void SetFunctionToBox( ); + void SetFunctionToCone( ); + void SetFunctionToCylinder( ); + void SetFunctionToImplicitBoolean( ); + void SetFunctionToImplicitDataSet( ); + void SetFunctionToImplicitHalo( ); + void SetFunctionToImplicitPolyDataDistance( ); + void SetFunctionToImplicitSelectionLoop( ); + void SetFunctionToImplicitSum( ); + void SetFunctionToImplicitVolume( ); + void SetFunctionToImplicitWindowFunction( ); + void SetFunctionToPerlinNoise( ); + void SetFunctionToPlane( ); + void SetFunctionToPlanes( ); + void SetFunctionToPlanesIntersection( ); + void SetFunctionToPolyPlane( ); + void SetFunctionToQuadric( ); + void SetFunctionToSphere( ); + void SetFunctionToSuperquadric( ); + + protected: + ImplicitFunction( ); + virtual ~ImplicitFunction( ); + + private: + // Purposely not implemented + ImplicitFunction( const Self& ); + Self& operator=( const Self& ); + }; + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ImplicitFunction.hxx b/lib/cpPlugins/Interface/ImplicitFunction.hxx new file mode 100644 index 0000000..307d437 --- /dev/null +++ b/lib/cpPlugins/Interface/ImplicitFunction.hxx @@ -0,0 +1,38 @@ +#ifndef __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__HXX__ +#define __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__HXX__ + +// ------------------------------------------------------------------------- +template< class F > +F* cpPlugins::Interface::ImplicitFunction:: +GetITKImplicitFunction( ) +{ + return( dynamic_cast< F* >( this->m_ITKObject.GetPointer( ) ) ); +} + +// ------------------------------------------------------------------------- +template< class F > +const F* cpPlugins::Interface::ImplicitFunction:: +GetITKImplicitFunction( ) const +{ + return( dynamic_cast< const F* >( this->m_ITKObject.GetPointer( ) ) ); +} + +// ------------------------------------------------------------------------- +template< class F > +F* cpPlugins::Interface::ImplicitFunction:: +GetVTKImplicitFunction( ) +{ + return( dynamic_cast< F* >( this->m_VTKObject.GetPointer( ) ) ); +} + +// ------------------------------------------------------------------------- +template< class F > +const F* cpPlugins::Interface::ImplicitFunction:: +GetVTKImplicitFunction( ) const +{ + return( dynamic_cast< const F* >( this->m_VTKObject.GetPointer( ) ) ); +} + +#endif // __CPPLUGINS__INTERFACE__IMPLICITFUNCTION__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index 82492db..51cf067 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -15,6 +15,8 @@ typedef char QWidget #include +class vtkAlgorithm; + namespace cpPlugins { namespace Interface @@ -34,6 +36,11 @@ namespace cpPlugins itkTypeMacro( ProcessObject, Object ); public: + virtual vtkAlgorithm* GetVTKAlgorithm( ) + { return( NULL ); } + virtual const vtkAlgorithm* GetVTKAlgorithm( ) const + { return( NULL ); } + virtual const Parameters& GetDefaultParameters( ) const; virtual void SetParameters( const Parameters& params ); diff --git a/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx new file mode 100644 index 0000000..0ae95d5 --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx @@ -0,0 +1,76 @@ +#include "Cutter.h" +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +vtkAlgorithm* cpPlugins::BasicFilters::Cutter:: +GetVTKAlgorithm( ) +{ + return( this->m_Algorithm ); +} + +// ------------------------------------------------------------------------- +const vtkAlgorithm* cpPlugins::BasicFilters::Cutter:: +GetVTKAlgorithm( ) const +{ + return( this->m_Algorithm ); +} + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::Cutter:: +Cutter( ) + : Superclass( ), + m_Algorithm( NULL ) +{ + this->m_ClassName = "cpPlugins::BasicFilters::Cutter"; + this->m_ClassCategory = "MeshToMeshFilter"; + + this->SetNumberOfInputs( 2 ); + this->SetNumberOfOutputs( 1 ); + this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 ); + + this->m_Parameters = this->m_DefaultParameters; +} + +// ------------------------------------------------------------------------- +cpPlugins::BasicFilters::Cutter:: +~Cutter( ) +{ + if( this->m_Algorithm != NULL ) + this->m_Algorithm->Delete( ); +} + +// ------------------------------------------------------------------------- +std::string cpPlugins::BasicFilters::Cutter:: +_GenerateData( ) +{ + // Get inputs + cpPlugins::Interface::Mesh* mesh = + this->GetInput< cpPlugins::Interface::Mesh >( 0 ); + cpPlugins::Interface::ImplicitFunction* function = + this->GetInput< cpPlugins::Interface::ImplicitFunction >( 1 ); + if( function == NULL ) + return( "Cutter: Input data 1 is not a valid implicit function." ); + + if( this->m_Algorithm != NULL ) + this->m_Algorithm->Delete( ); + + vtkCutter* cutter = vtkCutter::New( ); + cutter->SetInputData( mesh->GetVTKMesh( ) ); + cutter->SetCutFunction( function->GetVTKImplicitFunction( ) ); + cutter->GenerateTrianglesOff( ); + this->m_Algorithm = cutter; + + // Execute filter + this->m_Algorithm->Update( ); + cpPlugins::Interface::Mesh* out = + this->GetOutput< cpPlugins::Interface::Mesh >( 0 ); + out->SetVTKMesh( this->m_Algorithm->GetOutput( ) ); + + return( "" ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/Cutter.h b/lib/cpPlugins/Plugins/BasicFilters/Cutter.h new file mode 100644 index 0000000..8887adc --- /dev/null +++ b/lib/cpPlugins/Plugins/BasicFilters/Cutter.h @@ -0,0 +1,57 @@ +#ifndef __CPPLUGINS__PLUGINS__CUTTER__H__ +#define __CPPLUGINS__PLUGINS__CUTTER__H__ + +#include +#include + +class vtkAlgorithm; +class vtkPolyDataAlgorithm; + +namespace cpPlugins +{ + namespace BasicFilters + { + /** + */ + class cpPluginsBasicFilters_EXPORT Cutter + : public cpPlugins::Interface::MeshToMeshFilter + { + public: + typedef Cutter Self; + typedef cpPlugins::Interface::MeshToMeshFilter Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + public: + itkNewMacro( Self ); + itkTypeMacro( Cutter, cpPluginsInterfaceMeshToMeshFilter ); + + public: + virtual vtkAlgorithm* GetVTKAlgorithm( ); + virtual const vtkAlgorithm* GetVTKAlgorithm( ) const; + + protected: + Cutter( ); + virtual ~Cutter( ); + + virtual std::string _GenerateData( ); + + private: + // Purposely not implemented + Cutter( const Self& ); + Self& operator=( const Self& ); + + protected: + vtkPolyDataAlgorithm* m_Algorithm; + }; + + // --------------------------------------------------------------------- + CPPLUGINS_INHERIT_PROVIDER( Cutter ); + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__PLUGINS__CUTTER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx index 38f7dbc..e061017 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.cxx @@ -61,6 +61,7 @@ _GenerateData( ) else if( vtk_image->GetDataDimension( ) == 3 ) { vtkMarchingCubes* mc = vtkMarchingCubes::New( ); + mc->ComputeNormalsOff( ); mc->SetInputData( vtk_image ); for( unsigned int i = 0; i < values.size( ); ++i ) mc->SetValue( i, values[ i ] ); -- 2.45.1