]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
Raster filter updated. LUT image visualization strange bug :-(
[cpPlugins.git] / lib / cpExtensions / QT / SimpleMPRWidget.cxx
1 #include <cpExtensions/QT/SimpleMPRWidget.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <cpExtensions/QT/ui_SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/MPR3DWidget.h>
8 #include <cpExtensions/QT/MPRInteractionCommand.h>
9 #include <cpExtensions/QT/ConfigurationChooser.h>
10
11 #include <vtkImageData.h>
12 #include <vtkPolyData.h>
13 #include <vtkProp.h>
14 #include <vtkPropCollection.h>
15
16 // -------------------------------------------------------------------------
17 cpExtensions::QT::SimpleMPRWidget::
18 SimpleMPRWidget( QWidget* parent, Qt::WindowFlags f )
19   : Superclass( parent, f ),
20     m_UI( new Ui::SimpleMPRWidget ),
21     m_MainImageName( "" )
22 {
23   this->m_UI->setupUi( this );
24
25   // Prepare default configuration
26   this->m_UI->Q1->hide( );
27   this->m_UI->Q2->hide( );
28   this->m_UI->Q3->hide( );
29   this->m_UI->Q4->hide( );
30   this->m_UI->Q1->close( );
31   this->m_UI->Q2->close( );
32   this->m_UI->Q3->close( );
33   this->m_UI->Q4->close( );
34   delete this->m_UI->Q1;
35   delete this->m_UI->Q2;
36   delete this->m_UI->Q3;
37   delete this->m_UI->Q4;
38   this->m_XImage = new ImageWidget( this );
39   this->m_YImage = new ImageWidget( this );
40   this->m_ZImage = new ImageWidget( this );
41   this->m_3DView = new MPR3DWidget( this );
42   this->m_UI->Q1 = this->m_XImage;
43   this->m_UI->Q2 = this->m_YImage;
44   this->m_UI->Q3 = this->m_ZImage;
45   this->m_UI->Q4 = this->m_3DView;
46   this->Configure( 'y', 'x', 'w', 'z' );
47
48   // Interaction synchronizer
49   unsigned long ev1 = vtkCommand::UserEvent + 1;
50   unsigned long ev2 = vtkCommand::UserEvent + 2;
51   vtkSmartPointer< cpExtensions::QT::MPRInteractionCommand > cmd =
52     vtkSmartPointer< cpExtensions::QT::MPRInteractionCommand >::New( );
53   cmd->AddWidget( this->m_XImage );
54   cmd->AddWidget( this->m_YImage );
55   cmd->AddWidget( this->m_ZImage );
56   cmd->AddWidget( this->m_3DView );
57   this->m_XImage->GetStyle( )->AddObserver( ev1, cmd );
58   this->m_YImage->GetStyle( )->AddObserver( ev1, cmd );
59   this->m_ZImage->GetStyle( )->AddObserver( ev1, cmd );
60   this->m_XImage->GetStyle( )->AddObserver( ev2, cmd );
61   this->m_YImage->GetStyle( )->AddObserver( ev2, cmd );
62   this->m_ZImage->GetStyle( )->AddObserver( ev2, cmd );
63
64   // Connect slots
65   this->connect(
66     this->m_UI->Top, SIGNAL( splitterMoved( int, int ) ),
67     this, SLOT( _SyncBottom( int, int ) )
68     );
69   this->connect(
70     this->m_UI->Bottom, SIGNAL( splitterMoved( int, int ) ),
71     this, SLOT( _SyncTop( int, int ) )
72     );
73   this->connect(
74     this->m_UI->ConfigurationButton, SIGNAL( clicked( ) ),
75     this, SLOT( _ConfigurationButton( ) )
76     );
77 }
78
79 // -------------------------------------------------------------------------
80 cpExtensions::QT::SimpleMPRWidget::
81 ~SimpleMPRWidget( )
82 {
83   delete this->m_UI;
84 }
85
86 // -------------------------------------------------------------------------
87 void cpExtensions::QT::SimpleMPRWidget::
88 Configure( char q1, char q2, char q3, char q4 )
89 {
90   // Hide all widgets
91   this->m_UI->Q1->hide( );
92   this->m_UI->Q2->hide( );
93   this->m_UI->Q3->hide( );
94   this->m_UI->Q4->hide( );
95   this->m_UI->Q1->close( );
96   this->m_UI->Q2->close( );
97   this->m_UI->Q3->close( );
98   this->m_UI->Q4->close( );
99
100   // Reorder them
101   if     ( q1 == 'x' ) this->m_UI->Top->addWidget( this->m_XImage );
102   else if( q1 == 'y' ) this->m_UI->Top->addWidget( this->m_YImage );
103   else if( q1 == 'z' ) this->m_UI->Top->addWidget( this->m_ZImage );
104   else if( q1 == 'w' ) this->m_UI->Top->addWidget( this->m_3DView );
105   if     ( q2 == 'x' ) this->m_UI->Top->addWidget( this->m_XImage );
106   else if( q2 == 'y' ) this->m_UI->Top->addWidget( this->m_YImage );
107   else if( q2 == 'z' ) this->m_UI->Top->addWidget( this->m_ZImage );
108   else if( q2 == 'w' ) this->m_UI->Top->addWidget( this->m_3DView );
109   this->m_UI->Top->update( );
110   if     ( q4 == 'x' ) this->m_UI->Bottom->addWidget( this->m_XImage );
111   else if( q4 == 'y' ) this->m_UI->Bottom->addWidget( this->m_YImage );
112   else if( q4 == 'z' ) this->m_UI->Bottom->addWidget( this->m_ZImage );
113   else if( q4 == 'w' ) this->m_UI->Bottom->addWidget( this->m_3DView );
114   if     ( q3 == 'x' ) this->m_UI->Bottom->addWidget( this->m_XImage );
115   else if( q3 == 'y' ) this->m_UI->Bottom->addWidget( this->m_YImage );
116   else if( q3 == 'z' ) this->m_UI->Bottom->addWidget( this->m_ZImage );
117   else if( q3 == 'w' ) this->m_UI->Bottom->addWidget( this->m_3DView );
118   this->m_UI->Bottom->update( );
119
120   // Keep track
121   if     ( q1 == 'x' ) this->m_UI->Q1 = this->m_XImage;
122   else if( q1 == 'y' ) this->m_UI->Q1 = this->m_YImage;
123   else if( q1 == 'z' ) this->m_UI->Q1 = this->m_ZImage;
124   else if( q1 == 'w' ) this->m_UI->Q1 = this->m_3DView;
125   if     ( q2 == 'x' ) this->m_UI->Q2 = this->m_XImage;
126   else if( q2 == 'y' ) this->m_UI->Q2 = this->m_YImage;
127   else if( q2 == 'z' ) this->m_UI->Q2 = this->m_ZImage;
128   else if( q2 == 'w' ) this->m_UI->Q2 = this->m_3DView;
129   if     ( q3 == 'x' ) this->m_UI->Q3 = this->m_XImage;
130   else if( q3 == 'y' ) this->m_UI->Q3 = this->m_YImage;
131   else if( q3 == 'z' ) this->m_UI->Q3 = this->m_ZImage;
132   else if( q3 == 'w' ) this->m_UI->Q3 = this->m_3DView;
133   if     ( q4 == 'x' ) this->m_UI->Q4 = this->m_XImage;
134   else if( q4 == 'y' ) this->m_UI->Q4 = this->m_YImage;
135   else if( q4 == 'z' ) this->m_UI->Q4 = this->m_ZImage;
136   else if( q4 == 'w' ) this->m_UI->Q4 = this->m_3DView;
137
138   // Draw all
139   this->m_UI->Q1->show( );
140   this->m_UI->Q2->show( );
141   this->m_UI->Q3->show( );
142   this->m_UI->Q4->show( );
143   dynamic_cast< RendererWidget* >( this->m_UI->Q1 )->SetQuadrant( 1 );
144   dynamic_cast< RendererWidget* >( this->m_UI->Q2 )->SetQuadrant( 2 );
145   dynamic_cast< RendererWidget* >( this->m_UI->Q3 )->SetQuadrant( 3 );
146   dynamic_cast< RendererWidget* >( this->m_UI->Q4 )->SetQuadrant( 4 );
147 }
148
149 // -------------------------------------------------------------------------
150 bool cpExtensions::QT::SimpleMPRWidget::
151 HasImage( ) const
152 {
153   return( this->m_MainImage.GetPointer( ) != NULL );
154 }
155
156 // -------------------------------------------------------------------------
157 void cpExtensions::QT::SimpleMPRWidget::
158 SetImage( vtkImageData* image, const std::string& name )
159 {
160   if( this->m_MainImageName != "" || image == NULL )
161   {
162     // TODO: Clear visualization
163
164   } // fi
165   this->m_MainImageName = name;
166   this->m_MainImage = image;
167
168   if( this->m_MainImage != NULL && this->m_MainImageName != "" )
169   {
170     this->m_XImage->SetImage( this->m_MainImage, 0, name );
171     this->m_YImage->SetImage( this->m_MainImage, 1, name );
172     this->m_ZImage->SetImage( this->m_MainImage, 2, name );
173     this->m_3DView->SetImage( this->m_MainImage, name );
174
175   } // fi
176 }
177
178 // -------------------------------------------------------------------------
179 bool cpExtensions::QT::SimpleMPRWidget::
180 Add( vtkDataSet* data, const std::string& name )
181 {
182   bool success = true;
183   auto image = dynamic_cast< vtkImageData* >( data );
184   auto pdata = dynamic_cast< vtkPolyData* >( data );
185
186   if( image != NULL )
187   {
188     if( this->m_MainImageName != "" )
189     {
190       this->m_XImage->Add( image, name );
191       this->m_YImage->Add( image, name );
192       this->m_ZImage->Add( image, name );
193       // TODO: this->m_3DView->Add( image, name );
194     }
195     else
196       this->SetImage( image, name );
197   }
198   else if( pdata != NULL )
199     this->m_3DView->Add( pdata, name );
200   else
201     success = false;
202   return( success );
203 }
204
205 // -------------------------------------------------------------------------
206 cpExtensions::QT::SimpleMPRWidget::
207 TProps cpExtensions::QT::SimpleMPRWidget::
208 GetViewProps( const std::string& name ) const
209 {
210 /*
211   auto x = this->m_XImage->GetViewProps( name );
212   auto y = this->m_YImage->GetViewProps( name );
213   auto z = this->m_ZImage->GetViewProps( name );
214   auto w = this->m_3DView->GetViewProps( name );
215
216   TProps props;
217   if( x != NULL ) props.insert( x );
218   if( y != NULL ) props.insert( y );
219   if( z != NULL ) props.insert( z );
220   if( w != NULL ) props.insert( w );
221   return( props );
222 */
223 }
224
225 // -------------------------------------------------------------------------
226 cpExtensions::QT::SimpleMPRWidget::
227 TProps cpExtensions::QT::SimpleMPRWidget::
228 GetImageProps( ) const
229 {
230   return( this->GetViewProps( this->m_MainImageName ) );
231 }
232
233 // -------------------------------------------------------------------------
234 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
235 GetXInteractor( )
236 {
237   return( this->m_XImage->GetInteractor( ) );
238 }
239
240 // -------------------------------------------------------------------------
241 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
242 GetXInteractor( ) const
243 {
244   return( this->m_XImage->GetInteractor( ) );
245 }
246
247 // -------------------------------------------------------------------------
248 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
249 GetYInteractor( )
250 {
251   return( this->m_YImage->GetInteractor( ) );
252 }
253
254 // -------------------------------------------------------------------------
255 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
256 GetYInteractor( ) const
257 {
258   return( this->m_YImage->GetInteractor( ) );
259 }
260
261 // -------------------------------------------------------------------------
262 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
263 GetZInteractor( )
264 {
265   return( this->m_ZImage->GetInteractor( ) );
266 }
267
268 // -------------------------------------------------------------------------
269 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
270 GetZInteractor( ) const
271 {
272   return( this->m_ZImage->GetInteractor( ) );
273 }
274
275 // -------------------------------------------------------------------------
276 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
277 GetWInteractor( )
278 {
279   return( this->m_3DView->GetInteractor( ) );
280 }
281
282 // -------------------------------------------------------------------------
283 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
284 GetWInteractor( ) const
285 {
286   return( this->m_3DView->GetInteractor( ) );
287 }
288
289 // -------------------------------------------------------------------------
290 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
291 GetXRenderWindow( )
292 {
293   return( this->m_XImage->GetRenderWindow( ) );
294 }
295
296 // -------------------------------------------------------------------------
297 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
298 GetXRenderWindow( ) const
299 {
300   return( this->m_XImage->GetRenderWindow( ) );
301 }
302
303 // -------------------------------------------------------------------------
304 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
305 GetYRenderWindow( )
306 {
307   return( this->m_YImage->GetRenderWindow( ) );
308 }
309
310 // -------------------------------------------------------------------------
311 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
312 GetYRenderWindow( ) const
313 {
314   return( this->m_YImage->GetRenderWindow( ) );
315 }
316
317 // -------------------------------------------------------------------------
318 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
319 GetZRenderWindow( )
320 {
321   return( this->m_ZImage->GetRenderWindow( ) );
322 }
323
324 // -------------------------------------------------------------------------
325 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
326 GetZRenderWindow( ) const
327 {
328   return( this->m_ZImage->GetRenderWindow( ) );
329 }
330
331 // -------------------------------------------------------------------------
332 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
333 GetWRenderWindow( )
334 {
335   return( this->m_3DView->GetRenderWindow( ) );
336 }
337
338
339 // -------------------------------------------------------------------------
340 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
341 GetWRenderWindow( ) const
342 {
343   return( this->m_3DView->GetRenderWindow( ) );
344 }
345
346 // -------------------------------------------------------------------------
347 void cpExtensions::QT::SimpleMPRWidget::
348 GetScalarRange( double r[ 2 ] ) const
349 {
350 //  this->m_XImage->GetScalarRange( r );
351 }
352
353 // -------------------------------------------------------------------------
354 void cpExtensions::QT::SimpleMPRWidget::
355 GetWindowLevel( double wl[ 2 ] ) const
356 {
357 //  this->m_XImage->GetWindowLevel( wl );
358 }
359
360 // -------------------------------------------------------------------------
361 double cpExtensions::QT::SimpleMPRWidget::
362 GetImageOpacity( ) const
363 {
364 //  return( this->m_XImage->GetImageOpacity( ) );
365 }
366
367 // -------------------------------------------------------------------------
368 unsigned char cpExtensions::QT::SimpleMPRWidget::
369 GetImageInterpolation( ) const
370 {
371 //  return( this->m_XImage->GetImageInterpolation( ) );
372 }
373
374 // -------------------------------------------------------------------------
375 void cpExtensions::QT::SimpleMPRWidget::
376 SetScalarRange( double r[ 2 ] )
377 {
378 /*
379   this->m_XImage->SetScalarRange( r );
380   this->m_YImage->SetScalarRange( r );
381   this->m_ZImage->SetScalarRange( r );
382   this->m_3DView->SetScalarRange( r );
383 */
384 }
385
386 // -------------------------------------------------------------------------
387 void cpExtensions::QT::SimpleMPRWidget::
388 SetWindowLevel( double wl[ 2 ] )
389 {
390 /*
391   this->m_XImage->SetWindowLevel( wl );
392   this->m_YImage->SetWindowLevel( wl );
393   this->m_ZImage->SetWindowLevel( wl );
394   this->m_3DView->SetWindowLevel( wl );
395 */
396 }
397
398 // -------------------------------------------------------------------------
399 void cpExtensions::QT::SimpleMPRWidget::
400 SetImageOpacity( double o )
401 {
402 /*
403   this->m_XImage->SetImageOpacity( o );
404   this->m_YImage->SetImageOpacity( o );
405   this->m_ZImage->SetImageOpacity( o );
406   this->m_3DView->SetImageOpacity( o );
407 */
408 }
409
410 // -------------------------------------------------------------------------
411 void cpExtensions::QT::SimpleMPRWidget::
412 SetImageInterpolation( unsigned char i )
413 {
414   /*
415   this->m_XImage->SetImageInterpolation( i );
416   this->m_YImage->SetImageInterpolation( i );
417   this->m_ZImage->SetImageInterpolation( i );
418   this->m_3DView->SetImageInterpolation( i );
419 */
420 }
421
422 // -------------------------------------------------------------------------
423 void cpExtensions::QT::SimpleMPRWidget::
424 ResetCameras( )
425 {
426 /*
427   this->m_XImage->ResetCamera( );
428   this->m_YImage->ResetCamera( );
429   this->m_ZImage->ResetCamera( );
430   this->m_3DView->ResetCamera( );
431 */
432 }
433
434 // -------------------------------------------------------------------------
435 void cpExtensions::QT::SimpleMPRWidget::
436 Render( )
437 {
438 /*
439   this->m_XImage->Render( );
440   this->m_YImage->Render( );
441   this->m_ZImage->Render( );
442   this->m_3DView->Render( );
443 */
444 }
445
446 // -------------------------------------------------------------------------
447 void cpExtensions::QT::SimpleMPRWidget::
448 _SyncBottom( int a, int b )
449 {
450   this->m_UI->Bottom->setSizes( this->m_UI->Top->sizes( ) );
451 }
452
453 // -------------------------------------------------------------------------
454 void cpExtensions::QT::SimpleMPRWidget::
455 _SyncTop( int a, int b )
456 {
457   this->m_UI->Top->setSizes( this->m_UI->Bottom->sizes( ) );
458 }
459
460 // -------------------------------------------------------------------------
461 void cpExtensions::QT::SimpleMPRWidget::
462 _ConfigurationButton( )
463 {
464   auto dlg = new cpExtensions::QT::ConfigurationChooser( NULL );
465   dlg->setData( this );
466   dlg->exec( );
467 }
468
469 #endif // cpExtensions_QT4
470
471 // eof - $RCSfile$