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