#include "SeedWidget.h"
-#include <cpPlugins/Image.h>
-#include <cpExtensions/DataStructures/ImageIndexesContainer.h>
-#include <cpExtensions/QT/SimpleMPRWidget.h>
-#include <cpExtensions/Interaction/ImageInteractorStyle.h>
+#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
-#include <itkSimpleDataObjectDecorator.h>
-#include <itkSimpleDataObjectDecorator.hxx>
+#include <cpExtensions/QT/SimpleMPRWidget.h>
+
+// -------------------------------------------------------------------------
+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( ) );
}
// -------------------------------------------------------------------------
: Superclass( ),
m_Configured( false )
{
- this->_AddInput( "ReferenceImage" );
this->_AddOutput< cpPlugins::DataObject >( "Output" );
}
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$
#include <plugins/cpPluginsWidgets/cpPluginsWidgets_Export.h>
#include <cpPlugins/BaseWidget.h>
+#include <cpExtensions/Interaction/SeedWidget.h>
+#include <vtkImageActorPointPlacer.h>
+#include <vtkPointHandleRepresentation3D.h>
+#include <vtkSeedRepresentation.h>
+#include <vtkSmartPointer.h>
+
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;
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
protected:
bool m_Configured;
+ std::vector< WidgetData > m_Widgets;
};
} // ecapseman