]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRActors.cxx
MPR-OpenGL integration: not yet finished, just one step to go. IT DOES NOT COMPILE.
[cpPlugins.git] / lib / cpExtensions / Visualization / MPRActors.cxx
1 #include <cpExtensions/Visualization/MPRActors.h>
2
3 #include <vtkAlgorithmOutput.h>
4 #include <vtkImageData.h>
5 #include <vtkOutlineSource.h>
6 #include <vtkProperty.h>
7 #include <vtkRenderer.h>
8 #include <vtkRendererCollection.h>
9 #include <vtkRenderWindow.h>
10
11 // -------------------------------------------------------------------------
12 cpExtensions::Visualization::MPRActors*
13 cpExtensions::Visualization::MPRActors::
14 New( )
15 {
16   return( new Self( ) );
17 }
18
19 // -------------------------------------------------------------------------
20 cpExtensions::Visualization::
21 ImageSliceActors* cpExtensions::Visualization::MPRActors::
22 GetSliceActors( const int& i ) const
23 {
24   if( i < 3 )
25     return( this->Slices[ 0 ][ i ] );
26   else
27     return( NULL );
28 }
29
30 // -------------------------------------------------------------------------
31 void cpExtensions::Visualization::MPRActors::
32 SetInputConnection( vtkAlgorithmOutput* aout )
33 {
34   this->Slices[ 0 ][ 0 ]->SetInputConnection( aout );
35   this->Slices[ 0 ][ 1 ]->SetInputConnection( aout );
36   this->Slices[ 0 ][ 2 ]->SetInputConnection( aout );
37   this->Slices[ 1 ][ 0 ]->SetInputConnection( aout );
38   this->Slices[ 1 ][ 1 ]->SetInputConnection( aout );
39   this->Slices[ 1 ][ 2 ]->SetInputConnection( aout );
40 }
41
42 // -------------------------------------------------------------------------
43 void cpExtensions::Visualization::MPRActors::
44 SetInputImage( vtkImageData* data )
45 {
46     this->Slices[ 0 ][ 0 ]->SetInputImage( data );
47     this->Slices[ 0 ][ 1 ]->SetInputImage( data );
48     this->Slices[ 0 ][ 2 ]->SetInputImage( data );
49     this->Slices[ 1 ][ 0 ]->SetInputImage( data );
50     this->Slices[ 1 ][ 1 ]->SetInputImage( data );
51     this->Slices[ 1 ][ 2 ]->SetInputImage( data );
52 }
53
54 // -------------------------------------------------------------------------
55 int cpExtensions::Visualization::MPRActors::
56 AddBinaryConnection(
57   vtkAlgorithmOutput* aout,
58   const double& r, const double& g, const double& b
59   )
60 {
61   this->Slices[ 0 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
62   this->Slices[ 0 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
63   this->Slices[ 0 ][ 2 ]->AddBinaryConnection( aout, r, g, b );
64   this->Slices[ 1 ][ 0 ]->AddBinaryConnection( aout, r, g, b );
65   this->Slices[ 1 ][ 1 ]->AddBinaryConnection( aout, r, g, b );
66   return( this->Slices[ 1 ][ 2 ]->AddBinaryConnection( aout, r, g, b ) );
67 }
68
69 // -------------------------------------------------------------------------
70 int cpExtensions::Visualization::MPRActors::
71 AddBinaryImage(
72   vtkImageData* data,
73   const double& r, const double& g, const double& b
74   )
75 {
76   this->Slices[ 0 ][ 0 ]->AddBinaryImage( data, r, g, b );
77   this->Slices[ 0 ][ 1 ]->AddBinaryImage( data, r, g, b );
78   this->Slices[ 0 ][ 2 ]->AddBinaryImage( data, r, g, b );
79   this->Slices[ 1 ][ 0 ]->AddBinaryImage( data, r, g, b );
80   this->Slices[ 1 ][ 1 ]->AddBinaryImage( data, r, g, b );
81   return( this->Slices[ 1 ][ 2 ]->AddBinaryImage( data, r, g, b ) );
82 }
83
84 // -------------------------------------------------------------------------
85 void cpExtensions::Visualization::MPRActors::
86 Clear( )
87 {
88   this->Slices[ 0 ][ 0 ]->Clear( );
89   this->Slices[ 0 ][ 1 ]->Clear( );
90   this->Slices[ 0 ][ 2 ]->Clear( );
91   this->Slices[ 1 ][ 0 ]->Clear( );
92   this->Slices[ 1 ][ 1 ]->Clear( );
93   this->Slices[ 1 ][ 2 ]->Clear( );
94 }
95
96 // -------------------------------------------------------------------------
97 vtkImageData* cpExtensions::Visualization::MPRActors::
98 GetInputImage( )
99 {
100   return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
101 }
102
103 // -------------------------------------------------------------------------
104 const vtkImageData* cpExtensions::Visualization::MPRActors::
105 GetInputImage( ) const
106 {
107   return( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
108 }
109
110 // -------------------------------------------------------------------------
111 unsigned int cpExtensions::Visualization::MPRActors::
112 GetNumberOfImages( ) const
113 {
114   return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
115 }
116
117 // -------------------------------------------------------------------------
118 void cpExtensions::Visualization::MPRActors::
119 SetInterpolate( bool v )
120 {
121   this->Slices[ 0 ][ 0 ]->SetInterpolate( v );
122   this->Slices[ 0 ][ 1 ]->SetInterpolate( v );
123   this->Slices[ 0 ][ 2 ]->SetInterpolate( v );
124   this->Slices[ 1 ][ 0 ]->SetInterpolate( v );
125   this->Slices[ 1 ][ 1 ]->SetInterpolate( v );
126   this->Slices[ 1 ][ 2 ]->SetInterpolate( v );
127 }
128
129 // -------------------------------------------------------------------------
130 void cpExtensions::Visualization::MPRActors::
131 InterpolateOn( )
132 {
133   this->SetInterpolate( true );
134 }
135
136 // -------------------------------------------------------------------------
137 void cpExtensions::Visualization::MPRActors::
138 InterpolateOff( )
139 {
140   this->SetInterpolate( false );
141 }
142
143 // -------------------------------------------------------------------------
144 void cpExtensions::Visualization::MPRActors::
145 PushActorsInto(
146   vtkRenderWindow* x,
147   vtkRenderWindow* y,
148   vtkRenderWindow* z,
149   vtkRenderWindow* w
150   )
151 {
152   this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true );
153   this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true );
154   this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true );
155   this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false );
156   this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
157   this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
158
159   vtkRenderer* wren =
160     ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
161   if( wren != NULL )
162     wren->AddViewProp( this->ImageOutlineActor );
163 }
164
165 // -------------------------------------------------------------------------
166 void cpExtensions::Visualization::MPRActors::
167 PopActorsFrom(
168   vtkRenderWindow* x,
169   vtkRenderWindow* y,
170   vtkRenderWindow* z,
171   vtkRenderWindow* w
172   )
173 {
174   this->Slices[ 0 ][ 0 ]->PopActorsFrom( x );
175   this->Slices[ 0 ][ 1 ]->PopActorsFrom( y );
176   this->Slices[ 0 ][ 2 ]->PopActorsFrom( z );
177   this->Slices[ 1 ][ 0 ]->PopActorsFrom( w );
178   this->Slices[ 1 ][ 1 ]->PopActorsFrom( w );
179   this->Slices[ 1 ][ 2 ]->PopActorsFrom( w );
180
181   vtkRenderer* wren =
182     ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
183   if( wren != NULL )
184     wren->RemoveViewProp( this->ImageOutlineActor );
185 }
186
187 // -------------------------------------------------------------------------
188 double cpExtensions::Visualization::MPRActors::
189 GetMinWindow( ) const
190 {
191   return( this->Slices[ 0 ][ 0 ]->GetMinWindow( ) );
192 }
193
194 // -------------------------------------------------------------------------
195 double cpExtensions::Visualization::MPRActors::
196 GetMaxWindow( ) const
197 {
198   return( this->Slices[ 0 ][ 0 ]->GetMaxWindow( ) );
199 }
200
201 // -------------------------------------------------------------------------
202 double cpExtensions::Visualization::MPRActors::
203 GetMinLevel( ) const
204 {
205   return( this->Slices[ 0 ][ 0 ]->GetMinLevel( ) );
206 }
207
208 // -------------------------------------------------------------------------
209 double cpExtensions::Visualization::MPRActors::
210 GetMaxLevel( ) const
211 {
212   return( this->Slices[ 0 ][ 0 ]->GetMaxLevel( ) );
213 }
214
215 // -------------------------------------------------------------------------
216 double cpExtensions::Visualization::MPRActors::
217 GetWindow( )
218 {
219   return( this->Slices[ 0 ][ 0 ]->GetWindow( ) );
220 }
221
222 // -------------------------------------------------------------------------
223 double cpExtensions::Visualization::MPRActors::
224 GetLevel( )
225 {
226   return( this->Slices[ 0 ][ 0 ]->GetLevel( ) );
227 }
228
229 // -------------------------------------------------------------------------
230 void cpExtensions::Visualization::MPRActors::
231 SetWindow( double w )
232 {
233   this->Slices[ 0 ][ 0 ]->SetWindow( w );
234   this->Slices[ 0 ][ 1 ]->SetWindow( w );
235   this->Slices[ 0 ][ 2 ]->SetWindow( w );
236   this->Slices[ 1 ][ 0 ]->SetWindow( w );
237   this->Slices[ 1 ][ 1 ]->SetWindow( w );
238   this->Slices[ 1 ][ 2 ]->SetWindow( w );
239 }
240
241 // -------------------------------------------------------------------------
242 void cpExtensions::Visualization::MPRActors::
243 SetLevel( double l )
244 {
245   this->Slices[ 0 ][ 0 ]->SetLevel( l );
246   this->Slices[ 0 ][ 1 ]->SetLevel( l );
247   this->Slices[ 0 ][ 2 ]->SetLevel( l );
248   this->Slices[ 1 ][ 0 ]->SetLevel( l );
249   this->Slices[ 1 ][ 1 ]->SetLevel( l );
250   this->Slices[ 1 ][ 2 ]->SetLevel( l );
251 }
252
253 // -------------------------------------------------------------------------
254 void cpExtensions::Visualization::MPRActors::
255 SetWindowLevel( double w, double l )
256 {
257   this->Slices[ 0 ][ 0 ]->SetWindowLevel( w, l );
258   this->Slices[ 0 ][ 1 ]->SetWindowLevel( w, l );
259   this->Slices[ 0 ][ 2 ]->SetWindowLevel( w, l );
260   this->Slices[ 1 ][ 0 ]->SetWindowLevel( w, l );
261   this->Slices[ 1 ][ 1 ]->SetWindowLevel( w, l );
262   this->Slices[ 1 ][ 2 ]->SetWindowLevel( w, l );
263 }
264
265 // -------------------------------------------------------------------------
266 void cpExtensions::Visualization::MPRActors::
267 ResetWindowLevel( )
268 {
269   this->Slices[ 0 ][ 0 ]->ResetWindowLevel( );
270   this->Slices[ 0 ][ 1 ]->ResetWindowLevel( );
271   this->Slices[ 0 ][ 2 ]->ResetWindowLevel( );
272   this->Slices[ 1 ][ 0 ]->ResetWindowLevel( );
273   this->Slices[ 1 ][ 1 ]->ResetWindowLevel( );
274   this->Slices[ 1 ][ 2 ]->ResetWindowLevel( );
275 }
276
277 // -------------------------------------------------------------------------
278 int cpExtensions::Visualization::MPRActors::
279 GetSliceNumber( const int& axis ) const
280 {
281   if( axis < 3 )
282     return( this->Slices[ 0 ][ axis ]->GetSliceNumber( ) );
283   else
284     return( -1 );
285 }
286
287 // -------------------------------------------------------------------------
288 int cpExtensions::Visualization::MPRActors::
289 GetSliceNumberMinValue( const int& axis ) const
290 {
291   if( axis < 3 )
292     return( this->Slices[ 0 ][ axis ]->GetSliceNumberMinValue( ) );
293   else
294     return( -1 );
295 }
296
297 // -------------------------------------------------------------------------
298 int cpExtensions::Visualization::MPRActors::
299 GetSliceNumberMaxValue( const int& axis ) const
300 {
301   if( axis < 3 )
302     return( this->Slices[ 0 ][ axis ]->GetSliceNumberMaxValue( ) );
303   else
304     return( -1 );
305 }
306
307 // -------------------------------------------------------------------------
308 void cpExtensions::Visualization::MPRActors::
309 SetSliceNumber( const int& axis, const int& slice )
310 {
311   if( axis < 3 )
312   {
313     this->Slices[ 0 ][ axis ]->SetSliceNumber( slice );
314     this->Slices[ 1 ][ axis ]->SetSliceNumber( slice );
315
316   } // fi
317 }
318
319 // -------------------------------------------------------------------------
320 void cpExtensions::Visualization::MPRActors::
321 SetSlice( const int& axis, double* pos )
322 {
323   if( axis < 3 )
324   {
325     this->Slices[ 0 ][ axis ]->SetSlice( pos );
326     this->Slices[ 1 ][ axis ]->SetSlice( pos );
327
328   } // fi
329 }
330
331 // -------------------------------------------------------------------------
332 cpExtensions::Visualization::MPRActors::
333 MPRActors( )
334   : Superclass( )
335 {
336   this->ImageOutlineActor = vtkSmartPointer< vtkActor >::New( );
337   for( unsigned int i = 0; i < 2; ++i )
338     for( unsigned int j = 0; j < 3; ++j )
339       this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( );
340
341   this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] );
342   this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] );
343   this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] );
344
345   for( unsigned int i = 0; i < 3; ++ i )
346   {
347     this->Slices[ 0 ][ i ]->AddRenderCommand(
348       Self::_RenderCommand, this
349       );
350     this->Slices[ 0 ][ i ]->AddWindowLevelCommand(
351       Self::_WindowLevelCommand, this
352       );
353     this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this );
354
355   } // rof
356 }
357
358 // -------------------------------------------------------------------------
359 cpExtensions::Visualization::MPRActors::
360 ~MPRActors( )
361 {
362 }
363
364 // -------------------------------------------------------------------------
365 void cpExtensions::Visualization::MPRActors::
366 _CreateBoundingBox( )
367 {
368   vtkImageData* image =
369     dynamic_cast< vtkImageData* >( this->Slices[ 0 ][ 0 ]->GetInputImage( ) );
370   if( image == NULL )
371     return;
372
373   // Create 3D outline
374   double bb[ 6 ];
375   image->GetBounds( bb );
376
377   vtkSmartPointer< vtkOutlineSource > img_ol =
378     vtkSmartPointer< vtkOutlineSource >::New( );
379   img_ol->SetBounds( bb );
380
381   vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper =
382     vtkSmartPointer< vtkPolyDataMapper >::New( );
383   img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) );
384   this->ImageOutlineActor->SetMapper( img_ol_mapper );
385   this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 );
386   this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 );
387
388   this->AddItem( this->ImageOutlineActor );
389 }
390
391 // -------------------------------------------------------------------------
392 void cpExtensions::Visualization::MPRActors::
393 _SlicesCommand( double* pos, int axis, void* data )
394 {
395   MPRActors* actors = reinterpret_cast< MPRActors* >( data );
396   if( actors == NULL )
397     return;
398   for( unsigned int j = 0; j < 3; ++j )
399     if( actors->Slices[ 0 ][ j ]->GetAxis( ) != axis )
400       actors->SetSlice( j, pos );
401 }
402
403 // -------------------------------------------------------------------------
404 void cpExtensions::Visualization::MPRActors::
405 _WindowLevelCommand( double window, double level, void* data )
406 {
407   MPRActors* actors = reinterpret_cast< MPRActors* >( data );
408   if( actors == NULL )
409     return;
410   actors->SetWindowLevel( window, level );
411 }
412
413 // -------------------------------------------------------------------------
414 void cpExtensions::Visualization::MPRActors::
415 _RenderCommand( void* data )
416 {
417   MPRActors* actors = reinterpret_cast< MPRActors* >( data );
418   if( actors == NULL )
419     return;
420 }
421
422 // eof - $RCSfile$