1 #include "SeedWidget.h"
3 #include <vtkCommand.h>
4 #include <vtkProperty.h>
5 #include <vtkRenderWindowInteractor.h>
6 #include <cpExtensions/QT/SimpleMPRWidget.h>
8 // -------------------------------------------------------------------------
9 // This callback is responsible for changing update time
10 namespace cpPluginsWidgets
14 class SeedWidgetCallback
18 static SeedWidgetCallback* New( )
19 { return( new SeedWidgetCallback ); }
20 virtual void Execute( vtkObject* caller, unsigned long id, void* data )
23 id == vtkCommand::CursorChangedEvent ||
24 id == vtkCommand::PlacePointEvent
26 this->Widget->Modified( );
33 // -------------------------------------------------------------------------
34 void cpPluginsWidgets::SeedWidget::WidgetData::
36 cpPluginsWidgets::SeedWidget* parent,
37 vtkRenderWindowInteractor* interactor, vtkImageActor* actor
40 this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
41 this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
42 this->Seed = vtkSmartPointer< vtkSeedRepresentation >::New( );
44 vtkSmartPointer< cpExtensions::Interaction::SeedWidget >::New( );
46 this->Placer->SetImageActor( actor );
47 this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
48 this->Handle->SetPointPlacer( this->Placer );
49 this->Seed->SetHandleRepresentation( this->Handle );
50 this->Widget->SetRepresentation( this->Seed );
51 this->Widget->SetInteractor( interactor );
53 vtkSmartPointer< SeedWidgetCallback > cb =
54 vtkSmartPointer< SeedWidgetCallback >::New( );
56 this->Widget->AddObserver( vtkCommand::PlacePointEvent, cb );
57 this->Widget->AddObserver( vtkCommand::CursorChangedEvent, cb );
60 // -------------------------------------------------------------------------
61 void cpPluginsWidgets::SeedWidget::WidgetData::
67 // -------------------------------------------------------------------------
68 void cpPluginsWidgets::SeedWidget::WidgetData::
74 // -------------------------------------------------------------------------
75 cpPluginsWidgets::SeedWidget::
80 this->_AddOutput< cpPlugins::DataObject >( "Output" );
83 // -------------------------------------------------------------------------
84 cpPluginsWidgets::SeedWidget::
89 // -------------------------------------------------------------------------
90 void cpPluginsWidgets::SeedWidget::
93 if( this->m_Configured )
95 auto points = this->_CreateVTK< vtkPoints >( );
97 auto wIt = this->m_Widgets.begin( );
98 wIt != this->m_Widgets.end( );
103 for( unsigned int i = 0; i < wIt->Seed->GetNumberOfSeeds( ); ++i )
105 wIt->Seed->GetSeedWorldPosition( i, pos );
106 points->InsertNextPoint( pos );
111 this->GetOutput( "Output" )->SetVTK( points );
115 std::vector< vtkRenderWindowInteractor* > ints;
116 if( this->m_MPRViewer != NULL )
118 ints.push_back( this->m_MPRViewer->GetInteractor( 0 ) );
119 ints.push_back( this->m_MPRViewer->GetInteractor( 1 ) );
120 ints.push_back( this->m_MPRViewer->GetInteractor( 2 ) );
123 if( this->m_SingleInteractor != NULL )
124 ints.push_back( this->m_SingleInteractor );
126 for( auto iIt = ints.begin( ); iIt != ints.end( ); ++iIt )
128 auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
131 auto props = ren->GetViewProps( );
134 props->InitTraversal( );
136 while( ( prop = props->GetNextProp( ) ) != NULL )
138 auto actor = dynamic_cast< vtkImageActor* >( prop );
142 d.Configure( this, *iIt, actor );
144 this->m_Widgets.push_back( d );
145 this->m_Configured = true;
158 if( this->m_Configured )
162 "Could not create valid widget: are there any valid actors?"