]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRObjects.cxx
0e522491b933349501a6286a1fd75682f8799e45
[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->PushActorsInto(
55     this->m_Windows[ 0 ],
56     this->m_Windows[ 1 ],
57     this->m_Windows[ 2 ],
58     this->m_Windows[ 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->PushActorsInto(
78     this->m_Windows[ 0 ],
79     this->m_Windows[ 1 ],
80     this->m_Windows[ 2 ],
81     this->m_Windows[ 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       // TODO: 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       // TODO: this->m_Styles[ i ] = NULL;
107       continue;
108
109     } // fi
110
111     /* TODO
112        this->m_Styles[ i ] = vtkSmartPointer< TStyle >::New( );
113        this->m_Styles[ i ]->Configure( actors, this->m_MPRActors );
114        this->m_Styles[ i ]->
115        SetInteractor( this->m_Windows[ i ]->GetInteractor( ), i );
116        this->m_Styles[ i ]->SetModeToNavigation( );
117     */
118
119   } // rof
120
121   // Synch 2D and 3D renderers
122   for( int i = 0; i < 3; ++i )
123   {
124     for( int j = 0; j < 3; ++j )
125     {
126       /* TODO
127          if(
128          this->m_Windows[ i ] != NULL &&
129          this->m_Windows[ j ] != NULL &&
130          i != j
131          )
132          this->m_Styles[ i ]->
133          AssociateInteractor( this->m_Windows[ j ]->GetInteractor( ) );
134       */
135
136     } // rof
137     /* TODO
138        if( this->m_Windows[ 3 ] != NULL )
139        this->m_Styles[ i ]->
140        AssociateInteractor( this->m_Windows[ 3 ]->GetInteractor( ) );
141     */
142
143   } // rof
144
145   // Finish interactor linking
146   // TODO: this->m_MPRActors->LinkInteractors( );
147
148   // Restart rendering
149   this->ResetCameras( );
150   this->RenderAll( );
151 }
152
153 // -------------------------------------------------------------------------
154 void cpExtensions::Visualization::MPRObjects::
155 ResetCamera( const int& id )
156 {
157   if( id < 4 )
158     if( this->m_Windows[ id ] != NULL )
159       this->m_Renderers[ id ]->ResetCamera( );
160 }
161
162 // -------------------------------------------------------------------------
163 void cpExtensions::Visualization::MPRObjects::
164 ResetCameras( )
165 {
166   for( int i = 0; i < 4; ++i )
167     if( this->m_Windows[ i ] != NULL )
168       this->m_Renderers[ i ]->ResetCamera( );
169 }
170
171 // -------------------------------------------------------------------------
172 void cpExtensions::Visualization::MPRObjects::
173 Render( const int& id )
174 {
175   if( id < 4 )
176     if( this->m_Windows[ id ] != NULL )
177       this->m_Windows[ id ]->Render( );
178 }
179
180 // -------------------------------------------------------------------------
181 void cpExtensions::Visualization::MPRObjects::
182 RenderAll( )
183 {
184   for( int i = 0; i < 4; ++i )
185     if( this->m_Windows[ i ] != NULL )
186       this->m_Windows[ i ]->Render( );
187 }
188
189 // -------------------------------------------------------------------------
190 vtkRenderer* cpExtensions::Visualization::MPRObjects::
191 GetXRenderer( )
192 {
193   return( this->m_Renderers[ 0 ] );
194 }
195
196 // -------------------------------------------------------------------------
197 vtkRenderer* cpExtensions::Visualization::MPRObjects::
198 GetYRenderer( )
199 {
200   return( this->m_Renderers[ 1 ] );
201 }
202
203 // -------------------------------------------------------------------------
204 vtkRenderer* cpExtensions::Visualization::MPRObjects::
205 GetZRenderer( )
206 {
207   return( this->m_Renderers[ 2 ] );
208 }
209
210 // -------------------------------------------------------------------------
211 vtkRenderer* cpExtensions::Visualization::MPRObjects::
212 Get3DRenderer( )
213 {
214   return( this->m_Renderers[ 3 ] );
215 }
216
217 // -------------------------------------------------------------------------
218 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
219 GetXRenderer( ) const
220 {
221   return( this->m_Renderers[ 0 ] );
222 }
223
224 // -------------------------------------------------------------------------
225 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
226 GetYRenderer( ) const
227 {
228   return( this->m_Renderers[ 1 ] );
229 }
230
231 // -------------------------------------------------------------------------
232 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
233 GetZRenderer( ) const
234 {
235   return( this->m_Renderers[ 2 ] );
236 }
237
238 // -------------------------------------------------------------------------
239 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
240 Get3DRenderer( ) const
241 {
242   return( this->m_Renderers[ 3 ] );
243 }
244
245 // -------------------------------------------------------------------------
246 cpExtensions::Visualization::MPRObjects::
247 TMPRActors* cpExtensions::Visualization::MPRObjects::
248 GetMPRActors( )
249 {
250   return( this->m_MPRActors );
251 }
252
253 // -------------------------------------------------------------------------
254 const cpExtensions::Visualization::MPRObjects::
255 TMPRActors* cpExtensions::Visualization::MPRObjects::
256 GetMPRActors( ) const
257 {
258   return( this->m_MPRActors );
259 }
260
261 // -------------------------------------------------------------------------
262 cpExtensions::Visualization::MPRObjects::
263 MPRObjects( )
264   : vtkObject( )
265 {
266   // Prepare actors
267   this->m_MPRActors = vtkSmartPointer< TMPRActors >::New( );
268 }
269
270 // -------------------------------------------------------------------------
271 cpExtensions::Visualization::MPRObjects::
272 ~MPRObjects( )
273 {
274 }
275
276 // eof - $RCSfile$