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 std::cout << "seeds" << std::endl;
94 if( this->m_Configured )
96 std::cout << "ok" << std::endl;
97 auto points = this->_CreateVTK< vtkPoints >( );
99 auto wIt = this->m_Widgets.begin( );
100 wIt != this->m_Widgets.end( );
105 for( unsigned int i = 0; i < wIt->Seed->GetNumberOfSeeds( ); ++i )
107 wIt->Seed->GetSeedWorldPosition( i, pos );
108 points->InsertNextPoint( pos );
113 this->GetOutput( "Output" )->SetVTK( points );
117 std::vector< vtkRenderWindowInteractor* > ints;
118 if( this->m_MPRViewer != NULL )
120 ints.push_back( this->m_MPRViewer->GetInteractor( 0 ) );
121 ints.push_back( this->m_MPRViewer->GetInteractor( 1 ) );
122 ints.push_back( this->m_MPRViewer->GetInteractor( 2 ) );
125 if( this->m_SingleInteractor != NULL )
126 ints.push_back( this->m_SingleInteractor );
128 for( auto iIt = ints.begin( ); iIt != ints.end( ); ++iIt )
130 auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
133 auto props = ren->GetViewProps( );
136 props->InitTraversal( );
138 while( ( prop = props->GetNextProp( ) ) != NULL )
140 auto actor = dynamic_cast< vtkImageActor* >( prop );
144 d.Configure( this, *iIt, actor );
146 this->m_Widgets.push_back( d );
147 this->m_Configured = true;
160 if( this->m_Configured )
164 "Could not create valid widget: are there any valid actors?"