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