1 #include <cpExtensions/QT/MPRInteractionCommand.h>
3 #ifdef cpExtensions_QT4
5 #include <cpExtensions/Interaction/ImageSliceStyle.h>
6 #include <cpExtensions/Visualization/ImageViewerActors.h>
7 #include <cpExtensions/QT/ImageWidget.h>
8 #include <cpExtensions/QT/MPR3DWidget.h>
9 #include <vtkImageData.h>
11 // -------------------------------------------------------------------------
12 cpExtensions::QT::MPRInteractionCommand::
13 Self* cpExtensions::QT::MPRInteractionCommand::
16 return( new Self( ) );
19 // -------------------------------------------------------------------------
20 void cpExtensions::QT::MPRInteractionCommand::
21 AddWidget( QWidget* w )
23 typedef cpExtensions::QT::ImageWidget _TImageWidget;
24 typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget;
26 auto img = dynamic_cast< _TImageWidget* >( w );
27 auto ren = dynamic_cast< _TMPR3DWidget* >( w );
29 this->m_ImageWidgets.insert( img );
30 else if( ren != NULL )
31 this->m_MPR3DWidgets.insert( ren );
34 // -------------------------------------------------------------------------
35 void cpExtensions::QT::MPRInteractionCommand::
36 Execute( vtkObject* caller, unsigned long evId, void* data )
38 typedef cpExtensions::Interaction::ImageSliceStyle _TStyle;
40 static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1;
41 static const unsigned long _Slice = vtkCommand::UserEvent + 2;
43 // Prepare interaction data
44 auto* src = dynamic_cast< _TStyle* >( caller );
45 if( src == NULL || ( evId != _SuperCursor && evId != _Slice ) )
47 if( evId == _SuperCursor )
50 auto ori = src->GetActors( )->GetOrientation( );
51 auto img = src->GetActors( )->GetImage( );
52 auto pos = reinterpret_cast< double* >( data );
55 img->ComputeStructuredCoordinates( pos, ijk, pcoords );
58 auto i = this->m_ImageWidgets.begin( );
59 i != this->m_ImageWidgets.end( );
62 if( ( *i )->GetInteractorStyle( ) != src )
63 ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
66 auto r = this->m_MPR3DWidgets.begin( );
67 r != this->m_MPR3DWidgets.end( );
70 ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
73 else if( evId == _Slice )
75 int slc = src->GetSliceNumber( );
76 int ori = src->GetOrientation( );
78 auto r = this->m_MPR3DWidgets.begin( );
79 r != this->m_MPR3DWidgets.end( );
82 ( *r )->SetSliceNumber( ori, slc );
87 // -------------------------------------------------------------------------
88 cpExtensions::QT::MPRInteractionCommand::
89 MPRInteractionCommand( )
94 // -------------------------------------------------------------------------
95 cpExtensions::QT::MPRInteractionCommand::
96 ~MPRInteractionCommand( )
100 #endif // cpExtensions_QT4