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 );
70 // -------------------------------------------------------------------------
71 void cpExtensions::Visualization::ImageInteractorStyle::
72 OnMouseWheelBackward( )
74 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
75 if( rwi == NULL || this->MouseWheelCommand == NULL )
79 bool alt = ( rwi->GetAltKey( ) == 1 );
80 bool ctr = ( rwi->GetControlKey( ) == 1 );
81 bool sft = ( rwi->GetShiftKey( ) == 1 );
83 // Invoke possible events
84 this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
88 // -------------------------------------------------------------------------
89 void cpExtensions::Visualization::ImageInteractorStyle::
92 // Get current position on the associated actors
93 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
94 if( rwi == NULL || this->MouseClickCommand == NULL )
97 if( !( this->_PickPosition( pos ) ) )
101 bool alt = ( rwi->GetAltKey( ) == 1 );
102 bool ctr = ( rwi->GetControlKey( ) == 1 );
103 bool sft = ( rwi->GetShiftKey( ) == 1 );
105 // Invoke possible events
106 this->MouseClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
110 // -------------------------------------------------------------------------
111 void cpExtensions::Visualization::ImageInteractorStyle::
114 // Get current position on the associated actors
115 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
116 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
119 if( !( this->_PickPosition( pos ) ) )
123 bool alt = ( rwi->GetAltKey( ) == 1 );
124 bool ctr = ( rwi->GetControlKey( ) == 1 );
125 bool sft = ( rwi->GetShiftKey( ) == 1 );
127 // Invoke possible events
128 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Left, pos, alt, ctr, sft );
132 // -------------------------------------------------------------------------
133 void cpExtensions::Visualization::ImageInteractorStyle::
136 // Get current position on the associated actors
137 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
138 if( rwi == NULL || this->MouseClickCommand == NULL )
141 if( !( this->_PickPosition( pos ) ) )
145 bool alt = ( rwi->GetAltKey( ) == 1 );
146 bool ctr = ( rwi->GetControlKey( ) == 1 );
147 bool sft = ( rwi->GetShiftKey( ) == 1 );
149 // Invoke possible events
150 this->MouseClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
154 // -------------------------------------------------------------------------
155 void cpExtensions::Visualization::ImageInteractorStyle::
156 OnMiddleDoubleClick( )
158 // Get current position on the associated actors
159 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
160 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
163 if( !( this->_PickPosition( pos ) ) )
167 bool alt = ( rwi->GetAltKey( ) == 1 );
168 bool ctr = ( rwi->GetControlKey( ) == 1 );
169 bool sft = ( rwi->GetShiftKey( ) == 1 );
171 // Invoke possible events
172 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft );
176 // -------------------------------------------------------------------------
177 void cpExtensions::Visualization::ImageInteractorStyle::
180 // Get current position on the associated actors
181 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
182 if( rwi == NULL || this->MouseClickCommand == NULL )
185 if( !( this->_PickPosition( pos ) ) )
189 bool alt = ( rwi->GetAltKey( ) == 1 );
190 bool ctr = ( rwi->GetControlKey( ) == 1 );
191 bool sft = ( rwi->GetShiftKey( ) == 1 );
193 // Invoke possible events
194 this->MouseClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
198 // -------------------------------------------------------------------------
199 void cpExtensions::Visualization::ImageInteractorStyle::
200 OnRightDoubleClick( )
202 // Get current position on the associated actors
203 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
204 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
207 if( !( this->_PickPosition( pos ) ) )
211 bool alt = ( rwi->GetAltKey( ) == 1 );
212 bool ctr = ( rwi->GetControlKey( ) == 1 );
213 bool sft = ( rwi->GetShiftKey( ) == 1 );
215 // Invoke possible events
216 this->MouseDoubleClickCommand( this->Data, Self::ButtonID_Right, pos, alt, ctr, sft );
220 // -------------------------------------------------------------------------
221 void cpExtensions::Visualization::ImageInteractorStyle::
224 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
225 if( rwi == NULL || this->KeyCommand == NULL )
227 this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
231 // -------------------------------------------------------------------------
232 void cpExtensions::Visualization::ImageInteractorStyle::
235 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
241 // -------------------------------------------------------------------------
242 void cpExtensions::Visualization::ImageInteractorStyle::
245 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
251 // -------------------------------------------------------------------------
252 void cpExtensions::Visualization::ImageInteractorStyle::
255 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
261 // -------------------------------------------------------------------------
262 void cpExtensions::Visualization::ImageInteractorStyle::
265 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
271 // -------------------------------------------------------------------------
272 cpExtensions::Visualization::ImageInteractorStyle::
273 ImageInteractorStyle( )
276 MouseMoveCommand( NULL ),
277 MouseClickCommand( NULL ),
278 MouseDoubleClickCommand( NULL ),
279 MouseWheelCommand( NULL ),
282 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
283 this->PropPicker->PickFromListOn( );
286 // -------------------------------------------------------------------------
287 cpExtensions::Visualization::ImageInteractorStyle::
288 ~ImageInteractorStyle( )
292 // -------------------------------------------------------------------------
293 bool cpExtensions::Visualization::ImageInteractorStyle::
294 _PickPosition( double pos[ 3 ] )
296 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
300 // Find the renderer where the event has been raised
301 double x = double( rwi->GetEventPosition( )[ 0 ] );
302 double y = double( rwi->GetEventPosition( )[ 1 ] );
303 this->FindPokedRenderer( x, y );
305 // Pick a 3D position
306 int r = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
309 this->PropPicker->GetPickPosition( pos );
318 #include <vtkAnnotatedCubeActor.h>
319 #include <vtkAxesActor.h>
320 #include <vtkCallbackCommand.h>
321 #include <vtkCamera.h>
322 #include <vtkCellArray.h>
323 #include <vtkCommand.h>
324 #include <vtkMatrix4x4.h>
325 #include <vtkPropAssembly.h>
326 #include <vtkProperty.h>
327 #include <vtkRendererCollection.h>
328 #include <vtkRenderWindow.h>
329 #include <vtkRenderWindowInteractor.h>
331 #include <cpExtensions/Visualization/ImageSliceActors.h>
332 #include <cpExtensions/Visualization/MPRActors.h>
334 // -------------------------------------------------------------------------
335 const int cpExtensions::Visualization::
336 ImageInteractorStyle::CursorEvent = vtkCommand::UserEvent + 1;
337 const int cpExtensions::Visualization::
338 ImageInteractorStyle::RadiusEvent = vtkCommand::UserEvent + 2;
339 const int cpExtensions::Visualization::
340 ImageInteractorStyle::DoubleClickEvent = vtkCommand::UserEvent + 3;
342 // -------------------------------------------------------------------------
343 cpExtensions::Visualization::ImageInteractorStyle::
344 Self* cpExtensions::Visualization::ImageInteractorStyle::
347 return( new Self( ) );
350 // -------------------------------------------------------------------------
351 void cpExtensions::Visualization::ImageInteractorStyle::
352 Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
354 this->m_SliceActors = slice_actors;
355 this->m_MPRActors = mpr_actors;
356 this->SetModeToNavigation( );
357 this->PropPicker->AddPickList( slice_actors->GetImageActor( 0 ) );
361 // -------------------------------------------------------------------------
362 void cpExtensions::Visualization::ImageInteractorStyle::
363 AssociateInteractor( vtkRenderWindowInteractor* interactor )
365 if( interactor != NULL )
367 this->AssociatedInteractors.push_back( interactor );
373 // -------------------------------------------------------------------------
374 void cpExtensions::Visualization::ImageInteractorStyle::
375 SetModeToNavigation( )
377 this->Mode = Self::NavigationMode;
380 // -------------------------------------------------------------------------
381 void cpExtensions::Visualization::ImageInteractorStyle::
382 SetModeToDeformation( )
384 this->Mode = Self::DeformationMode;
387 // -------------------------------------------------------------------------
388 void cpExtensions::Visualization::ImageInteractorStyle::
389 SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
391 this->Superclass::SetInteractor( interactor );
392 this->OrientationWidget->SetInteractor( interactor );
393 interactor->SetInteractorStyle( this );
394 if( interactor == NULL )
397 // Get camera, avoiding segfaults
399 interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
402 vtkCamera* cam = ren->GetActiveCamera( );
406 // Parallel projections are better when displaying 2D images
407 cam->ParallelProjectionOn( );
408 cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
411 cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
412 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
416 cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
417 cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
419 else // if( axis == 2 )
421 cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
422 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
427 // Enable 2D orientation widget
428 this->OrientationWidget->SetEnabled( 1 );
429 this->OrientationWidget->InteractiveOff( );
432 // -------------------------------------------------------------------------
433 void cpExtensions::Visualization::ImageInteractorStyle::
436 if( this->m_MPRActors == NULL )
439 if( this->CursorMoving )
441 bool picked = this->_PickPosition( this->Cursor );
444 for( int i = 0; i < 3; ++i )
445 if( this->m_SliceActors->GetAxis( ) != i )
446 this->m_MPRActors->SetSlice( i, this->Cursor[ i ] );
447 this->InvokeEvent( Self::CursorEvent, this->Cursor );
448 this->Interactor->Render( );
449 this->_RenderAssociateInteractors( );
453 else if( this->RadiusMoving )
455 bool picked = this->_PickPosition( this->Radius );
458 this->InvokeEvent( Self::RadiusEvent, this->Radius );
459 this->_UpdateRadius( );
465 switch( this->State )
467 case VTKIS_WINDOW_LEVEL:
468 this->WindowLevel( );
481 // -------------------------------------------------------------------------
482 void cpExtensions::Visualization::ImageInteractorStyle::
485 static double pnt[ 3 ];
487 this->Interactor->GetEventPosition( pos );
488 this->FindPokedRenderer( pos[ 0 ], pos[ 1 ] );
489 if( this->CurrentRenderer == NULL )
491 this->GrabFocus( this->EventCallbackCommand );
493 // TODO: check this code
494 // Manage double-click
495 static const long epsilon_time = 800;
496 static long last_click_time = -( epsilon_time << 1 );
497 long click_time = static_cast< long >( std::clock( ) );
498 if( ( click_time - last_click_time ) < epsilon_time )
500 last_click_time = -( epsilon_time << 1 );
501 if( this->_PickPosition( pnt ) )
502 this->InvokeEvent( Self::DoubleClickEvent, pnt );
506 last_click_time = click_time;
507 if( this->Interactor->GetControlKey( ) )
508 this->StartCursorMoving( );
513 // -------------------------------------------------------------------------
514 void cpExtensions::Visualization::ImageInteractorStyle::
517 if( this->CursorMoving )
519 this->EndCursorMoving( );
520 if( this->Interactor )
521 this->ReleaseFocus( );
526 // -------------------------------------------------------------------------
527 void cpExtensions::Visualization::ImageInteractorStyle::
528 OnMiddleButtonDown( )
530 int x = this->Interactor->GetEventPosition( )[ 0 ];
531 int y = this->Interactor->GetEventPosition( )[ 1 ];
533 this->FindPokedRenderer( x, y );
534 if( this->CurrentRenderer == NULL )
536 this->GrabFocus( this->EventCallbackCommand );
538 if( this->Interactor->GetAltKey( ) )
541 else if( this->Interactor->GetControlKey( ) )
543 this->StartRadiusMoving( );
545 else if( this->Interactor->GetShiftKey( ) )
552 // -------------------------------------------------------------------------
553 void cpExtensions::Visualization::ImageInteractorStyle::
556 if( this->RadiusMoving )
558 this->EndRadiusMoving( );
559 if( this->Interactor )
560 this->ReleaseFocus( );
564 switch( this->State )
574 // -------------------------------------------------------------------------
575 void cpExtensions::Visualization::ImageInteractorStyle::
578 int x = this->Interactor->GetEventPosition( )[ 0 ];
579 int y = this->Interactor->GetEventPosition( )[ 1 ];
581 this->FindPokedRenderer( x, y );
582 if( this->CurrentRenderer == NULL )
584 this->GrabFocus( this->EventCallbackCommand );
586 if( this->Interactor->GetControlKey( ) )
588 this->WindowLevelStartPosition[ 0 ] = x;
589 this->WindowLevelStartPosition[ 1 ] = y;
590 this->StartWindowLevel( );
599 // -------------------------------------------------------------------------
600 void cpExtensions::Visualization::ImageInteractorStyle::
603 switch( this->State )
605 case VTKIS_WINDOW_LEVEL:
607 this->EndWindowLevel( );
608 if( this->Interactor )
609 this->ReleaseFocus( );
618 // -------------------------------------------------------------------------
619 void cpExtensions::Visualization::ImageInteractorStyle::
620 OnMouseWheelForward( )
622 if( this->m_SliceActors == NULL || this->Interactor == NULL )
625 if( this->Interactor->GetShiftKey( ) == 1 )
627 int s = this->m_SliceActors->GetSliceNumber( ) + off;
628 int maxs = this->m_SliceActors->GetSliceNumberMaxValue( );
629 this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs );
630 this->m_MPRActors->SetSlice(
631 this->m_SliceActors->GetAxis( ),
632 this->m_SliceActors->GetSliceNumber( )
634 this->Interactor->Render( );
635 this->_RenderAssociateInteractors( );
638 // -------------------------------------------------------------------------
639 void cpExtensions::Visualization::ImageInteractorStyle::
640 OnMouseWheelBackward( )
642 if( this->m_SliceActors == NULL || this->Interactor == NULL )
645 if( this->Interactor->GetShiftKey( ) == 1 )
647 int s = this->m_SliceActors->GetSliceNumber( ) - off;
648 int mins = this->m_SliceActors->GetSliceNumberMinValue( );
649 this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins );
650 this->m_MPRActors->SetSlice(
651 this->m_SliceActors->GetAxis( ),
652 this->m_SliceActors->GetSliceNumber( )
654 this->Interactor->Render( );
655 this->_RenderAssociateInteractors( );
658 // -------------------------------------------------------------------------
659 void cpExtensions::Visualization::ImageInteractorStyle::
662 switch( this->Interactor->GetKeyCode( ) )
667 this->Interactor->GetRenderWindow( )->
668 GetRenderers( )->GetFirstRenderer( );
671 this->Interactor->Render( );
674 case 'w': case 'W': case 'l': case 'L':
676 if( this->m_MPRActors != NULL )
678 this->m_MPRActors->ResetWindowLevel( 0 );
679 this->Interactor->Render( );
680 this->_RenderAssociateInteractors( );
688 // -------------------------------------------------------------------------
689 void cpExtensions::Visualization::ImageInteractorStyle::
692 if( this->Mode == Self::NavigationMode )
694 if( this->Interactor == NULL )
697 this->Interactor->GetRenderWindow( )->
698 GetRenderers( )->GetFirstRenderer( );
703 this->WindowLevelCurrentPosition[ 0 ] =
704 this->Interactor->GetEventPosition( )[ 0 ];
705 this->WindowLevelCurrentPosition[ 1 ] =
706 this->Interactor->GetEventPosition( )[ 1 ];
707 int* size = ren->GetSize( );
709 this->WindowLevelCurrentPosition[ 0 ] -
710 this->WindowLevelStartPosition[ 0 ]
711 ) / double( size[ 0 ] );
713 this->WindowLevelStartPosition[ 1 ] -
714 this->WindowLevelCurrentPosition[ 1 ]
715 ) / double( size[ 1 ] );
717 double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
718 double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
719 double minw = this->m_MPRActors->GetMinWindow( 0 );
720 double maxw = this->m_MPRActors->GetMaxWindow( 0 );
721 double minl = this->m_MPRActors->GetMinLevel( 0 );
722 double maxl = this->m_MPRActors->GetMaxLevel( 0 );
724 if( w < minw ) w = minw;
725 if( maxw < w ) w = maxw;
726 if( l < minl ) l = minl;
727 if( maxl < l ) l = maxl;
729 this->m_MPRActors->SetWindowLevel( 0, w, l );
730 this->Interactor->Render( );
731 this->_RenderAssociateInteractors( );
733 else if( this->Mode == Self::DeformationMode )
740 // -------------------------------------------------------------------------
741 void cpExtensions::Visualization::ImageInteractorStyle::
744 if( this->State != VTKIS_NONE )
746 if( this->Mode == Self::NavigationMode )
748 this->StartState( VTKIS_WINDOW_LEVEL );
750 this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( 0 );
751 this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( 0 );
753 else if( this->Mode == Self::DeformationMode )
760 // -------------------------------------------------------------------------
761 void cpExtensions::Visualization::ImageInteractorStyle::
764 if( this->Mode == Self::NavigationMode )
766 if( this->State != VTKIS_WINDOW_LEVEL )
777 // -------------------------------------------------------------------------
778 void cpExtensions::Visualization::ImageInteractorStyle::
781 if( this->CursorMoving )
783 this->_PickPosition( this->Cursor );
784 this->CursorMoving = true;
787 // -------------------------------------------------------------------------
788 void cpExtensions::Visualization::ImageInteractorStyle::
791 if( !( this->CursorMoving ) )
793 this->CursorMoving = false;
796 // -------------------------------------------------------------------------
797 void cpExtensions::Visualization::ImageInteractorStyle::
800 if( this->RadiusMoving )
802 this->_PickPosition( this->Radius );
803 this->RadiusMoving = true;
804 this->_UpdateRadius( );
807 // -------------------------------------------------------------------------
808 void cpExtensions::Visualization::ImageInteractorStyle::
811 if( !( this->RadiusMoving ) )
813 this->RadiusMoving = false;
814 this->_UpdateRadius( );
815 this->InvokeEvent( Self::RadiusEvent, NULL );
818 // -------------------------------------------------------------------------
819 cpExtensions::Visualization::ImageInteractorStyle::
820 ImageInteractorStyle( )
822 Mode( Self::NavigationMode ),
823 m_SliceActors( NULL ),
825 CursorMoving( false ),
826 RadiusMoving( false )
829 vtkSmartPointer< vtkAnnotatedCubeActor > cube =
830 vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
831 cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
832 cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
833 cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
834 cube->GetTextEdgesProperty( )->SetAmbient( 1 );
835 cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
836 cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
837 cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
838 cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
839 cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
840 cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
841 cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
842 cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
843 cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
844 cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
845 cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
846 cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
847 cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
849 vtkSmartPointer< vtkAxesActor > axes =
850 vtkSmartPointer< vtkAxesActor >::New( );
851 axes->AxisLabelsOff( );
852 axes->SetShaftTypeToCylinder( );
853 axes->SetTotalLength( 2, 2, 2 );
855 vtkSmartPointer< vtkPropAssembly > actors =
856 vtkSmartPointer< vtkPropAssembly >::New( );
857 actors->AddPart( cube );
858 actors->AddPart( axes );
860 this->OrientationWidget =
861 vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
862 this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
863 this->OrientationWidget->SetOrientationMarker( actors );
864 this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
867 unsigned long circle_samples = 1000;
868 this->Circle = vtkSmartPointer< vtkPolyData >::New( );
870 vtkSmartPointer< vtkPoints > circle_points =
871 vtkSmartPointer< vtkPoints >::New( );
872 vtkSmartPointer< vtkCellArray > circle_lines =
873 vtkSmartPointer< vtkCellArray >::New( );
874 for( unsigned long s = 0; s < circle_samples; ++s )
876 double t = double( 6.2832 ) * double( s ) / double( circle_samples );
877 circle_points->InsertNextPoint(
878 std::cos( t ), std::sin( t ), double( 0 )
881 circle_lines->InsertNextCell( 2 );
882 circle_lines->InsertCellPoint( s );
883 circle_lines->InsertCellPoint( ( s + 1 ) % circle_samples );
886 this->Circle->SetPoints( circle_points );
887 this->Circle->SetLines( circle_lines );
889 this->CircleMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
890 this->CircleMapper->SetInputData( this->Circle );
891 this->CircleActor = vtkSmartPointer< vtkActor >::New( );
892 this->CircleActor->SetMapper( this->CircleMapper );
893 this->CircleActor->GetProperty( )->SetColor( 1, 0, 1 );
894 this->CircleActor->GetProperty( )->SetLineWidth( 2 );
896 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
897 this->PropPicker->PickFromListOn( );
900 // -------------------------------------------------------------------------
901 cpExtensions::Visualization::ImageInteractorStyle::
902 ~ImageInteractorStyle( )
906 // -------------------------------------------------------------------------
907 void cpExtensions::Visualization::ImageInteractorStyle::
908 _RenderAssociateInteractors( )
910 std::vector< vtkRenderWindowInteractor* >::iterator rIt =
911 this->AssociatedInteractors.begin( );
912 for( ; rIt != this->AssociatedInteractors.end( ); ++rIt )
916 // -------------------------------------------------------------------------
917 bool cpExtensions::Visualization::ImageInteractorStyle::
918 _PickPosition( double pos[ 3 ] )
920 if( this->m_SliceActors == NULL )
923 double x = double( this->Interactor->GetEventPosition( )[ 0 ] );
924 double y = double( this->Interactor->GetEventPosition( )[ 1 ] );
925 this->FindPokedRenderer( x, y );
927 this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
930 this->PropPicker->GetPickPosition( pos );
932 int axis = this->m_SliceActors->GetAxis( );
933 double* bounds = this->m_SliceActors->GetDisplayBounds( );
934 pos[ axis ] = bounds[ axis << 1 ];
939 // -------------------------------------------------------------------------
940 void cpExtensions::Visualization::ImageInteractorStyle::
943 std::cout << "upcur" << std::endl;
946 // -------------------------------------------------------------------------
947 void cpExtensions::Visualization::ImageInteractorStyle::
951 this->Interactor->GetRenderWindow( )->
952 GetRenderers( )->GetFirstRenderer( );
955 vtkCamera* cam = ren->GetActiveCamera( );
959 if( this->RadiusMoving )
961 double x = this->Cursor[ 0 ] - this->Radius[ 0 ];
962 double y = this->Cursor[ 1 ] - this->Radius[ 1 ];
963 double z = this->Cursor[ 2 ] - this->Radius[ 2 ];
964 double r = std::sqrt( ( x * x ) + ( y * y ) + ( z * z ) );
966 vtkMatrix4x4* cam_matrix = cam->GetModelViewTransformMatrix( );
967 vtkSmartPointer< vtkMatrix4x4 > circle_matrix =
968 this->CircleActor->GetUserMatrix( );
969 if( circle_matrix.GetPointer( ) == NULL )
971 circle_matrix = vtkSmartPointer< vtkMatrix4x4 >::New( );
972 this->CircleActor->SetUserMatrix( circle_matrix );
975 for( int i = 0; i < 4; ++i )
977 for( int j = 0; j < 4; ++j )
979 double v = cam_matrix->GetElement( i, j );
980 if( i < 3 && j == 3 )
981 v = this->Cursor[ i ];
984 circle_matrix->SetElement( i, j, v );
989 this->CircleActor->Modified( );
990 ren->AddActor( this->CircleActor );
993 ren->RemoveActor( this->CircleActor );
995 this->Interactor->Render( );