1 #include <cpExtensions/Visualization/ImageInteractorStyle.h>
3 #include <vtkImageActor.h>
4 #include <vtkRenderWindowInteractor.h>
6 // -------------------------------------------------------------------------
7 cpExtensions::Visualization::ImageInteractorStyle::
8 Self* cpExtensions::Visualization::ImageInteractorStyle::
14 // -------------------------------------------------------------------------
15 void cpExtensions::Visualization::ImageInteractorStyle::
16 AssociateView( void* data )
21 // -------------------------------------------------------------------------
22 void cpExtensions::Visualization::ImageInteractorStyle::
23 AssociateImageActor( vtkImageActor* actor )
25 this->PropPicker->AddPickList( actor );
29 // -------------------------------------------------------------------------
30 void cpExtensions::Visualization::ImageInteractorStyle::
33 // Get current position on the associated actors
34 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
35 if( rwi == NULL || this->MouseMoveCommand == NULL )
38 if( !( this->_PickPosition( pos ) ) )
42 bool alt = ( rwi->GetAltKey( ) == 1 );
43 bool ctr = ( rwi->GetControlKey( ) == 1 );
44 bool sft = ( rwi->GetShiftKey( ) == 1 );
45 ButtonID button = this->GetButtonID( );
47 // Invoke possible events
48 this->MouseMoveCommand( this->Data, button, pos, alt, ctr, sft );
52 // -------------------------------------------------------------------------
53 void cpExtensions::Visualization::ImageInteractorStyle::
54 OnMouseWheelForward( )
56 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
57 if( rwi == NULL || this->MouseWheelCommand == NULL )
61 bool alt = ( rwi->GetAltKey( ) == 1 );
62 bool ctr = ( rwi->GetControlKey( ) == 1 );
63 bool sft = ( rwi->GetShiftKey( ) == 1 );
65 // Invoke possible events
66 this->MouseWheelCommand( this->Data, 1, alt, ctr, sft );
69 // -------------------------------------------------------------------------
70 void cpExtensions::Visualization::ImageInteractorStyle::
71 OnMouseWheelBackward( )
73 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
74 if( rwi == NULL || this->MouseWheelCommand == NULL )
78 bool alt = ( rwi->GetAltKey( ) == 1 );
79 bool ctr = ( rwi->GetControlKey( ) == 1 );
80 bool sft = ( rwi->GetShiftKey( ) == 1 );
82 // Invoke possible events
83 this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
86 // -------------------------------------------------------------------------
87 void cpExtensions::Visualization::ImageInteractorStyle::
90 // Get current position on the associated actors
91 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
92 if( rwi == NULL || this->MouseClickCommand == NULL )
95 if( !( this->_PickPosition( pos ) ) )
99 bool alt = ( rwi->GetAltKey( ) == 1 );
100 bool ctr = ( rwi->GetControlKey( ) == 1 );
101 bool sft = ( rwi->GetShiftKey( ) == 1 );
103 // Invoke possible events
104 this->MouseClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
107 // -------------------------------------------------------------------------
108 void cpExtensions::Visualization::ImageInteractorStyle::
111 // Get current position on the associated actors
112 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
113 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
116 if( !( this->_PickPosition( pos ) ) )
120 bool alt = ( rwi->GetAltKey( ) == 1 );
121 bool ctr = ( rwi->GetControlKey( ) == 1 );
122 bool sft = ( rwi->GetShiftKey( ) == 1 );
124 // Invoke possible events
125 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
128 // -------------------------------------------------------------------------
129 void cpExtensions::Visualization::ImageInteractorStyle::
132 // Get current position on the associated actors
133 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
134 if( rwi == NULL || this->MouseClickCommand == NULL )
137 if( !( this->_PickPosition( pos ) ) )
141 bool alt = ( rwi->GetAltKey( ) == 1 );
142 bool ctr = ( rwi->GetControlKey( ) == 1 );
143 bool sft = ( rwi->GetShiftKey( ) == 1 );
145 // Invoke possible events
146 this->MouseClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
149 // -------------------------------------------------------------------------
150 void cpExtensions::Visualization::ImageInteractorStyle::
151 OnMiddleDoubleClick( )
153 // Get current position on the associated actors
154 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
155 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
158 if( !( this->_PickPosition( pos ) ) )
162 bool alt = ( rwi->GetAltKey( ) == 1 );
163 bool ctr = ( rwi->GetControlKey( ) == 1 );
164 bool sft = ( rwi->GetShiftKey( ) == 1 );
166 // Invoke possible events
167 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
170 // -------------------------------------------------------------------------
171 void cpExtensions::Visualization::ImageInteractorStyle::
174 // Get current position on the associated actors
175 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
176 if( rwi == NULL || this->MouseClickCommand == NULL )
179 if( !( this->_PickPosition( pos ) ) )
183 bool alt = ( rwi->GetAltKey( ) == 1 );
184 bool ctr = ( rwi->GetControlKey( ) == 1 );
185 bool sft = ( rwi->GetShiftKey( ) == 1 );
187 // Invoke possible events
188 this->MouseClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
191 // -------------------------------------------------------------------------
192 void cpExtensions::Visualization::ImageInteractorStyle::
193 OnRightDoubleClick( )
195 // Get current position on the associated actors
196 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
197 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
200 if( !( this->_PickPosition( pos ) ) )
204 bool alt = ( rwi->GetAltKey( ) == 1 );
205 bool ctr = ( rwi->GetControlKey( ) == 1 );
206 bool sft = ( rwi->GetShiftKey( ) == 1 );
208 // Invoke possible events
209 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
212 // -------------------------------------------------------------------------
213 void cpExtensions::Visualization::ImageInteractorStyle::
216 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
217 if( rwi == NULL || this->KeyCommand == NULL )
219 this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
222 // -------------------------------------------------------------------------
223 void cpExtensions::Visualization::ImageInteractorStyle::
226 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
231 // -------------------------------------------------------------------------
232 void cpExtensions::Visualization::ImageInteractorStyle::
235 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
240 // -------------------------------------------------------------------------
241 void cpExtensions::Visualization::ImageInteractorStyle::
244 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
249 // -------------------------------------------------------------------------
250 void cpExtensions::Visualization::ImageInteractorStyle::
253 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
258 // -------------------------------------------------------------------------
259 cpExtensions::Visualization::ImageInteractorStyle::
260 ImageInteractorStyle( )
263 MouseMoveCommand( NULL ),
264 MouseClickCommand( NULL ),
265 MouseDoubleClickCommand( NULL ),
266 MouseWheelCommand( NULL ),
269 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
270 this->PropPicker->PickFromListOn( );
273 // -------------------------------------------------------------------------
274 cpExtensions::Visualization::ImageInteractorStyle::
275 ~ImageInteractorStyle( )
279 // -------------------------------------------------------------------------
280 bool cpExtensions::Visualization::ImageInteractorStyle::
281 _PickPosition( double pos[ 3 ] )
283 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
287 // Find the renderer where the event has been raised
288 double x = double( rwi->GetEventPosition( )[ 0 ] );
289 double y = double( rwi->GetEventPosition( )[ 1 ] );
290 this->FindPokedRenderer( x, y );
292 // Pick a 3D position
293 int r = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
296 this->PropPicker->GetPickPosition( pos );
305 #include <vtkAnnotatedCubeActor.h>
306 #include <vtkAxesActor.h>
307 #include <vtkCallbackCommand.h>
308 #include <vtkCamera.h>
309 #include <vtkCellArray.h>
310 #include <vtkCommand.h>
311 #include <vtkMatrix4x4.h>
312 #include <vtkPropAssembly.h>
313 #include <vtkProperty.h>
314 #include <vtkRendererCollection.h>
315 #include <vtkRenderWindow.h>
316 #include <vtkRenderWindowInteractor.h>
318 #include <cpExtensions/Visualization/ImageSliceActors.h>
319 #include <cpExtensions/Visualization/MPRActors.h>
321 // -------------------------------------------------------------------------
322 const int cpExtensions::Visualization::
323 ImageInteractorStyle::CursorEvent = vtkCommand::UserEvent + 1;
324 const int cpExtensions::Visualization::
325 ImageInteractorStyle::RadiusEvent = vtkCommand::UserEvent + 2;
326 const int cpExtensions::Visualization::
327 ImageInteractorStyle::DoubleClickEvent = vtkCommand::UserEvent + 3;
329 // -------------------------------------------------------------------------
330 cpExtensions::Visualization::ImageInteractorStyle::
331 Self* cpExtensions::Visualization::ImageInteractorStyle::
334 return( new Self( ) );
337 // -------------------------------------------------------------------------
338 void cpExtensions::Visualization::ImageInteractorStyle::
339 Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
341 this->m_SliceActors = slice_actors;
342 this->m_MPRActors = mpr_actors;
343 this->SetModeToNavigation( );
344 this->PropPicker->AddPickList( slice_actors->GetImageActor( 0 ) );
348 // -------------------------------------------------------------------------
349 void cpExtensions::Visualization::ImageInteractorStyle::
350 AssociateInteractor( vtkRenderWindowInteractor* interactor )
352 if( interactor != NULL )
354 this->AssociatedInteractors.push_back( interactor );
360 // -------------------------------------------------------------------------
361 void cpExtensions::Visualization::ImageInteractorStyle::
362 SetModeToNavigation( )
364 this->Mode = Self::NavigationMode;
367 // -------------------------------------------------------------------------
368 void cpExtensions::Visualization::ImageInteractorStyle::
369 SetModeToDeformation( )
371 this->Mode = Self::DeformationMode;
374 // -------------------------------------------------------------------------
375 void cpExtensions::Visualization::ImageInteractorStyle::
376 SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
378 this->Superclass::SetInteractor( interactor );
379 this->OrientationWidget->SetInteractor( interactor );
380 interactor->SetInteractorStyle( this );
381 if( interactor == NULL )
384 // Get camera, avoiding segfaults
386 interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
389 vtkCamera* cam = ren->GetActiveCamera( );
393 // Parallel projections are better when displaying 2D images
394 cam->ParallelProjectionOn( );
395 cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
398 cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
399 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
403 cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
404 cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
406 else // if( axis == 2 )
408 cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
409 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
414 // Enable 2D orientation widget
415 this->OrientationWidget->SetEnabled( 1 );
416 this->OrientationWidget->InteractiveOff( );
419 // -------------------------------------------------------------------------
420 void cpExtensions::Visualization::ImageInteractorStyle::
423 if( this->m_MPRActors == NULL )
426 if( this->CursorMoving )
428 bool picked = this->_PickPosition( this->Cursor );
431 for( int i = 0; i < 3; ++i )
432 if( this->m_SliceActors->GetAxis( ) != i )
433 this->m_MPRActors->SetSlice( i, this->Cursor[ i ] );
434 this->InvokeEvent( Self::CursorEvent, this->Cursor );
435 this->Interactor->Render( );
436 this->_RenderAssociateInteractors( );
440 else if( this->RadiusMoving )
442 bool picked = this->_PickPosition( this->Radius );
445 this->InvokeEvent( Self::RadiusEvent, this->Radius );
446 this->_UpdateRadius( );
452 switch( this->State )
454 case VTKIS_WINDOW_LEVEL:
455 this->WindowLevel( );
468 // -------------------------------------------------------------------------
469 void cpExtensions::Visualization::ImageInteractorStyle::
472 static double pnt[ 3 ];
474 this->Interactor->GetEventPosition( pos );
475 this->FindPokedRenderer( pos[ 0 ], pos[ 1 ] );
476 if( this->CurrentRenderer == NULL )
478 this->GrabFocus( this->EventCallbackCommand );
480 // TODO: check this code
481 // Manage double-click
482 static const long epsilon_time = 800;
483 static long last_click_time = -( epsilon_time << 1 );
484 long click_time = static_cast< long >( std::clock( ) );
485 if( ( click_time - last_click_time ) < epsilon_time )
487 last_click_time = -( epsilon_time << 1 );
488 if( this->_PickPosition( pnt ) )
489 this->InvokeEvent( Self::DoubleClickEvent, pnt );
493 last_click_time = click_time;
494 if( this->Interactor->GetControlKey( ) )
495 this->StartCursorMoving( );
500 // -------------------------------------------------------------------------
501 void cpExtensions::Visualization::ImageInteractorStyle::
504 if( this->CursorMoving )
506 this->EndCursorMoving( );
507 if( this->Interactor )
508 this->ReleaseFocus( );
513 // -------------------------------------------------------------------------
514 void cpExtensions::Visualization::ImageInteractorStyle::
515 OnMiddleButtonDown( )
517 int x = this->Interactor->GetEventPosition( )[ 0 ];
518 int y = this->Interactor->GetEventPosition( )[ 1 ];
520 this->FindPokedRenderer( x, y );
521 if( this->CurrentRenderer == NULL )
523 this->GrabFocus( this->EventCallbackCommand );
525 if( this->Interactor->GetAltKey( ) )
528 else if( this->Interactor->GetControlKey( ) )
530 this->StartRadiusMoving( );
532 else if( this->Interactor->GetShiftKey( ) )
539 // -------------------------------------------------------------------------
540 void cpExtensions::Visualization::ImageInteractorStyle::
543 if( this->RadiusMoving )
545 this->EndRadiusMoving( );
546 if( this->Interactor )
547 this->ReleaseFocus( );
551 switch( this->State )
561 // -------------------------------------------------------------------------
562 void cpExtensions::Visualization::ImageInteractorStyle::
565 int x = this->Interactor->GetEventPosition( )[ 0 ];
566 int y = this->Interactor->GetEventPosition( )[ 1 ];
568 this->FindPokedRenderer( x, y );
569 if( this->CurrentRenderer == NULL )
571 this->GrabFocus( this->EventCallbackCommand );
573 if( this->Interactor->GetControlKey( ) )
575 this->WindowLevelStartPosition[ 0 ] = x;
576 this->WindowLevelStartPosition[ 1 ] = y;
577 this->StartWindowLevel( );
586 // -------------------------------------------------------------------------
587 void cpExtensions::Visualization::ImageInteractorStyle::
590 switch( this->State )
592 case VTKIS_WINDOW_LEVEL:
594 this->EndWindowLevel( );
595 if( this->Interactor )
596 this->ReleaseFocus( );
605 // -------------------------------------------------------------------------
606 void cpExtensions::Visualization::ImageInteractorStyle::
607 OnMouseWheelForward( )
609 if( this->m_SliceActors == NULL || this->Interactor == NULL )
612 if( this->Interactor->GetShiftKey( ) == 1 )
614 int s = this->m_SliceActors->GetSliceNumber( ) + off;
615 int maxs = this->m_SliceActors->GetSliceNumberMaxValue( );
616 this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs );
617 this->m_MPRActors->SetSlice(
618 this->m_SliceActors->GetAxis( ),
619 this->m_SliceActors->GetSliceNumber( )
621 this->Interactor->Render( );
622 this->_RenderAssociateInteractors( );
625 // -------------------------------------------------------------------------
626 void cpExtensions::Visualization::ImageInteractorStyle::
627 OnMouseWheelBackward( )
629 if( this->m_SliceActors == NULL || this->Interactor == NULL )
632 if( this->Interactor->GetShiftKey( ) == 1 )
634 int s = this->m_SliceActors->GetSliceNumber( ) - off;
635 int mins = this->m_SliceActors->GetSliceNumberMinValue( );
636 this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins );
637 this->m_MPRActors->SetSlice(
638 this->m_SliceActors->GetAxis( ),
639 this->m_SliceActors->GetSliceNumber( )
641 this->Interactor->Render( );
642 this->_RenderAssociateInteractors( );
645 // -------------------------------------------------------------------------
646 void cpExtensions::Visualization::ImageInteractorStyle::
649 switch( this->Interactor->GetKeyCode( ) )
654 this->Interactor->GetRenderWindow( )->
655 GetRenderers( )->GetFirstRenderer( );
658 this->Interactor->Render( );
661 case 'w': case 'W': case 'l': case 'L':
663 if( this->m_MPRActors != NULL )
665 this->m_MPRActors->ResetWindowLevel( 0 );
666 this->Interactor->Render( );
667 this->_RenderAssociateInteractors( );
675 // -------------------------------------------------------------------------
676 void cpExtensions::Visualization::ImageInteractorStyle::
679 if( this->Mode == Self::NavigationMode )
681 if( this->Interactor == NULL )
684 this->Interactor->GetRenderWindow( )->
685 GetRenderers( )->GetFirstRenderer( );
690 this->WindowLevelCurrentPosition[ 0 ] =
691 this->Interactor->GetEventPosition( )[ 0 ];
692 this->WindowLevelCurrentPosition[ 1 ] =
693 this->Interactor->GetEventPosition( )[ 1 ];
694 int* size = ren->GetSize( );
696 this->WindowLevelCurrentPosition[ 0 ] -
697 this->WindowLevelStartPosition[ 0 ]
698 ) / double( size[ 0 ] );
700 this->WindowLevelStartPosition[ 1 ] -
701 this->WindowLevelCurrentPosition[ 1 ]
702 ) / double( size[ 1 ] );
704 double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
705 double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
706 double minw = this->m_MPRActors->GetMinWindow( 0 );
707 double maxw = this->m_MPRActors->GetMaxWindow( 0 );
708 double minl = this->m_MPRActors->GetMinLevel( 0 );
709 double maxl = this->m_MPRActors->GetMaxLevel( 0 );
711 if( w < minw ) w = minw;
712 if( maxw < w ) w = maxw;
713 if( l < minl ) l = minl;
714 if( maxl < l ) l = maxl;
716 this->m_MPRActors->SetWindowLevel( 0, w, l );
717 this->Interactor->Render( );
718 this->_RenderAssociateInteractors( );
720 else if( this->Mode == Self::DeformationMode )
727 // -------------------------------------------------------------------------
728 void cpExtensions::Visualization::ImageInteractorStyle::
731 if( this->State != VTKIS_NONE )
733 if( this->Mode == Self::NavigationMode )
735 this->StartState( VTKIS_WINDOW_LEVEL );
737 this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( 0 );
738 this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( 0 );
740 else if( this->Mode == Self::DeformationMode )
747 // -------------------------------------------------------------------------
748 void cpExtensions::Visualization::ImageInteractorStyle::
751 if( this->Mode == Self::NavigationMode )
753 if( this->State != VTKIS_WINDOW_LEVEL )
764 // -------------------------------------------------------------------------
765 void cpExtensions::Visualization::ImageInteractorStyle::
768 if( this->CursorMoving )
770 this->_PickPosition( this->Cursor );
771 this->CursorMoving = true;
774 // -------------------------------------------------------------------------
775 void cpExtensions::Visualization::ImageInteractorStyle::
778 if( !( this->CursorMoving ) )
780 this->CursorMoving = false;
783 // -------------------------------------------------------------------------
784 void cpExtensions::Visualization::ImageInteractorStyle::
787 if( this->RadiusMoving )
789 this->_PickPosition( this->Radius );
790 this->RadiusMoving = true;
791 this->_UpdateRadius( );
794 // -------------------------------------------------------------------------
795 void cpExtensions::Visualization::ImageInteractorStyle::
798 if( !( this->RadiusMoving ) )
800 this->RadiusMoving = false;
801 this->_UpdateRadius( );
802 this->InvokeEvent( Self::RadiusEvent, NULL );
805 // -------------------------------------------------------------------------
806 cpExtensions::Visualization::ImageInteractorStyle::
807 ImageInteractorStyle( )
809 Mode( Self::NavigationMode ),
810 m_SliceActors( NULL ),
812 CursorMoving( false ),
813 RadiusMoving( false )
816 vtkSmartPointer< vtkAnnotatedCubeActor > cube =
817 vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
818 cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
819 cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
820 cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
821 cube->GetTextEdgesProperty( )->SetAmbient( 1 );
822 cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
823 cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
824 cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
825 cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
826 cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
827 cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
828 cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
829 cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
830 cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
831 cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
832 cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
833 cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
834 cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
836 vtkSmartPointer< vtkAxesActor > axes =
837 vtkSmartPointer< vtkAxesActor >::New( );
838 axes->AxisLabelsOff( );
839 axes->SetShaftTypeToCylinder( );
840 axes->SetTotalLength( 2, 2, 2 );
842 vtkSmartPointer< vtkPropAssembly > actors =
843 vtkSmartPointer< vtkPropAssembly >::New( );
844 actors->AddPart( cube );
845 actors->AddPart( axes );
847 this->OrientationWidget =
848 vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
849 this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
850 this->OrientationWidget->SetOrientationMarker( actors );
851 this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
854 unsigned long circle_samples = 1000;
855 this->Circle = vtkSmartPointer< vtkPolyData >::New( );
857 vtkSmartPointer< vtkPoints > circle_points =
858 vtkSmartPointer< vtkPoints >::New( );
859 vtkSmartPointer< vtkCellArray > circle_lines =
860 vtkSmartPointer< vtkCellArray >::New( );
861 for( unsigned long s = 0; s < circle_samples; ++s )
863 double t = double( 6.2832 ) * double( s ) / double( circle_samples );
864 circle_points->InsertNextPoint(
865 std::cos( t ), std::sin( t ), double( 0 )
868 circle_lines->InsertNextCell( 2 );
869 circle_lines->InsertCellPoint( s );
870 circle_lines->InsertCellPoint( ( s + 1 ) % circle_samples );
873 this->Circle->SetPoints( circle_points );
874 this->Circle->SetLines( circle_lines );
876 this->CircleMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
877 this->CircleMapper->SetInputData( this->Circle );
878 this->CircleActor = vtkSmartPointer< vtkActor >::New( );
879 this->CircleActor->SetMapper( this->CircleMapper );
880 this->CircleActor->GetProperty( )->SetColor( 1, 0, 1 );
881 this->CircleActor->GetProperty( )->SetLineWidth( 2 );
883 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
884 this->PropPicker->PickFromListOn( );
887 // -------------------------------------------------------------------------
888 cpExtensions::Visualization::ImageInteractorStyle::
889 ~ImageInteractorStyle( )
893 // -------------------------------------------------------------------------
894 void cpExtensions::Visualization::ImageInteractorStyle::
895 _RenderAssociateInteractors( )
897 std::vector< vtkRenderWindowInteractor* >::iterator rIt =
898 this->AssociatedInteractors.begin( );
899 for( ; rIt != this->AssociatedInteractors.end( ); ++rIt )
903 // -------------------------------------------------------------------------
904 bool cpExtensions::Visualization::ImageInteractorStyle::
905 _PickPosition( double pos[ 3 ] )
907 if( this->m_SliceActors == NULL )
910 double x = double( this->Interactor->GetEventPosition( )[ 0 ] );
911 double y = double( this->Interactor->GetEventPosition( )[ 1 ] );
912 this->FindPokedRenderer( x, y );
914 this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
917 this->PropPicker->GetPickPosition( pos );
919 int axis = this->m_SliceActors->GetAxis( );
920 double* bounds = this->m_SliceActors->GetDisplayBounds( );
921 pos[ axis ] = bounds[ axis << 1 ];
926 // -------------------------------------------------------------------------
927 void cpExtensions::Visualization::ImageInteractorStyle::
930 std::cout << "upcur" << std::endl;
933 // -------------------------------------------------------------------------
934 void cpExtensions::Visualization::ImageInteractorStyle::
938 this->Interactor->GetRenderWindow( )->
939 GetRenderers( )->GetFirstRenderer( );
942 vtkCamera* cam = ren->GetActiveCamera( );
946 if( this->RadiusMoving )
948 double x = this->Cursor[ 0 ] - this->Radius[ 0 ];
949 double y = this->Cursor[ 1 ] - this->Radius[ 1 ];
950 double z = this->Cursor[ 2 ] - this->Radius[ 2 ];
951 double r = std::sqrt( ( x * x ) + ( y * y ) + ( z * z ) );
953 vtkMatrix4x4* cam_matrix = cam->GetModelViewTransformMatrix( );
954 vtkSmartPointer< vtkMatrix4x4 > circle_matrix =
955 this->CircleActor->GetUserMatrix( );
956 if( circle_matrix.GetPointer( ) == NULL )
958 circle_matrix = vtkSmartPointer< vtkMatrix4x4 >::New( );
959 this->CircleActor->SetUserMatrix( circle_matrix );
962 for( int i = 0; i < 4; ++i )
964 for( int j = 0; j < 4; ++j )
966 double v = cam_matrix->GetElement( i, j );
967 if( i < 3 && j == 3 )
968 v = this->Cursor[ i ];
971 circle_matrix->SetElement( i, j, v );
976 this->CircleActor->Modified( );
977 ren->AddActor( this->CircleActor );
980 ren->RemoveActor( this->CircleActor );
982 this->Interactor->Render( );