]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
f3f1eb3c10cf7bafbe6dce11a366b67e33c42666
[cpPlugins.git] / lib / cpExtensions / QT / SimpleMPRWidget.cxx
1 #include <cpExtensions/QT/SimpleMPRWidget.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <cpExtensions/ui_SimpleMPRWidget.h>
6 #include <vtkRenderWindow.h>
7
8 /* TODO
9    #include <vtkProperty.h>
10    #include <vtkRendererCollection.h>
11    double cpExtensions::QT::SimpleMPRWidget::
12    cm_Colors[ 8 ][ 3 ] =
13    {
14    { 1.0, 0.0, 0.0 },
15    { 0.0, 1.0, 0.0 },
16    { 0.0, 0.0, 1.0 },
17    { 0.0, 1.0, 1.0 },
18    { 1.0, 0.0, 1.0 },
19    { 1.0, 1.0, 0.0 },
20    { 1.0, 0.5, 0.0 },
21    { 1.0, 0.0, 0.5 }
22    };
23 */
24
25 // -------------------------------------------------------------------------
26 cpExtensions::QT::SimpleMPRWidget::
27 SimpleMPRWidget( QWidget* parent )
28   : QWidget( parent ),
29     m_UI( new Ui::SimpleMPRWidget )
30     /*
31       ,
32       m_MainImage( "" )
33     */
34 {
35   this->m_UI->setupUi( this );
36
37   // Configure VTK widgets
38   this->m_VTK[ 0 ] = this->m_UI->VTK01;
39   this->m_VTK[ 1 ] = this->m_UI->VTK00;
40   this->m_VTK[ 2 ] = this->m_UI->VTK10;
41   this->m_VTK[ 3 ] = this->m_UI->VTK11;
42
43   for( unsigned int i = 0; i < 4; ++i )
44   {
45     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
46     this->m_VTK[ i ]->GetRenderWindow( )->AddRenderer( this->m_Renderers[ i ] );
47
48   } // rof
49
50   /*
51     this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
52     this->m_MPRObjects->SetRenderWindows(
53     this->m_VTK[ 0 ]->GetRenderWindow( ),
54     this->m_VTK[ 1 ]->GetRenderWindow( ),
55     this->m_VTK[ 2 ]->GetRenderWindow( ),
56     this->m_VTK[ 3 ]->GetRenderWindow( )
57     );
58   */
59
60   // Connect slots
61   QObject::connect(
62     this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
63     this, SLOT( _SyncBottom( int, int ) )
64     );
65   QObject::connect(
66     this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
67     this, SLOT( _SyncTop( int, int ) )
68     );
69 }
70
71 // -------------------------------------------------------------------------
72 cpExtensions::QT::SimpleMPRWidget::
73 ~SimpleMPRWidget( )
74 {
75   delete this->m_UI;
76 }
77
78 // -------------------------------------------------------------------------
79 void cpExtensions::QT::SimpleMPRWidget::
80 SetMainImage( vtkImageData* image )
81 {
82   for( unsigned int i = 0; i < 3; ++i )
83   {
84     this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
85     this->m_2DSlices[ i ]->SetInputData( image, i );
86     this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
87     this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
88       SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
89
90     this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
91     this->m_3DSlices[ i ]->SetInputData( image, i );
92     this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
93     this->m_3DSlices[ i ]->SetStyle(
94       dynamic_cast< vtkInteractorStyle* >(
95         this->m_Renderers[ 3 ]->GetRenderWindow( )->
96         GetInteractor( )->GetInteractorStyle( )
97         )
98       );
99
100   } // rof
101
102   for( unsigned int i = 0; i < 3; ++i )
103   {
104     for( unsigned int j = 0; j < 3; ++j )
105     {
106       if( i != j )
107         this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
108       this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
109
110     } // rof
111
112   } // rof
113   for( unsigned int i = 0; i < 3; ++i )
114   {
115     this->m_2DSlices[ i ]->GetStyle( )->
116       SetCurrentRenderer( this->m_Renderers[ i ] );
117     this->m_Renderers[ i ]->ResetCamera( );
118     this->m_VTK[ i ]->GetRenderWindow( )->Render( );
119
120   } // rof
121   this->m_Renderers[ 3 ]->ResetCamera( );
122   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
123 }
124
125 // -------------------------------------------------------------------------
126 void cpExtensions::QT::SimpleMPRWidget::
127 _SyncBottom( int a, int b )
128 {
129   this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
130 }
131
132 // -------------------------------------------------------------------------
133 void cpExtensions::QT::SimpleMPRWidget::
134 _SyncTop( int a, int b )
135 {
136   this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
137 }
138
139 #endif // cpExtensions_QT4
140
141 // eof - $RCSfile$