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::
31 AssociateInteractor( vtkRenderWindowInteractor* rwi )
35 this->AssociatedInteractors.push_back( rwi );
41 // -------------------------------------------------------------------------
42 void cpExtensions::Visualization::ImageInteractorStyle::
45 this->Superclass::OnMouseMove( );
47 // Get current position on the associated actors
48 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
49 if( rwi == NULL || this->MouseMoveCommand == NULL )
53 bool alt = ( rwi->GetAltKey( ) == 1 );
54 bool ctr = ( rwi->GetControlKey( ) == 1 );
55 bool sft = ( rwi->GetShiftKey( ) == 1 );
56 ButtonID button = this->GetButtonID( );
59 if( !( this->_PickPosition( pos ) ) )
62 // Invoke possible events
63 this->MouseMoveCommand( this->Data, button, pos, alt, ctr, sft );
65 this->_RenderAssociatedInteractors( );
68 // -------------------------------------------------------------------------
69 void cpExtensions::Visualization::ImageInteractorStyle::
70 OnMouseWheelForward( )
72 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
73 if( rwi == NULL || this->MouseWheelCommand == NULL )
77 bool alt = ( rwi->GetAltKey( ) == 1 );
78 bool ctr = ( rwi->GetControlKey( ) == 1 );
79 bool sft = ( rwi->GetShiftKey( ) == 1 );
81 // Invoke possible events
82 this->MouseWheelCommand( this->Data, 1, alt, ctr, sft );
84 this->_RenderAssociatedInteractors( );
87 // -------------------------------------------------------------------------
88 void cpExtensions::Visualization::ImageInteractorStyle::
89 OnMouseWheelBackward( )
91 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
92 if( rwi == NULL || this->MouseWheelCommand == NULL )
96 bool alt = ( rwi->GetAltKey( ) == 1 );
97 bool ctr = ( rwi->GetControlKey( ) == 1 );
98 bool sft = ( rwi->GetShiftKey( ) == 1 );
100 // Invoke possible events
101 this->MouseWheelCommand( this->Data, -1, alt, ctr, sft );
103 this->_RenderAssociatedInteractors( );
106 // -------------------------------------------------------------------------
107 void cpExtensions::Visualization::ImageInteractorStyle::
110 // Get current position on the associated actors
111 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
112 if( rwi == NULL || this->MouseClickCommand == NULL )
115 if( !( this->_PickPosition( pos ) ) )
119 bool alt = ( rwi->GetAltKey( ) == 1 );
120 bool ctr = ( rwi->GetControlKey( ) == 1 );
121 bool sft = ( rwi->GetShiftKey( ) == 1 );
123 // Invoke possible events
124 this->MouseClickCommand(
125 this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
128 this->_RenderAssociatedInteractors( );
131 // -------------------------------------------------------------------------
132 void cpExtensions::Visualization::ImageInteractorStyle::
135 // Get current position on the associated actors
136 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
137 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
140 if( !( this->_PickPosition( pos ) ) )
144 bool alt = ( rwi->GetAltKey( ) == 1 );
145 bool ctr = ( rwi->GetControlKey( ) == 1 );
146 bool sft = ( rwi->GetShiftKey( ) == 1 );
148 // Invoke possible events
149 this->MouseDoubleClickCommand(
150 this->Data, Self::ButtonID_Left, pos, alt, ctr, sft
153 this->_RenderAssociatedInteractors( );
156 // -------------------------------------------------------------------------
157 void cpExtensions::Visualization::ImageInteractorStyle::
160 // Get current position on the associated actors
161 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
162 if( rwi == NULL || this->MouseClickCommand == NULL )
165 if( !( this->_PickPosition( pos ) ) )
169 bool alt = ( rwi->GetAltKey( ) == 1 );
170 bool ctr = ( rwi->GetControlKey( ) == 1 );
171 bool sft = ( rwi->GetShiftKey( ) == 1 );
173 // Invoke possible events
174 this->MouseClickCommand(
175 this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
178 this->_RenderAssociatedInteractors( );
181 // -------------------------------------------------------------------------
182 void cpExtensions::Visualization::ImageInteractorStyle::
183 OnMiddleDoubleClick( )
185 // Get current position on the associated actors
186 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
187 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
190 if( !( this->_PickPosition( pos ) ) )
194 bool alt = ( rwi->GetAltKey( ) == 1 );
195 bool ctr = ( rwi->GetControlKey( ) == 1 );
196 bool sft = ( rwi->GetShiftKey( ) == 1 );
198 // Invoke possible events
199 this->MouseDoubleClickCommand(
200 this->Data, Self::ButtonID_Middle, pos, alt, ctr, sft
203 this->_RenderAssociatedInteractors( );
206 // -------------------------------------------------------------------------
207 void cpExtensions::Visualization::ImageInteractorStyle::
210 // Get current position on the associated actors
211 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
212 if( rwi == NULL || this->MouseClickCommand == NULL )
215 if( !( this->_PickPosition( pos ) ) )
219 bool alt = ( rwi->GetAltKey( ) == 1 );
220 bool ctr = ( rwi->GetControlKey( ) == 1 );
221 bool sft = ( rwi->GetShiftKey( ) == 1 );
223 // Invoke possible events
224 this->MouseClickCommand(
225 this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
228 this->_RenderAssociatedInteractors( );
231 // -------------------------------------------------------------------------
232 void cpExtensions::Visualization::ImageInteractorStyle::
233 OnRightDoubleClick( )
235 // Get current position on the associated actors
236 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
237 if( rwi == NULL || this->MouseDoubleClickCommand == NULL )
240 if( !( this->_PickPosition( pos ) ) )
244 bool alt = ( rwi->GetAltKey( ) == 1 );
245 bool ctr = ( rwi->GetControlKey( ) == 1 );
246 bool sft = ( rwi->GetShiftKey( ) == 1 );
248 // Invoke possible events
249 this->MouseDoubleClickCommand(
250 this->Data, Self::ButtonID_Right, pos, alt, ctr, sft
253 this->_RenderAssociatedInteractors( );
256 // -------------------------------------------------------------------------
257 void cpExtensions::Visualization::ImageInteractorStyle::
260 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
261 if( rwi == NULL || this->KeyCommand == NULL )
263 this->KeyCommand( this->Data, rwi->GetKeyCode( ) );
265 this->_RenderAssociatedInteractors( );
268 // -------------------------------------------------------------------------
269 void cpExtensions::Visualization::ImageInteractorStyle::
272 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
276 this->_RenderAssociatedInteractors( );
279 // -------------------------------------------------------------------------
280 void cpExtensions::Visualization::ImageInteractorStyle::
283 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
287 this->_RenderAssociatedInteractors( );
290 // -------------------------------------------------------------------------
291 void cpExtensions::Visualization::ImageInteractorStyle::
294 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
298 this->_RenderAssociatedInteractors( );
301 // -------------------------------------------------------------------------
302 void cpExtensions::Visualization::ImageInteractorStyle::
305 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
309 this->_RenderAssociatedInteractors( );
312 // -------------------------------------------------------------------------
313 cpExtensions::Visualization::ImageInteractorStyle::
314 ImageInteractorStyle( )
317 MouseMoveCommand( NULL ),
318 MouseClickCommand( NULL ),
319 MouseDoubleClickCommand( NULL ),
320 MouseWheelCommand( NULL ),
323 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
324 this->PropPicker->PickFromListOn( );
327 // -------------------------------------------------------------------------
328 cpExtensions::Visualization::ImageInteractorStyle::
329 ~ImageInteractorStyle( )
333 // -------------------------------------------------------------------------
334 bool cpExtensions::Visualization::ImageInteractorStyle::
335 _PickPosition( double pos[ 3 ] )
337 vtkRenderWindowInteractor* rwi = this->GetInteractor( );
341 // Find the renderer where the event has been raised
342 double x = double( rwi->GetEventPosition( )[ 0 ] );
343 double y = double( rwi->GetEventPosition( )[ 1 ] );
344 this->FindPokedRenderer( x, y );
346 // Pick a 3D position
347 int r = this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
350 this->PropPicker->GetPickPosition( pos );
355 // -------------------------------------------------------------------------
356 void cpExtensions::Visualization::ImageInteractorStyle::
357 _RenderAssociatedInteractors( )
359 for( unsigned int i = 0; i < this->AssociatedInteractors.size( ); ++i )
360 this->AssociatedInteractors[ i ]->Render( );
367 #include <vtkAnnotatedCubeActor.h>
368 #include <vtkAxesActor.h>
369 #include <vtkCallbackCommand.h>
370 #include <vtkCamera.h>
371 #include <vtkCellArray.h>
372 #include <vtkCommand.h>
373 #include <vtkMatrix4x4.h>
374 #include <vtkPropAssembly.h>
375 #include <vtkProperty.h>
376 #include <vtkRendererCollection.h>
377 #include <vtkRenderWindow.h>
378 #include <vtkRenderWindowInteractor.h>
380 #include <cpExtensions/Visualization/ImageSliceActors.h>
381 #include <cpExtensions/Visualization/MPRActors.h>
383 // -------------------------------------------------------------------------
384 const int cpExtensions::Visualization::
385 ImageInteractorStyle::CursorEvent = vtkCommand::UserEvent + 1;
386 const int cpExtensions::Visualization::
387 ImageInteractorStyle::RadiusEvent = vtkCommand::UserEvent + 2;
388 const int cpExtensions::Visualization::
389 ImageInteractorStyle::DoubleClickEvent = vtkCommand::UserEvent + 3;
391 // -------------------------------------------------------------------------
392 cpExtensions::Visualization::ImageInteractorStyle::
393 Self* cpExtensions::Visualization::ImageInteractorStyle::
396 return( new Self( ) );
399 // -------------------------------------------------------------------------
400 void cpExtensions::Visualization::ImageInteractorStyle::
401 Configure( ImageSliceActors* slice_actors, MPRActors* mpr_actors )
403 this->m_SliceActors = slice_actors;
404 this->m_MPRActors = mpr_actors;
405 this->SetModeToNavigation( );
406 this->PropPicker->AddPickList( slice_actors->GetImageActor( 0 ) );
410 // -------------------------------------------------------------------------
411 void cpExtensions::Visualization::ImageInteractorStyle::
412 AssociateInteractor( vtkRenderWindowInteractor* interactor )
414 if( interactor != NULL )
416 this->AssociatedInteractors.push_back( interactor );
422 // -------------------------------------------------------------------------
423 void cpExtensions::Visualization::ImageInteractorStyle::
424 SetModeToNavigation( )
426 this->Mode = Self::NavigationMode;
429 // -------------------------------------------------------------------------
430 void cpExtensions::Visualization::ImageInteractorStyle::
431 SetModeToDeformation( )
433 this->Mode = Self::DeformationMode;
436 // -------------------------------------------------------------------------
437 void cpExtensions::Visualization::ImageInteractorStyle::
438 SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
440 this->Superclass::SetInteractor( interactor );
441 this->OrientationWidget->SetInteractor( interactor );
442 interactor->SetInteractorStyle( this );
443 if( interactor == NULL )
446 // Get camera, avoiding segfaults
448 interactor->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
451 vtkCamera* cam = ren->GetActiveCamera( );
455 // Parallel projections are better when displaying 2D images
456 cam->ParallelProjectionOn( );
457 cam->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
460 cam->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
461 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
465 cam->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
466 cam->SetViewUp ( double( 0 ), double( 0 ), double( -1 ) );
468 else // if( axis == 2 )
470 cam->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
471 cam->SetViewUp ( double( 0 ), double( 1 ), double( 0 ) );
476 // Enable 2D orientation widget
477 this->OrientationWidget->SetEnabled( 1 );
478 this->OrientationWidget->InteractiveOff( );
481 // -------------------------------------------------------------------------
482 void cpExtensions::Visualization::ImageInteractorStyle::
485 if( this->m_MPRActors == NULL )
488 if( this->CursorMoving )
490 bool picked = this->_PickPosition( this->Cursor );
493 for( int i = 0; i < 3; ++i )
494 if( this->m_SliceActors->GetAxis( ) != i )
495 this->m_MPRActors->SetSlice( i, this->Cursor[ i ] );
496 this->InvokeEvent( Self::CursorEvent, this->Cursor );
497 this->Interactor->Render( );
498 this->_RenderAssociateInteractors( );
502 else if( this->RadiusMoving )
504 bool picked = this->_PickPosition( this->Radius );
507 this->InvokeEvent( Self::RadiusEvent, this->Radius );
508 this->_UpdateRadius( );
514 switch( this->State )
516 case VTKIS_WINDOW_LEVEL:
517 this->WindowLevel( );
530 // -------------------------------------------------------------------------
531 void cpExtensions::Visualization::ImageInteractorStyle::
534 static double pnt[ 3 ];
536 this->Interactor->GetEventPosition( pos );
537 this->FindPokedRenderer( pos[ 0 ], pos[ 1 ] );
538 if( this->CurrentRenderer == NULL )
540 this->GrabFocus( this->EventCallbackCommand );
542 // TODO: check this code
543 // Manage double-click
544 static const long epsilon_time = 800;
545 static long last_click_time = -( epsilon_time << 1 );
546 long click_time = static_cast< long >( std::clock( ) );
547 if( ( click_time - last_click_time ) < epsilon_time )
549 last_click_time = -( epsilon_time << 1 );
550 if( this->_PickPosition( pnt ) )
551 this->InvokeEvent( Self::DoubleClickEvent, pnt );
555 last_click_time = click_time;
556 if( this->Interactor->GetControlKey( ) )
557 this->StartCursorMoving( );
562 // -------------------------------------------------------------------------
563 void cpExtensions::Visualization::ImageInteractorStyle::
566 if( this->CursorMoving )
568 this->EndCursorMoving( );
569 if( this->Interactor )
570 this->ReleaseFocus( );
575 // -------------------------------------------------------------------------
576 void cpExtensions::Visualization::ImageInteractorStyle::
577 OnMiddleButtonDown( )
579 int x = this->Interactor->GetEventPosition( )[ 0 ];
580 int y = this->Interactor->GetEventPosition( )[ 1 ];
582 this->FindPokedRenderer( x, y );
583 if( this->CurrentRenderer == NULL )
585 this->GrabFocus( this->EventCallbackCommand );
587 if( this->Interactor->GetAltKey( ) )
590 else if( this->Interactor->GetControlKey( ) )
592 this->StartRadiusMoving( );
594 else if( this->Interactor->GetShiftKey( ) )
601 // -------------------------------------------------------------------------
602 void cpExtensions::Visualization::ImageInteractorStyle::
605 if( this->RadiusMoving )
607 this->EndRadiusMoving( );
608 if( this->Interactor )
609 this->ReleaseFocus( );
613 switch( this->State )
623 // -------------------------------------------------------------------------
624 void cpExtensions::Visualization::ImageInteractorStyle::
627 int x = this->Interactor->GetEventPosition( )[ 0 ];
628 int y = this->Interactor->GetEventPosition( )[ 1 ];
630 this->FindPokedRenderer( x, y );
631 if( this->CurrentRenderer == NULL )
633 this->GrabFocus( this->EventCallbackCommand );
635 if( this->Interactor->GetControlKey( ) )
637 this->WindowLevelStartPosition[ 0 ] = x;
638 this->WindowLevelStartPosition[ 1 ] = y;
639 this->StartWindowLevel( );
648 // -------------------------------------------------------------------------
649 void cpExtensions::Visualization::ImageInteractorStyle::
652 switch( this->State )
654 case VTKIS_WINDOW_LEVEL:
656 this->EndWindowLevel( );
657 if( this->Interactor )
658 this->ReleaseFocus( );
667 // -------------------------------------------------------------------------
668 void cpExtensions::Visualization::ImageInteractorStyle::
669 OnMouseWheelForward( )
671 if( this->m_SliceActors == NULL || this->Interactor == NULL )
674 if( this->Interactor->GetShiftKey( ) == 1 )
676 int s = this->m_SliceActors->GetSliceNumber( ) + off;
677 int maxs = this->m_SliceActors->GetSliceNumberMaxValue( );
678 this->m_SliceActors->SetSliceNumber( ( s < maxs )? s: maxs );
679 this->m_MPRActors->SetSlice(
680 this->m_SliceActors->GetAxis( ),
681 this->m_SliceActors->GetSliceNumber( )
683 this->Interactor->Render( );
684 this->_RenderAssociateInteractors( );
687 // -------------------------------------------------------------------------
688 void cpExtensions::Visualization::ImageInteractorStyle::
689 OnMouseWheelBackward( )
691 if( this->m_SliceActors == NULL || this->Interactor == NULL )
694 if( this->Interactor->GetShiftKey( ) == 1 )
696 int s = this->m_SliceActors->GetSliceNumber( ) - off;
697 int mins = this->m_SliceActors->GetSliceNumberMinValue( );
698 this->m_SliceActors->SetSliceNumber( ( mins < s )? s: mins );
699 this->m_MPRActors->SetSlice(
700 this->m_SliceActors->GetAxis( ),
701 this->m_SliceActors->GetSliceNumber( )
703 this->Interactor->Render( );
704 this->_RenderAssociateInteractors( );
707 // -------------------------------------------------------------------------
708 void cpExtensions::Visualization::ImageInteractorStyle::
711 switch( this->Interactor->GetKeyCode( ) )
716 this->Interactor->GetRenderWindow( )->
717 GetRenderers( )->GetFirstRenderer( );
720 this->Interactor->Render( );
723 case 'w': case 'W': case 'l': case 'L':
725 if( this->m_MPRActors != NULL )
727 this->m_MPRActors->ResetWindowLevel( 0 );
728 this->Interactor->Render( );
729 this->_RenderAssociateInteractors( );
737 // -------------------------------------------------------------------------
738 void cpExtensions::Visualization::ImageInteractorStyle::
741 if( this->Mode == Self::NavigationMode )
743 if( this->Interactor == NULL )
746 this->Interactor->GetRenderWindow( )->
747 GetRenderers( )->GetFirstRenderer( );
752 this->WindowLevelCurrentPosition[ 0 ] =
753 this->Interactor->GetEventPosition( )[ 0 ];
754 this->WindowLevelCurrentPosition[ 1 ] =
755 this->Interactor->GetEventPosition( )[ 1 ];
756 int* size = ren->GetSize( );
758 this->WindowLevelCurrentPosition[ 0 ] -
759 this->WindowLevelStartPosition[ 0 ]
760 ) / double( size[ 0 ] );
762 this->WindowLevelStartPosition[ 1 ] -
763 this->WindowLevelCurrentPosition[ 1 ]
764 ) / double( size[ 1 ] );
766 double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
767 double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
768 double minw = this->m_MPRActors->GetMinWindow( 0 );
769 double maxw = this->m_MPRActors->GetMaxWindow( 0 );
770 double minl = this->m_MPRActors->GetMinLevel( 0 );
771 double maxl = this->m_MPRActors->GetMaxLevel( 0 );
773 if( w < minw ) w = minw;
774 if( maxw < w ) w = maxw;
775 if( l < minl ) l = minl;
776 if( maxl < l ) l = maxl;
778 this->m_MPRActors->SetWindowLevel( 0, w, l );
779 this->Interactor->Render( );
780 this->_RenderAssociateInteractors( );
782 else if( this->Mode == Self::DeformationMode )
789 // -------------------------------------------------------------------------
790 void cpExtensions::Visualization::ImageInteractorStyle::
793 if( this->State != VTKIS_NONE )
795 if( this->Mode == Self::NavigationMode )
797 this->StartState( VTKIS_WINDOW_LEVEL );
799 this->WindowLevelInitial[ 0 ] = this->m_MPRActors->GetWindow( 0 );
800 this->WindowLevelInitial[ 1 ] = this->m_MPRActors->GetLevel( 0 );
802 else if( this->Mode == Self::DeformationMode )
809 // -------------------------------------------------------------------------
810 void cpExtensions::Visualization::ImageInteractorStyle::
813 if( this->Mode == Self::NavigationMode )
815 if( this->State != VTKIS_WINDOW_LEVEL )
826 // -------------------------------------------------------------------------
827 void cpExtensions::Visualization::ImageInteractorStyle::
830 if( this->CursorMoving )
832 this->_PickPosition( this->Cursor );
833 this->CursorMoving = true;
836 // -------------------------------------------------------------------------
837 void cpExtensions::Visualization::ImageInteractorStyle::
840 if( !( this->CursorMoving ) )
842 this->CursorMoving = false;
845 // -------------------------------------------------------------------------
846 void cpExtensions::Visualization::ImageInteractorStyle::
849 if( this->RadiusMoving )
851 this->_PickPosition( this->Radius );
852 this->RadiusMoving = true;
853 this->_UpdateRadius( );
856 // -------------------------------------------------------------------------
857 void cpExtensions::Visualization::ImageInteractorStyle::
860 if( !( this->RadiusMoving ) )
862 this->RadiusMoving = false;
863 this->_UpdateRadius( );
864 this->InvokeEvent( Self::RadiusEvent, NULL );
867 // -------------------------------------------------------------------------
868 cpExtensions::Visualization::ImageInteractorStyle::
869 ImageInteractorStyle( )
871 Mode( Self::NavigationMode ),
872 m_SliceActors( NULL ),
874 CursorMoving( false ),
875 RadiusMoving( false )
878 vtkSmartPointer< vtkAnnotatedCubeActor > cube =
879 vtkSmartPointer< vtkAnnotatedCubeActor >::New( );
880 cube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 );
881 cube->GetTextEdgesProperty( )->SetLineWidth( 1 );
882 cube->GetTextEdgesProperty( )->SetDiffuse( 0 );
883 cube->GetTextEdgesProperty( )->SetAmbient( 1 );
884 cube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 );
885 cube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 );
886 cube->GetXPlusFaceProperty( )->SetInterpolationToFlat( );
887 cube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 );
888 cube->GetXMinusFaceProperty( )->SetInterpolationToFlat( );
889 cube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 );
890 cube->GetYPlusFaceProperty( )->SetInterpolationToFlat( );
891 cube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 );
892 cube->GetYMinusFaceProperty( )->SetInterpolationToFlat( );
893 cube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 );
894 cube->GetZPlusFaceProperty( )->SetInterpolationToFlat( );
895 cube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 );
896 cube->GetZMinusFaceProperty( )->SetInterpolationToFlat( );
898 vtkSmartPointer< vtkAxesActor > axes =
899 vtkSmartPointer< vtkAxesActor >::New( );
900 axes->AxisLabelsOff( );
901 axes->SetShaftTypeToCylinder( );
902 axes->SetTotalLength( 2, 2, 2 );
904 vtkSmartPointer< vtkPropAssembly > actors =
905 vtkSmartPointer< vtkPropAssembly >::New( );
906 actors->AddPart( cube );
907 actors->AddPart( axes );
909 this->OrientationWidget =
910 vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
911 this->OrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 );
912 this->OrientationWidget->SetOrientationMarker( actors );
913 this->OrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 );
916 unsigned long circle_samples = 1000;
917 this->Circle = vtkSmartPointer< vtkPolyData >::New( );
919 vtkSmartPointer< vtkPoints > circle_points =
920 vtkSmartPointer< vtkPoints >::New( );
921 vtkSmartPointer< vtkCellArray > circle_lines =
922 vtkSmartPointer< vtkCellArray >::New( );
923 for( unsigned long s = 0; s < circle_samples; ++s )
925 double t = double( 6.2832 ) * double( s ) / double( circle_samples );
926 circle_points->InsertNextPoint(
927 std::cos( t ), std::sin( t ), double( 0 )
930 circle_lines->InsertNextCell( 2 );
931 circle_lines->InsertCellPoint( s );
932 circle_lines->InsertCellPoint( ( s + 1 ) % circle_samples );
935 this->Circle->SetPoints( circle_points );
936 this->Circle->SetLines( circle_lines );
938 this->CircleMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
939 this->CircleMapper->SetInputData( this->Circle );
940 this->CircleActor = vtkSmartPointer< vtkActor >::New( );
941 this->CircleActor->SetMapper( this->CircleMapper );
942 this->CircleActor->GetProperty( )->SetColor( 1, 0, 1 );
943 this->CircleActor->GetProperty( )->SetLineWidth( 2 );
945 this->PropPicker = vtkSmartPointer< vtkPropPicker >::New( );
946 this->PropPicker->PickFromListOn( );
949 // -------------------------------------------------------------------------
950 cpExtensions::Visualization::ImageInteractorStyle::
951 ~ImageInteractorStyle( )
955 // -------------------------------------------------------------------------
956 void cpExtensions::Visualization::ImageInteractorStyle::
957 _RenderAssociateInteractors( )
959 std::vector< vtkRenderWindowInteractor* >::iterator rIt =
960 this->AssociatedInteractors.begin( );
961 for( ; rIt != this->AssociatedInteractors.end( ); ++rIt )
965 // -------------------------------------------------------------------------
966 bool cpExtensions::Visualization::ImageInteractorStyle::
967 _PickPosition( double pos[ 3 ] )
969 if( this->m_SliceActors == NULL )
972 double x = double( this->Interactor->GetEventPosition( )[ 0 ] );
973 double y = double( this->Interactor->GetEventPosition( )[ 1 ] );
974 this->FindPokedRenderer( x, y );
976 this->PropPicker->Pick( x, y, double( 0 ), this->CurrentRenderer );
979 this->PropPicker->GetPickPosition( pos );
981 int axis = this->m_SliceActors->GetAxis( );
982 double* bounds = this->m_SliceActors->GetDisplayBounds( );
983 pos[ axis ] = bounds[ axis << 1 ];
988 // -------------------------------------------------------------------------
989 void cpExtensions::Visualization::ImageInteractorStyle::
992 std::cout << "upcur" << std::endl;
995 // -------------------------------------------------------------------------
996 void cpExtensions::Visualization::ImageInteractorStyle::
1000 this->Interactor->GetRenderWindow( )->
1001 GetRenderers( )->GetFirstRenderer( );
1004 vtkCamera* cam = ren->GetActiveCamera( );
1008 if( this->RadiusMoving )
1010 double x = this->Cursor[ 0 ] - this->Radius[ 0 ];
1011 double y = this->Cursor[ 1 ] - this->Radius[ 1 ];
1012 double z = this->Cursor[ 2 ] - this->Radius[ 2 ];
1013 double r = std::sqrt( ( x * x ) + ( y * y ) + ( z * z ) );
1015 vtkMatrix4x4* cam_matrix = cam->GetModelViewTransformMatrix( );
1016 vtkSmartPointer< vtkMatrix4x4 > circle_matrix =
1017 this->CircleActor->GetUserMatrix( );
1018 if( circle_matrix.GetPointer( ) == NULL )
1020 circle_matrix = vtkSmartPointer< vtkMatrix4x4 >::New( );
1021 this->CircleActor->SetUserMatrix( circle_matrix );
1024 for( int i = 0; i < 4; ++i )
1026 for( int j = 0; j < 4; ++j )
1028 double v = cam_matrix->GetElement( i, j );
1029 if( i < 3 && j == 3 )
1030 v = this->Cursor[ i ];
1031 if( i < 3 && j < 3 )
1033 circle_matrix->SetElement( i, j, v );
1038 this->CircleActor->Modified( );
1039 ren->AddActor( this->CircleActor );
1042 ren->RemoveActor( this->CircleActor );
1044 this->Interactor->Render( );