Salome HOME
2c3050dd51f23160010c3669db1371e10dace150
[modules/visu.git] / src / OBJECT / VISU_MeshAct.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_MeshAct.cxx
24 //  Author : 
25 //  Module : VISU
26 //  $Header$
27 //
28 #include "VISU_MeshAct.h"
29
30 #include <vtkObjectFactory.h>
31 #include <vtkRenderer.h>
32 #include <vtkTexture.h>
33
34 #include <vtkFeatureEdges.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkDataSet.h>
37 #include <vtkMatrix4x4.h>
38 #include <vtkMapperCollection.h>
39
40
41 //----------------------------------------------------------------------------
42 vtkStandardNewMacro(VISU_MeshAct);
43
44
45 //----------------------------------------------------------------------------
46 VISU_MeshAct
47 ::VISU_MeshAct()
48 {
49   vtkMatrix4x4 *m;
50   m = vtkMatrix4x4::New();
51
52   mySurfaceActor = SVTK_DeviceActor::New();
53   mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
54   mySurfaceActor->SetUserMatrix(m);
55
56   myEdgeActor = SVTK_DeviceActor::New();
57   myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
58   myEdgeActor->SetUserMatrix(m);
59
60   myNodeActor = SVTK_DeviceActor::New();
61   myNodeActor->SetRepresentation(SVTK::Representation::Points);
62   myNodeActor->SetUserMatrix(m);
63
64   m->Delete();
65   SetRepresentation(SVTK::Representation::Surface);
66 }
67
68 VISU_MeshAct
69 ::~VISU_MeshAct()
70 {
71   mySurfaceActor->Delete();
72   myEdgeActor->Delete();
73   myNodeActor->Delete();
74 }
75
76
77 //----------------------------------------------------------------------------
78 void
79 VISU_MeshAct
80 ::DeepCopy(VISU_Actor *theActor)
81 {
82   if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
83     Superclass::DeepCopy(theActor);
84     GetSurfaceProperty()->DeepCopy(anActor->GetSurfaceProperty());
85     GetEdgeProperty()->DeepCopy(anActor->GetEdgeProperty());
86     GetNodeProperty()->DeepCopy(anActor->GetNodeProperty());
87   }
88 }
89
90
91 //----------------------------------------------------------------------------
92 void
93 VISU_MeshAct
94 ::SetMapperInput(vtkDataSet* theDataSet)
95 {
96   Superclass::SetMapperInput(theDataSet);
97
98   mySurfaceActor->SetInput(theDataSet);
99   myEdgeActor->SetInput(theDataSet);
100   myNodeActor->SetInput(theDataSet);
101 }
102
103
104 //----------------------------------------------------------------------------
105 void
106 VISU_MeshAct
107 ::SetTransform(VTKViewer_Transform* theTransform)
108 {
109   Superclass::SetTransform(theTransform);
110
111   mySurfaceActor->SetTransform(theTransform);
112   myEdgeActor->SetTransform(theTransform);
113   myNodeActor->SetTransform(theTransform);
114 }
115
116
117 //----------------------------------------------------------------------------
118 void
119 VISU_MeshAct
120 ::SetShrinkable(bool theIsShrinkable)
121 {
122   Superclass::SetShrinkable(theIsShrinkable);
123
124   mySurfaceActor->SetShrinkable(theIsShrinkable);
125   myEdgeActor->SetShrinkable(theIsShrinkable);
126 }
127
128 void
129 VISU_MeshAct
130 ::SetShrinkFactor(vtkFloatingPointType theValue)
131 {
132   Superclass::SetShrinkFactor(theValue);
133
134   mySurfaceActor->SetShrinkFactor(theValue);
135   myEdgeActor->SetShrinkFactor(theValue);
136 }
137
138
139 //----------------------------------------------------------------------------
140 vtkProperty* 
141 VISU_MeshAct
142 ::GetSurfaceProperty()
143 {
144   return mySurfaceActor->GetProperty();
145 }
146
147 vtkProperty* 
148 VISU_MeshAct
149 ::GetEdgeProperty()
150 {
151   return myEdgeActor->GetProperty();
152 }
153
154 vtkProperty* 
155 VISU_MeshAct
156 ::GetNodeProperty()
157 {
158   return myNodeActor->GetProperty();
159 }
160
161 //----------------------------------------------------------------------------
162 void
163 VISU_MeshAct
164 ::SetOpacity(vtkFloatingPointType theValue)
165 {
166   GetSurfaceProperty()->SetOpacity(theValue);
167 }
168
169 vtkFloatingPointType
170 VISU_MeshAct
171 ::GetOpacity()
172 {
173   return GetSurfaceProperty()->GetOpacity();
174 }
175
176 //----------------------------------------------------------------------------
177 void
178 VISU_MeshAct
179 ::SetLineWidth(vtkFloatingPointType theLineWidth)
180 {
181   GetEdgeProperty()->SetLineWidth(theLineWidth);
182 }
183
184 vtkFloatingPointType
185 VISU_MeshAct::GetLineWidth()
186 {
187   return GetEdgeProperty()->GetLineWidth();
188 }
189
190 //----------------------------------------------------------------------------
191 void
192 VISU_MeshAct
193 ::SetShrink()
194 {
195   if(myRepresentation == VTK_POINTS)
196     return;
197
198   Superclass::SetShrink();
199
200   mySurfaceActor->SetShrink();
201   myEdgeActor->SetShrink();
202 }
203
204 void
205 VISU_MeshAct
206 ::UnShrink()
207 {
208   Superclass::UnShrink();
209
210   mySurfaceActor->UnShrink();
211   myEdgeActor->UnShrink();
212 }
213
214 //----------------------------------------------------------------------------
215 void
216 VISU_MeshAct
217 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
218 {
219   Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
220
221   mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
222 }
223
224 void
225 VISU_MeshAct
226 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
227 {
228   Superclass::SetFeatureEdgesAngle(theValue);
229
230   mySurfaceActor->SetFeatureEdgesAngle(theValue);
231 }
232
233 void
234 VISU_MeshAct
235 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
236                        bool theIsBoundaryEdges,
237                        bool theIsManifoldEdges,
238                        bool theIsNonManifoldEdges)
239 {
240   Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
241                                    theIsBoundaryEdges,
242                                    theIsManifoldEdges,
243                                    theIsNonManifoldEdges);
244
245   mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
246                                        theIsBoundaryEdges,
247                                        theIsManifoldEdges,
248                                        theIsNonManifoldEdges);
249 }
250
251 void
252 VISU_MeshAct
253 ::SetFeatureEdgesColoring(bool theIsColoring)
254 {
255   Superclass::SetFeatureEdgesColoring(theIsColoring);
256
257   mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
258 }
259
260 //----------------------------------------------------------------------------
261 void
262 VISU_MeshAct
263 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
264 {
265   if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
266     return;
267
268   Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
269
270   mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
271 }
272
273 //----------------------------------------------------------------------------
274 void 
275 VISU_MeshAct
276 ::SetRepresentation(int theMode)
277 {
278   Superclass::SetRepresentation(theMode);
279
280   if(theMode == SVTK::Representation::Insideframe)
281     myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
282   else
283     myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
284 }
285
286 //----------------------------------------------------------------------------
287 unsigned long int
288 VISU_MeshAct
289 ::GetMemorySize()
290 {
291   vtkDataSet* aDataSet;
292   unsigned long int aSize = Superclass::GetMemorySize();
293   {
294     aDataSet = mySurfaceActor->GetInput();
295     aSize += aDataSet->GetActualMemorySize() * 1024;
296
297     aDataSet = mySurfaceActor->GetMapper()->GetInput();
298     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
299   }
300   {
301     aDataSet = myEdgeActor->GetInput();
302     aSize += aDataSet->GetActualMemorySize() * 1024;
303
304     aDataSet = myEdgeActor->GetMapper()->GetInput();
305     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
306   }
307   {
308     aDataSet = myNodeActor->GetInput();
309     aSize += aDataSet->GetActualMemorySize() * 1024;
310
311     aDataSet = myNodeActor->GetMapper()->GetInput();
312     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
313   }
314   return aSize;
315 }
316
317 //----------------------------------------------------------------------------
318 int
319 VISU_MeshAct
320 ::RenderOpaqueGeometry(vtkViewport *ren)
321 {
322   GetMatrix(myNodeActor->GetUserMatrix());
323   GetMatrix(myEdgeActor->GetUserMatrix());
324   GetMatrix(mySurfaceActor->GetUserMatrix());
325
326   using namespace SVTK::Representation;
327   switch(GetRepresentation()){
328   case Points : 
329     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
330     myNodeActor->RenderOpaqueGeometry(ren);
331     break;
332   case Wireframe : 
333   case Insideframe : 
334     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
335     myEdgeActor->RenderOpaqueGeometry(ren);
336     break;
337   case Surface : 
338     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
339     mySurfaceActor->RenderOpaqueGeometry(ren);
340     break;
341   case Surfaceframe : 
342     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
343     mySurfaceActor->RenderOpaqueGeometry(ren);
344
345     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
346     myEdgeActor->RenderOpaqueGeometry(ren);
347     break;
348   case FeatureEdges :
349     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
350     mySurfaceActor->RenderOpaqueGeometry(ren);
351     break;
352   }
353   return 1;
354 }
355
356 int
357 VISU_MeshAct
358 ::RenderTranslucentGeometry(vtkViewport *ren)
359 {
360   GetMatrix(myNodeActor->GetUserMatrix());
361   GetMatrix(myEdgeActor->GetUserMatrix());
362   GetMatrix(mySurfaceActor->GetUserMatrix());
363
364   using namespace SVTK::Representation;
365   switch(GetRepresentation()){
366   case Points : 
367     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
368     myNodeActor->RenderTranslucentGeometry(ren);
369     break;
370   case Wireframe : 
371   case Insideframe : 
372     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
373     myEdgeActor->RenderTranslucentGeometry(ren);
374     break;
375   case Surface : 
376     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
377     mySurfaceActor->RenderTranslucentGeometry(ren);
378     break;
379   case Surfaceframe : 
380     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
381     mySurfaceActor->RenderTranslucentGeometry(ren);
382
383     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
384     myEdgeActor->RenderTranslucentGeometry(ren);
385     break;
386   case FeatureEdges :
387     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
388     mySurfaceActor->RenderTranslucentGeometry(ren);
389     break;
390   }
391   return 1;
392 }