1 #include <cpPlugins/Extensions/Visualization/MPRActors.h>
3 #include <vtkImageData.h>
4 #include <vtkLookupTable.h>
5 #include <vtkOutlineSource.h>
6 #include <vtkPolyDataMapper.h>
7 #include <vtkProperty.h>
8 #include <vtkRenderer.h>
10 // -------------------------------------------------------------------------
11 cpPlugins::Extensions::Visualization::MPRActors*
12 cpPlugins::Extensions::Visualization::MPRActors::
15 return( new Self( ) );
18 // -------------------------------------------------------------------------
19 cpPlugins::Extensions::Visualization::
20 ImageSliceActors* cpPlugins::Extensions::Visualization::MPRActors::
21 GetSliceActors( const int& i ) const
24 return( this->Slices[ i ] );
29 // -------------------------------------------------------------------------
30 void cpPlugins::Extensions::Visualization::MPRActors::
31 SetInputData( vtkImageData* image )
38 this->ImageToWindowLevel->SetInputData( this->Image );
39 this->ResetWindowLevel( );
40 this->ImageToWindowLevel->Update( );
42 for( int i = 0; i < 3; ++i )
44 this->Slices[ i ]->SetInputConnection(
45 this->ImageToWindowLevel->GetOutputPort( ), i
47 this->Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
52 vtkSmartPointer< vtkOutlineSource > img_ol =
53 vtkSmartPointer< vtkOutlineSource >::New( );
54 img_ol->SetBounds( this->Image->GetBounds( ) );
56 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
57 vtkSmartPointer< vtkPolyDataMapper >::New( );
58 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
59 this->ImageOutlineActor->SetMapper( img_ol_mapper );
60 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
61 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
63 this->ImageOutlineActorIndex = this->GetNumberOfItems( );
64 this->AddItem( this->ImageOutlineActor );
69 image->GetSpacing( spac );
70 double radius = spac[ 0 ];
71 radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
72 radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
73 radius *= double( 6 );
74 this->Cursor->SetRadius( radius );
75 this->CursorMapper->Modified( );
76 this->CursorActor->Modified( );
79 for( int a = 0; a < 3; ++a )
82 this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
83 this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
84 this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
86 // Add them to renderer
87 vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
88 GetRenderers( )->GetFirstRenderer( );
90 vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
91 ren->AddActor( this->Planes[ a ].ImageActor );
92 ren->AddActor( this->Planes[ a ].TextActor );
94 for( int i = 0; i < 3; ++i )
95 this->Interactors[ a ]->GetRenderWindow( )->
96 GetRenderers( )->GetFirstRenderer( )->
97 AddActor( this->Planes[ i ].PlaneActor );
101 // Keep track into collection
103 this->XPlaneIndex = this->GetNumberOfItems( );
104 this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
105 this->XTextIndex = this->GetNumberOfItems( );
106 this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
107 this->XBoundsIndex = this->GetNumberOfItems( );
108 this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
110 this->YPlaneIndex = this->GetNumberOfItems( );
111 this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
112 this->YTextIndex = this->GetNumberOfItems( );
113 this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
114 this->YBoundsIndex = this->GetNumberOfItems( );
115 this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
117 this->ZPlaneIndex = this->GetNumberOfItems( );
118 this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
119 this->ZTextIndex = this->GetNumberOfItems( );
120 this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
121 this->ZBoundsIndex = this->GetNumberOfItems( );
122 this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
124 // Initialize slice visualization
125 this->ResetSlices( );
128 #error CONTOUR_WIDGET <- ACA VOY
129 static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
130 vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
131 static vtkSmartPointer<vtkContourWidget> contourWidget =
132 vtkSmartPointer<vtkContourWidget>::New();
133 contourWidget->SetInteractor( zi );
134 contourWidget->SetRepresentation( contourRep );
135 contourWidget->On( );
139 // -------------------------------------------------------------------------
140 void cpPlugins::Extensions::Visualization::MPRActors::
141 SetSegmentationData( vtkImageData* segmentation )
144 this->Segmentation = segmentation;
145 this->Segmentation->GetScalarRange( range );
147 vtkSmartPointer< vtkLookupTable > lut =
148 vtkSmartPointer< vtkLookupTable >::New( );
149 lut->SetNumberOfTableValues( 2 );
150 lut->SetTableRange( range );
151 lut->SetTableValue( 0, 0, 0, 0, 0 );
152 lut->SetTableValue( 1, 1, 0, 0, 0.4 );
154 this->SegmentationToColors->SetInputData( this->Segmentation );
155 this->SegmentationToColors->SetLookupTable( lut );
156 this->SegmentationToColors->Update( );
158 for( int i = 0; i < 3; ++i )
159 this->Slices[ i ]->SetSegmentationConnection(
160 this->SegmentationToColors->GetOutputPort( )
164 // -------------------------------------------------------------------------
165 void cpPlugins::Extensions::Visualization::MPRActors::
166 PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
168 vtkRenderer* rends[] = { x, y, z };
169 for( int i = 0; i < 3; ++i )
171 if( rends[ i ] != NULL )
173 rends[ i ]->AddActor( this->Slices[ i ]->GetImageActor( ) );
174 rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) );
175 for( int j = 0; j < 3; ++j )
176 rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) );
177 if( this->Segmentation != NULL )
178 rends[ i ]->AddActor( this->Slices[ i ]->GetSegmentationActor( ) );
180 w->AddActor( this->Slices[ i ]->GetPlaneActor( ) );
188 w->AddActor( this->ImageOutlineActor );
193 // -------------------------------------------------------------------------
194 void cpPlugins::Extensions::Visualization::MPRActors::
195 PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
199 // -------------------------------------------------------------------------
200 double cpPlugins::Extensions::Visualization::MPRActors::
201 GetMinWindow( ) const
203 return( double( 0 ) );
206 // -------------------------------------------------------------------------
207 double cpPlugins::Extensions::Visualization::MPRActors::
208 GetMaxWindow( ) const
210 if( this->Image == NULL )
211 return( double( 0 ) );
214 this->Image->GetScalarRange( range );
215 return( range[ 1 ] - range[ 0 ] );
218 // -------------------------------------------------------------------------
219 double cpPlugins::Extensions::Visualization::MPRActors::
222 if( this->Image == NULL )
223 return( double( 0 ) );
226 this->Image->GetScalarRange( range );
227 return( range[ 0 ] );
230 // -------------------------------------------------------------------------
231 double cpPlugins::Extensions::Visualization::MPRActors::
234 if( this->Image == NULL )
235 return( double( 0 ) );
238 this->Image->GetScalarRange( range );
239 return( range[ 1 ] );
242 // -------------------------------------------------------------------------
243 double cpPlugins::Extensions::Visualization::MPRActors::
246 if( this->Image != NULL )
247 return( this->ImageToWindowLevel->GetWindow( ) );
252 // -------------------------------------------------------------------------
253 double cpPlugins::Extensions::Visualization::MPRActors::
256 if( this->Image != NULL )
257 return( this->ImageToWindowLevel->GetLevel( ) );
262 // -------------------------------------------------------------------------
263 void cpPlugins::Extensions::Visualization::MPRActors::
264 SetWindow( const double& w )
266 if( this->Image != NULL )
267 this->ImageToWindowLevel->SetWindow( w );
270 // -------------------------------------------------------------------------
271 void cpPlugins::Extensions::Visualization::MPRActors::
272 SetLevel( const double& l )
274 if( this->Image != NULL )
275 this->ImageToWindowLevel->SetLevel( l );
278 // -------------------------------------------------------------------------
279 void cpPlugins::Extensions::Visualization::MPRActors::
280 SetWindowLevel( const double& w, const double& l )
282 this->ImageToWindowLevel->SetWindow( w );
283 this->ImageToWindowLevel->SetLevel( l );
284 for( int i = 0; i < 3; ++i )
285 this->Slices[ i ]->UpdateText( w, l );
288 // -------------------------------------------------------------------------
289 void cpPlugins::Extensions::Visualization::MPRActors::
293 this->Image->GetScalarRange( range );
294 this->SetWindowLevel(
295 range[ 1 ] - range[ 0 ],
296 ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ]
300 // -------------------------------------------------------------------------
301 vtkPlane* cpPlugins::Extensions::Visualization::MPRActors::
302 GetSlicePlane( const int& axis ) const
307 // -------------------------------------------------------------------------
308 int cpPlugins::Extensions::Visualization::MPRActors::
309 GetSliceNumberMinValue( const int& axis ) const
311 return( this->Slices[ axis ]->GetSliceNumberMinValue( ) );
314 // -------------------------------------------------------------------------
315 int cpPlugins::Extensions::Visualization::MPRActors::
316 GetSliceNumberMaxValue( const int& axis ) const
318 return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) );
321 // -------------------------------------------------------------------------
322 int cpPlugins::Extensions::Visualization::MPRActors::
323 GetSlice( const int& axis ) const
325 return( this->Slices[ axis ]->GetSliceNumber( ) );
328 // -------------------------------------------------------------------------
329 void cpPlugins::Extensions::Visualization::MPRActors::
330 SetSlice( const int& axis, const int& slice )
332 // Get image data extent
333 if( this->Image == NULL )
336 this->Image->GetExtent( ext );
338 // Check if the slice is valid
340 if( slice < ext[ axis << 1 ] )
341 real = ext[ axis << 1 ];
342 if( ext[ ( axis << 1 ) + 1 ] < slice )
343 real = ext[ ( axis << 1 ) + 1 ];
346 this->Slices[ axis ]->SetSliceNumber( real );
350 // -------------------------------------------------------------------------
351 void cpPlugins::Extensions::Visualization::MPRActors::
352 SetSlice( const int& axis, const double& slice )
354 if( this->Image == NULL )
357 double x[ 3 ] = { double( 0 ) };
362 this->Image->ComputeStructuredCoordinates( x, ijk, pcoords );
363 this->SetSlice( axis, ijk[ axis ] );
366 // -------------------------------------------------------------------------
367 void cpPlugins::Extensions::Visualization::MPRActors::
372 // -------------------------------------------------------------------------
373 void cpPlugins::Extensions::Visualization::MPRActors::
374 GetImageBounds( double bounds[ 6 ] ) const
378 // -------------------------------------------------------------------------
379 cpPlugins::Extensions::Visualization::MPRActors::
385 this->ImageToWindowLevel =
386 vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( );
387 this->SegmentationToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
388 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
389 this->Slices[ 0 ] = vtkSmartPointer< TSlice >::New( );
390 this->Slices[ 1 ] = vtkSmartPointer< TSlice >::New( );
391 this->Slices[ 2 ] = vtkSmartPointer< TSlice >::New( );
394 // -------------------------------------------------------------------------
395 cpPlugins::Extensions::Visualization::MPRActors::