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