]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/MPRInteractionCommand.cxx
Architecture updated.
[cpPlugins.git] / lib / cpExtensions / QT / MPRInteractionCommand.cxx
1 #include <cpExtensions/QT/MPRInteractionCommand.h>
2
3 #ifdef cpExtensions_QT4
4
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>
10
11 // -------------------------------------------------------------------------
12 cpExtensions::QT::MPRInteractionCommand::
13 Self* cpExtensions::QT::MPRInteractionCommand::
14 New( )
15 {
16   return( new Self( ) );
17 }
18
19 // -------------------------------------------------------------------------
20 void cpExtensions::QT::MPRInteractionCommand::
21 AddWidget( QWidget* w )
22 {
23   typedef cpExtensions::QT::ImageWidget _TImageWidget;
24   typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget;
25
26   auto img = dynamic_cast< _TImageWidget* >( w );
27   auto ren = dynamic_cast< _TMPR3DWidget* >( w );
28   if( img != NULL )
29     this->m_ImageWidgets.insert( img );
30   else if( ren != NULL )
31     this->m_MPR3DWidgets.insert( ren );
32 }
33
34 // -------------------------------------------------------------------------
35 void cpExtensions::QT::MPRInteractionCommand::
36 Execute( vtkObject* caller, unsigned long evId, void* data )
37 {
38   typedef cpExtensions::Interaction::ImageSliceStyle _TStyle;
39
40   static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1;
41   static const unsigned long _Slice = vtkCommand::UserEvent + 2;
42
43   // Prepare interaction data
44   auto* src = dynamic_cast< _TStyle* >( caller );
45   if( src == NULL || ( evId != _SuperCursor && evId != _Slice ) )
46     return;
47   if( evId == _SuperCursor )
48   {
49     auto ori = src->GetActors( )->GetOrientation( );
50     auto img = src->GetActors( )->GetImage( );
51     auto pos = reinterpret_cast< double* >( data );
52     int ijk[ 3 ];
53     double pcoords[ 3 ];
54     img->ComputeStructuredCoordinates( pos, ijk, pcoords );
55
56     for(
57       auto i = this->m_ImageWidgets.begin( );
58       i != this->m_ImageWidgets.end( );
59       ++i
60       )
61       if( ( *i )->GetInteractorStyle( ) != src )
62         ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
63     
64     for(
65       auto r = this->m_MPR3DWidgets.begin( );
66       r != this->m_MPR3DWidgets.end( );
67       ++r
68       )
69       ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
70   }
71   else if( evId == _Slice )
72   {
73     auto slice = *( reinterpret_cast< int* >( data ) );
74     auto ori = src->GetActors( )->GetOrientation( );
75     for(
76       auto r = this->m_MPR3DWidgets.begin( );
77       r != this->m_MPR3DWidgets.end( );
78       ++r
79       )
80       ( *r )->SetSliceNumber( ori, slice );
81     
82   } // fi
83 }
84       
85 // -------------------------------------------------------------------------
86 cpExtensions::QT::MPRInteractionCommand::
87 MPRInteractionCommand( )
88   : Superclass( )
89 {
90 }
91
92 // -------------------------------------------------------------------------
93 cpExtensions::QT::MPRInteractionCommand::
94 ~MPRInteractionCommand( )
95 {
96 }
97
98 #endif // cpExtensions_QT4
99
100 // eof - $RCSfile$