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 )
49 auto ori = src->GetActors( )->GetOrientation( );
50 auto img = src->GetActors( )->GetImage( );
51 auto pos = reinterpret_cast< double* >( data );
54 img->ComputeStructuredCoordinates( pos, ijk, pcoords );
57 auto i = this->m_ImageWidgets.begin( );
58 i != this->m_ImageWidgets.end( );
61 if( ( *i )->GetInteractorStyle( ) != src )
62 ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
65 auto r = this->m_MPR3DWidgets.begin( );
66 r != this->m_MPR3DWidgets.end( );
69 ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
71 else if( evId == _Slice )
73 auto slice = *( reinterpret_cast< int* >( data ) );
74 auto ori = src->GetActors( )->GetOrientation( );
76 auto r = this->m_MPR3DWidgets.begin( );
77 r != this->m_MPR3DWidgets.end( );
80 ( *r )->SetSliceNumber( ori, slice );
85 // -------------------------------------------------------------------------
86 cpExtensions::QT::MPRInteractionCommand::
87 MPRInteractionCommand( )
92 // -------------------------------------------------------------------------
93 cpExtensions::QT::MPRInteractionCommand::
94 ~MPRInteractionCommand( )
98 #endif // cpExtensions_QT4