]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Interaction/ImageSliceStyle.cxx
Architecture updated.
[cpPlugins.git] / lib / cpExtensions / Interaction / ImageSliceStyle.cxx
1 #include <cpExtensions/Interaction/ImageSliceStyle.h>
2 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
3 #include <cpExtensions/Visualization/ImageViewerActors.h>
4 #include <vtkPropPicker.h>
5
6 // -------------------------------------------------------------------------
7 cpExtensions::Interaction::ImageSliceStyle::
8 Self* cpExtensions::Interaction::ImageSliceStyle::
9 New( )
10 {
11   return( new Self( ) );
12 }
13
14 // -------------------------------------------------------------------------
15 cpExtensions::Visualization::ImageViewerActors*
16 cpExtensions::Interaction::ImageSliceStyle::
17 GetActors( )
18 {
19   return( this->m_Actors );
20 }
21
22 // -------------------------------------------------------------------------
23 const cpExtensions::Visualization::ImageViewerActors*
24 cpExtensions::Interaction::ImageSliceStyle::
25 GetActors( ) const
26 {
27   return( this->m_Actors );
28 }
29
30 // -------------------------------------------------------------------------
31 void cpExtensions::Interaction::ImageSliceStyle::
32 SetActors( cpExtensions::Visualization::ImageViewerActors* actors )
33 {
34   this->m_Actors = actors;
35   if( actors != NULL )
36   {
37     this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
38     this->m_PropPicker->PickFromListOn( );
39     this->m_PropPicker->GetPickList( )->RemoveAllItems( );
40     this->m_PropPicker->
41       AddPickList( this->m_Actors->GetWindowLevelImageActor( ) );
42   }
43   else
44     this->m_PropPicker = NULL;
45 }
46
47 // -------------------------------------------------------------------------
48 void cpExtensions::Interaction::ImageSliceStyle::
49 OnMouseMove( )
50 {
51   this->Superclass::OnMouseMove( );
52   if( this->m_Actors.GetPointer( ) == NULL )
53     return;
54
55   // Slice synch
56   static int idx[ 2 ];
57   static double pos[ 3 ];
58   if( this->_PickPosition( idx, pos ) )
59   {
60     if(
61       this->Interactor->GetControlKey( ) == 1 &&
62       this->GetButtonID( ) == Self::ButtonID_Left
63       )
64     {
65       this->m_Actors->SetSuperCursor( pos, this->m_Actors->GetOrientation( ) == 2 );
66       this->InvokeEvent( vtkCommand::UserEvent + 1, pos );
67     }
68     else
69       this->m_Actors->SetCursor( pos, this->m_Actors->GetOrientation( ) == 2 );
70   }
71   else
72     this->m_Actors->HideViewerActors( );
73   this->Interactor->Render( );
74 }
75
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::ImageSliceStyle::
78 OnMouseWheelForward( )
79 {
80   static int s = 0;
81   if( this->m_Actors.GetPointer( ) == NULL )
82     return;
83   s = this->m_Actors->GetSliceNumber( );
84   s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1;
85   this->m_Actors->SetSliceNumber( s );
86   s = this->m_Actors->GetSliceNumber( );
87   this->InvokeEvent( vtkCommand::UserEvent + 2, &s );
88   this->Interactor->Render( );
89   this->OnMouseMove( );
90 }
91
92 // -------------------------------------------------------------------------
93 void cpExtensions::Interaction::ImageSliceStyle::
94 OnMouseWheelBackward( )
95 {
96   static int s = 0;
97   if( this->m_Actors.GetPointer( ) == NULL )
98     return;
99   s = this->m_Actors->GetSliceNumber( );
100   s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1;
101   this->m_Actors->SetSliceNumber( s );
102   s = this->m_Actors->GetSliceNumber( );
103   this->InvokeEvent( vtkCommand::UserEvent + 2, &s );
104   this->Interactor->Render( );
105   this->OnMouseMove( );
106 }
107
108 // -------------------------------------------------------------------------
109 void cpExtensions::Interaction::ImageSliceStyle::
110 OnChar( )
111 {
112 }
113
114 // -------------------------------------------------------------------------
115 cpExtensions::Interaction::ImageSliceStyle::
116 ImageSliceStyle( )
117   : Superclass( )
118 {
119 }
120
121 // -------------------------------------------------------------------------
122 cpExtensions::Interaction::ImageSliceStyle::
123 ~ImageSliceStyle( )
124 {
125 }
126
127 // -------------------------------------------------------------------------
128 bool cpExtensions::Interaction::ImageSliceStyle::
129 _PickPosition( int idx[ 2 ], double pos[ 3 ] )
130 {
131   if(
132     this->Interactor == NULL ||
133     this->CurrentRenderer == NULL ||
134     this->m_PropPicker.GetPointer( ) == NULL
135     )
136     return( false );
137
138   // Find the renderer where the event has been raised
139   idx[ 0 ] = this->Interactor->GetEventPosition( )[ 0 ];
140   idx[ 1 ] = this->Interactor->GetEventPosition( )[ 1 ];
141   this->FindPokedRenderer( double( idx[ 0 ] ), double( idx[ 1 ] ) );
142
143   // Pick a 3D position
144   int r = this->m_PropPicker->Pick(
145     double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
146     this->CurrentRenderer
147     );
148   if( r == 0 )
149     return( false );
150   this->m_PropPicker->GetPickPosition( pos );
151   return( true );
152 }
153
154 // eof - $RCSfile$