1 #include <cpPlugins/Extensions/Visualization/MPRActors.h>
3 #include <vtkImageData.h>
4 #include <vtkOutlineSource.h>
5 #include <vtkPolyDataMapper.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderer.h>
9 // -------------------------------------------------------------------------
10 cpPlugins::Extensions::Visualization::MPRActors*
11 cpPlugins::Extensions::Visualization::MPRActors::
14 return( new Self( ) );
17 // -------------------------------------------------------------------------
18 cpPlugins::Extensions::Visualization::
19 ImageSliceActors* cpPlugins::Extensions::Visualization::MPRActors::
20 GetSliceActors( const int& i ) const
23 return( this->Slices[ i ] );
28 // -------------------------------------------------------------------------
29 void cpPlugins::Extensions::Visualization::MPRActors::
30 SetInputData( vtkImageData* image )
37 this->ImageToWindowLevel->SetInputData( this->Image );
38 this->ResetWindowLevel( );
39 this->ImageToWindowLevel->Update( );
41 for( int i = 0; i < 3; ++i )
43 Slices[ i ]->SetInputConnection(
44 this->ImageToWindowLevel->GetOutputPort( ), i
46 Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
51 vtkSmartPointer< vtkOutlineSource > img_ol =
52 vtkSmartPointer< vtkOutlineSource >::New( );
53 img_ol->SetBounds( this->Image->GetBounds( ) );
55 vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
56 vtkSmartPointer< vtkPolyDataMapper >::New( );
57 img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
58 this->ImageOutlineActor->SetMapper( img_ol_mapper );
59 this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
60 this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
62 this->ImageOutlineActorIndex = this->GetNumberOfItems( );
63 this->AddItem( this->ImageOutlineActor );
68 image->GetSpacing( spac );
69 double radius = spac[ 0 ];
70 radius = ( spac[ 1 ] < radius )? spac[ 1 ]: radius;
71 radius = ( spac[ 2 ] < radius )? spac[ 2 ]: radius;
72 radius *= double( 6 );
73 this->Cursor->SetRadius( radius );
74 this->CursorMapper->Modified( );
75 this->CursorActor->Modified( );
78 for( int a = 0; a < 3; ++a )
81 this->Planes[ a ].Configure( this->ImageToWindowLevel->GetOutputPort( ), a );
82 this->Planes[ a ].ConfigureRegion( this->Region->GetOutputPort( ) );
83 this->Planes[ a ].UpdateText( this->GetWindow( ), this->GetLevel( ) );
85 // Add them to renderer
86 vtkRenderer* ren = this->Interactors[ a ]->GetRenderWindow( )->
87 GetRenderers( )->GetFirstRenderer( );
89 vtkErrorMacro( "At least one interactor doesn't have a valid renderer" );
90 ren->AddActor( this->Planes[ a ].ImageActor );
91 ren->AddActor( this->Planes[ a ].TextActor );
93 for( int i = 0; i < 3; ++i )
94 this->Interactors[ a ]->GetRenderWindow( )->
95 GetRenderers( )->GetFirstRenderer( )->
96 AddActor( this->Planes[ i ].PlaneActor );
100 // Keep track into collection
102 this->XPlaneIndex = this->GetNumberOfItems( );
103 this->AddItem( this->Planes[ 0 ].ImageActor.GetPointer( ) );
104 this->XTextIndex = this->GetNumberOfItems( );
105 this->AddItem( this->Planes[ 0 ].TextActor.GetPointer( ) );
106 this->XBoundsIndex = this->GetNumberOfItems( );
107 this->AddItem( this->Planes[ 0 ].PlaneActor.GetPointer( ) );
109 this->YPlaneIndex = this->GetNumberOfItems( );
110 this->AddItem( this->Planes[ 1 ].ImageActor.GetPointer( ) );
111 this->YTextIndex = this->GetNumberOfItems( );
112 this->AddItem( this->Planes[ 1 ].TextActor.GetPointer( ) );
113 this->YBoundsIndex = this->GetNumberOfItems( );
114 this->AddItem( this->Planes[ 1 ].PlaneActor.GetPointer( ) );
116 this->ZPlaneIndex = this->GetNumberOfItems( );
117 this->AddItem( this->Planes[ 2 ].ImageActor.GetPointer( ) );
118 this->ZTextIndex = this->GetNumberOfItems( );
119 this->AddItem( this->Planes[ 2 ].TextActor.GetPointer( ) );
120 this->ZBoundsIndex = this->GetNumberOfItems( );
121 this->AddItem( this->Planes[ 2 ].PlaneActor.GetPointer( ) );
123 // Initialize slice visualization
124 this->ResetSlices( );
127 #error CONTOUR_WIDGET <- ACA VOY
128 static vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep =
129 vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
130 static vtkSmartPointer<vtkContourWidget> contourWidget =
131 vtkSmartPointer<vtkContourWidget>::New();
132 contourWidget->SetInteractor( zi );
133 contourWidget->SetRepresentation( contourRep );
134 contourWidget->On( );
138 // -------------------------------------------------------------------------
139 void cpPlugins::Extensions::Visualization::MPRActors::
140 SetSegmentationData( vtkImageData* segmentation )
144 // -------------------------------------------------------------------------
145 void cpPlugins::Extensions::Visualization::MPRActors::
146 PushDataInto( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
148 vtkRenderer* rends[] = { x, y, z };
149 for( int i = 0; i < 3; ++i )
151 if( rends[ i ] != NULL )
153 rends[ i ]->AddActor( this->Slices[ i ]->GetImageActor( ) );
154 rends[ i ]->AddActor( this->Slices[ i ]->GetTextActor( ) );
155 for( int j = 0; j < 3; ++j )
156 rends[ i ]->AddActor( this->Slices[ j ]->GetPlaneActor( ) );
157 if( this->Segmentation != NULL )
158 rends[ i ]->AddActor( this->Slices[ i ]->GetSegmentationActor( ) );
160 w->AddActor( this->Slices[ i ]->GetPlaneActor( ) );
168 w->AddActor( this->ImageOutlineActor );
173 // -------------------------------------------------------------------------
174 void cpPlugins::Extensions::Visualization::MPRActors::
175 PopDataFrom( vtkRenderer* x, vtkRenderer* y, vtkRenderer* z, vtkRenderer* w )
179 // -------------------------------------------------------------------------
180 double cpPlugins::Extensions::Visualization::MPRActors::
181 GetMinWindow( ) const
183 return( double( 0 ) );
186 // -------------------------------------------------------------------------
187 double cpPlugins::Extensions::Visualization::MPRActors::
188 GetMaxWindow( ) const
190 if( this->Image == NULL )
191 return( double( 0 ) );
194 this->Image->GetScalarRange( range );
195 return( range[ 1 ] - range[ 0 ] );
198 // -------------------------------------------------------------------------
199 double cpPlugins::Extensions::Visualization::MPRActors::
202 if( this->Image == NULL )
203 return( double( 0 ) );
206 this->Image->GetScalarRange( range );
207 return( range[ 0 ] );
210 // -------------------------------------------------------------------------
211 double cpPlugins::Extensions::Visualization::MPRActors::
214 if( this->Image == NULL )
215 return( double( 0 ) );
218 this->Image->GetScalarRange( range );
219 return( range[ 1 ] );
222 // -------------------------------------------------------------------------
223 double cpPlugins::Extensions::Visualization::MPRActors::
226 if( this->Image != NULL )
227 return( this->ImageToWindowLevel->GetWindow( ) );
232 // -------------------------------------------------------------------------
233 double cpPlugins::Extensions::Visualization::MPRActors::
236 if( this->Image != NULL )
237 return( this->ImageToWindowLevel->GetLevel( ) );
242 // -------------------------------------------------------------------------
243 void cpPlugins::Extensions::Visualization::MPRActors::
244 SetWindow( const double& w )
246 if( this->Image != NULL )
247 this->ImageToWindowLevel->SetWindow( w );
250 // -------------------------------------------------------------------------
251 void cpPlugins::Extensions::Visualization::MPRActors::
252 SetLevel( const double& l )
254 if( this->Image != NULL )
255 this->ImageToWindowLevel->SetLevel( l );
258 // -------------------------------------------------------------------------
259 void cpPlugins::Extensions::Visualization::MPRActors::
260 SetWindowLevel( const double& w, const double& l )
262 this->ImageToWindowLevel->SetWindow( w );
263 this->ImageToWindowLevel->SetLevel( l );
264 for( int i = 0; i < 3; ++i )
265 this->Slices[ i ]->UpdateText( w, l );
268 // -------------------------------------------------------------------------
269 void cpPlugins::Extensions::Visualization::MPRActors::
273 this->Image->GetScalarRange( range );
274 this->SetWindowLevel(
275 range[ 1 ] - range[ 0 ],
276 ( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) ) + range[ 0 ]
280 // -------------------------------------------------------------------------
281 vtkPlane* cpPlugins::Extensions::Visualization::MPRActors::
282 GetSlicePlane( const int& axis ) const
286 // -------------------------------------------------------------------------
287 int cpPlugins::Extensions::Visualization::MPRActors::
288 GetSliceNumberMinValue( const int& axis ) const
292 // -------------------------------------------------------------------------
293 int cpPlugins::Extensions::Visualization::MPRActors::
294 GetSliceNumberMaxValue( const int& axis ) const
298 // -------------------------------------------------------------------------
299 int cpPlugins::Extensions::Visualization::MPRActors::
300 GetSlice( const int& axis ) const
304 // -------------------------------------------------------------------------
305 void cpPlugins::Extensions::Visualization::MPRActors::
306 SetSlice( const int& axis, const int& slice )
310 // -------------------------------------------------------------------------
311 void cpPlugins::Extensions::Visualization::MPRActors::
312 SetSlice( const int& axis, const double& slice )
316 // -------------------------------------------------------------------------
317 void cpPlugins::Extensions::Visualization::MPRActors::
322 // -------------------------------------------------------------------------
323 void cpPlugins::Extensions::Visualization::MPRActors::
324 GetImageBounds( double bounds[ 6 ] ) const
328 // -------------------------------------------------------------------------
329 cpPlugins::Extensions::Visualization::MPRActors::
335 this->ImageToWindowLevel =
336 vtkSmartPointer< vtkImageMapToWindowLevelColors >::New( );
337 this->SegmentationToColors = vtkSmartPointer< vtkImageMapToColors >::New( );
338 this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
339 this->Slices[ 0 ] = vtkSmartPointer< TSlice >::New( );
340 this->Slices[ 1 ] = vtkSmartPointer< TSlice >::New( );
341 this->Slices[ 2 ] = vtkSmartPointer< TSlice >::New( );
344 // -------------------------------------------------------------------------
345 cpPlugins::Extensions::Visualization::MPRActors::