X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=plugins%2FcpPluginsWidgets%2FSeedWidget.cxx;h=64069e4ce4602c971cde376a7600b3a23b5c411f;hb=427bc1753f9db20528ba5e89c46997ee12985a5a;hp=9e7a408b33d0d559622991c825438cea27bb1fff;hpb=00d030e4e10fea579b427297027e3ac37ff960b6;p=cpPlugins.git 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$