1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_MeshAct.cxx
29 #include "VISU_MeshAct.h"
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkRenderer.h>
36 #include <vtkTexture.h>
38 #include <vtkFeatureEdges.h>
39 #include <vtkDataSetMapper.h>
40 #include <vtkDataSet.h>
41 #include <vtkMatrix4x4.h>
42 #include <vtkMapperCollection.h>
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_MeshAct);
49 //----------------------------------------------------------------------------
54 m = vtkMatrix4x4::New();
56 mySurfaceActor = SVTK_DeviceActor::New();
57 mySurfaceActor->SetRepresentation(VTKViewer::Representation::Surface);
58 mySurfaceActor->SetUserMatrix(m);
59 mySurfaceActor->SetCoincident3DAllowed(true);
61 myEdgeActor = SVTK_DeviceActor::New();
62 myEdgeActor->SetRepresentation(VTKViewer::Representation::Wireframe);
63 myEdgeActor->SetUserMatrix(m);
64 myEdgeActor->SetCoincident3DAllowed(true);
66 myNodeActor = SVTK_DeviceActor::New();
67 myNodeActor->SetRepresentation(VTKViewer::Representation::Points);
68 myNodeActor->SetUserMatrix(m);
71 SetRepresentation(VTKViewer::Representation::Surface);
73 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
74 //Quadratic 2D elements representation
76 //----------------------------------------------------------------------------
77 int aQuadraticAngle = aResourceMgr->integerValue( "VISU", "max_angle", 2);
78 mySurfaceActor->SetQuadraticArcAngle(aQuadraticAngle);
79 myEdgeActor->SetQuadraticArcAngle(aQuadraticAngle);
81 int anElem0DSize = aResourceMgr->integerValue( "VISU", "elem0d_size", 5);
82 GetSurfaceProperty()->SetPointSize(anElem0DSize);
89 mySurfaceActor->Delete();
90 myEdgeActor->Delete();
91 myNodeActor->Delete();
95 //----------------------------------------------------------------------------
98 ::DeepCopy(VISU_Actor *theActor)
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());
109 //----------------------------------------------------------------------------
112 ::SetMapperInput(vtkDataSet* theDataSet)
114 Superclass::SetMapperInput(theDataSet);
116 mySurfaceActor->SetInput(theDataSet);
117 myEdgeActor->SetInput(theDataSet);
118 myNodeActor->SetInput(theDataSet);
122 //----------------------------------------------------------------------------
125 ::SetTransform(VTKViewer_Transform* theTransform)
127 Superclass::SetTransform(theTransform);
129 mySurfaceActor->SetTransform(theTransform);
130 myEdgeActor->SetTransform(theTransform);
131 myNodeActor->SetTransform(theTransform);
135 //----------------------------------------------------------------------------
138 ::SetShrinkable(bool theIsShrinkable)
140 Superclass::SetShrinkable(theIsShrinkable);
142 mySurfaceActor->SetShrinkable(theIsShrinkable);
143 myEdgeActor->SetShrinkable(theIsShrinkable);
148 ::SetShrinkFactor(double theValue)
150 Superclass::SetShrinkFactor(theValue);
152 mySurfaceActor->SetShrinkFactor(theValue);
153 myEdgeActor->SetShrinkFactor(theValue);
157 //----------------------------------------------------------------------------
160 ::GetSurfaceProperty()
162 return mySurfaceActor->GetProperty();
169 return myEdgeActor->GetProperty();
176 return myNodeActor->GetProperty();
179 //----------------------------------------------------------------------------
182 ::SetOpacity(double theValue)
184 GetSurfaceProperty()->SetOpacity(theValue);
191 return GetSurfaceProperty()->GetOpacity();
194 //----------------------------------------------------------------------------
197 ::SetLineWidth(double theLineWidth)
199 GetEdgeProperty()->SetLineWidth(theLineWidth);
203 VISU_MeshAct::GetLineWidth()
205 return GetEdgeProperty()->GetLineWidth();
208 //----------------------------------------------------------------------------
213 if(myRepresentation == VTK_POINTS)
216 Superclass::SetShrink();
218 mySurfaceActor->SetShrink();
219 myEdgeActor->SetShrink();
226 Superclass::UnShrink();
228 mySurfaceActor->UnShrink();
229 myEdgeActor->UnShrink();
232 //----------------------------------------------------------------------------
235 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
237 Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
239 mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
244 ::SetFeatureEdgesAngle(double theValue)
246 Superclass::SetFeatureEdgesAngle(theValue);
248 mySurfaceActor->SetFeatureEdgesAngle(theValue);
253 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
254 bool theIsBoundaryEdges,
255 bool theIsManifoldEdges,
256 bool theIsNonManifoldEdges)
258 Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
261 theIsNonManifoldEdges);
263 mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
266 theIsNonManifoldEdges);
271 ::SetFeatureEdgesColoring(bool theIsColoring)
273 Superclass::SetFeatureEdgesColoring(theIsColoring);
275 mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
278 //----------------------------------------------------------------------------
281 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
283 if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
286 Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
288 mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
291 //----------------------------------------------------------------------------
294 ::SetRepresentation(int theMode)
296 Superclass::SetRepresentation(theMode);
298 if(theMode == VTKViewer::Representation::Insideframe)
299 myEdgeActor->SetRepresentation(VTKViewer::Representation::Insideframe);
301 myEdgeActor->SetRepresentation(VTKViewer::Representation::Wireframe);
304 //----------------------------------------------------------------------------
309 vtkDataSet* aDataSet;
310 unsigned long int aSize = Superclass::GetMemorySize();
312 aDataSet = mySurfaceActor->GetInput();
313 aSize += aDataSet->GetActualMemorySize() * 1024;
315 aDataSet = mySurfaceActor->GetMapper()->GetInput();
316 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
319 aDataSet = myEdgeActor->GetInput();
320 aSize += aDataSet->GetActualMemorySize() * 1024;
322 aDataSet = myEdgeActor->GetMapper()->GetInput();
323 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
326 aDataSet = myNodeActor->GetInput();
327 aSize += aDataSet->GetActualMemorySize() * 1024;
329 aDataSet = myNodeActor->GetMapper()->GetInput();
330 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
335 //----------------------------------------------------------------------------
338 ::RenderOpaqueGeometry(vtkViewport *ren)
340 GetMatrix(myNodeActor->GetUserMatrix());
341 GetMatrix(myEdgeActor->GetUserMatrix());
342 GetMatrix(mySurfaceActor->GetUserMatrix());
344 using namespace VTKViewer::Representation;
345 switch(GetRepresentation()){
347 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
348 myNodeActor->RenderOpaqueGeometry(ren);
352 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
353 myEdgeActor->RenderOpaqueGeometry(ren);
357 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
358 mySurfaceActor->RenderOpaqueGeometry(ren);
361 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
362 mySurfaceActor->RenderOpaqueGeometry(ren);
364 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
365 myEdgeActor->RenderOpaqueGeometry(ren);
373 #if (VTK_XVERSION < 0x050100)
374 ::RenderTranslucentGeometry(vtkViewport *ren)
376 ::RenderTranslucentPolygonalGeometry(vtkViewport *ren)
379 GetMatrix(myNodeActor->GetUserMatrix());
380 GetMatrix(myEdgeActor->GetUserMatrix());
381 GetMatrix(mySurfaceActor->GetUserMatrix());
383 using namespace VTKViewer::Representation;
384 switch(GetRepresentation()){
386 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
387 #if (VTK_XVERSION < 0x050100)
388 myNodeActor->RenderTranslucentGeometry(ren);
390 myNodeActor->RenderTranslucentPolygonalGeometry(ren);
395 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
396 #if (VTK_XVERSION < 0x050100)
397 myEdgeActor->RenderTranslucentGeometry(ren);
399 myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
404 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
405 #if (VTK_XVERSION < 0x050100)
406 mySurfaceActor->RenderTranslucentGeometry(ren);
408 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
412 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
413 #if (VTK_XVERSION < 0x050100)
414 mySurfaceActor->RenderTranslucentGeometry(ren);
416 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
419 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
420 #if (VTK_XVERSION < 0x050100)
421 myEdgeActor->RenderTranslucentGeometry(ren);
423 myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
430 #if (VTK_XVERSION >= 0x050100)
433 ::HasTranslucentPolygonalGeometry()
437 using namespace VTKViewer::Representation;
438 switch ( GetRepresentation() ) {
440 result |= myNodeActor->HasTranslucentPolygonalGeometry();
444 result |= myEdgeActor->HasTranslucentPolygonalGeometry();
448 result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
451 result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
452 result |= myEdgeActor->HasTranslucentPolygonalGeometry();
462 VISU_Actor::EQuadratic2DRepresentation
463 VISU_MeshAct::GetQuadratic2DRepresentation() const
465 bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
467 return VISU_Actor::eArcs;
470 return VISU_Actor::eLines;
473 void VISU_MeshAct::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
475 Superclass::SetQuadratic2DRepresentation( theMode );
477 case VISU_Actor::eArcs:
478 mySurfaceActor->SetQuadraticArcMode(true);
479 myEdgeActor->SetQuadraticArcMode(true);
481 case VISU_Actor::eLines:
482 mySurfaceActor->SetQuadraticArcMode(false);
483 myEdgeActor->SetQuadraticArcMode(false);
490 void VISU_MeshAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
492 Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
493 myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
496 void VISU_MeshAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
498 Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
499 myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );