]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.cxx
Tree data updated.
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
1 #include <cpExtensions/Visualization/ImageSliceActors.h>
2
3 #include <cmath>
4 #include <sstream>
5
6 #include <vtkAlgorithmOutput.h>
7 #include <vtkCamera.h>
8 #include <vtkCellArray.h>
9 #include <vtkImageData.h>
10 #include <vtkInformation.h>
11 #include <vtkPlane.h>
12 #include <vtkPoints.h>
13 #include <vtkProperty.h>
14 #include <vtkRenderer.h>
15 #include <vtkRendererCollection.h>
16 #include <vtkRenderWindow.h>
17 #include <vtkRenderWindowInteractor.h>
18 #include <vtkStreamingDemandDrivenPipeline.h>
19 #include <vtkTextProperty.h>
20 #include <vtkWindowLevelLookupTable.h>
21
22 // -------------------------------------------------------------------------
23 cpExtensions::Visualization::ImageSliceActors*
24 cpExtensions::Visualization::ImageSliceActors::
25 New( )
26 {
27   return( new Self( ) );
28 }
29
30 // -------------------------------------------------------------------------
31 void cpExtensions::Visualization::ImageSliceActors::
32 AddInputConnection( vtkAlgorithmOutput* aout, int axis )
33 {
34   // Get input vtkImageData
35   if( aout == NULL )
36     return;
37   vtkAlgorithm* producer = aout->GetProducer( );
38   vtkImageData* data = dynamic_cast< vtkImageData* >(
39     producer->GetOutputDataObject( aout->GetIndex( ) )
40     );
41   if( data == NULL )
42     return;
43
44   // Try to infere if input comes from a color mapping filter
45   vtkImageMapToColors* new_map =
46     dynamic_cast< vtkImageMapToColors* >( producer );
47   if( new_map == NULL )
48   {
49     // Configure LUT, if possible (NULL is returned if not)
50     this->_ConfigureNewLUT( data );
51     new_map = *( this->m_ImageMaps.rbegin( ) );
52     if( new_map != NULL )
53     {
54       new_map->SetInputConnection( aout );
55       new_map->Update( );
56
57     } // fi
58   }
59   else
60     this->m_ImageMaps.push_back( new_map );
61
62   // Update window level values
63   if( new_map != NULL )
64   {
65     double range[ 2 ];
66     dynamic_cast< vtkImageData* >( new_map->GetInput( ) )->
67       GetScalarRange( range );
68     this->m_MinWindow = double( 0 );
69     this->m_MaxWindow = range[ 1 ] - range[ 0 ];
70     this->m_MinLevel = range[ 0 ];
71     this->m_MaxLevel = range[ 1 ];
72
73   } // fi
74
75   // Create mapper and actors
76   vtkSmartPointer< vtkImageSliceMapper > mapper =
77     vtkSmartPointer< vtkImageSliceMapper >::New( );
78   if( new_map != NULL )
79     mapper->SetInputConnection( new_map->GetOutputPort( ) );
80   else
81     mapper->SetInputConnection( aout );
82   this->m_SliceMappers.push_back( mapper );
83   this->_ConfigureNewInput( axis );
84 }
85
86 // -------------------------------------------------------------------------
87 void cpExtensions::Visualization::ImageSliceActors::
88 AddInputData( vtkImageData* data, int axis )
89 {
90   // Update window level values
91   if( this->m_ImageMaps.size( ) == 0 )
92   {
93     double range[ 2 ];
94     data->GetScalarRange( range );
95     this->m_MinWindow = double( 0 );
96     this->m_MaxWindow = range[ 1 ] - range[ 0 ];
97     this->m_MinLevel = range[ 0 ];
98     this->m_MaxLevel = range[ 1 ];
99
100   } // fi
101
102   // Configure LUT, if possible (NULL is returned if not)
103   this->_ConfigureNewLUT( data );
104   vtkImageMapToColors* new_map = *( this->m_ImageMaps.rbegin( ) );
105   if( new_map != NULL )
106   {
107     new_map->SetInputData( data );
108     new_map->Update( );
109
110   } // fi
111
112   // Create mapper and actors
113   vtkSmartPointer< vtkImageSliceMapper > mapper =
114     vtkSmartPointer< vtkImageSliceMapper >::New( );
115   if( new_map != NULL )
116     mapper->SetInputConnection( new_map->GetOutputPort( ) );
117   else
118     mapper->SetInputData( data );
119   this->m_SliceMappers.push_back( mapper );
120   this->_ConfigureNewInput( axis );
121 }
122
123 // -------------------------------------------------------------------------
124 void cpExtensions::Visualization::ImageSliceActors::
125 Clear( )
126 {
127   // Reset values
128   this->m_MinWindow = double( 0 );
129   this->m_MaxWindow = double( 0 );
130   this->m_MinLevel = double( 0 );
131   this->m_MaxLevel = double( 0 );
132
133   // Unbind from container
134   this->RemoveAllItems( );
135
136   // Delete all images
137   this->m_ImageMaps.clear( );
138   this->m_SliceMappers.clear( );
139   this->m_ImageActors.clear( );
140
141   // Reconfigure unique objects
142   this->m_Cursor        = vtkSmartPointer< vtkPolyData >::New( );
143   this->m_CursorMapper  = vtkSmartPointer< vtkPolyDataMapper >::New( );
144   this->m_CursorActor   = vtkSmartPointer< vtkActor >::New( );
145   this->m_Plane         = vtkSmartPointer< vtkPolyData >::New( );
146   this->m_PlaneMapper   = vtkSmartPointer< vtkPolyDataMapper >::New( );
147   this->m_TextActor     = vtkSmartPointer< vtkTextActor >::New( );
148   this->m_PlaneActor    = vtkSmartPointer< vtkActor >::New( );
149   this->m_TextBuffer[ 0 ] = '\0';
150
151   // Unique objects configuration
152   vtkSmartPointer< vtkPoints > cursor_points =
153     vtkSmartPointer< vtkPoints >::New( );
154   vtkSmartPointer< vtkCellArray > cursor_lines =
155     vtkSmartPointer< vtkCellArray >::New( );
156   cursor_points->InsertNextPoint( 0, 0, 0 );
157   cursor_points->InsertNextPoint( 0, 0, 0 );
158   cursor_points->InsertNextPoint( 0, 0, 0 );
159   cursor_points->InsertNextPoint( 0, 0, 0 );
160   cursor_points->InsertNextPoint( 0, 0, 0 );
161   cursor_points->InsertNextPoint( 0, 0, 0 );
162   cursor_points->InsertNextPoint( 0, 0, 0 );
163   cursor_points->InsertNextPoint( 0, 0, 0 );
164   cursor_lines->InsertNextCell( 2 );
165   cursor_lines->InsertCellPoint( 0 );
166   cursor_lines->InsertCellPoint( 1 );
167   cursor_lines->InsertNextCell( 2 );
168   cursor_lines->InsertCellPoint( 2 );
169   cursor_lines->InsertCellPoint( 3 );
170   cursor_lines->InsertNextCell( 2 );
171   cursor_lines->InsertCellPoint( 4 );
172   cursor_lines->InsertCellPoint( 5 );
173   cursor_lines->InsertNextCell( 2 );
174   cursor_lines->InsertCellPoint( 6 );
175   cursor_lines->InsertCellPoint( 7 );
176   this->m_Cursor->SetPoints( cursor_points );
177   this->m_Cursor->SetLines( cursor_lines );
178   this->m_CursorMapper->SetInputData( this->m_Cursor );
179   this->m_CursorActor->SetMapper( this->m_CursorMapper );
180
181   vtkSmartPointer< vtkPoints > plane_points =
182     vtkSmartPointer< vtkPoints >::New( );
183   vtkSmartPointer< vtkCellArray > plane_lines =
184     vtkSmartPointer< vtkCellArray >::New( );
185
186   plane_points->InsertNextPoint( 0, 0, 0 );
187   plane_points->InsertNextPoint( 0, 1, 0 );
188   plane_points->InsertNextPoint( 1, 1, 0 );
189   plane_points->InsertNextPoint( 1, 0, 0 );
190   plane_lines->InsertNextCell( 5 );
191   plane_lines->InsertCellPoint( 0 );
192   plane_lines->InsertCellPoint( 1 );
193   plane_lines->InsertCellPoint( 2 );
194   plane_lines->InsertCellPoint( 3 );
195   plane_lines->InsertCellPoint( 0 );
196   this->m_Plane->SetPoints( plane_points );
197   this->m_Plane->SetLines( plane_lines );
198
199   this->m_PlaneMapper->SetInputData( this->m_Plane );
200   this->m_PlaneActor->SetMapper( this->m_PlaneMapper );
201
202   this->m_TextActor->SetTextScaleModeToNone( );
203   vtkTextProperty* textprop = this->m_TextActor->GetTextProperty( );
204   textprop->SetColor( 1, 1, 1 );
205   textprop->SetFontFamilyToCourier( );
206   textprop->SetFontSize( 18 );
207   textprop->BoldOff( );
208   textprop->ItalicOff( );
209   textprop->ShadowOff( );
210   textprop->SetJustificationToLeft( );
211   textprop->SetVerticalJustificationToBottom( );
212   vtkCoordinate* coord = this->m_TextActor->GetPositionCoordinate( );
213   coord->SetCoordinateSystemToNormalizedViewport( );
214   coord->SetValue( 0.01, 0.01 );
215
216   // Update actor collection
217   this->AddItem( this->m_CursorActor );
218   this->AddItem( this->m_TextActor );
219   this->AddItem( this->m_PlaneActor );
220 }
221
222 // -------------------------------------------------------------------------
223 void cpExtensions::Visualization::ImageSliceActors::
224 AssociateSlice( Self* slice )
225 {
226   this->m_AssociatedSlices.push_back( slice );
227   this->Modified( );
228 }
229
230 // -------------------------------------------------------------------------
231 vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
232 GetStyle( )
233 {
234   return( this->m_Style.GetPointer( ) );
235 }
236
237 // -------------------------------------------------------------------------
238 const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
239 GetStyle( ) const
240 {
241   return( this->m_Style.GetPointer( ) );
242 }
243
244 // -------------------------------------------------------------------------
245 vtkImageData* cpExtensions::Visualization::ImageSliceActors::
246 GetInputImage( unsigned int id )
247 {
248   vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
249   vtkImageData* image = dynamic_cast< vtkImageData* >(
250     aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
251     );
252   return( image );
253 }
254
255 // -------------------------------------------------------------------------
256 const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
257 GetInputImage( unsigned int id ) const
258 {
259   vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
260   const vtkImageData* image = dynamic_cast< const vtkImageData* >(
261     aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
262     );
263   return( image );
264 }
265
266 // -------------------------------------------------------------------------
267 void cpExtensions::Visualization::ImageSliceActors::
268 PushActorsInto( vtkRenderWindow* window, bool force_style )
269 {
270   this->m_Window = window;
271   if( window == NULL )
272     return;
273   vtkRenderWindowInteractor* rwi = window->GetInteractor( );
274   vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
275   if( rwi == NULL || renderer == NULL )
276     return;
277
278   // Update style
279   if( this->m_Style.GetPointer( ) != NULL && force_style )
280     rwi->SetInteractorStyle( this->m_Style );
281
282   // Update actors
283   vtkProp* prop;
284   this->InitTraversal( );
285   while( prop = this->GetNextProp( ) )
286     renderer->AddViewProp( prop );
287   renderer->Modified( );
288   if( !force_style )
289   {
290     renderer->RemoveViewProp( this->m_CursorActor );
291     renderer->RemoveViewProp( this->m_TextActor );
292
293   } // fi
294
295   // Configure camera
296   vtkCamera* camera = renderer->GetActiveCamera( );
297   if( camera != NULL && force_style )
298   {
299     // Parallel projections are better when displaying 2D images
300     int axis = this->GetAxis( );
301     camera->ParallelProjectionOn( );
302     camera->SetFocalPoint( double( 0 ), double( 0 ), double( 0 ) );
303     if( axis == 0 )
304     {
305       camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
306       camera->SetViewUp  ( double( 0 ), double( 0 ), double( 1 ) );
307     }
308     else if( axis == 1 )
309     {
310       camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
311       camera->SetViewUp  ( double( 0 ), double( 0 ), double( 1 ) );
312     }
313     else // if( axis == 2 )
314     {
315       camera->SetPosition( double( 0 ), double(  0 ), double( -1 ) );
316       camera->SetViewUp  ( double( 0 ), double( -1 ), double(  0 ) );
317
318     } // fi
319
320   } // fi
321   renderer->ResetCamera( );
322   rwi->Render( );
323 }
324
325 // -------------------------------------------------------------------------
326 void cpExtensions::Visualization::ImageSliceActors::
327 PopActorsFrom( vtkRenderWindow* window )
328 {
329   vtkRenderWindowInteractor* rwi = window->GetInteractor( );
330   vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
331
332   if( renderer != NULL )
333   {
334     // Update actors
335     vtkProp* prop;
336     this->InitTraversal( );
337     while( prop = this->GetNextProp( ) )
338       renderer->RemoveViewProp( prop );
339     renderer->Modified( );
340
341   } // fi
342   if( rwi != NULL )
343     rwi->Render( );
344 }
345
346 // -------------------------------------------------------------------------
347 unsigned int cpExtensions::Visualization::ImageSliceActors::
348 GetNumberOfImageActors( ) const
349 {
350   return( this->m_ImageActors.size( ) );
351 }
352
353 // -------------------------------------------------------------------------
354 vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
355 GetImageActor( unsigned int id )
356 {
357   if( id < this->m_ImageActors.size( ) )
358     return( this->m_ImageActors[ id ] );
359   else
360     return( NULL );
361 }
362
363 // -------------------------------------------------------------------------
364 const vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
365 GetImageActor( unsigned int id ) const
366 {
367   if( id < this->m_ImageActors.size( ) )
368     return( this->m_ImageActors[ id ] );
369   else
370     return( NULL );
371 }
372
373 // -------------------------------------------------------------------------
374 vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
375 GetTextActor( )
376 {
377   return( this->m_TextActor );
378 }
379
380 // -------------------------------------------------------------------------
381 const vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
382 GetTextActor( ) const
383 {
384   return( this->m_TextActor );
385 }
386
387 // -------------------------------------------------------------------------
388 vtkActor* cpExtensions::Visualization::ImageSliceActors::
389 GetPlaneActor( )
390 {
391   return( this->m_PlaneActor );
392 }
393
394 // -------------------------------------------------------------------------
395 const vtkActor* cpExtensions::Visualization::ImageSliceActors::
396 GetPlaneActor( ) const
397 {
398   return( this->m_PlaneActor );
399 }
400
401 // -------------------------------------------------------------------------
402 vtkPlane* cpExtensions::Visualization::ImageSliceActors::
403 GetPlaneFunction( )
404 {
405   return( this->m_SliceMappers[ 0 ]->GetSlicePlane( ) );
406 }
407
408 // -------------------------------------------------------------------------
409 const vtkPlane* cpExtensions::Visualization::ImageSliceActors::
410 GetPlaneFunction( ) const
411 {
412   return( this->m_SliceMappers[ 0 ]->GetSlicePlane( ) );
413 }
414
415 // -------------------------------------------------------------------------
416 void cpExtensions::Visualization::ImageSliceActors::
417 SetInterpolate( bool v )
418 {
419   if( this->m_Interpolate != v )
420   {
421     for( unsigned int i = 0; i < this->m_ImageActors.size( ); ++i )
422       this->m_ImageActors[ i ]->SetInterpolate( v );
423     this->m_Interpolate = v;
424     this->Modified( );
425
426   } // fi
427 }
428
429 // -------------------------------------------------------------------------
430 void cpExtensions::Visualization::ImageSliceActors::
431 InterpolateOn( )
432 {
433   this->SetInterpolate( true );
434 }
435
436 // -------------------------------------------------------------------------
437 void cpExtensions::Visualization::ImageSliceActors::
438 InterpolateOff( )
439 {
440   this->SetInterpolate( false );
441 }
442
443 // -------------------------------------------------------------------------
444 double* cpExtensions::Visualization::ImageSliceActors::
445 GetDisplayBounds( ) const
446 {
447   if( this->m_ImageActors.size( ) > 0 )
448     return( this->m_ImageActors[ 0 ]->GetDisplayBounds( ) );
449   else
450     return( NULL );
451 }
452
453 // -------------------------------------------------------------------------
454 void cpExtensions::Visualization::ImageSliceActors::
455 GetDisplayBounds( double bounds[ 6 ] ) const
456 {
457   if( this->m_ImageActors.size( ) == 0 )
458   {
459     bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 );
460     bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 );
461   }
462   else
463     this->m_ImageActors[ 0 ]->GetDisplayBounds( bounds );
464 }
465
466 // -------------------------------------------------------------------------
467 void cpExtensions::Visualization::ImageSliceActors::
468 ResetCursor( )
469 {
470   if( this->m_SliceMappers.size( ) > 0 )
471   {
472     double bounds[ 6 ];
473     this->m_SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds );
474     double pos[] = { bounds[ 0 ], bounds[ 2 ], bounds[ 4 ] };
475     this->SetCursor( pos );
476   }
477   else
478   {
479     vtkPoints* points = this->m_Cursor->GetPoints( );
480     points->SetPoint( 0, 0, 0, 0 );
481     points->SetPoint( 1, 0, 0, 0 );
482     points->SetPoint( 2, 0, 0, 0 );
483     points->SetPoint( 3, 0, 0, 0 );
484     points->SetPoint( 4, 0, 0, 0 );
485     points->SetPoint( 5, 0, 0, 0 );
486     points->SetPoint( 6, 0, 0, 0 );
487     points->SetPoint( 7, 0, 0, 0 );
488     this->m_Cursor->Modified( );
489     this->m_CursorMapper->Modified( );
490     this->m_CursorActor->Modified( );
491
492   } // fi
493 }
494
495 // -------------------------------------------------------------------------
496 void cpExtensions::Visualization::ImageSliceActors::
497 SetCursor( double pos[ 3 ] )
498 {
499   if( this->m_SliceMappers.size( ) == 0 )
500     return;
501
502   // Get ordered axes
503   int a0 = this->GetAxis( );
504   int a1 = ( a0 + 1 ) % 3;
505   int a2 = ( a0 + 2 ) % 3;
506   int ma0 = a0 << 1;
507   int ma1 = a1 << 1;
508   int ma2 = a2 << 1;
509
510   double bounds[ 6 ];
511   this->m_SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds );
512
513   double
514     p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ],
515     p4[ 3 ], p5[ 3 ], p6[ 3 ], p7[ 3 ];
516
517   p0[ a2 ] = p1[ a2 ] = p4[ a2 ] = p5[ a2 ] = pos[ a2 ];
518   p2[ a1 ] = p3[ a1 ] = p6[ a1 ] = p7[ a1 ] = pos[ a1 ];
519   p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ];
520   p4[ a0 ] = p5[ a0 ] = p6[ a0 ] = p7[ a0 ] = bounds[ ma0 + 1 ];
521   p0[ a1 ] = p4[ a1 ] = bounds[ ma1 ];
522   p1[ a1 ] = p5[ a1 ] = bounds[ ma1 + 1 ];
523   p2[ a2 ] = p6[ a2 ] = bounds[ ma2 ];
524   p3[ a2 ] = p7[ a2 ] = bounds[ ma2 + 1 ];
525
526   vtkPoints* points = this->m_Cursor->GetPoints( );
527   points->SetPoint( 0, p0 );
528   points->SetPoint( 1, p1 );
529   points->SetPoint( 2, p2 );
530   points->SetPoint( 3, p3 );
531   points->SetPoint( 4, p4 );
532   points->SetPoint( 5, p5 );
533   points->SetPoint( 6, p6 );
534   points->SetPoint( 7, p7 );
535   this->m_Cursor->Modified( );
536   this->m_CursorMapper->Modified( );
537   this->m_CursorActor->Modified( );
538 }
539
540 // -------------------------------------------------------------------------
541 vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
542 GetImageMap( unsigned int id )
543 {
544   if( id < this->m_ImageMaps.size( ) )
545     return( this->m_ImageMaps[ id ].GetPointer( ) );
546   else
547     return( NULL );
548 }
549
550 // -------------------------------------------------------------------------
551 const vtkImageMapToColors* cpExtensions::Visualization::ImageSliceActors::
552 GetImageMap( unsigned int id ) const
553 {
554   if( id < this->m_ImageMaps.size( ) )
555     return( this->m_ImageMaps[ id ].GetPointer( ) );
556   else
557     return( NULL );
558 }
559
560 // -------------------------------------------------------------------------
561 double cpExtensions::Visualization::ImageSliceActors::
562 GetMinWindow( ) const
563 {
564   return( this->m_MinWindow );
565 }
566
567 // -------------------------------------------------------------------------
568 double cpExtensions::Visualization::ImageSliceActors::
569 GetMaxWindow( ) const
570 {
571   return( this->m_MaxWindow );
572 }
573
574 // -------------------------------------------------------------------------
575 double cpExtensions::Visualization::ImageSliceActors::
576 GetMinLevel( ) const
577 {
578   return( this->m_MinLevel );
579 }
580
581 // -------------------------------------------------------------------------
582 double cpExtensions::Visualization::ImageSliceActors::
583 GetMaxLevel( ) const
584 {
585   return( this->m_MaxLevel );
586 }
587
588 // -------------------------------------------------------------------------
589 double cpExtensions::Visualization::ImageSliceActors::
590 GetWindow( ) const
591 {
592   if( this->m_ImageMaps.size( ) == 0 )
593     return( double( 0 ) );
594   if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
595     return( double( 0 ) );
596
597   vtkWindowLevelLookupTable* lut =
598     dynamic_cast< vtkWindowLevelLookupTable* >(
599       this->m_ImageMaps[ 0 ]->GetLookupTable( )
600       );
601   if( lut != NULL )
602     return( lut->GetWindow( ) );
603   else
604     return( double( 0 ) );
605 }
606
607 // -------------------------------------------------------------------------
608 double cpExtensions::Visualization::ImageSliceActors::
609 GetLevel( ) const
610 {
611   if( this->m_ImageMaps.size( ) == 0 )
612     return( double( 0 ) );
613   if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
614     return( double( 0 ) );
615
616   vtkWindowLevelLookupTable* lut =
617     dynamic_cast< vtkWindowLevelLookupTable* >(
618       this->m_ImageMaps[ 0 ]->GetLookupTable( )
619       );
620   if( lut != NULL )
621     return( lut->GetLevel( ) );
622   else
623     return( double( 0 ) );
624 }
625
626 // -------------------------------------------------------------------------
627 void cpExtensions::Visualization::ImageSliceActors::
628 SetWindow( double w )
629 {
630   if( this->m_ImageMaps.size( ) == 0 )
631     return;
632   if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
633     return;
634   vtkWindowLevelLookupTable* lut =
635     dynamic_cast< vtkWindowLevelLookupTable* >(
636       this->m_ImageMaps[ 0 ]->GetLookupTable( )
637       );
638   if( lut == NULL )
639     return;
640
641   if( w < this->m_MinWindow )
642     w = this->m_MinWindow;
643   if( w > this->m_MaxWindow )
644     w = this->m_MaxWindow;
645
646   lut->SetWindow( w );
647   lut->Build( );
648   this->m_ImageMaps[ 0 ]->Modified( );
649   this->Modified( );
650 }
651
652 // -------------------------------------------------------------------------
653 void cpExtensions::Visualization::ImageSliceActors::
654 SetLevel( double l )
655 {
656   if( this->m_ImageMaps.size( ) == 0 )
657     return;
658   if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
659     return;
660   vtkWindowLevelLookupTable* lut =
661     dynamic_cast< vtkWindowLevelLookupTable* >(
662       this->m_ImageMaps[ 0 ]->GetLookupTable( )
663       );
664   if( lut == NULL )
665     return;
666
667   if( l < this->m_MinLevel )
668     l = this->m_MinLevel;
669   if( l > this->m_MaxLevel )
670     l = this->m_MaxLevel;
671
672   lut->SetLevel( l );
673   lut->Build( );
674   this->m_ImageMaps[ 0 ]->Modified( );
675   this->Modified( );
676 }
677
678 // -------------------------------------------------------------------------
679 void cpExtensions::Visualization::ImageSliceActors::
680 SetWindowLevel( double w, double l )
681 {
682   if( this->m_ImageMaps.size( ) == 0 )
683     return;
684   if( this->m_ImageMaps[ 0 ].GetPointer( ) == NULL )
685     return;
686   vtkWindowLevelLookupTable* lut =
687     dynamic_cast< vtkWindowLevelLookupTable* >(
688       this->m_ImageMaps[ 0 ]->GetLookupTable( )
689       );
690   if( lut == NULL )
691     return;
692
693   if( w < this->m_MinWindow )
694     w = this->m_MinWindow;
695   if( w > this->m_MaxWindow )
696     w = this->m_MaxWindow;
697   if( l < this->m_MinLevel )
698     l = this->m_MinLevel;
699   if( l > this->m_MaxLevel )
700     l = this->m_MaxLevel;
701
702   lut->SetWindow( w );
703   lut->SetLevel( l );
704   lut->Build( );
705   this->m_ImageMaps[ 0 ]->Modified( );
706   this->UpdateText( w, l );
707   this->Modified( );
708 }
709
710 // -------------------------------------------------------------------------
711 void cpExtensions::Visualization::ImageSliceActors::
712 ResetWindowLevel( )
713 {
714   static const double _2 = double( 2 );
715   this->SetWindowLevel(
716     this->m_MaxWindow, ( this->m_MaxLevel + this->m_MinLevel ) / _2
717     );
718 }
719
720 // -------------------------------------------------------------------------
721 void cpExtensions::Visualization::ImageSliceActors::
722 SetLookupTable( unsigned int id, vtkLookupTable* lut )
723 {
724   if( id < this->m_ImageMaps.size( ) && id > 0 )
725   {
726     if( this->m_ImageMaps[ id ].GetPointer( ) != NULL )
727     {
728       this->m_ImageMaps[ id ]->SetLookupTable( lut );
729       this->m_ImageMaps[ id ]->Modified( );
730       this->Modified( );
731
732     } // fi
733
734   } // fi
735 }
736
737 // -------------------------------------------------------------------------
738 void cpExtensions::Visualization::ImageSliceActors::
739 SetLookupTableAsColor( unsigned int id, double r, double g, double b )
740 {
741   static const double _0 = double( 0 );
742   static const double _2 = double( 2 );
743   static const double _4 = double( 4 );
744   static const double _6 = double( 6 );
745   static const double _OPACITY = double( 0.6 );
746
747   // Check ID consistency
748   if( id == 0 || id >= this->m_ImageMaps.size( ) )
749     return;
750
751   // Get image scalar range
752   vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( );
753   vtkImageData* image = dynamic_cast< vtkImageData* >(
754     aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) )
755     );
756   double range[ 2 ];
757   image->GetScalarRange( range );
758
759   // Get HSV from display color
760   double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax;
761   double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin;
762   double d = cmax - cmin;
763
764   double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0;
765   double value = cmax;
766   double hue = _0;
767   if( d > _0 )
768   {
769     if( r == cmax )
770       hue = std::fmod( ( g - b ) / d, _6 );
771     else if( g == cmax )
772       hue = ( ( b - r ) / d ) + _2;
773     else if( b == cmax )
774       hue = ( ( r - g ) / d ) + _4;
775     hue /= _6;
776
777   } // fi
778
779   // Define new lookup table
780   vtkSmartPointer< vtkLookupTable > lut =
781     vtkSmartPointer< vtkLookupTable >::New( );
782   lut->SetScaleToLinear( );
783   lut->SetNanColor( _0, _0, _0, _0 );
784   lut->SetTableRange( range[ 0 ], range[ 1 ] );
785   lut->SetAlphaRange( _0, _OPACITY );
786   lut->SetHueRange( _0, hue );
787   lut->SetSaturationRange( _0, saturation );
788   lut->SetValueRange( _0, value );
789   lut->Build( );
790   this->SetLookupTable( id, lut );
791 }
792
793 // -------------------------------------------------------------------------
794 int cpExtensions::Visualization::ImageSliceActors::
795 GetAxis( ) const
796 {
797   if( this->m_SliceMappers.size( ) > 0 )
798     return( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
799   else
800     return( -1 );
801 }
802
803 // -------------------------------------------------------------------------
804 int cpExtensions::Visualization::ImageSliceActors::
805 GetSliceNumber( ) const
806 {
807   if( this->m_SliceMappers.size( ) > 0 )
808     return( this->m_SliceMappers[ 0 ]->GetSliceNumber( ) );
809   else
810     return( -1 );
811 }
812
813 // -------------------------------------------------------------------------
814 int cpExtensions::Visualization::ImageSliceActors::
815 GetSliceNumberMinValue( ) const
816 {
817   if( this->m_SliceMappers.size( ) > 0 )
818     return( this->m_SliceMappers[ 0 ]->GetSliceNumberMinValue( ) );
819   else
820     return( -1 );
821 }
822
823 // -------------------------------------------------------------------------
824 int cpExtensions::Visualization::ImageSliceActors::
825 GetSliceNumberMaxValue( ) const
826 {
827   if( this->m_SliceMappers.size( ) > 0 )
828     return( this->m_SliceMappers[ 0 ]->GetSliceNumberMaxValue( ) );
829   else
830     return( -1 );
831 }
832
833 // -------------------------------------------------------------------------
834 void cpExtensions::Visualization::ImageSliceActors::
835 SetSliceNumber( const int& slice )
836 {
837   unsigned int nImages = this->m_SliceMappers.size( );
838   if( nImages == 0 )
839     return;
840
841   // Change visualization extent
842   for( unsigned int i = 0; i < nImages; ++i )
843   {
844     this->m_SliceMappers[ i ]->SetSliceNumber( slice );
845     this->m_SliceMappers[ i ]->Modified( );
846     this->m_ImageActors[ i ]->Modified( );
847     this->m_SliceMappers[ i ]->Update( );
848
849   } // rof
850
851   double bnds[ 6 ];
852   this->m_SliceMappers[ 0 ]->GetBounds( bnds );
853   double x0[][ 3 ] =
854   {
855     { bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] },
856     { bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] }
857   };
858   double p0[ 2 ][ 3 ];
859
860   vtkPlane* plane = this->m_SliceMappers[ 0 ]->GetSlicePlane( );
861   plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] );
862   plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] );
863
864   int axis = this->GetAxis( );
865   bnds[ 0 ] = p0[ 0 ][ 0 ];
866   bnds[ 1 ] = p0[ 1 ][ 0 ];
867   bnds[ 2 ] = p0[ 0 ][ 1 ];
868   bnds[ 3 ] = p0[ 1 ][ 1 ];
869   bnds[ 4 ] = p0[ 0 ][ 2 ];
870   bnds[ 5 ] = p0[ 1 ][ 2 ];
871
872   // Configure visualization and implicit plane orientation
873   this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
874   this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 );
875   vtkPoints* plane_points = this->m_Plane->GetPoints( );
876   plane_points->SetPoint( 0, bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] );
877   plane_points->SetPoint( 2, bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] );
878   if( axis == 0 || axis == 2 ) // YZ, x-normal
879   {
880     plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] );
881     plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] );
882     if( axis == 0 )
883       this->m_PlaneActor->GetProperty( )->SetColor( 1, 0, 0 );
884     else
885       this->m_PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
886   }
887   else if( axis == 1 ) // ZX, y-normal
888   {
889     plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] );
890     plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] );
891     this->m_PlaneActor->GetProperty( )->SetColor( 0, 1, 0 );
892
893   } // fi
894   this->m_Plane->Modified( );
895   this->m_PlaneMapper->Modified( );
896   this->m_PlaneActor->Modified( );
897
898   // Update text
899   this->UpdateText( );
900 }
901
902 // -------------------------------------------------------------------------
903 void cpExtensions::Visualization::ImageSliceActors::
904 SetSlice( double* pos )
905 {
906   vtkImageData* image;
907   if( this->m_ImageMaps[ 0 ] != NULL )
908     image =
909       dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
910   else
911     image = this->m_SliceMappers[ 0 ]->GetInput( );
912
913   int ijk[ 3 ];
914   double pcoords[ 3 ];
915   image->ComputeStructuredCoordinates( pos, ijk, pcoords );
916   this->SetSliceNumber( ijk[ this->GetAxis( ) ] );
917 }
918
919 // -------------------------------------------------------------------------
920 void cpExtensions::Visualization::ImageSliceActors::
921 UpdateText( )
922 {
923   if( this->m_SliceMappers.size( ) > 0 )
924   {
925     char axis;
926     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
927     if     ( axId == 0 ) axis = 'X';
928     else if( axId == 1 ) axis = 'Y';
929     else if( axId == 2 ) axis = 'Z';
930
931     std::sprintf(
932       this->m_TextBuffer, "Axis: %c (%d)",
933       axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( )
934       );
935   }
936   else
937     this->m_TextBuffer[ 0 ] = '\0';
938   this->m_TextActor->SetInput( this->m_TextBuffer );
939   this->m_TextActor->Modified( );
940   this->Modified( );
941 }
942
943 // -------------------------------------------------------------------------
944 void cpExtensions::Visualization::ImageSliceActors::
945 UpdateText( double pos[ 3 ] )
946 {
947   if( this->m_SliceMappers.size( ) > 0 )
948   {
949     char axis;
950     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
951     if     ( axId == 0 ) axis = 'X';
952     else if( axId == 1 ) axis = 'Y';
953     else if( axId == 2 ) axis = 'Z';
954     int slice = this->GetSliceNumber( );
955
956     vtkImageData* image;
957     if( this->m_ImageMaps[ 0 ] != NULL )
958       image =
959         dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
960     else
961       image = this->m_SliceMappers[ 0 ]->GetInput( );
962
963     int ijk[ 3 ];
964     double pcoords[ 3 ];
965     image->ComputeStructuredCoordinates( pos, ijk, pcoords );
966     ijk[ axId ] = slice;
967
968     int ext[ 6 ];
969     image->GetExtent( ext );
970     if(
971       ext[ 0 ] <= ijk[ 0 ] && ijk[ 0 ] <= ext[ 1 ] &&
972       ext[ 2 ] <= ijk[ 1 ] && ijk[ 1 ] <= ext[ 3 ] &&
973       ext[ 4 ] <= ijk[ 2 ] && ijk[ 2 ] <= ext[ 5 ]
974       )
975     {
976       int nScl = image->GetNumberOfScalarComponents( );
977       std::stringstream str;
978       str
979         << "[" << ijk[ 0 ]
980         << "," << ijk[ 1 ]
981         << "," << ijk[ 2 ] << "]=(";
982       str <<
983         image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
984       for( int n = 1; n < nScl; ++n )
985         str
986           << " "
987           << image->GetScalarComponentAsFloat(
988             ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n
989             );
990       str << ")";
991       std::sprintf(
992         this->m_TextBuffer, "Axis: %c (%d)\nPixel %s",
993         axis, slice, str.str( ).c_str( )
994         );
995
996     } // fi
997   }
998   else
999     this->m_TextBuffer[ 0 ] = '\0';
1000   this->m_TextActor->SetInput( this->m_TextBuffer );
1001   this->m_TextActor->Modified( );
1002   this->Modified( );
1003 }
1004
1005 // -------------------------------------------------------------------------
1006 void cpExtensions::Visualization::ImageSliceActors::
1007 UpdateText( const double& w, const double& l )
1008 {
1009   if( this->m_SliceMappers.size( ) > 0 )
1010   {
1011     char axis;
1012     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
1013     if     ( axId == 0 ) axis = 'X';
1014     else if( axId == 1 ) axis = 'Y';
1015     else if( axId == 2 ) axis = 'Z';
1016
1017     std::sprintf(
1018       this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)",
1019       axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ), w, l
1020       );
1021   }
1022   else
1023     this->m_TextBuffer[ 0 ] = '\0';
1024   this->m_TextActor->SetInput( this->m_TextBuffer );
1025   this->m_TextActor->Modified( );
1026   this->Modified( );
1027 }
1028
1029 // -------------------------------------------------------------------------
1030 void cpExtensions::Visualization::ImageSliceActors::
1031 Render( const double& t )
1032 {
1033   if( this->m_Window != NULL )
1034   {
1035     vtkRenderer* renderer =
1036       this->m_Window->GetRenderers( )->GetFirstRenderer( );
1037     if( renderer != NULL )
1038       renderer->SetAllocatedRenderTime( t );
1039     this->m_Window->Render( );
1040
1041   } // fi
1042 }
1043
1044 // -------------------------------------------------------------------------
1045 void cpExtensions::Visualization::ImageSliceActors::
1046 ResetCamera( )
1047 {
1048   if( this->m_Window == NULL )
1049     return;
1050   vtkRenderer* renderer =
1051     this->m_Window->GetRenderers( )->GetFirstRenderer( );
1052   if( renderer != NULL )
1053     renderer->ResetCamera( );
1054 }
1055
1056 // -------------------------------------------------------------------------
1057 cpExtensions::Visualization::ImageSliceActors::
1058 ImageSliceActors( )
1059   : Superclass( ),
1060     m_Window( NULL ),
1061     m_Interpolate( false )
1062 {
1063   this->Clear( );
1064   this->_ConfigureStyle( );
1065 }
1066
1067 // -------------------------------------------------------------------------
1068 cpExtensions::Visualization::ImageSliceActors::
1069 ~ImageSliceActors( )
1070 {
1071 }
1072
1073 // -------------------------------------------------------------------------
1074 void cpExtensions::Visualization::ImageSliceActors::
1075 _ConfigureStyle( )
1076 {
1077   // Connect this view with a controller
1078   this->m_Style = vtkSmartPointer< TStyle >::New( );
1079   this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this );
1080   this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this );
1081   this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this );
1082   this->m_Style->AddKeyCommand( Self::_KeyCommand, this );
1083   this->m_Style->AddEnterCommand( Self::_EnterCommand, this );
1084   this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this );
1085 }
1086
1087 // -------------------------------------------------------------------------
1088 void cpExtensions::Visualization::ImageSliceActors::
1089 _ConfigureNewLUT( vtkImageData* data )
1090 {
1091   // Does the new LUT is a window-level one?
1092   unsigned int nImgs = this->m_ImageMaps.size( );
1093   unsigned int nCmps = data->GetNumberOfScalarComponents( );
1094
1095   if( nCmps > 1 )
1096   {
1097     this->m_ImageMaps.push_back( NULL );
1098     return;
1099
1100   } // fi
1101
1102   // Create LUT filter
1103   this->m_ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) );
1104   if( nImgs == 0 )
1105   {
1106     double range[ 2 ];
1107     data->GetScalarRange( range );
1108     vtkSmartPointer< vtkWindowLevelLookupTable > lut =
1109       vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
1110     lut->SetScaleToLinear( );
1111     lut->SetTableRange( range );
1112     lut->SetWindow( range[ 1 ] - range[ 0 ] );
1113     lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) );
1114     lut->Build( );
1115     this->m_ImageMaps[ 0 ]->SetLookupTable( lut );
1116   }
1117   else
1118     this->SetLookupTableAsColor( nImgs, 1, 0, 0 );
1119 }
1120
1121 // -------------------------------------------------------------------------
1122 void cpExtensions::Visualization::ImageSliceActors::
1123 _ConfigureNewInput( int axis )
1124 {
1125   unsigned int nImages = this->m_ImageActors.size( );
1126
1127   // Configure mapper
1128   vtkImageSliceMapper* mapper = this->m_SliceMappers[ nImages ];
1129   if( nImages == 0 )
1130     mapper->SetOrientation( axis );
1131   else
1132     mapper->SetOrientation( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
1133   mapper->Update( );
1134
1135   // Create actor
1136   vtkSmartPointer< vtkImageActor > actor =
1137     vtkSmartPointer< vtkImageActor >::New( );
1138   this->m_ImageActors.push_back( actor );
1139   actor->SetMapper( mapper );
1140   actor->SetInterpolate( this->m_Interpolate );
1141   actor->Modified( );
1142
1143   if( nImages == 0 )
1144     this->m_Style->AssociateImageActor( actor );
1145   this->AddItem( actor );
1146
1147   if( nImages > 1 )
1148     this->SetSliceNumber( this->GetSliceNumber( ) );
1149   else
1150     this->SetSliceNumber( this->GetSliceNumberMaxValue( ) );
1151   this->ResetCursor( );
1152   this->Modified( );
1153 }
1154
1155 // -------------------------------------------------------------------------
1156 void cpExtensions::Visualization::ImageSliceActors::
1157 _MouseMoveCommand(
1158   void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
1159   bool alt, bool ctr, bool sft
1160   )
1161 {
1162   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1163   if( actors == NULL )
1164     return;
1165
1166   if( btn == TStyle::ButtonID_None )
1167   {
1168     // Just show the pixel information
1169     actors->SetCursor( pos );
1170     actors->UpdateText( pos );
1171     actors->Render( 1e-3 );
1172   }
1173   else if( btn == TStyle::ButtonID_Left )
1174   {
1175     if( !alt && ctr && !sft )
1176     {
1177       // Interactively move slices
1178       auto i = actors->m_SlicesCommands.begin( );
1179       for( ; i != actors->m_SlicesCommands.end( ); ++i )
1180         i->first( pos, actors->GetAxis( ), i->second );
1181       actors->Render( 1e-3 );
1182
1183     } // fi
1184   }
1185   else if( btn == TStyle::ButtonID_Right )
1186   {
1187     if( !alt && !ctr && sft )
1188     {
1189       // Change image window level
1190       double bounds[ 6 ];
1191       actors->m_SliceMappers[ 0 ]->GetBounds( bounds );
1192
1193       int a0 = actors->GetAxis( );
1194       int a1 = ( a0 + 1 ) % 3;
1195       int a2 = ( a0 + 2 ) % 3;
1196       double dx = pos[ a1 ] - actors->m_StartWindowLevelPos[ a1 ];
1197       double dy = pos[ a2 ] - actors->m_StartWindowLevelPos[ a2 ];
1198       dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ];
1199       dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ];
1200
1201       dx *= actors->m_StartWindowLevel[ 0 ];
1202       dy *= actors->m_StartWindowLevel[ 1 ];
1203       dx += actors->m_StartWindowLevel[ 0 ];
1204       dy += actors->m_StartWindowLevel[ 1 ];
1205       actors->SetWindowLevel( dx, dy );
1206       actors->Render( 1e-3 );
1207
1208       // Associate objects
1209       auto i = actors->m_WindowLevelCommands.begin( );
1210       for( ; i != actors->m_WindowLevelCommands.end( ); ++i )
1211         i->first( dx, dy, i->second );
1212       
1213     } // fi
1214
1215   } // fi
1216 }
1217
1218 // -------------------------------------------------------------------------
1219 void cpExtensions::Visualization::ImageSliceActors::
1220 _MouseClickCommand(
1221   void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
1222   bool alt, bool ctr, bool sft
1223   )
1224 {
1225   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1226   if( actors == NULL )
1227     return;
1228
1229   actors->m_StartWindowLevelPos[ 0 ] = pos[ 0 ];
1230   actors->m_StartWindowLevelPos[ 1 ] = pos[ 1 ];
1231   actors->m_StartWindowLevelPos[ 2 ] = pos[ 2 ];
1232   actors->m_StartWindowLevel[ 0 ] = actors->GetWindow( );
1233   actors->m_StartWindowLevel[ 1 ] = actors->GetLevel( );
1234 }
1235
1236 // -------------------------------------------------------------------------
1237 void cpExtensions::Visualization::ImageSliceActors::
1238 _MouseWheelCommand(
1239   void* data, const int& dir,
1240   bool alt, bool ctr, bool sft
1241   )
1242 {
1243   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1244   if( actors == NULL )
1245     return;
1246
1247   if( !alt && !ctr )
1248   {
1249     int slice = actors->GetSliceNumber( ) + ( dir * ( ( sft )? 10: 1 ) );
1250     if( slice < actors->GetSliceNumberMinValue( ) )
1251       slice = actors->GetSliceNumberMinValue( );
1252     if( slice > actors->GetSliceNumberMaxValue( ) )
1253       slice = actors->GetSliceNumberMaxValue( );
1254     actors->SetSliceNumber( slice );
1255
1256     auto a = actors->m_AssociatedSlices.begin( );
1257     for( ; a != actors->m_AssociatedSlices.end( ); ++a )
1258     {
1259       ( *a )->SetSliceNumber( slice );
1260       ( *a )->Render( 1e-3 );
1261
1262     } // rof
1263     actors->Render( 1e-3 );
1264     
1265     // Associate objects
1266     auto i = actors->m_RenderCommands.begin( );
1267     for( ; i != actors->m_RenderCommands.end( ); ++i )
1268       i->first( i->second );
1269
1270   } // fi
1271 }
1272
1273 // -------------------------------------------------------------------------
1274 void cpExtensions::Visualization::ImageSliceActors::
1275 _KeyCommand( void* data, const char& key )
1276 {
1277   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1278   if( actors == NULL )
1279     return;
1280
1281   switch( key )
1282   {
1283   case 'r': case 'R':
1284   {
1285     actors->ResetCamera( );
1286     actors->Render( 1e-3 );
1287
1288     // Associate objects
1289     auto i = actors->m_RenderCommands.begin( );
1290     for( ; i != actors->m_RenderCommands.end( ); ++i )
1291       i->first( i->second );
1292   }
1293   break;
1294   case 'w': case 'W':
1295   {
1296     actors->ResetWindowLevel( );
1297     actors->Render( 1e-3 );
1298
1299     // Associate objects
1300     auto i = actors->m_RenderCommands.begin( );
1301     for( ; i != actors->m_RenderCommands.end( ); ++i )
1302       i->first( i->second );
1303   }
1304   break;
1305   default:
1306     break;
1307   } // hctiws
1308 }
1309
1310 // -------------------------------------------------------------------------
1311 void cpExtensions::Visualization::ImageSliceActors::
1312 _EnterCommand( void* data )
1313 {
1314   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1315   if( actors == NULL )
1316     return;
1317
1318   actors->ResetCursor( );
1319   actors->m_CursorActor->VisibilityOn( );
1320   actors->Render( 1e-3 );
1321 }
1322
1323 // -------------------------------------------------------------------------
1324 void cpExtensions::Visualization::ImageSliceActors::
1325 _LeaveCommand( void* data )
1326 {
1327   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1328   if( actors == NULL )
1329     return;
1330
1331   actors->ResetCursor( );
1332   actors->m_CursorActor->VisibilityOff( );
1333   actors->Render( 1e-3 );
1334 }
1335
1336 // eof - $RCSfile$