]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
ab47c28a32e0e354b1e4a0dafcd57ac0ad852c80
[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 // -------------------------------------------------------------------------
9 cpExtensions::QT::SimpleMPRWidget::
10 SimpleMPRWidget( QWidget* parent )
11   : QWidget( parent ),
12     m_UI( new Ui::SimpleMPRWidget )
13 {
14   this->m_UI->setupUi( this );
15
16   // Configure VTK widgets
17   this->m_VTK[ 0 ] = this->m_UI->VTK01;
18   this->m_VTK[ 1 ] = this->m_UI->VTK00;
19   this->m_VTK[ 2 ] = this->m_UI->VTK10;
20   this->m_VTK[ 3 ] = this->m_UI->VTK11;
21
22   for( unsigned int i = 0; i < 4; ++i )
23   {
24     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
25     this->m_VTK[ i ]->GetRenderWindow( )->
26       AddRenderer( this->m_Renderers[ i ] );
27
28   } // rof
29
30   // Connect slots
31   QObject::connect(
32     this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
33     this, SLOT( _SyncBottom( int, int ) )
34     );
35   QObject::connect(
36     this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
37     this, SLOT( _SyncTop( int, int ) )
38     );
39 }
40
41 // -------------------------------------------------------------------------
42 cpExtensions::QT::SimpleMPRWidget::
43 ~SimpleMPRWidget( )
44 {
45   delete this->m_UI;
46 }
47
48 // -------------------------------------------------------------------------
49 void cpExtensions::QT::SimpleMPRWidget::
50 Clear( )
51 {
52   for( unsigned int i = 0; i < 4; ++i )
53     this->m_Renderers[ i ]->RemoveAllViewProps( );
54   for( unsigned int i = 0; i < 3; ++i )
55   {
56     if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
57       this->m_2DSlices[ i ]->Clear( );
58     if( this->m_3DSlices[ i ].GetPointer( ) != NULL )
59       this->m_3DSlices[ i ]->Clear( );
60
61   } // rof
62   this->m_PolyDatas.clear( );
63 }
64
65 // -------------------------------------------------------------------------
66 void cpExtensions::QT::SimpleMPRWidget::
67 SetMainImage( vtkImageData* image )
68 {
69   for( unsigned int i = 0; i < 3; ++i )
70   {
71     this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
72     this->m_2DSlices[ i ]->SetInputData( image, i );
73     this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
74     this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
75       SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
76
77     this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
78     this->m_3DSlices[ i ]->SetInputData( image, i );
79     this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
80     this->m_3DSlices[ i ]->SetStyle(
81       dynamic_cast< vtkInteractorStyle* >(
82         this->m_Renderers[ 3 ]->GetRenderWindow( )->
83         GetInteractor( )->GetInteractorStyle( )
84         )
85       );
86
87   } // rof
88
89   for( unsigned int i = 0; i < 3; ++i )
90   {
91     for( unsigned int j = 0; j < 3; ++j )
92     {
93       if( i != j )
94         this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
95       this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
96
97     } // rof
98
99   } // rof
100   for( unsigned int i = 0; i < 3; ++i )
101   {
102     this->m_2DSlices[ i ]->GetStyle( )->
103       SetCurrentRenderer( this->m_Renderers[ i ] );
104     this->m_Renderers[ i ]->ResetCamera( );
105     this->m_VTK[ i ]->GetRenderWindow( )->Render( );
106
107   } // rof
108   this->m_Renderers[ 3 ]->ResetCamera( );
109   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
110 }
111
112 // -------------------------------------------------------------------------
113 void cpExtensions::QT::SimpleMPRWidget::
114 AddMesh( vtkPolyData* mesh )
115 {
116   PolyDataActor a;
117   a.Configure( mesh );
118   this->m_PolyDatas[ mesh ] = a;
119   this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
120
121   bool has_main_image = false;
122   for( unsigned int i = 0; i < 3; ++i )
123   {
124     if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
125     {
126       if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
127       {
128         has_main_image = true;
129         this->m_2DSlices[ i ]->AddMesh( mesh );
130         this->m_2DSlices[ i ]->Render( );
131
132       } // fi
133
134     } // fi
135
136   } // rof
137   if( !has_main_image )
138     this->m_Renderers[ 3 ]->ResetCamera( );
139   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
140 }
141
142 // -------------------------------------------------------------------------
143 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
144 GetInteractor( unsigned int i )
145 {
146   if( i < 4 )
147     return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
148   else
149     return( NULL );
150 }
151
152 // -------------------------------------------------------------------------
153 vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
154 GetRenderer( unsigned int i )
155 {
156   if( i < 4 )
157     return( this->m_Renderers[ i ] );
158   else
159     return( NULL );
160 }
161
162 // -------------------------------------------------------------------------
163 std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
164 cpExtensions::QT::SimpleMPRWidget::
165 GetMainImageActors( )
166 {
167   std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
168   for( unsigned int i = 0; i < 3; ++i )
169   {
170     actors.push_back(
171       std::pair< vtkImageActor*, vtkRenderer* >(
172         this->m_2DSlices[ i ]->GetImageActor( ),
173         this->m_Renderers[ i ]
174         )
175       );
176     actors.push_back(
177       std::pair< vtkImageActor*, vtkRenderer* >(
178         this->m_3DSlices[ i ]->GetImageActor( ),
179         this->m_Renderers[ 3 ]
180         )
181       );
182
183   } // rof
184   return( actors );
185 }
186
187 // -------------------------------------------------------------------------
188 vtkActor* cpExtensions::QT::SimpleMPRWidget::
189 GetActor( vtkPolyData* mesh )
190 {
191   auto i = this->m_PolyDatas.find( mesh );
192   if( i != this->m_PolyDatas.end( ) )
193     return( i->second.Actor.GetPointer( ) );
194   else
195     return( NULL );
196 }
197
198 // -------------------------------------------------------------------------
199 void cpExtensions::QT::SimpleMPRWidget::
200 _SyncBottom( int a, int b )
201 {
202   this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
203 }
204
205 // -------------------------------------------------------------------------
206 void cpExtensions::QT::SimpleMPRWidget::
207 _SyncTop( int a, int b )
208 {
209   this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
210 }
211
212 #endif // cpExtensions_QT4
213
214 // eof - $RCSfile$