]> Creatis software - cpMesh.git/blob - appli/InteractiveDeformableMeshSegmentation/VolumeActors.cxx
First commit
[cpMesh.git] / appli / InteractiveDeformableMeshSegmentation / VolumeActors.cxx
1 #include "VolumeActors.h"
2
3 #include <cmath>
4
5 #include <vtkAlgorithmOutput.h>
6 #include <vtkImageData.h>
7 #include <vtkInformation.h>
8 #include <vtkLookupTable.h>
9 #include <vtkPlane.h>
10 #include <vtkProperty.h>
11 #include <vtkRenderer.h>
12 #include <vtkRendererCollection.h>
13 #include <vtkRenderWindow.h>
14 #include <vtkRenderWindowInteractor.h>
15 #include <vtkStreamingDemandDrivenPipeline.h>
16 #include <vtkTextProperty.h>
17
18 #include <vtkOrientedGlyphContourRepresentation.h>
19 #include <vtkContourWidget.h>
20
21
22 // -------------------------------------------------------------------------
23 idms::VolumeActors::SliceActor::
24 SliceActor( )
25 {
26   this->SliceMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
27   this->PlaneSource = vtkSmartPointer< vtkPlaneSource >::New( );
28   this->PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
29   this->PlaneActor = vtkSmartPointer< vtkActor >::New( );
30   this->ImageActor = vtkSmartPointer< vtkImageActor >::New( );
31   this->TextActor = vtkSmartPointer< vtkTextActor >::New( );
32   this->RegionCutterPlane = vtkSmartPointer< vtkPlane >::New( );
33
34   this->PlaneSource->SetXResolution( 1 );
35   this->PlaneSource->SetYResolution( 1 );
36   this->PlaneMapper->
37     SetInputConnection( this->PlaneSource->GetOutputPort( ) );
38   this->PlaneActor->SetMapper( this->PlaneMapper );
39
40   this->TextActor->SetTextScaleModeToNone( );
41   vtkTextProperty* textprop = this->TextActor->GetTextProperty( );
42   textprop->SetColor( 1, 1, 1 );
43   textprop->SetFontFamilyToCourier( );
44   textprop->SetFontSize( 18 );
45   textprop->BoldOff( );
46   textprop->ItalicOff( );
47   textprop->ShadowOff( );
48   textprop->SetJustificationToLeft( );
49   textprop->SetVerticalJustificationToBottom( );
50   vtkCoordinate* coord = this->TextActor->GetPositionCoordinate( );
51   coord->SetCoordinateSystemToNormalizedViewport( );
52   coord->SetValue( 0.01, 0.01 );
53 }
54
55 // -------------------------------------------------------------------------
56 void idms::VolumeActors::SliceActor::
57 Configure( vtkAlgorithmOutput* aout, int axis )
58 {
59   this->SliceMapper->SetInputConnection( aout );
60   this->SliceMapper->SetOrientation( axis );
61   this->ImageActor->SetMapper( this->SliceMapper );
62   this->ImageActor->Modified( );
63 }
64
65 // -------------------------------------------------------------------------
66 void idms::VolumeActors::SliceActor::
67 ConfigureRegion( vtkAlgorithmOutput* aout )
68 {
69   this->RegionCutter = vtkSmartPointer< vtkCutter >::New( );
70   this->RegionCutterMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
71   this->RegionCutterActor = vtkSmartPointer< vtkActor >::New( );
72
73   this->RegionCutter->SetInputConnection( aout );
74   this->RegionCutter->SetCutFunction( this->RegionCutterPlane );
75   this->RegionCutterMapper->
76     SetInputConnection( this->RegionCutter->GetOutputPort( ) );
77   this->RegionCutterActor->SetMapper( this->RegionCutterMapper );
78   this->RegionCutterActor->GetProperty( )->SetColor( 0, 0, 1 );
79 }
80
81 // -------------------------------------------------------------------------
82 void idms::VolumeActors::SliceActor::
83 SetSegmentation( vtkAlgorithmOutput* aout )
84 {
85   this->SegmentationSliceMapper =
86     vtkSmartPointer< vtkImageSliceMapper >::New( );
87   this->SegmentationSliceMapper->SetInputConnection( aout );
88   this->SegmentationSliceMapper->
89     SetOrientation( this->SliceMapper->GetOrientation( ) );
90   this->SegmentationSliceMapper->
91     SetSliceNumber( this->SliceMapper->GetSliceNumber( ) );
92
93   this->SegmentationActor = vtkSmartPointer< vtkImageActor >::New( );
94   this->SegmentationActor->SetMapper( this->SegmentationSliceMapper );
95   this->SegmentationActor->Modified( );
96 }
97
98 // -------------------------------------------------------------------------
99 void idms::VolumeActors::SliceActor::
100 SetSliceNumber( const int& slice )
101 {
102   this->SliceMapper->SetSliceNumber( slice );
103   this->SliceMapper->Update( );
104   if( this->SegmentationSliceMapper.GetPointer( ) != NULL )
105   {
106     this->SegmentationSliceMapper->SetSliceNumber( slice );
107     this->SegmentationSliceMapper->Update( );
108
109   } // fi
110
111   // Compute plane
112   vtkAlgorithm* algo = this->SliceMapper->GetInputAlgorithm( );
113   vtkInformation* info = algo->GetOutputInformation( 0 );
114   int ext[ 6 ];
115   double ori[ 3 ], spac[ 3 ], pos[ 3 ];
116   info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext );
117   info->Get( vtkDataObject::ORIGIN( ), ori );
118   info->Get( vtkDataObject::SPACING( ), spac );
119   this->SliceMapper->GetSlicePlane( )->GetOrigin( pos );
120
121   // Prevent obscuring voxels by offsetting the plane geometry
122   double xbnds[ ] =
123     {
124       ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ),
125       ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) )
126     };
127   double ybnds[ ] =
128     {
129       ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ),
130       ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) )
131     };
132   double zbnds[ ] =
133     {
134       ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ),
135       ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) )
136     };
137
138   if( spac[ 0 ] < double( 0 ) )
139   {
140     double t = xbnds[ 0 ];
141     xbnds[ 0 ] = xbnds[ 1 ];
142     xbnds[ 1 ] = t;
143
144   } // fi
145   if( spac[ 1 ] < double( 0 ) )
146   {
147     double t = ybnds[ 0 ];
148     ybnds[ 0 ] = ybnds[ 1 ];
149     ybnds[ 1 ] = t;
150
151   } // fi
152   if( spac[ 2 ] < double( 0 ) )
153   {
154     double t = zbnds[ 0 ];
155     zbnds[ 0 ] = zbnds[ 1 ];
156     zbnds[ 1 ] = t;
157
158   } // fi
159
160   int axis = this->SliceMapper->GetOrientation( );
161   this->PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
162   this->PlaneActor->GetProperty( )->SetLineWidth( 2 );
163   if( axis == 0 ) // YZ, x-normal
164   {
165     this->PlaneSource->SetOrigin( pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ]);
166     this->PlaneSource->SetPoint1( pos[ 0 ], ybnds[ 1 ], zbnds[ 0 ] );
167     this->PlaneSource->SetPoint2( pos[ 0 ], ybnds[ 0 ], zbnds[ 1 ] );
168     this->PlaneActor->GetProperty( )->SetColor( 1, 0, 0 );
169
170     this->RegionCutterPlane->SetOrigin( pos[ 0 ], ybnds[ 0 ], zbnds[ 0 ]);
171     this->RegionCutterPlane->SetNormal( 1, 0, 0 );
172   }
173   else if( axis == 1 ) // ZX, y-normal
174   {
175     this->PlaneSource->SetOrigin( xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] );
176     this->PlaneSource->SetPoint1( xbnds[ 0 ], pos[ 1 ], zbnds[ 1 ] );
177     this->PlaneSource->SetPoint2( xbnds[ 1 ], pos[ 1 ], zbnds[ 0 ] );
178     this->PlaneActor->GetProperty( )->SetColor( 0, 1, 0 );
179
180     this->RegionCutterPlane->SetOrigin( xbnds[ 0 ], pos[ 1 ], zbnds[ 0 ] );
181     this->RegionCutterPlane->SetNormal( 0, 1, 0 );
182   }
183   else // XY, z-normal
184   {
185     this->PlaneSource->SetOrigin( xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] );
186     this->PlaneSource->SetPoint1( xbnds[ 1 ], ybnds[ 0 ], pos[ 2 ] );
187     this->PlaneSource->SetPoint2( xbnds[ 0 ], ybnds[ 1 ], pos[ 2 ] );
188     this->PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
189
190     this->RegionCutterPlane->SetOrigin( xbnds[ 0 ], ybnds[ 0 ], pos[ 2 ] );
191     this->RegionCutterPlane->SetNormal( 0, 0, 1 );
192
193   } // fi
194
195   this->RegionCutter->Modified( );
196   this->RegionCutterMapper->Modified( );
197   this->RegionCutterActor->Modified( );
198 }
199
200 // -------------------------------------------------------------------------
201 void idms::VolumeActors::SliceActor::
202 UpdateText( const double& w, const double& l )
203 {
204   char axis;
205   if     ( this->SliceMapper->GetOrientation( ) == 0 ) axis = 'X';
206   else if( this->SliceMapper->GetOrientation( ) == 1 ) axis = 'Y';
207   else if( this->SliceMapper->GetOrientation( ) == 2 ) axis = 'Z';
208
209   std::sprintf(
210     this->TextBuffer, "Axis: %c (%d)\nWin/Lev: %.2f/%.2f",
211     axis, this->SliceMapper->GetSliceNumber( ), w, l
212     );
213   this->TextActor->SetInput( this->TextBuffer );
214   this->TextActor->Modified( );
215 }
216
217 // -------------------------------------------------------------------------
218 idms::VolumeActors* idms::VolumeActors::
219 New( )
220 {
221   return( new Self( ) );
222 }
223
224 // -------------------------------------------------------------------------
225 void idms::VolumeActors::
226 Configure(
227   vtkImageData* image,
228   vtkRenderWindowInteractor* xi,
229   vtkRenderWindowInteractor* yi,
230   vtkRenderWindowInteractor* zi
231   )
232 {
233   if( image == NULL || xi == NULL || yi == NULL || zi == NULL )
234     vtkErrorMacro( "At least one object is \"NULL\"" );
235
236   this->Image = image;
237   this->Interactors[ 0 ] = xi;
238   this->Interactors[ 1 ] = yi;
239   this->Interactors[ 2 ] = zi;
240
241   this->ImageToWindowLevel->SetInputData( this->Image );
242   this->ResetWindowLevel( );
243   this->ImageToWindowLevel->Update( );
244
245   // Create 3D outline
246   this->ImageOutlineSource =
247     vtkSmartPointer< vtkOutlineSource >::New( );
248   vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
249     vtkSmartPointer< vtkPolyDataMapper >::New( );
250   this->ImageOutlineSource->SetBounds( this->Image->GetBounds( ) );
251   img_ol_mapper->SetInputConnection(
252     this->ImageOutlineSource->GetOutputPort( )
253     );
254   this->ImageOutlineIndex = this->GetNumberOfItems( );
255   vtkSmartPointer< vtkActor > img_ol_actor =
256     vtkSmartPointer< vtkActor >::New( );
257   img_ol_actor->SetMapper( img_ol_mapper );
258   img_ol_actor->GetProperty( )->SetColor( 1, 1, 1 );
259   img_ol_actor->GetProperty( )->SetLineWidth( 1 );
260   this->AddItem( img_ol_actor );
261
262   // Cursor radius
263   double spac[ 3 ];
264   image->GetSpacing( spac );
265   double radius = spac[ 0 ];
266   radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
267   radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
268   radius *= double( 6 );
269   this->Cursor->SetRadius( radius );
270   this->CursorMapper->Modified( );
271   this->CursorActor->Modified( );
272
273   // Plane actors
274   for( int a = 0; a < 3; ++a )
275   {
276     // Configure actors
277     this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
278     this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
279     this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
280
281     // Add them to renderer
282     vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
283       GetRenderers( )->GetFirstRenderer( );
284     if( ren == NULL )
285       vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
286     ren->AddActor( this->Planes[ a ].ImageActor );
287     ren->AddActor( this->Planes[ a ].TextActor );
288
289     for( int i = 0; i < 3; ++i )
290       this->Interactors[ a ]->GetRenderWindow( )->
291         GetRenderers( )->GetFirstRenderer( )->
292         AddActor( this->Planes[ i ].PlaneActor );
293
294   } // rof
295
296   // Keep track into collection
297 /*
298   this->XPlaneIndex = this->GetNumberOfItems( );
299   this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
300   this->XTextIndex = this->GetNumberOfItems( );
301   this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
302   this->XBoundsIndex = this->GetNumberOfItems( );
303   this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
304
305   this->YPlaneIndex = this->GetNumberOfItems( );
306   this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
307   this->YTextIndex = this->GetNumberOfItems( );
308   this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
309   this->YBoundsIndex = this->GetNumberOfItems( );
310   this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
311
312   this->ZPlaneIndex = this->GetNumberOfItems( );
313   this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
314   this->ZTextIndex = this->GetNumberOfItems( );
315   this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
316   this->ZBoundsIndex = this->GetNumberOfItems( );
317   this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
318 */
319   // Initialize slice visualization
320   this->ResetSlices( );
321
322   /*
323     #error CONTOUR_WIDGET <- ACA VOY
324     static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
325     vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
326     static vtkSmartPointer<vtkContourWidget> contourWidget =
327     vtkSmartPointer<vtkContourWidget>::New();
328     contourWidget->SetInteractor( zi );
329     contourWidget->SetRepresentation( contourRep );
330     contourWidget->On( );
331   */
332
333
334
335
336
337
338
339
340
341 }
342
343 // -------------------------------------------------------------------------
344 void idms::VolumeActors::
345 SetSegmentation( vtkImageData* segmentation )
346 {
347   double range[ 2 ];
348   this->Segmentation = segmentation;
349   this->Segmentation->GetScalarRange( range );
350
351   vtkSmartPointer< vtkLookupTable > lut =
352     vtkSmartPointer< vtkLookupTable >::New( );
353   lut->SetNumberOfTableValues( 2 );
354   lut->SetTableRange( range );
355   lut->SetTableValue( 0, 0, 0, 0, 0 );
356   lut->SetTableValue( 1, 1, 0, 0, 0.4 );
357
358   this->SegmentationToColors->SetInputData( this->Segmentation );
359   this->SegmentationToColors->SetLookupTable( lut );
360   this->SegmentationToColors->Update( );
361
362   for( unsigned int a = 0; a < 3; ++a )
363   {
364     this->Planes[ a ].SetSegmentation(
365       this->SegmentationToColors->GetOutputPort( )
366       );
367     vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
368       GetRenderers( )->GetFirstRenderer( );
369     ren->AddActor( this->Planes[ a ].SegmentationActor );
370
371   } // rof
372   this->Render( );
373 }
374
375 // -------------------------------------------------------------------------
376 void idms::VolumeActors::
377 AddAuxiliaryInteractor( vtkRenderWindowInteractor* i )
378 {
379   if( i != NULL )
380   {
381     this->AuxiliaryInteractors.insert( i );
382     this->Modified( );
383
384   } // fi
385 }
386
387 // -------------------------------------------------------------------------
388 double idms::VolumeActors::
389 GetMinWindow( ) const
390 {
391   return( double( 0.01 ) );
392 }
393
394 // -------------------------------------------------------------------------
395 double idms::VolumeActors::
396 GetMaxWindow( ) const
397 {
398   if( this->Image == NULL )
399     return( double( 0 ) );
400
401   double range[ 2 ];
402   this->Image->GetScalarRange( range );
403   return( range[ 1 ] - range[ 0 ] );
404 }
405
406 // -------------------------------------------------------------------------
407 double idms::VolumeActors::
408 GetMinLevel( ) const
409 {
410   if( this->Image == NULL )
411     return( double( 0 ) );
412
413   double range[ 2 ];
414   this->Image->GetScalarRange( range );
415   return( range[ 0 ] );
416 }
417
418 // -------------------------------------------------------------------------
419 double idms::VolumeActors::
420 GetMaxLevel( ) const
421 {
422   if( this->Image == NULL )
423     return( double( 0 ) );
424
425   double range[ 2 ];
426   this->Image->GetScalarRange( range );
427   return( range[ 1 ] );
428 }
429
430 // -------------------------------------------------------------------------
431 double idms::VolumeActors::
432 GetWindow( ) const
433 {
434   return( this->ImageToWindowLevel->GetWindow( ) );
435 }
436
437 // -------------------------------------------------------------------------
438 double idms::VolumeActors::
439 GetLevel( ) const
440 {
441   return( this->ImageToWindowLevel->GetLevel( ) );
442 }
443
444 // -------------------------------------------------------------------------
445 void idms::VolumeActors::
446 SetWindow( const double& w )
447 {
448   this->ImageToWindowLevel->SetWindow( w );
449 }
450
451 // -------------------------------------------------------------------------
452 void idms::VolumeActors::
453 SetLevel( const double& l )
454 {
455   this->ImageToWindowLevel->SetLevel( l );
456 }
457
458 // -------------------------------------------------------------------------
459 void idms::VolumeActors::
460 SetWindowLevel( const double& w, const double& l )
461 {
462   this->ImageToWindowLevel->SetWindow( w );
463   this->ImageToWindowLevel->SetLevel( l );
464   for( int a = 0; a < 3; ++a )
465     this->Planes[ a ].UpdateText( w, l );
466 }
467
468 // -------------------------------------------------------------------------
469 void idms::VolumeActors::
470 ResetWindowLevel( )
471 {
472   double range[ 2 ];
473   this->Image->GetScalarRange( range );
474   this->SetWindowLevel(
475     range[ 1 ] - range[ 0 ],
476     ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ]
477     );
478 }
479
480 // -------------------------------------------------------------------------
481 vtkPlane* idms::VolumeActors::
482 GetSlicePlane( const int& axis ) const
483 {
484   return( this->Planes[ axis ].SliceMapper->GetSlicePlane( ) );
485 }
486
487 // -------------------------------------------------------------------------
488 int idms::VolumeActors::
489 GetSliceNumberMinValue( const int& axis ) const
490 {
491   return( this->Planes[ axis ].SliceMapper->GetSliceNumberMinValue( ) );
492 }
493
494 // -------------------------------------------------------------------------
495 int idms::VolumeActors::
496 GetSliceNumberMaxValue( const int& axis ) const
497 {
498   return( this->Planes[ axis ].SliceMapper->GetSliceNumberMaxValue( ) );
499 }
500
501 // -------------------------------------------------------------------------
502 int idms::VolumeActors::
503 GetSlice( const int& axis ) const
504 {
505   return( this->Planes[ axis ].SliceMapper->GetSliceNumber( ) );
506 }
507
508 // -------------------------------------------------------------------------
509 void idms::VolumeActors::
510 SetSlice( const int& axis, const int& slice )
511 {
512   this->Planes[ axis ].SetSliceNumber( slice );
513   this->Planes[ axis ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
514   this->RenderAuxiliaryInteractors( );
515 }
516
517 // -------------------------------------------------------------------------
518 void idms::VolumeActors::
519 SetSlice( const int& axis, const double& slice )
520 {
521   vtkAlgorithm* algo =
522     this->Planes[ axis ].SliceMapper->GetInputAlgorithm( );
523   vtkInformation* info = algo->GetOutputInformation( 0 );
524   int ext[ 6 ];
525   double ori[ 3 ], spac[ 3 ];
526   info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext );
527   info->Get( vtkDataObject::ORIGIN( ), ori );
528   info->Get( vtkDataObject::SPACING( ), spac );
529   this->SetSlice(
530     axis,
531     int( ( slice - ori[ axis ] ) / spac[ axis ] ) + ext[ axis << 1 ]
532     );
533 }
534
535 // -------------------------------------------------------------------------
536 void idms::VolumeActors::
537 ResetSlices( )
538 {
539   for( int a = 0; a < 3; ++a )
540     this->SetSlice( a, this->GetSliceNumberMinValue( a ) );
541   this->Render( );
542 }
543
544 // -------------------------------------------------------------------------
545 void idms::VolumeActors::
546 AddSeed( int idx[ 3 ] )
547 {
548   this->Seeds.push_back( std::vector< int >( idx, idx + 3 ) );
549   this->Modified( );
550 }
551
552 // -------------------------------------------------------------------------
553 void idms::VolumeActors::
554 AddSeed( double pos[ 3 ] )
555 {
556   /* TODO
557      this->Seeds.push_back( std::vector< double >( pos, pos + 3 ) );
558      this->Modified( );
559   */
560 }
561
562 // -------------------------------------------------------------------------
563 unsigned int idms::VolumeActors::
564 GetNumberOfSeeds( ) const
565 {
566   return( this->Seeds.size( ) );
567 }
568
569 // -------------------------------------------------------------------------
570 void idms::VolumeActors::
571 GetSeed( unsigned int i, int idx[ 3 ] ) const
572 {
573   if( i < this->Seeds.size( ) )
574   {
575     idx[ 0 ] = this->Seeds[ i ][ 0 ];
576     idx[ 1 ] = this->Seeds[ i ][ 1 ];
577     idx[ 2 ] = this->Seeds[ i ][ 2 ];
578
579   } // fi
580 }
581
582 // -------------------------------------------------------------------------
583 void idms::VolumeActors::
584 SetCursorPosition( double pos[ 3 ] )
585 {
586   this->Cursor->SetCenter( pos );
587 }
588
589 // -------------------------------------------------------------------------
590 void idms::VolumeActors::
591 ShowRegion( int a )
592 {
593   vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
594     GetRenderers( )->GetFirstRenderer( );
595   ren->AddActor( this->Planes[ a ].RegionCutterActor );
596 }
597
598 // -------------------------------------------------------------------------
599 void idms::VolumeActors::
600 HideRegion( int a )
601 {
602   vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
603     GetRenderers( )->GetFirstRenderer( );
604   ren->RemoveActor( this->Planes[ a ].RegionCutterActor );
605 }
606
607 // -------------------------------------------------------------------------
608 void idms::VolumeActors::
609 SetRegionPosition( double pos[ 3 ] )
610 {
611   this->Region->SetCenter( pos );
612 }
613
614 // -------------------------------------------------------------------------
615 void idms::VolumeActors::
616 SetRegionRadius( double pos[ 3 ] )
617 {
618   double rpos[ 3 ];
619
620   this->Region->GetCenter( rpos );
621   double x = pos[ 0 ] - rpos[ 0 ];
622   double y = pos[ 1 ] - rpos[ 1 ];
623   double z = pos[ 2 ] - rpos[ 2 ];
624   double d = ( x * x ) + ( y * y ) + ( z * z );
625   if( double( 0 ) < d )
626     d = std::sqrt( d );
627   else
628     d = double( 0 );
629   this->Region->SetRadius( d );
630   this->Planes[ 0 ].RegionCutter->Modified( );
631   this->Planes[ 1 ].RegionCutter->Modified( );
632   this->Planes[ 2 ].RegionCutter->Modified( );
633   this->Planes[ 0 ].RegionCutterMapper->Modified( );
634   this->Planes[ 1 ].RegionCutterMapper->Modified( );
635   this->Planes[ 2 ].RegionCutterMapper->Modified( );
636   this->Planes[ 0 ].RegionCutterActor->Modified( );
637   this->Planes[ 1 ].RegionCutterActor->Modified( );
638   this->Planes[ 2 ].RegionCutterActor->Modified( );
639   this->Render( );
640 }
641
642 // -------------------------------------------------------------------------
643 void idms::VolumeActors::
644 GetImageBounds( double bounds[ 6 ] ) const
645 {
646   if( this->Image != NULL )
647     this->Image->GetBounds( bounds );
648 }
649
650 // -------------------------------------------------------------------------
651 void idms::VolumeActors::
652 Render( )
653 {
654   for( int a = 0; a < 3; ++a )
655     if( this->Interactors[ a ] != NULL )
656       this->Interactors[ a ]->Render( );
657 }
658
659 // -------------------------------------------------------------------------
660 void idms::VolumeActors::
661 RenderAuxiliaryInteractors( )
662 {
663   for(
664     TInteractors::iterator iIt = this->AuxiliaryInteractors.begin( );
665     iIt != this->AuxiliaryInteractors.end( );
666     ++iIt
667     )
668     ( *iIt )->Render( );
669 }
670
671 // -------------------------------------------------------------------------
672 void idms::VolumeActors::
673 ResetCameras( )
674 {
675   double b[ 6 ];
676   this->GetImageBounds( b );
677   for( int a = 0; a < 3; ++a )
678   {
679     if( this->Interactors[ a ] == NULL )
680       continue;
681     vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
682       GetRenderers( )->GetFirstRenderer( );
683     if( ren != NULL ) ren->ResetCamera( b );
684
685   } // rof
686 }
687
688 // -------------------------------------------------------------------------
689 idms::VolumeActors::
690 VolumeActors( )
691   : Superclass( ),
692     Image( NULL ),
693     Segmentation( NULL )
694 {
695   for( int a = 0; a < 3; ++a )
696     this->Interactors[ a ] = NULL;
697
698   this->ImageToWindowLevel =
699     vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( );
700   this->ImageToWindowLevel->SetOutputFormatToLuminance( );
701   this->SegmentationToColors =
702     vtkSmartPointer< vtkImageMapToColors >::New( );
703
704   this->Cursor = vtkSmartPointer< vtkSphereSource >::New( );
705   this->CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
706   this->CursorActor = vtkSmartPointer< vtkActor >::New( );
707
708   this->Cursor->SetPhiResolution( 36 );
709   this->Cursor->SetThetaResolution( 36 );
710   this->CursorMapper->SetInputConnection( this->Cursor->GetOutputPort( ) );
711   this->CursorActor->SetMapper( this->CursorMapper );
712   this->CursorActor->GetProperty( )->SetColor( 1, 1, 0 );
713   this->CursorIndex = this->GetNumberOfItems( );
714   this->AddItem( this->CursorActor );
715
716   this->Region = vtkSmartPointer< vtkSphereSource >::New( );
717   this->RegionMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
718   this->RegionActor = vtkSmartPointer< vtkActor >::New( );
719
720   this->Region->SetPhiResolution( 36 );
721   this->Region->SetThetaResolution( 36 );
722   this->RegionMapper->SetInputConnection( this->Region->GetOutputPort( ) );
723   this->RegionActor->SetMapper( this->RegionMapper );
724   this->RegionActor->GetProperty( )->SetColor( 0, 0, 1 );
725   this->RegionActor->GetProperty( )->SetOpacity( 0 );
726   this->RegionIndex = this->GetNumberOfItems( );
727   this->AddItem( this->RegionActor );
728
729   this->XPlaneIndex = this->GetNumberOfItems( );
730   this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
731   this->XTextIndex = this->GetNumberOfItems( );
732   this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
733   this->XBoundsIndex = this->GetNumberOfItems( );
734   this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
735
736   this->YPlaneIndex = this->GetNumberOfItems( );
737   this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
738   this->YTextIndex = this->GetNumberOfItems( );
739   this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
740   this->YBoundsIndex = this->GetNumberOfItems( );
741   this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
742
743   this->ZPlaneIndex = this->GetNumberOfItems( );
744   this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
745   this->ZTextIndex = this->GetNumberOfItems( );
746   this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
747   this->ZBoundsIndex = this->GetNumberOfItems( );
748   this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
749 }
750
751 // -------------------------------------------------------------------------
752 idms::VolumeActors::
753 ~VolumeActors( )
754 {
755 }
756
757 // eof - $RCSfile$