]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_MeshAct.cxx
Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/visu.git] / src / OBJECT / VISU_MeshAct.cxx
1 // Copyright (C) 2007-2011  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
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_MeshAct.cxx
25 //  Author : 
26 //  Module : VISU
27 //  $Header$
28 //
29 #include "VISU_MeshAct.h"
30
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33
34 #include <vtkObjectFactory.h>
35 #include <vtkRenderer.h>
36 #include <vtkTexture.h>
37
38 #include <vtkFeatureEdges.h>
39 #include <vtkDataSetMapper.h>
40 #include <vtkDataSet.h>
41 #include <vtkMatrix4x4.h>
42 #include <vtkMapperCollection.h>
43
44
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_MeshAct);
47
48
49 //----------------------------------------------------------------------------
50 VISU_MeshAct
51 ::VISU_MeshAct()
52 {
53   vtkMatrix4x4 *m;
54   m = vtkMatrix4x4::New();
55
56   mySurfaceActor = SVTK_DeviceActor::New();
57   mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
58   mySurfaceActor->SetUserMatrix(m);
59
60   myEdgeActor = SVTK_DeviceActor::New();
61   myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
62   myEdgeActor->SetUserMatrix(m);
63
64   myNodeActor = SVTK_DeviceActor::New();
65   myNodeActor->SetRepresentation(SVTK::Representation::Points);
66   myNodeActor->SetUserMatrix(m);
67
68   m->Delete();
69   SetRepresentation(SVTK::Representation::Surface);
70
71   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
72   //Quadratic 2D elements representation
73   if(aResourceMgr) {
74     //----------------------------------------------------------------------------
75     int aQuadraticAngle = aResourceMgr->integerValue( "VISU", "max_angle", 2);
76     mySurfaceActor->SetQuadraticArcAngle(aQuadraticAngle);
77     myEdgeActor->SetQuadraticArcAngle(aQuadraticAngle);
78
79     int anElem0DSize = aResourceMgr->integerValue( "VISU", "elem0d_size", 5);
80     GetSurfaceProperty()->SetPointSize(anElem0DSize);
81   }  
82 }
83
84 VISU_MeshAct
85 ::~VISU_MeshAct()
86 {
87   mySurfaceActor->Delete();
88   myEdgeActor->Delete();
89   myNodeActor->Delete();
90 }
91
92
93 //----------------------------------------------------------------------------
94 void
95 VISU_MeshAct
96 ::DeepCopy(VISU_Actor *theActor)
97 {
98   if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
99     Superclass::DeepCopy(theActor);
100     GetSurfaceProperty()->DeepCopy(anActor->GetSurfaceProperty());
101     GetEdgeProperty()->DeepCopy(anActor->GetEdgeProperty());
102     GetNodeProperty()->DeepCopy(anActor->GetNodeProperty());
103   }
104 }
105
106
107 //----------------------------------------------------------------------------
108 void
109 VISU_MeshAct
110 ::SetMapperInput(vtkDataSet* theDataSet)
111 {
112   Superclass::SetMapperInput(theDataSet);
113
114   mySurfaceActor->SetInput(theDataSet);
115   myEdgeActor->SetInput(theDataSet);
116   myNodeActor->SetInput(theDataSet);
117 }
118
119
120 //----------------------------------------------------------------------------
121 void
122 VISU_MeshAct
123 ::SetTransform(VTKViewer_Transform* theTransform)
124 {
125   Superclass::SetTransform(theTransform);
126
127   mySurfaceActor->SetTransform(theTransform);
128   myEdgeActor->SetTransform(theTransform);
129   myNodeActor->SetTransform(theTransform);
130 }
131
132
133 //----------------------------------------------------------------------------
134 void
135 VISU_MeshAct
136 ::SetShrinkable(bool theIsShrinkable)
137 {
138   Superclass::SetShrinkable(theIsShrinkable);
139
140   mySurfaceActor->SetShrinkable(theIsShrinkable);
141   myEdgeActor->SetShrinkable(theIsShrinkable);
142 }
143
144 void
145 VISU_MeshAct
146 ::SetShrinkFactor(vtkFloatingPointType theValue)
147 {
148   Superclass::SetShrinkFactor(theValue);
149
150   mySurfaceActor->SetShrinkFactor(theValue);
151   myEdgeActor->SetShrinkFactor(theValue);
152 }
153
154
155 //----------------------------------------------------------------------------
156 vtkProperty* 
157 VISU_MeshAct
158 ::GetSurfaceProperty()
159 {
160   return mySurfaceActor->GetProperty();
161 }
162
163 vtkProperty* 
164 VISU_MeshAct
165 ::GetEdgeProperty()
166 {
167   return myEdgeActor->GetProperty();
168 }
169
170 vtkProperty* 
171 VISU_MeshAct
172 ::GetNodeProperty()
173 {
174   return myNodeActor->GetProperty();
175 }
176
177 //----------------------------------------------------------------------------
178 void
179 VISU_MeshAct
180 ::SetOpacity(vtkFloatingPointType theValue)
181 {
182   GetSurfaceProperty()->SetOpacity(theValue);
183 }
184
185 vtkFloatingPointType
186 VISU_MeshAct
187 ::GetOpacity()
188 {
189   return GetSurfaceProperty()->GetOpacity();
190 }
191
192 //----------------------------------------------------------------------------
193 void
194 VISU_MeshAct
195 ::SetLineWidth(vtkFloatingPointType theLineWidth)
196 {
197   GetEdgeProperty()->SetLineWidth(theLineWidth);
198 }
199
200 vtkFloatingPointType
201 VISU_MeshAct::GetLineWidth()
202 {
203   return GetEdgeProperty()->GetLineWidth();
204 }
205
206 //----------------------------------------------------------------------------
207 void
208 VISU_MeshAct
209 ::SetShrink()
210 {
211   if(myRepresentation == VTK_POINTS)
212     return;
213
214   Superclass::SetShrink();
215
216   mySurfaceActor->SetShrink();
217   myEdgeActor->SetShrink();
218 }
219
220 void
221 VISU_MeshAct
222 ::UnShrink()
223 {
224   Superclass::UnShrink();
225
226   mySurfaceActor->UnShrink();
227   myEdgeActor->UnShrink();
228 }
229
230 //----------------------------------------------------------------------------
231 void
232 VISU_MeshAct
233 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
234 {
235   Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
236
237   mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
238 }
239
240 void
241 VISU_MeshAct
242 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
243 {
244   Superclass::SetFeatureEdgesAngle(theValue);
245
246   mySurfaceActor->SetFeatureEdgesAngle(theValue);
247 }
248
249 void
250 VISU_MeshAct
251 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
252                        bool theIsBoundaryEdges,
253                        bool theIsManifoldEdges,
254                        bool theIsNonManifoldEdges)
255 {
256   Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
257                                    theIsBoundaryEdges,
258                                    theIsManifoldEdges,
259                                    theIsNonManifoldEdges);
260
261   mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
262                                        theIsBoundaryEdges,
263                                        theIsManifoldEdges,
264                                        theIsNonManifoldEdges);
265 }
266
267 void
268 VISU_MeshAct
269 ::SetFeatureEdgesColoring(bool theIsColoring)
270 {
271   Superclass::SetFeatureEdgesColoring(theIsColoring);
272
273   mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
274 }
275
276 //----------------------------------------------------------------------------
277 void
278 VISU_MeshAct
279 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
280 {
281   if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
282     return;
283
284   Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
285
286   mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
287 }
288
289 //----------------------------------------------------------------------------
290 void 
291 VISU_MeshAct
292 ::SetRepresentation(int theMode)
293 {
294   Superclass::SetRepresentation(theMode);
295
296   if(theMode == SVTK::Representation::Insideframe)
297     myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
298   else
299     myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
300 }
301
302 //----------------------------------------------------------------------------
303 unsigned long int
304 VISU_MeshAct
305 ::GetMemorySize()
306 {
307   vtkDataSet* aDataSet;
308   unsigned long int aSize = Superclass::GetMemorySize();
309   {
310     aDataSet = mySurfaceActor->GetInput();
311     aSize += aDataSet->GetActualMemorySize() * 1024;
312
313     aDataSet = mySurfaceActor->GetMapper()->GetInput();
314     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
315   }
316   {
317     aDataSet = myEdgeActor->GetInput();
318     aSize += aDataSet->GetActualMemorySize() * 1024;
319
320     aDataSet = myEdgeActor->GetMapper()->GetInput();
321     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
322   }
323   {
324     aDataSet = myNodeActor->GetInput();
325     aSize += aDataSet->GetActualMemorySize() * 1024;
326
327     aDataSet = myNodeActor->GetMapper()->GetInput();
328     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
329   }
330   return aSize;
331 }
332
333 //----------------------------------------------------------------------------
334 int
335 VISU_MeshAct
336 ::RenderOpaqueGeometry(vtkViewport *ren)
337 {
338   GetMatrix(myNodeActor->GetUserMatrix());
339   GetMatrix(myEdgeActor->GetUserMatrix());
340   GetMatrix(mySurfaceActor->GetUserMatrix());
341
342   using namespace SVTK::Representation;
343   switch(GetRepresentation()){
344   case Points : 
345     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
346     myNodeActor->RenderOpaqueGeometry(ren);
347     break;
348   case Wireframe : 
349   case Insideframe : 
350     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
351     myEdgeActor->RenderOpaqueGeometry(ren);
352     break;
353   case Surface : 
354   case FeatureEdges :
355     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
356     mySurfaceActor->RenderOpaqueGeometry(ren);
357     break;
358   case Surfaceframe : 
359     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
360     mySurfaceActor->RenderOpaqueGeometry(ren);
361
362     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
363     myEdgeActor->RenderOpaqueGeometry(ren);
364     break;
365   }
366   return 1;
367 }
368
369 int
370 VISU_MeshAct
371 #if (VTK_XVERSION < 0x050100)
372 ::RenderTranslucentGeometry(vtkViewport *ren)
373 #else
374 ::RenderTranslucentPolygonalGeometry(vtkViewport *ren)
375 #endif
376 {
377   GetMatrix(myNodeActor->GetUserMatrix());
378   GetMatrix(myEdgeActor->GetUserMatrix());
379   GetMatrix(mySurfaceActor->GetUserMatrix());
380
381   using namespace SVTK::Representation;
382   switch(GetRepresentation()){
383   case Points : 
384     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
385 #if (VTK_XVERSION < 0x050100)
386     myNodeActor->RenderTranslucentGeometry(ren);
387 #else
388     myNodeActor->RenderTranslucentPolygonalGeometry(ren);
389 #endif
390     break;
391   case Wireframe : 
392   case Insideframe : 
393     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
394 #if (VTK_XVERSION < 0x050100)
395     myEdgeActor->RenderTranslucentGeometry(ren);
396 #else
397     myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
398 #endif
399     break;
400   case Surface : 
401   case FeatureEdges :
402     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
403 #if (VTK_XVERSION < 0x050100)
404     mySurfaceActor->RenderTranslucentGeometry(ren);
405 #else
406     mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
407 #endif
408     break;
409   case Surfaceframe : 
410     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
411 #if (VTK_XVERSION < 0x050100)
412     mySurfaceActor->RenderTranslucentGeometry(ren);
413 #else
414     mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
415 #endif
416
417     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
418 #if (VTK_XVERSION < 0x050100)
419     myEdgeActor->RenderTranslucentGeometry(ren);
420 #else
421     myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
422 #endif
423     break;
424   }
425   return 1;
426 }
427
428 #if (VTK_XVERSION >= 0x050100)
429 int
430 VISU_MeshAct
431 ::HasTranslucentPolygonalGeometry()
432 {
433   int result = 0; 
434
435   using namespace SVTK::Representation;
436   switch ( GetRepresentation() ) {
437   case Points:
438     result |= myNodeActor->HasTranslucentPolygonalGeometry();
439     break;
440   case Wireframe: 
441   case Insideframe: 
442     result |= myEdgeActor->HasTranslucentPolygonalGeometry();
443     break;
444   case Surface:
445   case FeatureEdges:
446     result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
447     break;
448   case Surfaceframe:
449     result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
450     result |= myEdgeActor->HasTranslucentPolygonalGeometry();
451     break;
452   default:
453     break;
454   }
455
456   return result;
457 }
458 #endif
459
460 VISU_Actor::EQuadratic2DRepresentation 
461 VISU_MeshAct::GetQuadratic2DRepresentation() const
462 {
463   bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
464   if(mode){
465     return VISU_Actor::eArcs;
466   }
467   else
468     return VISU_Actor::eLines;
469 }
470
471 void VISU_MeshAct::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
472 {
473   Superclass::SetQuadratic2DRepresentation( theMode );
474   switch(theMode) {
475   case VISU_Actor::eArcs:
476     mySurfaceActor->SetQuadraticArcMode(true);
477     myEdgeActor->SetQuadraticArcMode(true);
478     break;
479   case VISU_Actor::eLines:
480     mySurfaceActor->SetQuadraticArcMode(false);
481     myEdgeActor->SetQuadraticArcMode(false);
482     break;
483   default:
484     break;
485   }    
486 }
487
488 void VISU_MeshAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
489 {
490   Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
491   myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
492 }
493
494 void VISU_MeshAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
495 {
496   Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
497   myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
498 }