]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/SimpleMPRWidget.cxx
Spline widget added.
[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 /*
184   auto image = dynamic_cast< vtkImageData* >( data );
185   auto pdata = dynamic_cast< vtkPolyData* >( data );
186
187   if( image != NULL )
188   {
189     if( this->m_MainImageName != "" )
190     {
191       this->m_XImage->Add( image, name );
192       this->m_YImage->Add( image, name );
193       this->m_ZImage->Add( image, name );
194       this->m_3DView->Add( image, name );
195     }
196     else
197       this->SetImage( image, name );
198   }
199   else if( pdata != NULL )
200     this->m_3DView->Add( pdata, name );
201   else
202     success = false;
203 */
204   return( success );
205 }
206
207 // -------------------------------------------------------------------------
208 cpExtensions::QT::SimpleMPRWidget::
209 TProps cpExtensions::QT::SimpleMPRWidget::
210 GetViewProps( const std::string& name ) const
211 {
212 /*
213   auto x = this->m_XImage->GetViewProps( name );
214   auto y = this->m_YImage->GetViewProps( name );
215   auto z = this->m_ZImage->GetViewProps( name );
216   auto w = this->m_3DView->GetViewProps( name );
217
218   TProps props;
219   if( x != NULL ) props.insert( x );
220   if( y != NULL ) props.insert( y );
221   if( z != NULL ) props.insert( z );
222   if( w != NULL ) props.insert( w );
223   return( props );
224 */
225 }
226
227 // -------------------------------------------------------------------------
228 cpExtensions::QT::SimpleMPRWidget::
229 TProps cpExtensions::QT::SimpleMPRWidget::
230 GetImageProps( ) const
231 {
232   return( this->GetViewProps( this->m_MainImageName ) );
233 }
234
235 // -------------------------------------------------------------------------
236 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
237 GetXInteractor( )
238 {
239   return( this->m_XImage->GetInteractor( ) );
240 }
241
242 // -------------------------------------------------------------------------
243 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
244 GetXInteractor( ) const
245 {
246   return( this->m_XImage->GetInteractor( ) );
247 }
248
249 // -------------------------------------------------------------------------
250 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
251 GetYInteractor( )
252 {
253   return( this->m_YImage->GetInteractor( ) );
254 }
255
256 // -------------------------------------------------------------------------
257 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
258 GetYInteractor( ) const
259 {
260   return( this->m_YImage->GetInteractor( ) );
261 }
262
263 // -------------------------------------------------------------------------
264 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
265 GetZInteractor( )
266 {
267   return( this->m_ZImage->GetInteractor( ) );
268 }
269
270 // -------------------------------------------------------------------------
271 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
272 GetZInteractor( ) const
273 {
274   return( this->m_ZImage->GetInteractor( ) );
275 }
276
277 // -------------------------------------------------------------------------
278 vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
279 GetWInteractor( )
280 {
281   return( this->m_3DView->GetInteractor( ) );
282 }
283
284 // -------------------------------------------------------------------------
285 const vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
286 GetWInteractor( ) const
287 {
288   return( this->m_3DView->GetInteractor( ) );
289 }
290
291 // -------------------------------------------------------------------------
292 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
293 GetXRenderWindow( )
294 {
295   return( this->m_XImage->GetRenderWindow( ) );
296 }
297
298 // -------------------------------------------------------------------------
299 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
300 GetXRenderWindow( ) const
301 {
302   return( this->m_XImage->GetRenderWindow( ) );
303 }
304
305 // -------------------------------------------------------------------------
306 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
307 GetYRenderWindow( )
308 {
309   return( this->m_YImage->GetRenderWindow( ) );
310 }
311
312 // -------------------------------------------------------------------------
313 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
314 GetYRenderWindow( ) const
315 {
316   return( this->m_YImage->GetRenderWindow( ) );
317 }
318
319 // -------------------------------------------------------------------------
320 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
321 GetZRenderWindow( )
322 {
323   return( this->m_ZImage->GetRenderWindow( ) );
324 }
325
326 // -------------------------------------------------------------------------
327 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
328 GetZRenderWindow( ) const
329 {
330   return( this->m_ZImage->GetRenderWindow( ) );
331 }
332
333 // -------------------------------------------------------------------------
334 vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
335 GetWRenderWindow( )
336 {
337   return( this->m_3DView->GetRenderWindow( ) );
338 }
339
340
341 // -------------------------------------------------------------------------
342 const vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
343 GetWRenderWindow( ) const
344 {
345   return( this->m_3DView->GetRenderWindow( ) );
346 }
347
348 // -------------------------------------------------------------------------
349 void cpExtensions::QT::SimpleMPRWidget::
350 GetScalarRange( double r[ 2 ] ) const
351 {
352 //  this->m_XImage->GetScalarRange( r );
353 }
354
355 // -------------------------------------------------------------------------
356 void cpExtensions::QT::SimpleMPRWidget::
357 GetWindowLevel( double wl[ 2 ] ) const
358 {
359 //  this->m_XImage->GetWindowLevel( wl );
360 }
361
362 // -------------------------------------------------------------------------
363 double cpExtensions::QT::SimpleMPRWidget::
364 GetImageOpacity( ) const
365 {
366 //  return( this->m_XImage->GetImageOpacity( ) );
367 }
368
369 // -------------------------------------------------------------------------
370 unsigned char cpExtensions::QT::SimpleMPRWidget::
371 GetImageInterpolation( ) const
372 {
373 //  return( this->m_XImage->GetImageInterpolation( ) );
374 }
375
376 // -------------------------------------------------------------------------
377 void cpExtensions::QT::SimpleMPRWidget::
378 SetScalarRange( double r[ 2 ] )
379 {
380 /*
381   this->m_XImage->SetScalarRange( r );
382   this->m_YImage->SetScalarRange( r );
383   this->m_ZImage->SetScalarRange( r );
384   this->m_3DView->SetScalarRange( r );
385 */
386 }
387
388 // -------------------------------------------------------------------------
389 void cpExtensions::QT::SimpleMPRWidget::
390 SetWindowLevel( double wl[ 2 ] )
391 {
392 /*
393   this->m_XImage->SetWindowLevel( wl );
394   this->m_YImage->SetWindowLevel( wl );
395   this->m_ZImage->SetWindowLevel( wl );
396   this->m_3DView->SetWindowLevel( wl );
397 */
398 }
399
400 // -------------------------------------------------------------------------
401 void cpExtensions::QT::SimpleMPRWidget::
402 SetImageOpacity( double o )
403 {
404 /*
405   this->m_XImage->SetImageOpacity( o );
406   this->m_YImage->SetImageOpacity( o );
407   this->m_ZImage->SetImageOpacity( o );
408   this->m_3DView->SetImageOpacity( o );
409 */
410 }
411
412 // -------------------------------------------------------------------------
413 void cpExtensions::QT::SimpleMPRWidget::
414 SetImageInterpolation( unsigned char i )
415 {
416   /*
417   this->m_XImage->SetImageInterpolation( i );
418   this->m_YImage->SetImageInterpolation( i );
419   this->m_ZImage->SetImageInterpolation( i );
420   this->m_3DView->SetImageInterpolation( i );
421 */
422 }
423
424 // -------------------------------------------------------------------------
425 void cpExtensions::QT::SimpleMPRWidget::
426 ResetCameras( )
427 {
428 /*
429   this->m_XImage->ResetCamera( );
430   this->m_YImage->ResetCamera( );
431   this->m_ZImage->ResetCamera( );
432   this->m_3DView->ResetCamera( );
433 */
434 }
435
436 // -------------------------------------------------------------------------
437 void cpExtensions::QT::SimpleMPRWidget::
438 Render( )
439 {
440 /*
441   this->m_XImage->Render( );
442   this->m_YImage->Render( );
443   this->m_ZImage->Render( );
444   this->m_3DView->Render( );
445 */
446 }
447
448 // -------------------------------------------------------------------------
449 void cpExtensions::QT::SimpleMPRWidget::
450 _SyncBottom( int a, int b )
451 {
452   this->m_UI->Bottom->setSizes( this->m_UI->Top->sizes( ) );
453 }
454
455 // -------------------------------------------------------------------------
456 void cpExtensions::QT::SimpleMPRWidget::
457 _SyncTop( int a, int b )
458 {
459   this->m_UI->Top->setSizes( this->m_UI->Bottom->sizes( ) );
460 }
461
462 // -------------------------------------------------------------------------
463 void cpExtensions::QT::SimpleMPRWidget::
464 _ConfigurationButton( )
465 {
466   auto dlg = new cpExtensions::QT::ConfigurationChooser( NULL );
467   dlg->setData( this );
468   dlg->exec( );
469 }
470
471 #endif // cpExtensions_QT4
472
473 // eof - $RCSfile$