]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/MPRInteractionCommand.cxx
...
[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     /* TODO
50        auto ori = src->GetActors( )->GetOrientation( );
51        auto img = src->GetActors( )->GetImage( );
52        auto pos = reinterpret_cast< double* >( data );
53        int ijk[ 3 ];
54        double pcoords[ 3 ];
55        img->ComputeStructuredCoordinates( pos, ijk, pcoords );
56
57        for(
58        auto i = this->m_ImageWidgets.begin( );
59        i != this->m_ImageWidgets.end( );
60        ++i
61        )
62        if( ( *i )->GetInteractorStyle( ) != src )
63        ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
64     
65        for(
66        auto r = this->m_MPR3DWidgets.begin( );
67        r != this->m_MPR3DWidgets.end( );
68        ++r
69        )
70        ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
71     */
72   }
73   else if( evId == _Slice )
74   {
75     int slc = src->GetSliceNumber( );
76     int ori = src->GetOrientation( );
77     for(
78       auto r = this->m_MPR3DWidgets.begin( );
79       r != this->m_MPR3DWidgets.end( );
80       ++r
81       )
82       ( *r )->SetSliceNumber( ori, slc );
83
84   } // fi
85 }
86       
87 // -------------------------------------------------------------------------
88 cpExtensions::QT::MPRInteractionCommand::
89 MPRInteractionCommand( )
90   : Superclass( )
91 {
92 }
93
94 // -------------------------------------------------------------------------
95 cpExtensions::QT::MPRInteractionCommand::
96 ~MPRInteractionCommand( )
97 {
98 }
99
100 #endif // cpExtensions_QT4
101
102 // eof - $RCSfile$