From 427bc1753f9db20528ba5e89c46997ee12985a5a Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Thu, 21 Apr 2016 11:47:34 -0500 Subject: [PATCH] ... --- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 10 ++ lib/cpExtensions/QT/SimpleMPRWidget.h | 8 +- plugins/cpPluginsWidgets/SeedWidget.cxx | 180 +++++++++++++----------- plugins/cpPluginsWidgets/SeedWidget.h | 27 +++- 4 files changed, 134 insertions(+), 91 deletions(-) diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index d335f53..911921b 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -169,6 +169,16 @@ AddMesh( vtkPolyData* mesh ) this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); } +// ------------------------------------------------------------------------- +vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget:: +GetInteractor( unsigned int i ) +{ + if( i < 4 ) + return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) ); + else + return( NULL ); +} + // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: _SyncBottom( int a, int b ) diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.h b/lib/cpExtensions/QT/SimpleMPRWidget.h index 42a09f6..5aed9ec 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.h +++ b/lib/cpExtensions/QT/SimpleMPRWidget.h @@ -110,7 +110,11 @@ namespace cpExtensions void Clear( ); void SetMainImage( vtkImageData* image ); void AddMesh( vtkPolyData* mesh ); - + + // Visual objects + vtkRenderWindowInteractor* GetInteractor( unsigned int i ); + + /* TODO unsigned int GetNumberOfData( ) const; bool AddData( @@ -136,8 +140,6 @@ namespace cpExtensions double GetWindow( ) const; double GetLevel( ) const; - vtkRenderWindowInteractor* GetInteractor( unsigned int i ); - // Visual objects accessors std::string GetSelectedData( ) const; vtkProp* GetProp( const std::string& name ); diff --git a/plugins/cpPluginsWidgets/SeedWidget.cxx b/plugins/cpPluginsWidgets/SeedWidget.cxx index 9e7a408..64069e4 100644 --- a/plugins/cpPluginsWidgets/SeedWidget.cxx +++ b/plugins/cpPluginsWidgets/SeedWidget.cxx @@ -1,19 +1,47 @@ #include "SeedWidget.h" -#include -#include -#include -#include +#include #include -#include -#include +#include + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SeedWidget::WidgetData:: +Configure( vtkRenderWindowInteractor* interactor, vtkImageActor* actor ) +{ + this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( ); + this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + this->Seed = vtkSmartPointer< vtkSeedRepresentation >::New( ); + this->Widget = + vtkSmartPointer< cpExtensions::Interaction::SeedWidget >::New( ); + + this->Placer->SetImageActor( actor ); + this->Handle->GetProperty( )->SetColor( 1, 0, 0 ); + this->Handle->SetPointPlacer( this->Placer ); + this->Seed->SetHandleRepresentation( this->Handle ); + this->Widget->SetRepresentation( this->Seed ); + this->Widget->SetInteractor( interactor ); +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SeedWidget::WidgetData:: +On( ) +{ + this->Widget->On( ); +} + +// ------------------------------------------------------------------------- +void cpPluginsWidgets::SeedWidget::WidgetData:: +Off( ) +{ + this->Widget->Off( ); +} // ------------------------------------------------------------------------- itk::ModifiedTimeType cpPluginsWidgets::SeedWidget:: GetMTime( ) const { - // std::cout << "Seed GetMTime" << std::endl; - return( 0 /*this->Superclass::GetMTime( )*/ ); + this->Modified( ); + return( this->Superclass::GetMTime( ) ); } // ------------------------------------------------------------------------- @@ -22,7 +50,6 @@ SeedWidget( ) : Superclass( ), m_Configured( false ) { - this->_AddInput( "ReferenceImage" ); this->_AddOutput< cpPlugins::DataObject >( "Output" ); } @@ -36,94 +63,75 @@ cpPluginsWidgets::SeedWidget:: void cpPluginsWidgets::SeedWidget:: _GenerateData( ) { - auto image = this->GetInputData< itk::DataObject >( "ReferenceImage" ); - cpPlugins_Image_Demangle_Dim ( _GD0, image, 2 ); - else cpPlugins_Image_Demangle_Dim( _GD0, image, 3 ); - else this->_Error( "No valid input image." ); -} - -// ------------------------------------------------------------------------- -template< class _TImage > -void cpPluginsWidgets::SeedWidget:: -_GD0( _TImage* image ) -{ - - /* - typedef - cpExtensions::DataStructures::ImageIndexesContainer< _TImage::ImageDimension > - _TContainer; - typedef cpExtensions::Interaction::ImageInteractorStyle _S; - - if( image != NULL ) - { - auto container = this->_CreateITK< _TContainer >( ); - double aux_pnt[ 3 ]; - unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - container->Get( ).clear( ); - - // MPR - if( this->m_MPRViewer != NULL ) - { - for( unsigned int i = 0; i < 4; ++i ) - { - _S* s = - dynamic_cast< _S* >( - this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( ) - ); - if( s != NULL ) - { - if( this->m_Configured ) + if( this->m_Configured ) + { + auto points = this->_CreateVTK< vtkPoints >( ); + for( + auto wIt = this->m_Widgets.begin( ); + wIt != this->m_Widgets.end( ); + ++wIt + ) { - for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) - { - s->GetSeedAsPoint( i, aux_pnt ); - typename _TImage::PointType seed; - for( unsigned int d = 0; d < dim; ++d ) - seed[ d ] = aux_pnt[ d ]; - typename _TImage::IndexType idx; - if( image->TransformPhysicalPointToIndex( seed, idx ) ) - container->Get( ).push_back( idx ); + double pos[ 3 ]; + for( unsigned int i = 0; i < wIt->Seed->GetNumberOfSeeds( ); ++i ) + { + wIt->Seed->GetSeedWorldPosition( i, pos ); + points->InsertNextPoint( pos ); - } // rof - } - else - s->SeedWidgetOn( ); - - } // fi + } // rof } // rof + this->GetOutput( "Output" )->SetVTK( points ); + } + else + { + std::vector< vtkRenderWindowInteractor* > ints; + if( this->m_MPRViewer != NULL ) + { + ints.push_back( this->m_MPRViewer->GetInteractor( 0 ) ); + ints.push_back( this->m_MPRViewer->GetInteractor( 1 ) ); + ints.push_back( this->m_MPRViewer->GetInteractor( 2 ) ); } // fi + if( this->m_SingleInteractor != NULL ) + ints.push_back( this->m_SingleInteractor ); - // Single interactor - _S* s = dynamic_cast< _S* >( this->m_SingleInteractor ); - if( s != NULL ) - { - if( this->m_Configured ) + for( auto iIt = ints.begin( ); iIt != ints.end( ); ++iIt ) { - for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i ) - { - s->GetSeedAsPoint( i, aux_pnt ); - typename _TImage::PointType seed; - for( unsigned int d = 0; d < dim; ++d ) - seed[ d ] = aux_pnt[ d ]; - typename _TImage::IndexType idx; - if( image->TransformPhysicalPointToIndex( seed, idx ) ) - container->Get( ).push_back( idx ); + auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( ); + if( ren != NULL ) + { + auto props = ren->GetViewProps( ); + if( props != NULL ) + { + props->InitTraversal( ); + vtkProp* prop; + while( ( prop = props->GetNextProp( ) ) != NULL ) + { + auto actor = dynamic_cast< vtkImageActor* >( prop ); + if( actor != NULL ) + { + WidgetData d; + d.Configure( *iIt, actor ); + d.On( ); + this->m_Widgets.push_back( d ); + this->m_Configured = true; + + } // fi + + } // elihw + + } // fi + + } // fi } // rof - } - else - s->SeedWidgetOn( ); - } // fi - this->m_Configured = true; - container->SetReferenceImage( image ); - this->GetOutputData( "Output" )->SetITK( container ); - } - else - this->_Error( "Input image dimension not supported." ); - */ + } // fi + if( !( this->m_Configured ) ) + this->_Error( + "Could not create valid widget: are there any valid actors?" + ); } // eof - $RCSfile$ diff --git a/plugins/cpPluginsWidgets/SeedWidget.h b/plugins/cpPluginsWidgets/SeedWidget.h index b53b346..74dfc0b 100644 --- a/plugins/cpPluginsWidgets/SeedWidget.h +++ b/plugins/cpPluginsWidgets/SeedWidget.h @@ -4,6 +4,12 @@ #include #include +#include +#include +#include +#include +#include + namespace cpPluginsWidgets { /** @@ -22,6 +28,20 @@ namespace cpPluginsWidgets itkTypeMacro( SeedWidget, cpPlugins::BaseWidget ); cpPlugins_Id_Macro( SeedWidget, Widgets ); + struct WidgetData + { + vtkSmartPointer< cpExtensions::Interaction::SeedWidget > Widget; + vtkSmartPointer< vtkImageActorPointPlacer > Placer; + vtkSmartPointer< vtkPointHandleRepresentation3D > Handle; + vtkSmartPointer< vtkSeedRepresentation > Seed; + + void Configure( + vtkRenderWindowInteractor* interactor, vtkImageActor* actor + ); + void On( ); + void Off( ); + }; + public: virtual itk::ModifiedTimeType GetMTime( ) const ITK_OVERRIDE; @@ -31,8 +51,10 @@ namespace cpPluginsWidgets virtual void _GenerateData( ) ITK_OVERRIDE; - template< class _TImage > - inline void _GD0( _TImage* image ); + /* TODO + template< class _TImage > + inline void _GD0( _TImage* image ); + */ private: // Purposely not implemented @@ -41,6 +63,7 @@ namespace cpPluginsWidgets protected: bool m_Configured; + std::vector< WidgetData > m_Widgets; }; } // ecapseman -- 2.45.1