]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageSliceActors.cxx
...
[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   this->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   int axis = this->GetAxis( );
843   for( unsigned int i = 0; i < nImages; ++i )
844   {
845     // Update mappers and display bounds
846     this->m_SliceMappers[ i ]->SetSliceNumber( slice );
847     this->m_SliceMappers[ i ]->Modified( );
848     this->m_ImageActors[ i ]->Modified( );
849     this->m_SliceMappers[ i ]->Update( );
850
851     // Update display extent (this isn't done automatically)
852     vtkImageData* image = this->m_SliceMappers[ i ]->GetInput( );
853     int ext[ 6 ];
854     image->GetExtent( ext );
855     ext[ axis << 1 ] = slice;
856     ext[ ( axis << 1 ) + 1 ] = slice;
857     this->m_ImageActors[ i ]->SetDisplayExtent( ext );
858
859   } // rof
860
861   double bnds[ 6 ];
862   this->m_SliceMappers[ 0 ]->GetBounds( bnds );
863   double x0[][ 3 ] =
864   {
865     { bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] },
866     { bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] }
867   };
868   double p0[ 2 ][ 3 ];
869
870   vtkPlane* plane = this->m_SliceMappers[ 0 ]->GetSlicePlane( );
871   plane->GeneralizedProjectPoint( x0[ 0 ], p0[ 0 ] );
872   plane->GeneralizedProjectPoint( x0[ 1 ], p0[ 1 ] );
873
874   bnds[ 0 ] = p0[ 0 ][ 0 ];
875   bnds[ 1 ] = p0[ 1 ][ 0 ];
876   bnds[ 2 ] = p0[ 0 ][ 1 ];
877   bnds[ 3 ] = p0[ 1 ][ 1 ];
878   bnds[ 4 ] = p0[ 0 ][ 2 ];
879   bnds[ 5 ] = p0[ 1 ][ 2 ];
880
881   // Configure visualization and implicit plane orientation
882   this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
883   this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 );
884   vtkPoints* plane_points = this->m_Plane->GetPoints( );
885   plane_points->SetPoint( 0, bnds[ 0 ], bnds[ 2 ], bnds[ 4 ] );
886   plane_points->SetPoint( 2, bnds[ 1 ], bnds[ 3 ], bnds[ 5 ] );
887   if( axis == 0 || axis == 2 ) // YZ, x-normal
888   {
889     plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] );
890     plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] );
891     if( axis == 0 )
892       this->m_PlaneActor->GetProperty( )->SetColor( 1, 0, 0 );
893     else
894       this->m_PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
895   }
896   else if( axis == 1 ) // ZX, y-normal
897   {
898     plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] );
899     plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] );
900     this->m_PlaneActor->GetProperty( )->SetColor( 0, 1, 0 );
901
902   } // fi
903   this->m_Plane->Modified( );
904   this->m_PlaneMapper->Modified( );
905   this->m_PlaneActor->Modified( );
906
907   // Update text
908   this->UpdateText( );
909 }
910
911 // -------------------------------------------------------------------------
912 void cpExtensions::Visualization::ImageSliceActors::
913 SetSlice( double* pos )
914 {
915   vtkImageData* image;
916   if( this->m_ImageMaps[ 0 ] != NULL )
917     image =
918       dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
919   else
920     image = this->m_SliceMappers[ 0 ]->GetInput( );
921
922   int ijk[ 3 ];
923   double pcoords[ 3 ];
924   image->ComputeStructuredCoordinates( pos, ijk, pcoords );
925   this->SetSliceNumber( ijk[ this->GetAxis( ) ] );
926 }
927
928 // -------------------------------------------------------------------------
929 void cpExtensions::Visualization::ImageSliceActors::
930 UpdateText( )
931 {
932   if( this->m_SliceMappers.size( ) > 0 )
933   {
934     char axis;
935     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
936     if     ( axId == 0 ) axis = 'X';
937     else if( axId == 1 ) axis = 'Y';
938     else if( axId == 2 ) axis = 'Z';
939
940     std::sprintf(
941       this->m_TextBuffer, "Axis: %c (%d)",
942       axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( )
943       );
944   }
945   else
946     this->m_TextBuffer[ 0 ] = '\0';
947   this->m_TextActor->SetInput( this->m_TextBuffer );
948   this->m_TextActor->Modified( );
949   this->Modified( );
950 }
951
952 // -------------------------------------------------------------------------
953 void cpExtensions::Visualization::ImageSliceActors::
954 UpdateText( double pos[ 3 ] )
955 {
956   if( this->m_SliceMappers.size( ) > 0 )
957   {
958     char axis;
959     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
960     if     ( axId == 0 ) axis = 'X';
961     else if( axId == 1 ) axis = 'Y';
962     else if( axId == 2 ) axis = 'Z';
963     int slice = this->GetSliceNumber( );
964
965     vtkImageData* image;
966     if( this->m_ImageMaps[ 0 ] != NULL )
967       image =
968         dynamic_cast< vtkImageData* >( this->m_ImageMaps[ 0 ]->GetInput( ) );
969     else
970       image = this->m_SliceMappers[ 0 ]->GetInput( );
971
972     int ijk[ 3 ];
973     double pcoords[ 3 ];
974     image->ComputeStructuredCoordinates( pos, ijk, pcoords );
975     ijk[ axId ] = slice;
976
977     int ext[ 6 ];
978     image->GetExtent( ext );
979     if(
980       ext[ 0 ] <= ijk[ 0 ] && ijk[ 0 ] <= ext[ 1 ] &&
981       ext[ 2 ] <= ijk[ 1 ] && ijk[ 1 ] <= ext[ 3 ] &&
982       ext[ 4 ] <= ijk[ 2 ] && ijk[ 2 ] <= ext[ 5 ]
983       )
984     {
985       int nScl = image->GetNumberOfScalarComponents( );
986       std::stringstream str;
987       str
988         << "[" << ijk[ 0 ]
989         << "," << ijk[ 1 ]
990         << "," << ijk[ 2 ] << "]=(";
991       str <<
992         image->GetScalarComponentAsFloat( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0 );
993       for( int n = 1; n < nScl; ++n )
994         str
995           << " "
996           << image->GetScalarComponentAsFloat(
997             ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n
998             );
999       str << ")";
1000       std::sprintf(
1001         this->m_TextBuffer, "Axis: %c (%d)\nPixel %s",
1002         axis, slice, str.str( ).c_str( )
1003         );
1004
1005     } // fi
1006   }
1007   else
1008     this->m_TextBuffer[ 0 ] = '\0';
1009   this->m_TextActor->SetInput( this->m_TextBuffer );
1010   this->m_TextActor->Modified( );
1011   this->Modified( );
1012 }
1013
1014 // -------------------------------------------------------------------------
1015 void cpExtensions::Visualization::ImageSliceActors::
1016 UpdateText( const double& w, const double& l )
1017 {
1018   if( this->m_SliceMappers.size( ) > 0 )
1019   {
1020     char axis;
1021     int axId = this->m_SliceMappers[ 0 ]->GetOrientation( );
1022     if     ( axId == 0 ) axis = 'X';
1023     else if( axId == 1 ) axis = 'Y';
1024     else if( axId == 2 ) axis = 'Z';
1025
1026     std::sprintf(
1027       this->m_TextBuffer, "Axis: %c (%d)\nW/L (%.2f/%.2f)",
1028       axis, this->m_SliceMappers[ 0 ]->GetSliceNumber( ), w, l
1029       );
1030   }
1031   else
1032     this->m_TextBuffer[ 0 ] = '\0';
1033   this->m_TextActor->SetInput( this->m_TextBuffer );
1034   this->m_TextActor->Modified( );
1035   this->Modified( );
1036 }
1037
1038 // -------------------------------------------------------------------------
1039 void cpExtensions::Visualization::ImageSliceActors::
1040 Render( const double& t )
1041 {
1042   if( this->m_Window != NULL )
1043   {
1044     vtkRenderer* renderer =
1045       this->m_Window->GetRenderers( )->GetFirstRenderer( );
1046     if( renderer != NULL )
1047       renderer->SetAllocatedRenderTime( t );
1048     this->m_Window->Render( );
1049
1050   } // fi
1051 }
1052
1053 // -------------------------------------------------------------------------
1054 void cpExtensions::Visualization::ImageSliceActors::
1055 ResetCamera( )
1056 {
1057   if( this->m_Window == NULL )
1058     return;
1059   vtkRenderer* renderer =
1060     this->m_Window->GetRenderers( )->GetFirstRenderer( );
1061   if( renderer != NULL )
1062     renderer->ResetCamera( );
1063 #error ACA VOY: reconfigurar la camara alrededor Ãºnicamente del plano.
1064 }
1065
1066 // -------------------------------------------------------------------------
1067 cpExtensions::Visualization::ImageSliceActors::
1068 ImageSliceActors( )
1069   : Superclass( ),
1070     m_Window( NULL ),
1071     m_Interpolate( false )
1072 {
1073   this->Clear( );
1074   this->_ConfigureStyle( );
1075 }
1076
1077 // -------------------------------------------------------------------------
1078 cpExtensions::Visualization::ImageSliceActors::
1079 ~ImageSliceActors( )
1080 {
1081 }
1082
1083 // -------------------------------------------------------------------------
1084 void cpExtensions::Visualization::ImageSliceActors::
1085 _ConfigureStyle( )
1086 {
1087   // Connect this view with a controller
1088   this->m_Style = vtkSmartPointer< TStyle >::New( );
1089   this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this );
1090   this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this );
1091   this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this );
1092   this->m_Style->AddKeyCommand( Self::_KeyCommand, this );
1093   this->m_Style->AddEnterCommand( Self::_EnterCommand, this );
1094   this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this );
1095 }
1096
1097 // -------------------------------------------------------------------------
1098 void cpExtensions::Visualization::ImageSliceActors::
1099 _ConfigureNewLUT( vtkImageData* data )
1100 {
1101   // Does the new LUT is a window-level one?
1102   unsigned int nImgs = this->m_ImageMaps.size( );
1103   unsigned int nCmps = data->GetNumberOfScalarComponents( );
1104
1105   if( nCmps > 1 )
1106   {
1107     this->m_ImageMaps.push_back( NULL );
1108     return;
1109
1110   } // fi
1111
1112   // Create LUT filter
1113   this->m_ImageMaps.push_back( vtkSmartPointer< vtkImageMapToColors >::New( ) );
1114   if( nImgs == 0 )
1115   {
1116     double range[ 2 ];
1117     data->GetScalarRange( range );
1118     vtkSmartPointer< vtkWindowLevelLookupTable > lut =
1119       vtkSmartPointer< vtkWindowLevelLookupTable >::New( );
1120     lut->SetScaleToLinear( );
1121     lut->SetTableRange( range );
1122     lut->SetWindow( range[ 1 ] - range[ 0 ] );
1123     lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) );
1124     lut->Build( );
1125     this->m_ImageMaps[ 0 ]->SetLookupTable( lut );
1126   }
1127   else
1128     this->SetLookupTableAsColor( nImgs, 1, 0, 0 );
1129 }
1130
1131 // -------------------------------------------------------------------------
1132 void cpExtensions::Visualization::ImageSliceActors::
1133 _ConfigureNewInput( int axis )
1134 {
1135   unsigned int nImages = this->m_ImageActors.size( );
1136
1137   // Configure mapper
1138   vtkImageSliceMapper* mapper = this->m_SliceMappers[ nImages ];
1139   if( nImages == 0 )
1140     mapper->SetOrientation( axis );
1141   else
1142     mapper->SetOrientation( this->m_SliceMappers[ 0 ]->GetOrientation( ) );
1143   mapper->Update( );
1144
1145   // Create actor
1146   vtkSmartPointer< vtkImageActor > actor =
1147     vtkSmartPointer< vtkImageActor >::New( );
1148   this->m_ImageActors.push_back( actor );
1149   actor->SetMapper( mapper );
1150   actor->SetInterpolate( this->m_Interpolate );
1151   actor->Modified( );
1152
1153   if( nImages == 0 )
1154     this->m_Style->AssociateImageActor( actor );
1155   this->AddItem( actor );
1156
1157   if( nImages > 1 )
1158     this->SetSliceNumber( this->GetSliceNumber( ) );
1159   else
1160     this->SetSliceNumber( this->GetSliceNumberMaxValue( ) );
1161   this->ResetCursor( );
1162   this->Modified( );
1163 }
1164
1165 // -------------------------------------------------------------------------
1166 void cpExtensions::Visualization::ImageSliceActors::
1167 _MouseMoveCommand(
1168   void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
1169   bool alt, bool ctr, bool sft
1170   )
1171 {
1172   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1173   if( actors == NULL )
1174     return;
1175
1176   if( btn == TStyle::ButtonID_None )
1177   {
1178     // Just show the pixel information
1179     actors->SetCursor( pos );
1180     actors->UpdateText( pos );
1181     actors->Render( 1e-3 );
1182   }
1183   else if( btn == TStyle::ButtonID_Left )
1184   {
1185     if( !alt && ctr && !sft )
1186     {
1187       // Interactively move slices
1188       auto i = actors->m_SlicesCommands.begin( );
1189       for( ; i != actors->m_SlicesCommands.end( ); ++i )
1190         i->first( pos, actors->GetAxis( ), i->second );
1191       actors->Render( 1e-3 );
1192
1193     } // fi
1194   }
1195   else if( btn == TStyle::ButtonID_Right )
1196   {
1197     if( !alt && !ctr && sft )
1198     {
1199       // Change image window level
1200       double bounds[ 6 ];
1201       actors->m_SliceMappers[ 0 ]->GetBounds( bounds );
1202
1203       int a0 = actors->GetAxis( );
1204       int a1 = ( a0 + 1 ) % 3;
1205       int a2 = ( a0 + 2 ) % 3;
1206       double dx = pos[ a1 ] - actors->m_StartWindowLevelPos[ a1 ];
1207       double dy = pos[ a2 ] - actors->m_StartWindowLevelPos[ a2 ];
1208       dx /= bounds[ ( a1 << 1 ) + 1 ] - bounds[ a1 << 1 ];
1209       dy /= bounds[ ( a2 << 1 ) + 1 ] - bounds[ a2 << 1 ];
1210
1211       dx *= actors->m_StartWindowLevel[ 0 ];
1212       dy *= actors->m_StartWindowLevel[ 1 ];
1213       dx += actors->m_StartWindowLevel[ 0 ];
1214       dy += actors->m_StartWindowLevel[ 1 ];
1215       actors->SetWindowLevel( dx, dy );
1216       actors->Render( 1e-3 );
1217
1218       // Associate objects
1219       auto i = actors->m_WindowLevelCommands.begin( );
1220       for( ; i != actors->m_WindowLevelCommands.end( ); ++i )
1221         i->first( dx, dy, i->second );
1222       
1223     } // fi
1224
1225   } // fi
1226 }
1227
1228 // -------------------------------------------------------------------------
1229 void cpExtensions::Visualization::ImageSliceActors::
1230 _MouseClickCommand(
1231   void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
1232   bool alt, bool ctr, bool sft
1233   )
1234 {
1235   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1236   if( actors == NULL )
1237     return;
1238
1239   actors->m_StartWindowLevelPos[ 0 ] = pos[ 0 ];
1240   actors->m_StartWindowLevelPos[ 1 ] = pos[ 1 ];
1241   actors->m_StartWindowLevelPos[ 2 ] = pos[ 2 ];
1242   actors->m_StartWindowLevel[ 0 ] = actors->GetWindow( );
1243   actors->m_StartWindowLevel[ 1 ] = actors->GetLevel( );
1244 }
1245
1246 // -------------------------------------------------------------------------
1247 void cpExtensions::Visualization::ImageSliceActors::
1248 _MouseWheelCommand(
1249   void* data, const int& dir,
1250   bool alt, bool ctr, bool sft
1251   )
1252 {
1253   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1254   if( actors == NULL )
1255     return;
1256
1257   if( !alt && !ctr )
1258   {
1259     int slice = actors->GetSliceNumber( ) + ( dir * ( ( sft )? 10: 1 ) );
1260     if( slice < actors->GetSliceNumberMinValue( ) )
1261       slice = actors->GetSliceNumberMinValue( );
1262     if( slice > actors->GetSliceNumberMaxValue( ) )
1263       slice = actors->GetSliceNumberMaxValue( );
1264     actors->SetSliceNumber( slice );
1265
1266     auto a = actors->m_AssociatedSlices.begin( );
1267     for( ; a != actors->m_AssociatedSlices.end( ); ++a )
1268     {
1269       ( *a )->SetSliceNumber( slice );
1270       ( *a )->Render( 1e-3 );
1271
1272     } // rof
1273     actors->Render( 1e-3 );
1274     
1275     // Associate objects
1276     auto i = actors->m_RenderCommands.begin( );
1277     for( ; i != actors->m_RenderCommands.end( ); ++i )
1278       i->first( i->second );
1279
1280   } // fi
1281 }
1282
1283 // -------------------------------------------------------------------------
1284 void cpExtensions::Visualization::ImageSliceActors::
1285 _KeyCommand( void* data, const char& key )
1286 {
1287   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1288   if( actors == NULL )
1289     return;
1290
1291   switch( key )
1292   {
1293   case 'r': case 'R':
1294   {
1295     actors->ResetCamera( );
1296     actors->Render( 1e-3 );
1297
1298     // Associate objects
1299     auto i = actors->m_RenderCommands.begin( );
1300     for( ; i != actors->m_RenderCommands.end( ); ++i )
1301       i->first( i->second );
1302   }
1303   break;
1304   case 'w': case 'W':
1305   {
1306     actors->ResetWindowLevel( );
1307     actors->Render( 1e-3 );
1308
1309     // Associate objects
1310     auto i = actors->m_RenderCommands.begin( );
1311     for( ; i != actors->m_RenderCommands.end( ); ++i )
1312       i->first( i->second );
1313   }
1314   break;
1315   default:
1316     break;
1317   } // hctiws
1318 }
1319
1320 // -------------------------------------------------------------------------
1321 void cpExtensions::Visualization::ImageSliceActors::
1322 _EnterCommand( void* data )
1323 {
1324   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1325   if( actors == NULL )
1326     return;
1327
1328   actors->ResetCursor( );
1329   actors->m_CursorActor->VisibilityOn( );
1330   actors->Render( 1e-3 );
1331 }
1332
1333 // -------------------------------------------------------------------------
1334 void cpExtensions::Visualization::ImageSliceActors::
1335 _LeaveCommand( void* data )
1336 {
1337   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
1338   if( actors == NULL )
1339     return;
1340
1341   actors->ResetCursor( );
1342   actors->m_CursorActor->VisibilityOff( );
1343   actors->Render( 1e-3 );
1344 }
1345
1346 // eof - $RCSfile$