]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/MPRObjects.cxx
Double click widget integrated with segmentation and deformation filters.
[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 AddImage( 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   if( this->m_MPRActors->GetNumberOfImages( ) == 1 )
63   {
64     this->m_MPRActors->ResetSlices( );
65     this->ResetCameras( );
66
67   } // fi
68   this->RenderAll( 1e-3 );
69 }
70
71 // -------------------------------------------------------------------------
72 void cpExtensions::Visualization::MPRObjects::
73 ClearAll( )
74 {
75   this->m_MPRActors->PopActorsFrom(
76     this->m_Windows[ 0 ],
77     this->m_Windows[ 1 ],
78     this->m_Windows[ 2 ],
79     this->m_Windows[ 3 ]
80     );
81   this->ResetCameras( );
82   this->RenderAll( 1e-3 );
83 }
84
85 // -------------------------------------------------------------------------
86 void cpExtensions::Visualization::MPRObjects::
87 ResetCamera( const int& id )
88 {
89   if( id < 4 )
90     if( this->m_Windows[ id ] != NULL )
91       this->m_Renderers[ id ]->ResetCamera( );
92 }
93
94 // -------------------------------------------------------------------------
95 void cpExtensions::Visualization::MPRObjects::
96 ResetCameras( )
97 {
98   for( int i = 0; i < 4; ++i )
99     if( this->m_Windows[ i ] != NULL )
100       this->m_Renderers[ i ]->ResetCamera( );
101 }
102
103 // -------------------------------------------------------------------------
104 void cpExtensions::Visualization::MPRObjects::
105 Render( const int& id, const double& t )
106 {
107   if( id < 4 )
108   {
109     if( this->m_Windows[ id ] != NULL )
110     {
111       if( this->m_Renderers[ id ] != NULL )
112         this->m_Renderers[ id ]->SetAllocatedRenderTime( t );
113       this->m_Windows[ id ]->Render( );
114       
115     } // fi
116
117   } // fi
118 }
119
120 // -------------------------------------------------------------------------
121 void cpExtensions::Visualization::MPRObjects::
122 RenderAll( const double& t )
123 {
124   for( int i = 0; i < 4; ++i )
125   {
126     if( this->m_Windows[ i ] != NULL )
127     {
128       if( this->m_Renderers[ i ] != NULL )
129         this->m_Renderers[ i ]->SetAllocatedRenderTime( t );
130       this->m_Windows[ i ]->Render( );
131
132     } // fi
133
134   } // rof
135 }
136
137 // -------------------------------------------------------------------------
138 vtkRenderer* cpExtensions::Visualization::MPRObjects::
139 GetXRenderer( )
140 {
141   return( this->m_Renderers[ 0 ] );
142 }
143
144 // -------------------------------------------------------------------------
145 vtkRenderer* cpExtensions::Visualization::MPRObjects::
146 GetYRenderer( )
147 {
148   return( this->m_Renderers[ 1 ] );
149 }
150
151 // -------------------------------------------------------------------------
152 vtkRenderer* cpExtensions::Visualization::MPRObjects::
153 GetZRenderer( )
154 {
155   return( this->m_Renderers[ 2 ] );
156 }
157
158 // -------------------------------------------------------------------------
159 vtkRenderer* cpExtensions::Visualization::MPRObjects::
160 Get3DRenderer( )
161 {
162   return( this->m_Renderers[ 3 ] );
163 }
164
165 // -------------------------------------------------------------------------
166 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
167 GetXRenderer( ) const
168 {
169   return( this->m_Renderers[ 0 ] );
170 }
171
172 // -------------------------------------------------------------------------
173 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
174 GetYRenderer( ) const
175 {
176   return( this->m_Renderers[ 1 ] );
177 }
178
179 // -------------------------------------------------------------------------
180 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
181 GetZRenderer( ) const
182 {
183   return( this->m_Renderers[ 2 ] );
184 }
185
186 // -------------------------------------------------------------------------
187 const vtkRenderer* cpExtensions::Visualization::MPRObjects::
188 Get3DRenderer( ) const
189 {
190   return( this->m_Renderers[ 3 ] );
191 }
192
193 // -------------------------------------------------------------------------
194 cpExtensions::Visualization::
195 MPRActors* cpExtensions::Visualization::MPRObjects::
196 GetMPRActors( )
197 {
198   return( this->m_MPRActors );
199 }
200
201 // -------------------------------------------------------------------------
202 const cpExtensions::Visualization::
203 MPRActors* cpExtensions::Visualization::MPRObjects::
204 GetMPRActors( ) const
205 {
206   return( this->m_MPRActors );
207 }
208
209 // -------------------------------------------------------------------------
210 double cpExtensions::Visualization::MPRObjects::
211 GetWindow( ) const
212 {
213   return( this->m_MPRActors->GetWindow( ) );
214 }
215
216 // -------------------------------------------------------------------------
217 double cpExtensions::Visualization::MPRObjects::
218 GetLevel( ) const
219 {
220   return( this->m_MPRActors->GetLevel( ) );
221 }
222
223 // -------------------------------------------------------------------------
224 cpExtensions::Visualization::MPRObjects::
225 MPRObjects( )
226   : vtkObject( )
227 {
228   // Prepare actors
229   this->m_MPRActors = vtkSmartPointer< MPRActors >::New( );
230 }
231
232 // -------------------------------------------------------------------------
233 cpExtensions::Visualization::MPRObjects::
234 ~MPRObjects( )
235 {
236 }
237
238 // eof - $RCSfile$