1 #include <cpExtensions/Interaction/ImageSliceStyle.h>
2 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
3 #include <cpExtensions/Visualization/ImageViewerActors.h>
4 #include <vtkPropPicker.h>
6 // -------------------------------------------------------------------------
7 cpExtensions::Interaction::ImageSliceStyle::
8 Self* cpExtensions::Interaction::ImageSliceStyle::
11 return( new Self( ) );
14 // -------------------------------------------------------------------------
15 cpExtensions::Visualization::ImageViewerActors*
16 cpExtensions::Interaction::ImageSliceStyle::
19 return( this->m_Actors );
22 // -------------------------------------------------------------------------
23 const cpExtensions::Visualization::ImageViewerActors*
24 cpExtensions::Interaction::ImageSliceStyle::
27 return( this->m_Actors );
30 // -------------------------------------------------------------------------
31 void cpExtensions::Interaction::ImageSliceStyle::
32 SetActors( cpExtensions::Visualization::ImageViewerActors* actors )
34 this->m_Actors = actors;
37 this->m_PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
38 this->m_PropPicker->PickFromListOn( );
39 this->m_PropPicker->GetPickList( )->RemoveAllItems( );
41 AddPickList( this->m_Actors->GetWindowLevelImageActor( ) );
44 this->m_PropPicker = NULL;
47 // -------------------------------------------------------------------------
48 void cpExtensions::Interaction::ImageSliceStyle::
51 this->Superclass::OnMouseMove( );
52 if( this->m_Actors.GetPointer( ) == NULL )
57 static double pos[ 3 ];
58 if( this->_PickPosition( idx, pos ) )
61 this->Interactor->GetControlKey( ) == 1 &&
62 this->GetButtonID( ) == Self::ButtonID_Left
65 this->m_Actors->SetSuperCursor( pos, this->m_Actors->GetOrientation( ) == 2 );
66 this->InvokeEvent( vtkCommand::UserEvent + 1, pos );
69 this->m_Actors->SetCursor( pos, this->m_Actors->GetOrientation( ) == 2 );
72 this->m_Actors->HideViewerActors( );
73 this->Interactor->Render( );
76 // -------------------------------------------------------------------------
77 void cpExtensions::Interaction::ImageSliceStyle::
78 OnMouseWheelForward( )
81 if( this->m_Actors.GetPointer( ) == NULL )
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( );
92 // -------------------------------------------------------------------------
93 void cpExtensions::Interaction::ImageSliceStyle::
94 OnMouseWheelBackward( )
97 if( this->m_Actors.GetPointer( ) == NULL )
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( );
108 // -------------------------------------------------------------------------
109 void cpExtensions::Interaction::ImageSliceStyle::
114 // -------------------------------------------------------------------------
115 cpExtensions::Interaction::ImageSliceStyle::
121 // -------------------------------------------------------------------------
122 cpExtensions::Interaction::ImageSliceStyle::
127 // -------------------------------------------------------------------------
128 bool cpExtensions::Interaction::ImageSliceStyle::
129 _PickPosition( int idx[ 2 ], double pos[ 3 ] )
132 this->Interactor == NULL ||
133 this->CurrentRenderer == NULL ||
134 this->m_PropPicker.GetPointer( ) == NULL
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 ] ) );
143 // Pick a 3D position
144 int r = this->m_PropPicker->Pick(
145 double( idx[ 0 ] ), double( idx[ 1 ] ), double( 0 ),
146 this->CurrentRenderer
150 this->m_PropPicker->GetPickPosition( pos );