1 #include <cpExtensions/QT/MPRInteractionCommand.h>
2 #include <cpExtensions/Interaction/ImageSliceStyle.h>
3 #include <cpExtensions/Visualization/ImageViewerActors.h>
4 #include <cpExtensions/QT/ImageWidget.h>
5 #include <cpExtensions/QT/MPR3DWidget.h>
6 #include <vtkImageData.h>
8 // -------------------------------------------------------------------------
9 cpExtensions::QT::MPRInteractionCommand::
10 Self* cpExtensions::QT::MPRInteractionCommand::
13 return( new Self( ) );
16 // -------------------------------------------------------------------------
17 void cpExtensions::QT::MPRInteractionCommand::
18 AddWidget( QWidget* w )
20 typedef cpExtensions::QT::ImageWidget _TImageWidget;
21 typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget;
23 auto img = dynamic_cast< _TImageWidget* >( w );
24 auto ren = dynamic_cast< _TMPR3DWidget* >( w );
26 this->m_ImageWidgets.insert( img );
27 else if( ren != NULL )
28 this->m_MPR3DWidgets.insert( ren );
31 // -------------------------------------------------------------------------
32 void cpExtensions::QT::MPRInteractionCommand::
33 Execute( vtkObject* caller, unsigned long evId, void* data )
35 typedef cpExtensions::Interaction::ImageSliceStyle _TStyle;
37 static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1;
38 static const unsigned long _Slice = vtkCommand::UserEvent + 2;
40 // Prepare interaction data
41 auto* src = dynamic_cast< _TStyle* >( caller );
42 if( src == NULL || ( evId != _SuperCursor && evId != _Slice ) )
44 if( evId == _SuperCursor )
47 auto ori = src->GetActors( )->GetOrientation( );
48 auto img = src->GetActors( )->GetImage( );
49 auto pos = reinterpret_cast< double* >( data );
52 img->ComputeStructuredCoordinates( pos, ijk, pcoords );
55 auto i = this->m_ImageWidgets.begin( );
56 i != this->m_ImageWidgets.end( );
59 if( ( *i )->GetInteractorStyle( ) != src )
60 ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
63 auto r = this->m_MPR3DWidgets.begin( );
64 r != this->m_MPR3DWidgets.end( );
67 ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
70 else if( evId == _Slice )
72 int slc = src->GetSliceNumber( );
73 int ori = src->GetOrientation( );
75 auto r = this->m_MPR3DWidgets.begin( );
76 r != this->m_MPR3DWidgets.end( );
79 ( *r )->SetSliceNumber( ori, slc );
84 // -------------------------------------------------------------------------
85 cpExtensions::QT::MPRInteractionCommand::
86 MPRInteractionCommand( )
91 // -------------------------------------------------------------------------
92 cpExtensions::QT::MPRInteractionCommand::
93 ~MPRInteractionCommand( )