]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRObjects.cxx
a32824c455926d3f674f3f6d310afa629668af2c
[cpPlugins.git] / lib / cpExtensions / Visualization / MPRObjects.cxx
1 #include <cpExtensions/Visualization/MPRObjects.h>
2
3 #include <cmath>
4 #include <vtkImageData.h>
5 #include <vtkLookupTable.h>
6
7 // -------------------------------------------------------------------------
8 cpExtensions::Visualization::MPRObjects*
9 cpExtensions::Visualization::MPRObjects::
10 New( )
11 {
12   return( new Self( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 void cpExtensions::Visualization::MPRObjects::
17 SetRenderWindows(
18   vtkRenderWindow* wx, vtkRenderWindow* wy,
19   vtkRenderWindow* wz, vtkRenderWindow* w3D
20   )
21 {
22   this->m_Windows[ 0 ] = wx;
23   this->m_Windows[ 1 ] = wy;
24   this->m_Windows[ 2 ] = wz;
25   this->m_Windows[ 3 ] = w3D;
26
27   // Prepare 2D renderers
28   for( int i = 0; i < 4; ++i )
29   {
30     if( this->m_Windows[ i ] == NULL )
31     {
32       this->m_Renderers[ i ] = NULL;
33       continue;
34
35     } // fi
36
37     // Create renderer, if render window exists
38     this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
39     this->m_Renderers[ i ]->SetBackground( 0.1, 0.3, 0.8 );
40     this->m_Windows[ i ]->AddRenderer( this->m_Renderers[ i ] );
41
42   } // rof
43
44   // Create 3D renderer
45   if( this->m_Windows[ 3 ] != NULL )
46     this->m_Renderers[ 3 ]->SetBackground( 0.2, 0.2, 0.2 );
47 }
48
49 // -------------------------------------------------------------------------
50 void cpExtensions::Visualization::MPRObjects::
51 SetImage( vtkImageData* image )
52 {
53   this->m_MPRActors->AddInputData( image );
54   this->m_MPRActors->PushDataInto(
55     this->m_Renderers[ 0 ],
56     this->m_Renderers[ 1 ],
57     this->m_Renderers[ 2 ],
58     this->m_Renderers[ 3 ]
59     );
60
61   // First rendering
62   this->m_MPRActors->ResetSlices( );
63   this->ResetCameras( );
64   this->RenderAll( );
65 }
66
67 // -------------------------------------------------------------------------
68 void cpExtensions::Visualization::MPRObjects::
69 AddAuxiliaryImage( vtkImageData* image )
70 {
71   // Try to add new image
72   int id = this->m_MPRActors->AddInputData( image );
73   if( id < 0 )
74     return;
75
76   // Push everything on renderers
77   this->m_MPRActors->PushDataInto(
78     this->m_Renderers[ 0 ],
79     this->m_Renderers[ 1 ],
80     this->m_Renderers[ 2 ],
81     this->m_Renderers[ 3 ]
82     );
83
84   // Rendering
85   this->RenderAll( );
86 }
87
88 // -------------------------------------------------------------------------
89 void cpExtensions::Visualization::MPRObjects::
90 ActivateInteractors( )
91 {
92   // Prepare renderers
93   for( int i = 0; i < 3; ++i )
94   {
95     // Check prerrequisites
96     if( this->m_Windows[ i ] == NULL || this->m_Renderers[ i ] == NULL )
97     {
98       this->m_Styles[ i ] = NULL;
99       continue;
100
101     } // fi
102
103     ImageSliceActors* actors = this->m_MPRActors->GetSliceActors( i );
104     if( actors == NULL )
105     {
106       this->m_Styles[ i ] = NULL;
107       continue;
108
109     } // fi
110
111     this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( );
112     this->m_Styles[ i ]->Configure( actors, this->m_MPRActors );
113     this->m_Styles[ i ]->
114       SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i );
115     this->m_Styles[ i ]->SetModeToNavigation( );
116
117   } // rof
118
119   // Synch 2D and 3D renderers
120   for( int i = 0; i < 3; ++i )
121   {
122     for( int j = 0; j < 3; ++j )
123     {
124       if(
125         this->m_Windows[ i ] != NULL &&
126         this->m_Windows[ j ] != NULL &&
127         i != j
128         )
129         this->m_Styles[ i ]->
130           AssociateInteractor( this->m_Windows[ j ]->GetInteractor( ) );
131
132     } // rof
133     if( this->m_Windows[ 3 ] != NULL )
134       this->m_Styles[ i ]->
135         AssociateInteractor( this->m_Windows[ 3 ]->GetInteractor( ) );
136
137   } // rof
138
139   // Finish interactor linking
140   this->m_MPRActors->LinkInteractors( );
141
142   // Restart rendering
143   this->ResetCameras( );
144   this->RenderAll( );
145 }
146
147 // -------------------------------------------------------------------------
148 void cpExtensions::Visualization::MPRObjects::
149 ResetCamera( const int& id )
150 {
151   if( id < 4 )
152     if( this->m_Windows[ id ] != NULL )
153       this->m_Renderers[ id ]->ResetCamera( );
154 }
155
156 // -------------------------------------------------------------------------
157 void cpExtensions::Visualization::MPRObjects::
158 ResetCameras( )
159 {
160   for( int i = 0; i < 4; ++i )
161     if( this->m_Windows[ i ] != NULL )
162       this->m_Renderers[ i ]->ResetCamera( );
163 }
164
165 // -------------------------------------------------------------------------
166 void cpExtensions::Visualization::MPRObjects::
167 Render( const int& id )
168 {
169   if( id < 4 )
170     if( this->m_Windows[ id ] != NULL )
171       this->m_Windows[ id ]->Render( );
172 }
173
174 // -------------------------------------------------------------------------
175 void cpExtensions::Visualization::MPRObjects::
176 RenderAll( )
177 {
178   for( int i = 0; i < 4; ++i )
179     if( this->m_Windows[ i ] != NULL )
180       this->m_Windows[ i ]->Render( );
181 }
182
183 // -------------------------------------------------------------------------
184 vtkRenderer* cpExtensions::Visualization::MPRObjects::
185 GetXRenderer( )
186 {
187   return( this->m_Renderers[ 0 ] );
188 }
189
190 // -------------------------------------------------------------------------
191 vtkRenderer* cpExtensions::Visualization::MPRObjects::
192 GetYRenderer( )
193 {
194   return( this->m_Renderers[ 1 ] );
195 }
196
197 // -------------------------------------------------------------------------
198 vtkRenderer* cpExtensions::Visualization::MPRObjects::
199 GetZRenderer( )
200 {
201   return( this->m_Renderers[ 2 ] );
202 }
203
204 // -------------------------------------------------------------------------
205 vtkRenderer* cpExtensions::Visualization::MPRObjects::
206 Get3DRenderer( )
207 {
208   return( this->m_Renderers[ 3 ] );
209 }
210
211 // -------------------------------------------------------------------------
212 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
213 GetXRenderer( ) const
214 {
215   return( this->m_Renderers[ 0 ] );
216 }
217
218 // -------------------------------------------------------------------------
219 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
220 GetYRenderer( ) const
221 {
222   return( this->m_Renderers[ 1 ] );
223 }
224
225 // -------------------------------------------------------------------------
226 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
227 GetZRenderer( ) const
228 {
229   return( this->m_Renderers[ 2 ] );
230 }
231
232 // -------------------------------------------------------------------------
233 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
234 Get3DRenderer( ) const
235 {
236   return( this->m_Renderers[ 3 ] );
237 }
238
239 // -------------------------------------------------------------------------
240 cpExtensions::Visualization::MPRObjects::
241 TMPRActors* cpExtensions::Visualization::MPRObjects::
242 GetMPRActors( )
243 {
244   return( this->m_MPRActors );
245 }
246
247 // -------------------------------------------------------------------------
248 const cpExtensions::Visualization::MPRObjects::
249 TMPRActors* cpExtensions::Visualization::MPRObjects::
250 GetMPRActors( ) const
251 {
252   return( this->m_MPRActors );
253 }
254
255 // -------------------------------------------------------------------------
256 cpExtensions::Visualization::MPRObjects::
257 MPRObjects( )
258   : vtkObject( )
259 {
260   // Prepare actors
261   this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( );
262 }
263
264 // -------------------------------------------------------------------------
265 cpExtensions::Visualization::MPRObjects::
266 ~MPRObjects( )
267 {
268 }
269
270 // eof - $RCSfile$