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 this->Superclass::OnMouseMove( );
35 // Get current position on the associated actors
36 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
37 if( rwi == NULL || this->MouseMoveCommand == NULL )
41 bool alt = ( rwi->GetAltKey( ) == 1 );
42 bool ctr = ( rwi->GetControlKey( ) == 1 );
43 bool sft = ( rwi->GetShiftKey( ) == 1 );
44 ButtonID button = this->GetButtonID( );
47 if( !( this->_PickPosition( pos ) ) )
50 // Invoke possible events
51 this->MouseMoveCommand( this->Data, button, pos, alt, ctr, sft );
55 // -------------------------------------------------------------------------
56 void cpExtensions::Visualization::ImageInteractorStyle::
57 OnMouseWheelForward( )
59 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
60 if( rwi == NULL || this->MouseWheelCommand == NULL )
64 bool alt = ( rwi->GetAltKey( ) == 1 );
65 bool ctr = ( rwi->GetControlKey( ) == 1 );
66 bool sft = ( rwi->GetShiftKey( ) == 1 );
68 // Invoke possible events
69 this->MouseWheelCommand( this->Data, 1, alt, ctr, sft );
73 // -------------------------------------------------------------------------
74 void cpExtensions::Visualization::ImageInteractorStyle::
75 OnMouseWheelBackward( )
77 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
78 if( rwi == NULL || this->MouseWheelCommand == NULL )
82 bool alt = ( rwi->GetAltKey( ) == 1 );
83 bool ctr = ( rwi->GetControlKey( ) == 1 );
84 bool sft = ( rwi->GetShiftKey( ) == 1 );
86 // Invoke possible events
87 this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
91 // -------------------------------------------------------------------------
92 void cpExtensions::Visualization::ImageInteractorStyle::
95 // Get current position on the associated actors
96 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
97 if( rwi == NULL || this->MouseClickCommand == NULL )
100 if( !( this->_PickPosition( pos ) ) )
104 bool alt = ( rwi->GetAltKey( ) == 1 );
105 bool ctr = ( rwi->GetControlKey( ) == 1 );
106 bool sft = ( rwi->GetShiftKey( ) == 1 );
108 // Invoke possible events
109 this->MouseClickCommand(
110 this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
115 // -------------------------------------------------------------------------
116 void cpExtensions::Visualization::ImageInteractorStyle::
119 // Get current position on the associated actors
120 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
121 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
124 if( !( this->_PickPosition( pos ) ) )
128 bool alt = ( rwi->GetAltKey( ) == 1 );
129 bool ctr = ( rwi->GetControlKey( ) == 1 );
130 bool sft = ( rwi->GetShiftKey( ) == 1 );
132 // Invoke possible events
133 this->MouseDoubleClickCommand(
134 this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
139 // -------------------------------------------------------------------------
140 void cpExtensions::Visualization::ImageInteractorStyle::
143 // Get current position on the associated actors
144 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
145 if( rwi == NULL || this->MouseClickCommand == NULL )
148 if( !( this->_PickPosition( pos ) ) )
152 bool alt = ( rwi->GetAltKey( ) == 1 );
153 bool ctr = ( rwi->GetControlKey( ) == 1 );
154 bool sft = ( rwi->GetShiftKey( ) == 1 );
156 // Invoke possible events
157 this->MouseClickCommand(
158 this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
163 // -------------------------------------------------------------------------
164 void cpExtensions::Visualization::ImageInteractorStyle::
165 OnMiddleDoubleClick( )
167 // Get current position on the associated actors
168 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
169 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
172 if( !( this->_PickPosition( pos ) ) )
176 bool alt = ( rwi->GetAltKey( ) == 1 );
177 bool ctr = ( rwi->GetControlKey( ) == 1 );
178 bool sft = ( rwi->GetShiftKey( ) == 1 );
180 // Invoke possible events
181 this->MouseDoubleClickCommand(
182 this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
187 // -------------------------------------------------------------------------
188 void cpExtensions::Visualization::ImageInteractorStyle::
191 // Get current position on the associated actors
192 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
193 if( rwi == NULL || this->MouseClickCommand == NULL )
196 if( !( this->_PickPosition( pos ) ) )
200 bool alt = ( rwi->GetAltKey( ) == 1 );
201 bool ctr = ( rwi->GetControlKey( ) == 1 );
202 bool sft = ( rwi->GetShiftKey( ) == 1 );
204 // Invoke possible events
205 this->MouseClickCommand(
206 this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
211 // -------------------------------------------------------------------------
212 void cpExtensions::Visualization::ImageInteractorStyle::
213 OnRightDoubleClick( )
215 // Get current position on the associated actors
216 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
217 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
220 if( !( this->_PickPosition( pos ) ) )
224 bool alt = ( rwi->GetAltKey( ) == 1 );
225 bool ctr = ( rwi->GetControlKey( ) == 1 );
226 bool sft = ( rwi->GetShiftKey( ) == 1 );
228 // Invoke possible events
229 this->MouseDoubleClickCommand(
230 this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
235 // -------------------------------------------------------------------------
236 void cpExtensions::Visualization::ImageInteractorStyle::
239 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
240 if( rwi == NULL || this->KeyCommand == NULL )
242 this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
246 // -------------------------------------------------------------------------
247 void cpExtensions::Visualization::ImageInteractorStyle::
250 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
256 // -------------------------------------------------------------------------
257 void cpExtensions::Visualization::ImageInteractorStyle::
260 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
266 // -------------------------------------------------------------------------
267 void cpExtensions::Visualization::ImageInteractorStyle::
270 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
276 // -------------------------------------------------------------------------
277 void cpExtensions::Visualization::ImageInteractorStyle::
280 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
286 // -------------------------------------------------------------------------
287 cpExtensions::Visualization::ImageInteractorStyle::
288 ImageInteractorStyle( )
291 MouseMoveCommand( NULL ),
292 MouseClickCommand( NULL ),
293 MouseDoubleClickCommand( NULL ),
294 MouseWheelCommand( NULL ),
297 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
298 this->PropPicker->PickFromListOn( );
301 // -------------------------------------------------------------------------
302 cpExtensions::Visualization::ImageInteractorStyle::
303 ~ImageInteractorStyle( )
307 // -------------------------------------------------------------------------
308 bool cpExtensions::Visualization::ImageInteractorStyle::
309 _PickPosition( double pos[ 3 ] )
311 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
315 // Find the renderer where the event has been raised
316 double x = double( rwi->GetEventPosition( )[ 0 ] );
317 double y = double( rwi->GetEventPosition( )[ 1 ] );
318 this->FindPokedRenderer( x, y );
320 // Pick a 3D position
321 int r = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
324 this->PropPicker->GetPickPosition( pos );
333 #include <vtkAnnotatedCubeActor.h>
334 #include <vtkAxesActor.h>
335 #include <vtkCallbackCommand.h>
336 #include <vtkCamera.h>
337 #include <vtkCellArray.h>
338 #include <vtkCommand.h>
339 #include <vtkMatrix4x4.h>
340 #include <vtkPropAssembly.h>
341 #include <vtkProperty.h>
342 #include <vtkRendererCollection.h>
343 #include <vtkRenderWindow.h>
344 #include <vtkRenderWindowInteractor.h>
346 #include <cpExtensions/Visualization/ImageSliceActors.h>
347 #include <cpExtensions/Visualization/MPRActors.h>
349 // -------------------------------------------------------------------------
350 const int cpExtensions::Visualization::
351 ImageInteractorStyle::CursorEvent = vtkCommand::UserEvent + 1;
352 const int cpExtensions::Visualization::
353 ImageInteractorStyle::RadiusEvent = vtkCommand::UserEvent + 2;
354 const int cpExtensions::Visualization::
355 ImageInteractorStyle::DoubleClickEvent = vtkCommand::UserEvent + 3;
357 // -------------------------------------------------------------------------
358 cpExtensions::Visualization::ImageInteractorStyle::
359 Self* cpExtensions::Visualization::ImageInteractorStyle::
362 return( new Self( ) );
365 // -------------------------------------------------------------------------
366 void cpExtensions::Visualization::ImageInteractorStyle::
367 Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
369 this->m_SliceActors = slice_actors;
370 this->m_MPRActors = mpr_actors;
371 this->SetModeToNavigation( );
372 this->PropPicker->AddPickList( slice_actors->GetImageActor( 0 ) );
376 // -------------------------------------------------------------------------
377 void cpExtensions::Visualization::ImageInteractorStyle::
378 AssociateInteractor( vtkRenderWindowInteractor* interactor )
380 if( interactor != NULL )
382 this->AssociatedInteractors.push_back( interactor );
388 // -------------------------------------------------------------------------
389 void cpExtensions::Visualization::ImageInteractorStyle::
390 SetModeToNavigation( )
392 this->Mode = Self::NavigationMode;
395 // -------------------------------------------------------------------------
396 void cpExtensions::Visualization::ImageInteractorStyle::
397 SetModeToDeformation( )
399 this->Mode = Self::DeformationMode;
402 // -------------------------------------------------------------------------
403 void cpExtensions::Visualization::ImageInteractorStyle::
404 SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
406 this->Superclass::SetInteractor( interactor );
407 this->OrientationWidget->SetInteractor( interactor );
408 interactor->SetInteractorStyle( this );
409 if( interactor == NULL )
412 // Get camera, avoiding segfaults
414 interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
417 vtkCamera* cam = ren->GetActiveCamera( );
421 // Parallel projections are better when displaying 2D images
422 cam->ParallelProjectionOn( );
423 cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
426 cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
427 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
431 cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
432 cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
434 else // if( axis == 2 )
436 cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
437 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
442 // Enable 2D orientation widget
443 this->OrientationWidget->SetEnabled( 1 );
444 this->OrientationWidget->InteractiveOff( );
447 // -------------------------------------------------------------------------
448 void cpExtensions::Visualization::ImageInteractorStyle::
451 if( this->m_MPRActors == NULL )
454 if( this->CursorMoving )
456 bool picked = this->_PickPosition( this->Cursor );
459 for( int i = 0; i < 3; ++i )
460 if( this->m_SliceActors->GetAxis( ) != i )
461 this->m_MPRActors->SetSlice( i, this->Cursor[ i ] );
462 this->InvokeEvent( Self::CursorEvent, this->Cursor );
463 this->Interactor->Render( );
464 this->_RenderAssociateInteractors( );
468 else if( this->RadiusMoving )
470 bool picked = this->_PickPosition( this->Radius );
473 this->InvokeEvent( Self::RadiusEvent, this->Radius );
474 this->_UpdateRadius( );
480 switch( this->State )
482 case VTKIS_WINDOW_LEVEL:
483 this->WindowLevel( );
496 // -------------------------------------------------------------------------
497 void cpExtensions::Visualization::ImageInteractorStyle::
500 static double pnt[ 3 ];
502 this->Interactor->GetEventPosition( pos );
503 this->FindPokedRenderer( pos[ 0 ], pos[ 1 ] );
504 if( this->CurrentRenderer == NULL )
506 this->GrabFocus( this->EventCallbackCommand );
508 // TODO: check this code
509 // Manage double-click
510 static const long epsilon_time = 800;
511 static long last_click_time = -( epsilon_time << 1 );
512 long click_time = static_cast< long >( std::clock( ) );
513 if( ( click_time - last_click_time ) < epsilon_time )
515 last_click_time = -( epsilon_time << 1 );
516 if( this->_PickPosition( pnt ) )
517 this->InvokeEvent( Self::DoubleClickEvent, pnt );
521 last_click_time = click_time;
522 if( this->Interactor->GetControlKey( ) )
523 this->StartCursorMoving( );
528 // -------------------------------------------------------------------------
529 void cpExtensions::Visualization::ImageInteractorStyle::
532 if( this->CursorMoving )
534 this->EndCursorMoving( );
535 if( this->Interactor )
536 this->ReleaseFocus( );
541 // -------------------------------------------------------------------------
542 void cpExtensions::Visualization::ImageInteractorStyle::
543 OnMiddleButtonDown( )
545 int x = this->Interactor->GetEventPosition( )[ 0 ];
546 int y = this->Interactor->GetEventPosition( )[ 1 ];
548 this->FindPokedRenderer( x, y );
549 if( this->CurrentRenderer == NULL )
551 this->GrabFocus( this->EventCallbackCommand );
553 if( this->Interactor->GetAltKey( ) )
556 else if( this->Interactor->GetControlKey( ) )
558 this->StartRadiusMoving( );
560 else if( this->Interactor->GetShiftKey( ) )
567 // -------------------------------------------------------------------------
568 void cpExtensions::Visualization::ImageInteractorStyle::
571 if( this->RadiusMoving )
573 this->EndRadiusMoving( );
574 if( this->Interactor )
575 this->ReleaseFocus( );
579 switch( this->State )
589 // -------------------------------------------------------------------------
590 void cpExtensions::Visualization::ImageInteractorStyle::
593 int x = this->Interactor->GetEventPosition( )[ 0 ];
594 int y = this->Interactor->GetEventPosition( )[ 1 ];
596 this->FindPokedRenderer( x, y );
597 if( this->CurrentRenderer == NULL )
599 this->GrabFocus( this->EventCallbackCommand );
601 if( this->Interactor->GetControlKey( ) )
603 this->WindowLevelStartPosition[ 0 ] = x;
604 this->WindowLevelStartPosition[ 1 ] = y;
605 this->StartWindowLevel( );
614 // -------------------------------------------------------------------------
615 void cpExtensions::Visualization::ImageInteractorStyle::
618 switch( this->State )
620 case VTKIS_WINDOW_LEVEL:
622 this->EndWindowLevel( );
623 if( this->Interactor )
624 this->ReleaseFocus( );
633 // -------------------------------------------------------------------------
634 void cpExtensions::Visualization::ImageInteractorStyle::
635 OnMouseWheelForward( )
637 if( this->m_SliceActors == NULL || this->Interactor == NULL )
640 if( this->Interactor->GetShiftKey( ) == 1 )
642 int s = this->m_SliceActors->GetSliceNumber( ) + off;
643 int maxs = this->m_SliceActors->GetSliceNumberMaxValue( );
644 this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs );
645 this->m_MPRActors->SetSlice(
646 this->m_SliceActors->GetAxis( ),
647 this->m_SliceActors->GetSliceNumber( )
649 this->Interactor->Render( );
650 this->_RenderAssociateInteractors( );
653 // -------------------------------------------------------------------------
654 void cpExtensions::Visualization::ImageInteractorStyle::
655 OnMouseWheelBackward( )
657 if( this->m_SliceActors == NULL || this->Interactor == NULL )
660 if( this->Interactor->GetShiftKey( ) == 1 )
662 int s = this->m_SliceActors->GetSliceNumber( ) - off;
663 int mins = this->m_SliceActors->GetSliceNumberMinValue( );
664 this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins );
665 this->m_MPRActors->SetSlice(
666 this->m_SliceActors->GetAxis( ),
667 this->m_SliceActors->GetSliceNumber( )
669 this->Interactor->Render( );
670 this->_RenderAssociateInteractors( );
673 // -------------------------------------------------------------------------
674 void cpExtensions::Visualization::ImageInteractorStyle::
677 switch( this->Interactor->GetKeyCode( ) )
682 this->Interactor->GetRenderWindow( )->
683 GetRenderers( )->GetFirstRenderer( );
686 this->Interactor->Render( );
689 case 'w': case 'W': case 'l': case 'L':
691 if( this->m_MPRActors != NULL )
693 this->m_MPRActors->ResetWindowLevel( 0 );
694 this->Interactor->Render( );
695 this->_RenderAssociateInteractors( );
703 // -------------------------------------------------------------------------
704 void cpExtensions::Visualization::ImageInteractorStyle::
707 if( this->Mode == Self::NavigationMode )
709 if( this->Interactor == NULL )
712 this->Interactor->GetRenderWindow( )->
713 GetRenderers( )->GetFirstRenderer( );
718 this->WindowLevelCurrentPosition[ 0 ] =
719 this->Interactor->GetEventPosition( )[ 0 ];
720 this->WindowLevelCurrentPosition[ 1 ] =
721 this->Interactor->GetEventPosition( )[ 1 ];
722 int* size = ren->GetSize( );
724 this->WindowLevelCurrentPosition[ 0 ] -
725 this->WindowLevelStartPosition[ 0 ]
726 ) / double( size[ 0 ] );
728 this->WindowLevelStartPosition[ 1 ] -
729 this->WindowLevelCurrentPosition[ 1 ]
730 ) / double( size[ 1 ] );
732 double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
733 double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
734 double minw = this->m_MPRActors->GetMinWindow( 0 );
735 double maxw = this->m_MPRActors->GetMaxWindow( 0 );
736 double minl = this->m_MPRActors->GetMinLevel( 0 );
737 double maxl = this->m_MPRActors->GetMaxLevel( 0 );
739 if( w < minw ) w = minw;
740 if( maxw < w ) w = maxw;
741 if( l < minl ) l = minl;
742 if( maxl < l ) l = maxl;
744 this->m_MPRActors->SetWindowLevel( 0, w, l );
745 this->Interactor->Render( );
746 this->_RenderAssociateInteractors( );
748 else if( this->Mode == Self::DeformationMode )
755 // -------------------------------------------------------------------------
756 void cpExtensions::Visualization::ImageInteractorStyle::
759 if( this->State != VTKIS_NONE )
761 if( this->Mode == Self::NavigationMode )
763 this->StartState( VTKIS_WINDOW_LEVEL );
765 this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( 0 );
766 this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( 0 );
768 else if( this->Mode == Self::DeformationMode )
775 // -------------------------------------------------------------------------
776 void cpExtensions::Visualization::ImageInteractorStyle::
779 if( this->Mode == Self::NavigationMode )
781 if( this->State != VTKIS_WINDOW_LEVEL )
792 // -------------------------------------------------------------------------
793 void cpExtensions::Visualization::ImageInteractorStyle::
796 if( this->CursorMoving )
798 this->_PickPosition( this->Cursor );
799 this->CursorMoving = true;
802 // -------------------------------------------------------------------------
803 void cpExtensions::Visualization::ImageInteractorStyle::
806 if( !( this->CursorMoving ) )
808 this->CursorMoving = false;
811 // -------------------------------------------------------------------------
812 void cpExtensions::Visualization::ImageInteractorStyle::
815 if( this->RadiusMoving )
817 this->_PickPosition( this->Radius );
818 this->RadiusMoving = true;
819 this->_UpdateRadius( );
822 // -------------------------------------------------------------------------
823 void cpExtensions::Visualization::ImageInteractorStyle::
826 if( !( this->RadiusMoving ) )
828 this->RadiusMoving = false;
829 this->_UpdateRadius( );
830 this->InvokeEvent( Self::RadiusEvent, NULL );
833 // -------------------------------------------------------------------------
834 cpExtensions::Visualization::ImageInteractorStyle::
835 ImageInteractorStyle( )
837 Mode( Self::NavigationMode ),
838 m_SliceActors( NULL ),
840 CursorMoving( false ),
841 RadiusMoving( false )
844 vtkSmartPointer< vtkAnnotatedCubeActor > cube =
845 vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
846 cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
847 cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
848 cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
849 cube->GetTextEdgesProperty( )->SetAmbient( 1 );
850 cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
851 cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
852 cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
853 cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
854 cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
855 cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
856 cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
857 cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
858 cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
859 cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
860 cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
861 cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
862 cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
864 vtkSmartPointer< vtkAxesActor > axes =
865 vtkSmartPointer< vtkAxesActor >::New( );
866 axes->AxisLabelsOff( );
867 axes->SetShaftTypeToCylinder( );
868 axes->SetTotalLength( 2, 2, 2 );
870 vtkSmartPointer< vtkPropAssembly > actors =
871 vtkSmartPointer< vtkPropAssembly >::New( );
872 actors->AddPart( cube );
873 actors->AddPart( axes );
875 this->OrientationWidget =
876 vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
877 this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
878 this->OrientationWidget->SetOrientationMarker( actors );
879 this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
882 unsigned long circle_samples = 1000;
883 this->Circle = vtkSmartPointer< vtkPolyData >::New( );
885 vtkSmartPointer< vtkPoints > circle_points =
886 vtkSmartPointer< vtkPoints >::New( );
887 vtkSmartPointer< vtkCellArray > circle_lines =
888 vtkSmartPointer< vtkCellArray >::New( );
889 for( unsigned long s = 0; s < circle_samples; ++s )
891 double t = double( 6.2832 ) * double( s ) / double( circle_samples );
892 circle_points->InsertNextPoint(
893 std::cos( t ), std::sin( t ), double( 0 )
896 circle_lines->InsertNextCell( 2 );
897 circle_lines->InsertCellPoint( s );
898 circle_lines->InsertCellPoint( ( s + 1 ) % circle_samples );
901 this->Circle->SetPoints( circle_points );
902 this->Circle->SetLines( circle_lines );
904 this->CircleMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
905 this->CircleMapper->SetInputData( this->Circle );
906 this->CircleActor = vtkSmartPointer< vtkActor >::New( );
907 this->CircleActor->SetMapper( this->CircleMapper );
908 this->CircleActor->GetProperty( )->SetColor( 1, 0, 1 );
909 this->CircleActor->GetProperty( )->SetLineWidth( 2 );
911 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
912 this->PropPicker->PickFromListOn( );
915 // -------------------------------------------------------------------------
916 cpExtensions::Visualization::ImageInteractorStyle::
917 ~ImageInteractorStyle( )
921 // -------------------------------------------------------------------------
922 void cpExtensions::Visualization::ImageInteractorStyle::
923 _RenderAssociateInteractors( )
925 std::vector< vtkRenderWindowInteractor* >::iterator rIt =
926 this->AssociatedInteractors.begin( );
927 for( ; rIt != this->AssociatedInteractors.end( ); ++rIt )
931 // -------------------------------------------------------------------------
932 bool cpExtensions::Visualization::ImageInteractorStyle::
933 _PickPosition( double pos[ 3 ] )
935 if( this->m_SliceActors == NULL )
938 double x = double( this->Interactor->GetEventPosition( )[ 0 ] );
939 double y = double( this->Interactor->GetEventPosition( )[ 1 ] );
940 this->FindPokedRenderer( x, y );
942 this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
945 this->PropPicker->GetPickPosition( pos );
947 int axis = this->m_SliceActors->GetAxis( );
948 double* bounds = this->m_SliceActors->GetDisplayBounds( );
949 pos[ axis ] = bounds[ axis << 1 ];
954 // -------------------------------------------------------------------------
955 void cpExtensions::Visualization::ImageInteractorStyle::
958 std::cout << "upcur" << std::endl;
961 // -------------------------------------------------------------------------
962 void cpExtensions::Visualization::ImageInteractorStyle::
966 this->Interactor->GetRenderWindow( )->
967 GetRenderers( )->GetFirstRenderer( );
970 vtkCamera* cam = ren->GetActiveCamera( );
974 if( this->RadiusMoving )
976 double x = this->Cursor[ 0 ] - this->Radius[ 0 ];
977 double y = this->Cursor[ 1 ] - this->Radius[ 1 ];
978 double z = this->Cursor[ 2 ] - this->Radius[ 2 ];
979 double r = std::sqrt( ( x * x ) + ( y * y ) + ( z * z ) );
981 vtkMatrix4x4* cam_matrix = cam->GetModelViewTransformMatrix( );
982 vtkSmartPointer< vtkMatrix4x4 > circle_matrix =
983 this->CircleActor->GetUserMatrix( );
984 if( circle_matrix.GetPointer( ) == NULL )
986 circle_matrix = vtkSmartPointer< vtkMatrix4x4 >::New( );
987 this->CircleActor->SetUserMatrix( circle_matrix );
990 for( int i = 0; i < 4; ++i )
992 for( int j = 0; j < 4; ++j )
994 double v = cam_matrix->GetElement( i, j );
995 if( i < 3 && j == 3 )
996 v = this->Cursor[ i ];
999 circle_matrix->SetElement( i, j, v );
1004 this->CircleActor->Modified( );
1005 ren->AddActor( this->CircleActor );
1008 ren->RemoveActor( this->CircleActor );
1010 this->Interactor->Render( );