]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/QT/RendererWidget.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpExtensions / QT / RendererWidget.cxx
1 #include <cpExtensions/QT/RendererWidget.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <vtkAxesActor.h>
6 #include <vtkCamera.h>
7 #include <vtkImageProperty.h>
8 #include <vtkInteractorStyle.h>
9 #include <vtkOrientationMarkerWidget.h>
10 #include <vtkProperty.h>
11 #include <vtkRenderer.h>
12 #include <vtkRenderWindow.h>
13 #include <cpExtensions/Visualization/LUTImageActor.h>
14 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
15
16 // -------------------------------------------------------------------------
17 cpExtensions::QT::RendererWidget::
18 RendererWidget( QWidget* parent, Qt::WindowFlags f )
19   : Superclass( parent, f ),
20     Superclass2( )
21 {
22   this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
23   this->GetRenderWindow( )->AddRenderer( this->m_Renderer );
24
25   vtkAxesActor* axes = vtkAxesActor::New( );
26   axes->AxisLabelsOff( );
27   this->m_Marker = vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
28   this->m_Marker->SetOutlineColor( 1, 1, 1 );
29   this->m_Marker->SetOrientationMarker( axes );
30   this->m_Marker->SetInteractor( this->GetRenderWindow( )->GetInteractor( ) );
31   this->m_Marker->EnabledOn( );
32   this->m_Marker->InteractiveOff( );
33   axes->Delete( );
34   this->SetQuadrant( 0 );
35 }
36
37 // -------------------------------------------------------------------------
38 cpExtensions::QT::RendererWidget::
39 ~RendererWidget( )
40 {
41 }
42
43 // -------------------------------------------------------------------------
44 int cpExtensions::QT::RendererWidget::
45 GetQuadrant( ) const
46 {
47   return( this->m_Quadrant );
48 }
49
50 // -------------------------------------------------------------------------
51 void cpExtensions::QT::RendererWidget::
52 SetQuadrant( int q )
53 {
54   this->m_Quadrant = ( q - 1 ) % 4;
55   if( this->m_Quadrant == 0 )
56     this->m_Marker->SetViewport( 0.85, 0.00, 1.00, 0.15 );
57   else if( this->m_Quadrant == 1 )
58     this->m_Marker->SetViewport( 0.00, 0.00, 0.15, 0.15 );
59   else if( this->m_Quadrant == 2 )
60     this->m_Marker->SetViewport( 0.00, 0.85, 0.15, 1.00 );
61   else if( this->m_Quadrant == 3 )
62     this->m_Marker->SetViewport( 0.85, 0.85, 1.00, 1.00 );
63 }
64
65 // -------------------------------------------------------------------------
66 vtkRenderer* cpExtensions::QT::RendererWidget::
67 GetRenderer( )
68 {
69   return( this->m_Renderer );
70 }
71
72 // -------------------------------------------------------------------------
73 const vtkRenderer* cpExtensions::QT::RendererWidget::
74 GetRenderer( ) const
75 {
76   return( this->m_Renderer );
77 }
78
79 // -------------------------------------------------------------------------
80 vtkInteractorStyle* cpExtensions::QT::RendererWidget::
81 GetStyle( )
82 {
83   auto iren = this->GetInteractor( );
84   if( iren != NULL )
85     return(
86       dynamic_cast< vtkInteractorStyle* >( iren->GetInteractorStyle( ) )
87       );
88   else
89     return( NULL );
90 }
91
92 // -------------------------------------------------------------------------
93 const vtkInteractorStyle* cpExtensions::QT::RendererWidget::
94 GetStyle( ) const
95 {
96   // Ugly, but necessary :-(
97   Self* self = const_cast< Self* >( this );
98   if( self != NULL )
99   {
100     auto iren = self->GetInteractor( );
101     if( iren != NULL )
102       return(
103         dynamic_cast< const vtkInteractorStyle* >(
104           iren->GetInteractorStyle( )
105           )
106         );
107     else
108       return( NULL );
109   }
110   else
111     return( NULL );
112 }
113
114 // -------------------------------------------------------------------------
115 void cpExtensions::QT::RendererWidget::
116 SetStyle( vtkInteractorStyle* style )
117 {
118   this->GetInteractor( )->SetInteractorStyle( style );
119 }
120
121 // -------------------------------------------------------------------------
122 vtkCamera* cpExtensions::QT::RendererWidget::
123 GetActiveCamera( )
124 {
125   return( this->m_Renderer->GetActiveCamera( ) );
126 }
127
128 // -------------------------------------------------------------------------
129 const vtkCamera* cpExtensions::QT::RendererWidget::
130 GetActiveCamera( ) const
131 {
132   return( this->m_Renderer->GetActiveCamera( ) );
133 }
134
135 // -------------------------------------------------------------------------
136 void cpExtensions::QT::RendererWidget::
137 AddViewProp( vtkProp* prop, const std::string& name )
138 {
139   if( prop != NULL )
140   {
141     auto i = this->m_ViewProps.find( name );
142     if( i == this->m_ViewProps.end( ) )
143       i =
144         this->m_ViewProps.insert(
145           TPropCollection::value_type( name, TProps( ) )
146           ).first;
147     i->second.insert( prop );
148     this->m_Renderer->AddViewProp( prop );
149
150   } // fi
151 }
152
153 // -------------------------------------------------------------------------
154 void cpExtensions::QT::RendererWidget::
155 AddViewProps( vtkPropCollection* props, const std::string& name )
156 {
157   if( props != NULL )
158   {
159     auto i = this->m_ViewProps.find( name );
160     if( i == this->m_ViewProps.end( ) )
161       i =
162         this->m_ViewProps.insert(
163           TPropCollection::value_type( name, TProps( ) )
164           ).first;
165     props->InitTraversal( );
166     while( vtkProp* prop = props->GetNextProp( ) )
167     {
168       i->second.insert( prop );
169       this->m_Renderer->AddViewProp( prop );
170
171     } // elihw
172
173   } // fi
174 }
175
176 // -------------------------------------------------------------------------
177 void cpExtensions::QT::RendererWidget::
178 AddAuxViewProp( vtkProp* prop, const std::string& name )
179 {
180   if( prop != NULL )
181   {
182     auto i = this->m_AuxViewProps.find( name );
183     if( i == this->m_AuxViewProps.end( ) )
184       i =
185         this->m_AuxViewProps.insert(
186           TPropCollection::value_type( name, TProps( ) )
187           ).first;
188     i->second.insert( prop );
189     this->m_Renderer->AddViewProp( prop );
190
191   } // fi
192 }
193
194 // -------------------------------------------------------------------------
195 void cpExtensions::QT::RendererWidget::
196 AddAuxViewProps( vtkPropCollection* props, const std::string& name )
197 {
198   if( props != NULL )
199   {
200     auto i = this->m_AuxViewProps.find( name );
201     if( i == this->m_AuxViewProps.end( ) )
202       i =
203         this->m_AuxViewProps.insert(
204           TPropCollection::value_type( name, TProps( ) )
205           ).first;
206     props->InitTraversal( );
207     while( vtkProp* prop = props->GetNextProp( ) )
208     {
209       i->second.insert( prop );
210       this->m_Renderer->AddViewProp( prop );
211
212     } // elhiw
213
214   } // fi
215 }
216
217 // -------------------------------------------------------------------------
218 cpExtensions::QT::RendererWidget::
219 TProps& cpExtensions::QT::RendererWidget::
220 GetViewProps( const std::string& name )
221 {
222   static TProps zero;
223   auto i = this->m_ViewProps.find( name );
224   if( i == this->m_ViewProps.end( ) )
225   {
226     zero.clear( );
227     return( zero );
228   }
229   else
230     return( i->second );
231 }
232
233 // -------------------------------------------------------------------------
234 const cpExtensions::QT::RendererWidget::
235 TProps& cpExtensions::QT::RendererWidget::
236 GetViewProps( const std::string& name ) const
237 {
238   static const TProps zero;
239   auto i = this->m_ViewProps.find( name );
240   if( i == this->m_ViewProps.end( ) )
241     return( zero );
242   else
243     return( i->second );
244 }
245
246 // -------------------------------------------------------------------------
247 cpExtensions::QT::RendererWidget::
248 TProps& cpExtensions::QT::RendererWidget::
249 GetAuxViewProps( const std::string& name )
250 {
251   static TProps zero;
252   auto i = this->m_AuxViewProps.find( name );
253   if( i == this->m_AuxViewProps.end( ) )
254   {
255     zero.clear( );
256     return( zero );
257   }
258   else
259     return( i->second );
260 }
261
262 // -------------------------------------------------------------------------
263 const cpExtensions::QT::RendererWidget::
264 TProps& cpExtensions::QT::RendererWidget::
265 GetAuxViewProps( const std::string& name ) const
266 {
267   static const TProps zero;
268   auto i = this->m_AuxViewProps.find( name );
269   if( i == this->m_AuxViewProps.end( ) )
270     return( zero );
271   else
272     return( i->second );
273 }
274
275 // -------------------------------------------------------------------------
276 void cpExtensions::QT::RendererWidget::
277 RemoveViewProps( const std::string& name )
278 {
279   auto i = this->m_ViewProps.find( name );
280   if( i != this->m_ViewProps.end( ) )
281   {
282     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
283       this->m_Renderer->RemoveViewProp( *p );
284     this->m_ViewProps.erase( i );
285
286   } // fi
287
288   i = this->m_AuxViewProps.find( name );
289   if( i != this->m_AuxViewProps.end( ) )
290   {
291     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
292       this->m_Renderer->RemoveViewProp( *p );
293     this->m_AuxViewProps.erase( i );
294
295   } // fi
296 }
297
298 // -------------------------------------------------------------------------
299 void cpExtensions::QT::RendererWidget::
300 RemoveViewProps( )
301 {
302   this->m_Renderer->RemoveAllViewProps( );
303   this->m_ViewProps.clear( );
304   this->m_AuxViewProps.clear( );
305 }
306
307 // -------------------------------------------------------------------------
308 void cpExtensions::QT::RendererWidget::
309 HideViewProps( const std::string& name )
310 {
311   auto i = this->m_ViewProps.find( name );
312   if( i != this->m_ViewProps.end( ) )
313     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
314       ( *p )->VisibilityOff( );
315   i = this->m_AuxViewProps.find( name );
316   if( i != this->m_AuxViewProps.end( ) )
317     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
318       ( *p )->VisibilityOff( );
319 }
320
321 // -------------------------------------------------------------------------
322 void cpExtensions::QT::RendererWidget::
323 ShowViewProps( const std::string& name )
324 {
325   auto i = this->m_ViewProps.find( name );
326   if( i != this->m_ViewProps.end( ) )
327     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
328       ( *p )->VisibilityOn( );
329   i = this->m_AuxViewProps.find( name );
330   if( i != this->m_AuxViewProps.end( ) )
331     for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
332       ( *p )->VisibilityOn( );
333 }
334
335 // -------------------------------------------------------------------------
336 void cpExtensions::QT::RendererWidget::
337 ResetCamera( )
338 {
339   this->m_Renderer->ResetCamera( );
340 }
341
342 // -------------------------------------------------------------------------
343 void cpExtensions::QT::RendererWidget::
344 Render( )
345 {
346   this->GetRenderWindow( )->Render( );
347 }
348
349 // -------------------------------------------------------------------------
350 std::set< vtkRenderWindowInteractor* > cpExtensions::QT::RendererWidget::
351 GetInteractors( ) const
352 {
353   Self* self = const_cast< Self* >( this );
354   std::set< vtkRenderWindowInteractor* > ret;
355   ret.insert( self->GetRenderWindow( )->GetInteractor( ) );
356   return( ret );
357 }
358
359 // -------------------------------------------------------------------------
360 std::set< std::string > cpExtensions::QT::RendererWidget::
361 GetActorsNames( ) const
362 {
363   std::set< std::string > names;
364   for(
365     auto p = this->m_ViewProps.begin( );
366     p != this->m_ViewProps.end( );
367     ++p
368     )
369     names.insert( p->first );
370   return( names );
371 }
372
373 // -------------------------------------------------------------------------
374 bool cpExtensions::QT::RendererWidget::
375 IsWindowLevelImageActor( const std::string& name ) const
376 {
377   auto it = this->m_ViewProps.find( name );
378   if( it != this->m_ViewProps.end( ) )
379   {
380     auto a = it->second.begin( );
381     if( a != it->second.end( ) )
382       return( dynamic_cast< TWLActor* >( a->GetPointer( ) ) != NULL );
383     else
384       return( false );
385   }
386   else
387     return( false );
388 }
389
390 // -------------------------------------------------------------------------
391 bool cpExtensions::QT::RendererWidget::
392 IsLUTImageActor( const std::string& name ) const
393 {
394   auto it = this->m_ViewProps.find( name );
395   if( it != this->m_ViewProps.end( ) )
396   {
397     auto a = it->second.begin( );
398     if( a != it->second.end( ) )
399       return( dynamic_cast< TLUTActor* >( a->GetPointer( ) ) != NULL );
400     else
401       return( false );
402   }
403   else
404     return( false );
405 }
406
407 // -------------------------------------------------------------------------
408 bool cpExtensions::QT::RendererWidget::
409 Is3DActor( const std::string& name ) const
410 {
411   auto it = this->m_ViewProps.find( name );
412   if( it != this->m_ViewProps.end( ) )
413   {
414     auto a = it->second.begin( );
415     if( a != it->second.end( ) )
416       return( dynamic_cast< vtkActor* >( a->GetPointer( ) ) != NULL );
417     else
418       return( false );
419   }
420   else
421     return( false );
422 }
423
424 // -------------------------------------------------------------------------
425 void cpExtensions::QT::RendererWidget::
426 GetScalarRange( const std::string& name, double r[ 2 ] ) const
427 {
428   auto it = this->m_ViewProps.find( name );
429   if( it != this->m_ViewProps.end( ) )
430   {
431     auto p = it->second.begin( );
432     TWLActor* a = NULL;
433     while( a == NULL && p != it->second.end( ) )
434     {
435       a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
436       p++;
437
438     } // elihw
439     if( a != NULL )
440       a->GetRange( r );
441
442   } // fi
443 }
444
445 // -------------------------------------------------------------------------
446 void cpExtensions::QT::RendererWidget::
447 GetWindowLevel( const std::string& name, double wl[ 2 ] ) const
448 {
449   auto it = this->m_ViewProps.find( name );
450   if( it != this->m_ViewProps.end( ) )
451   {
452     auto p = it->second.begin( );
453     TWLActor* a = NULL;
454     while( a == NULL && p != it->second.end( ) )
455     {
456       a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
457       p++;
458
459     } // elihw
460     if( a != NULL )
461       a->GetWindowLevel( wl );
462
463   } // fi
464 }
465
466 // -------------------------------------------------------------------------
467 double cpExtensions::QT::RendererWidget::
468 GetWindow( const std::string& name ) const
469 {
470   auto it = this->m_ViewProps.find( name );
471   if( it != this->m_ViewProps.end( ) )
472   {
473     auto p = it->second.begin( );
474     TWLActor* a = NULL;
475     while( a == NULL && p != it->second.end( ) )
476     {
477       a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
478       p++;
479
480     } // elihw
481     if( a != NULL )
482       return( a->GetWindow( ) );
483     else
484       return( 0 );
485   }
486   else
487     return( 0 );
488 }
489
490 // -------------------------------------------------------------------------
491 double cpExtensions::QT::RendererWidget::
492 GetLevel( const std::string& name ) const
493 {
494   auto it = this->m_ViewProps.find( name );
495   if( it != this->m_ViewProps.end( ) )
496   {
497     auto p = it->second.begin( );
498     TWLActor* a = NULL;
499     while( a == NULL && p != it->second.end( ) )
500     {
501       a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
502       p++;
503
504     } // elihw
505     if( a != NULL )
506       return( a->GetLevel( ) );
507     else
508       return( 0 );
509   }
510   else
511     return( 0 );
512 }
513
514 // -------------------------------------------------------------------------
515 char cpExtensions::QT::RendererWidget::
516 GetImageInterpolation( const std::string& name ) const
517 {
518   auto it = this->m_ViewProps.find( name );
519   if( it != this->m_ViewProps.end( ) )
520   {
521     auto p = it->second.begin( );
522     TWLActor* a = NULL;
523     while( a == NULL && p != it->second.end( ) )
524     {
525       a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
526       p++;
527
528     } // elihw
529     if( a != NULL )
530     {
531       int int_type = a->GetProperty( )->GetInterpolationType( );
532       char ret = 0;
533       switch( int_type )
534       {
535       case VTK_NEAREST_INTERPOLATION: ret = 'N'; break;
536       case VTK_LINEAR_INTERPOLATION: ret = 'L'; break;
537       case VTK_CUBIC_INTERPOLATION: ret = 'C'; break;
538       default: ret = 0; break;
539       } // hctiws
540       return( ret );
541     }
542     else
543       return( 0 );
544   }
545   else
546     return( 0 );
547 }
548
549 // -------------------------------------------------------------------------
550 void cpExtensions::QT::RendererWidget::
551 GetColor( const std::string& name, double& r, double& g, double& b ) const
552 {
553   auto it = this->m_ViewProps.find( name );
554   if( it != this->m_ViewProps.end( ) )
555   {
556     auto p = it->second.begin( );
557     vtkActor* a = NULL;
558     while( a == NULL && p != it->second.end( ) )
559     {
560       a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
561       p++;
562
563     } // elihw
564     if( a != NULL )
565       return( a->GetProperty( )->GetColor( r, g, b ) );
566
567   } // fi
568 }
569
570 // -------------------------------------------------------------------------
571 double cpExtensions::QT::RendererWidget::
572 GetOpacity( const std::string& name ) const
573 {
574   auto it = this->m_ViewProps.find( name );
575   if( it != this->m_ViewProps.end( ) )
576   {
577     auto p = it->second.begin( );
578     vtkActor* a = NULL;
579     vtkImageSlice* s = NULL;
580     while( a == NULL && s == NULL && p != it->second.end( ) )
581     {
582       a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
583       s = dynamic_cast< vtkImageSlice* >( p->GetPointer( ) );
584       p++;
585
586     } // elihw
587     if( a != NULL )
588       return( a->GetProperty( )->GetOpacity( ) );
589     else if( s != NULL )
590       return( s->GetProperty( )->GetOpacity( ) );
591     else
592       return( 0 );
593   }
594   return( 0 );
595 }
596
597 // -------------------------------------------------------------------------
598 double cpExtensions::QT::RendererWidget::
599 GetPointSize( const std::string& name ) const
600 {
601   auto it = this->m_ViewProps.find( name );
602   if( it != this->m_ViewProps.end( ) )
603   {
604     auto p = it->second.begin( );
605     vtkActor* a = NULL;
606     while( a == NULL && p != it->second.end( ) )
607     {
608       a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
609       p++;
610
611     } // elihw
612     if( a != NULL )
613       return( a->GetProperty( )->GetPointSize( ) );
614     else
615       return( 0 );
616   }
617   return( 0 );
618 }
619
620 // -------------------------------------------------------------------------
621 double cpExtensions::QT::RendererWidget::
622 GetLineWidth( const std::string& name ) const
623 {
624   auto it = this->m_ViewProps.find( name );
625   if( it != this->m_ViewProps.end( ) )
626   {
627     auto p = it->second.begin( );
628     vtkActor* a = NULL;
629     while( a == NULL && p != it->second.end( ) )
630     {
631       a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
632       p++;
633
634     } // elihw
635     if( a != NULL )
636       return( a->GetProperty( )->GetLineWidth( ) );
637     else
638       return( 0 );
639   }
640   return( 0 );
641 }
642
643 // -------------------------------------------------------------------------
644 int cpExtensions::QT::RendererWidget::
645 GetRepresentation( const std::string& name ) const
646 {
647   auto it = this->m_ViewProps.find( name );
648   if( it != this->m_ViewProps.end( ) )
649   {
650     auto p = it->second.begin( );
651     vtkActor* a = NULL;
652     while( a == NULL && p != it->second.end( ) )
653     {
654       a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
655       p++;
656
657     } // elihw
658     if( a != NULL )
659       return( a->GetProperty( )->GetRepresentation( ) );
660     else
661       return( -1 );
662   }
663   return( -1 );
664 }
665
666 // -------------------------------------------------------------------------
667 void cpExtensions::QT::RendererWidget::
668 SetScalarRange( const std::string& name, double r[ 2 ] )
669 {
670   this->SetScalarRange( name, r[ 0 ], r[ 1 ] );
671 }
672
673 // -------------------------------------------------------------------------
674 void cpExtensions::QT::RendererWidget::
675 SetScalarRange( const std::string& name, double min, double max )
676 {
677   auto it = this->m_ViewProps.find( name );
678   if( it != this->m_ViewProps.end( ) )
679   {
680     bool render = false;
681     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
682     {
683       TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
684       if( a != NULL )
685       {
686         render = true;
687         a->SetRange( min, max );
688
689       } // fi
690
691     } // rof
692     if( render )
693       this->Render( );
694
695   } // fi
696 }
697
698 // -------------------------------------------------------------------------
699 void cpExtensions::QT::RendererWidget::
700 SetWindowLevel( const std::string& name, double wl[ 2 ] )
701 {
702   this->SetWindowLevel( name, wl[ 0 ], wl[ 1 ] );
703 }
704
705 // -------------------------------------------------------------------------
706 void cpExtensions::QT::RendererWidget::
707 SetWindowLevel( const std::string& name, double w, double l )
708 {
709   auto it = this->m_ViewProps.find( name );
710   if( it != this->m_ViewProps.end( ) )
711   {
712     bool render = false;
713     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
714     {
715       TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
716       if( a != NULL )
717       {
718         render = true;
719         a->SetWindowLevel( w, l );
720
721       } // fi
722
723     } // rof
724     if( render )
725       this->Render( );
726
727   } // fi
728 }
729
730 // -------------------------------------------------------------------------
731 void cpExtensions::QT::RendererWidget::
732 SetWindow( const std::string& name, double w )
733 {
734   auto it = this->m_ViewProps.find( name );
735   if( it != this->m_ViewProps.end( ) )
736   {
737     bool render = false;
738     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
739     {
740       TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
741       if( a != NULL )
742       {
743         render = true;
744         a->SetWindow( w );
745
746       } // fi
747
748     } // rof
749     if( render )
750       this->Render( );
751
752   } // fi
753 }
754
755 // -------------------------------------------------------------------------
756 void cpExtensions::QT::RendererWidget::
757 SetLevel( const std::string& name, double l )
758 {
759   auto it = this->m_ViewProps.find( name );
760   if( it != this->m_ViewProps.end( ) )
761   {
762     bool render = false;
763     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
764     {
765       TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
766       if( a != NULL )
767       {
768         render = true;
769         a->SetLevel( l );
770
771       } // fi
772
773     } // rof
774     if( render )
775       this->Render( );
776
777   } // fi
778 }
779
780 // -------------------------------------------------------------------------
781 void cpExtensions::QT::RendererWidget::
782 SetImageInterpolation( const std::string& name, char i )
783 {
784   auto it = this->m_ViewProps.find( name );
785   if( it != this->m_ViewProps.end( ) )
786   {
787     bool render = false;
788     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
789     {
790       TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
791       if( a != NULL )
792       {
793         render = true;
794         int int_type = VTK_NEAREST_INTERPOLATION;
795         switch( i )
796         {
797         case 'L': int_type = VTK_LINEAR_INTERPOLATION; break;
798         case 'C': int_type = VTK_CUBIC_INTERPOLATION; break;
799         default:  int_type = VTK_NEAREST_INTERPOLATION; break;
800         } // hctiws
801         a->GetProperty( )->SetInterpolationType( int_type );
802
803       } // fi
804
805     } // rof
806     if( render )
807       this->Render( );
808
809   } // fi
810 }
811
812 // -------------------------------------------------------------------------
813 void cpExtensions::QT::RendererWidget::
814 SetColor( const std::string& name, double r, double g, double b )
815 {
816   auto it = this->m_ViewProps.find( name );
817   if( it != this->m_ViewProps.end( ) )
818   {
819     bool render = false;
820     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
821     {
822       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
823       if( a != NULL )
824       {
825         render = true;
826         a->GetProperty( )->SetColor( r, g, b );
827
828       } // fi
829
830     } // rof
831     if( render )
832       this->Render( );
833
834   } // fi
835 }
836
837 // -------------------------------------------------------------------------
838 void cpExtensions::QT::RendererWidget::
839 SetOpacity( const std::string& name, double o )
840 {
841   auto it = this->m_ViewProps.find( name );
842   if( it != this->m_ViewProps.end( ) )
843   {
844     bool render = false;
845     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
846     {
847       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
848       vtkImageSlice* s = dynamic_cast< vtkImageSlice* >( p->GetPointer( ) );
849       if( a != NULL )
850       {
851         render = true;
852         a->GetProperty( )->SetOpacity( o );
853       }
854       else if( s != NULL )
855       {
856         render = true;
857         s->GetProperty( )->SetOpacity( o );
858
859       } // fi
860
861     } // rof
862     if( render )
863       this->Render( );
864
865   } // fi
866 }
867
868 // -------------------------------------------------------------------------
869 void cpExtensions::QT::RendererWidget::
870 SetPointSize( const std::string& name, double s )
871 {
872   auto it = this->m_ViewProps.find( name );
873   if( it != this->m_ViewProps.end( ) )
874   {
875     bool render = false;
876     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
877     {
878       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
879       if( a != NULL )
880       {
881         render = true;
882         a->GetProperty( )->SetPointSize( s );
883
884       } // fi
885
886     } // rof
887     if( render )
888       this->Render( );
889
890   } // fi
891 }
892
893 // -------------------------------------------------------------------------
894 void cpExtensions::QT::RendererWidget::
895 SetLineWidth( const std::string& name, double w )
896 {
897   auto it = this->m_ViewProps.find( name );
898   if( it != this->m_ViewProps.end( ) )
899   {
900     bool render = false;
901     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
902     {
903       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
904       if( a != NULL )
905       {
906         render = true;
907         a->GetProperty( )->SetLineWidth( w );
908
909       } // fi
910
911     } // rof
912     if( render )
913       this->Render( );
914
915   } // fi
916 }
917
918 // -------------------------------------------------------------------------
919 void cpExtensions::QT::RendererWidget::
920 SetRepresentationToPoints( const std::string& name )
921 {
922   auto it = this->m_ViewProps.find( name );
923   if( it != this->m_ViewProps.end( ) )
924   {
925     bool render = false;
926     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
927     {
928       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
929       if( a != NULL )
930       {
931         render = true;
932         a->GetProperty( )->SetRepresentationToPoints( );
933
934       } // fi
935
936     } // rof
937     if( render )
938       this->Render( );
939
940   } // fi
941 }
942
943 // -------------------------------------------------------------------------
944 void cpExtensions::QT::RendererWidget::
945 SetRepresentationToSurface( const std::string& name )
946 {
947   auto it = this->m_ViewProps.find( name );
948   if( it != this->m_ViewProps.end( ) )
949   {
950     bool render = false;
951     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
952     {
953       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
954       if( a != NULL )
955       {
956         render = true;
957         a->GetProperty( )->SetRepresentationToSurface( );
958
959       } // fi
960
961     } // rof
962     if( render )
963       this->Render( );
964
965   } // fi
966 }
967
968 // -------------------------------------------------------------------------
969 void cpExtensions::QT::RendererWidget::
970 SetRepresentationToWireframe( const std::string& name )
971 {
972   auto it = this->m_ViewProps.find( name );
973   if( it != this->m_ViewProps.end( ) )
974   {
975     bool render = false;
976     for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
977     {
978       vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
979       if( a != NULL )
980       {
981         render = true;
982         a->GetProperty( )->SetRepresentationToWireframe( );
983
984       } // fi
985
986     } // rof
987     if( render )
988       this->Render( );
989
990   } // fi
991 }
992
993 #endif // cpExtensions_QT4
994
995 // eof - $RCSfile$