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 )
24 typedef cpExtensions::QT::ImageWidget _TImageWidget;
25 typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget;
27 auto img = dynamic_cast< _TImageWidget* >( w );
28 auto ren = dynamic_cast< _TMPR3DWidget* >( w );
30 this->m_ImageWidgets.insert( img );
31 else if( ren != NULL )
32 this->m_MPR3DWidgets.insert( ren );
36 // -------------------------------------------------------------------------
37 void cpExtensions::QT::MPRInteractionCommand::
38 Execute( vtkObject* caller, unsigned long evId, void* data )
41 typedef cpExtensions::Interaction::ImageSliceStyle _TStyle;
43 static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1;
44 static const unsigned long _Slice = vtkCommand::UserEvent + 2;
46 // Prepare interaction data
47 auto* src = dynamic_cast< _TStyle* >( caller );
48 if( src == NULL || ( evId != _SuperCursor && evId != _Slice ) )
50 if( evId == _SuperCursor )
52 auto ori = src->GetActors( )->GetOrientation( );
53 auto img = src->GetActors( )->GetImage( );
54 auto pos = reinterpret_cast< double* >( data );
57 img->ComputeStructuredCoordinates( pos, ijk, pcoords );
60 auto i = this->m_ImageWidgets.begin( );
61 i != this->m_ImageWidgets.end( );
64 if( ( *i )->GetInteractorStyle( ) != src )
65 ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
68 auto r = this->m_MPR3DWidgets.begin( );
69 r != this->m_MPR3DWidgets.end( );
72 ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
74 else if( evId == _Slice )
76 auto slice = *( reinterpret_cast< int* >( data ) );
77 auto ori = src->GetActors( )->GetOrientation( );
79 auto r = this->m_MPR3DWidgets.begin( );
80 r != this->m_MPR3DWidgets.end( );
83 ( *r )->SetSliceNumber( ori, slice );
89 // -------------------------------------------------------------------------
90 cpExtensions::QT::MPRInteractionCommand::
91 MPRInteractionCommand( )
96 // -------------------------------------------------------------------------
97 cpExtensions::QT::MPRInteractionCommand::
98 ~MPRInteractionCommand( )
102 #endif // cpExtensions_QT4