]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/ImageInteractorStyle.cxx
bf82ba68140b1bb38ef89a2d1193b6240f4c62af
[cpPlugins.git] / lib / cpExtensions / Interaction / ImageInteractorStyle.cxx
1 #include <cpExtensions/Interaction/ImageInteractorStyle.h>
2
3 #include <vtkImageActor.h>
4 #include <vtkPropCollection.h>
5 #include <vtkProperty.h>
6 #include <vtkRenderWindowInteractor.h>
7
8 // -------------------------------------------------------------------------
9 cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
10 TSeedWidget( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
11 {
12   this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
13   this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
14   this->Representation = vtkSmartPointer< vtkSeedRepresentation >::New( );
15   this->Widget = vtkSmartPointer< SeedWidget >::New( );
16
17   this->Placer->SetImageActor( actor );
18   this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
19   this->Handle->SetPointPlacer( this->Placer );
20   this->Representation->SetHandleRepresentation( this->Handle );
21   this->Widget->SetRepresentation( this->Representation );
22   this->Widget->SetInteractor( interactor );
23 }
24
25 // -------------------------------------------------------------------------
26 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
27 On( )
28 {
29   this->Widget->On( );
30 }
31
32 // -------------------------------------------------------------------------
33 void cpExtensions::Interaction::ImageInteractorStyle::TSeedWidget::
34 Off( )
35 {
36   this->Widget->Off( );
37 }
38
39 // -------------------------------------------------------------------------
40 cpExtensions::Interaction::ImageInteractorStyle::
41 Self* cpExtensions::Interaction::ImageInteractorStyle::
42 New( )
43 {
44   return( new Self );
45 }
46
47 // -------------------------------------------------------------------------
48 void cpExtensions::Interaction::ImageInteractorStyle::
49 AssociateImageActor( vtkImageActor* actor )
50 {
51   if( actor != NULL )
52   {
53     this->m_PropPicker->AddPickList( actor );
54     this->Modified( );
55
56   } // fi
57 }
58
59 // -------------------------------------------------------------------------
60 void cpExtensions::Interaction::ImageInteractorStyle::
61 SeedWidgetOn( )
62 {
63   if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
64
65   this->m_PropPicker->GetPickList( )->InitTraversal( );
66   this->m_SeedWidget = new TSeedWidget(
67     this->Interactor,
68     dynamic_cast< vtkImageActor* >(
69       this->m_PropPicker->GetPickList( )->GetNextProp( )
70       )
71     );
72   this->m_SeedWidget->On( );
73 }
74
75 // -------------------------------------------------------------------------
76 void cpExtensions::Interaction::ImageInteractorStyle::
77 SeedWidgetOff( )
78 {
79   if( this->m_SeedWidget != NULL )
80   {
81     this->m_SeedWidget->Off( );
82     delete this->m_SeedWidget;
83     this->m_SeedWidget = NULL;
84
85   } // fi
86 }
87
88 // -------------------------------------------------------------------------
89 cpExtensions::Interaction::ImageInteractorStyle::
90 ImageInteractorStyle( )
91   : Superclass( ),
92     m_SeedWidget( NULL )
93 {
94   this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
95   this->m_PropPicker->PickFromListOn( );
96 }
97
98 // -------------------------------------------------------------------------
99 cpExtensions::Interaction::ImageInteractorStyle::
100 ~ImageInteractorStyle( )
101 {
102   if( this->m_SeedWidget != NULL ) delete this->m_SeedWidget;
103 }
104
105 // -------------------------------------------------------------------------
106 bool cpExtensions::Interaction::ImageInteractorStyle::
107 _PickPosition( int idx[ 2 ], double pos[ 3 ] )
108 {
109   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
110   if( rwi == NULL )
111     return( false );
112
113   // Find the renderer where the event has been raised
114   idx[ 0 ] = rwi->GetEventPosition( )[ 0 ];
115   idx[ 1 ] = rwi->GetEventPosition( )[ 1 ];
116   this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) );
117
118   // Pick a 3D position
119   int r = this->m_PropPicker->Pick(
120     double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
121     this->CurrentRenderer
122     );
123   if( r == 0 )
124     return( false );
125   this->m_PropPicker->GetPickPosition( pos );
126   return( true );
127 }
128
129 // eof - $RCSfile$