1 // Copyright (C) 2007-2011 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(SVTK::Representation::Surface);
58 mySurfaceActor->SetUserMatrix(m);
60 myEdgeActor = SVTK_DeviceActor::New();
61 myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
62 myEdgeActor->SetUserMatrix(m);
64 myNodeActor = SVTK_DeviceActor::New();
65 myNodeActor->SetRepresentation(SVTK::Representation::Points);
66 myNodeActor->SetUserMatrix(m);
69 SetRepresentation(SVTK::Representation::Surface);
71 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
72 //Quadratic 2D elements representation
74 //----------------------------------------------------------------------------
75 int aQuadraticAngle = aResourceMgr->integerValue( "VISU", "max_angle", 2);
76 mySurfaceActor->SetQuadraticArcAngle(aQuadraticAngle);
77 myEdgeActor->SetQuadraticArcAngle(aQuadraticAngle);
79 int anElem0DSize = aResourceMgr->integerValue( "VISU", "elem0d_size", 5);
80 GetSurfaceProperty()->SetPointSize(anElem0DSize);
87 mySurfaceActor->Delete();
88 myEdgeActor->Delete();
89 myNodeActor->Delete();
93 //----------------------------------------------------------------------------
96 ::DeepCopy(VISU_Actor *theActor)
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());
107 //----------------------------------------------------------------------------
110 ::SetMapperInput(vtkDataSet* theDataSet)
112 Superclass::SetMapperInput(theDataSet);
114 mySurfaceActor->SetInput(theDataSet);
115 myEdgeActor->SetInput(theDataSet);
116 myNodeActor->SetInput(theDataSet);
120 //----------------------------------------------------------------------------
123 ::SetTransform(VTKViewer_Transform* theTransform)
125 Superclass::SetTransform(theTransform);
127 mySurfaceActor->SetTransform(theTransform);
128 myEdgeActor->SetTransform(theTransform);
129 myNodeActor->SetTransform(theTransform);
133 //----------------------------------------------------------------------------
136 ::SetShrinkable(bool theIsShrinkable)
138 Superclass::SetShrinkable(theIsShrinkable);
140 mySurfaceActor->SetShrinkable(theIsShrinkable);
141 myEdgeActor->SetShrinkable(theIsShrinkable);
146 ::SetShrinkFactor(vtkFloatingPointType theValue)
148 Superclass::SetShrinkFactor(theValue);
150 mySurfaceActor->SetShrinkFactor(theValue);
151 myEdgeActor->SetShrinkFactor(theValue);
155 //----------------------------------------------------------------------------
158 ::GetSurfaceProperty()
160 return mySurfaceActor->GetProperty();
167 return myEdgeActor->GetProperty();
174 return myNodeActor->GetProperty();
177 //----------------------------------------------------------------------------
180 ::SetOpacity(vtkFloatingPointType theValue)
182 GetSurfaceProperty()->SetOpacity(theValue);
189 return GetSurfaceProperty()->GetOpacity();
192 //----------------------------------------------------------------------------
195 ::SetLineWidth(vtkFloatingPointType theLineWidth)
197 GetEdgeProperty()->SetLineWidth(theLineWidth);
201 VISU_MeshAct::GetLineWidth()
203 return GetEdgeProperty()->GetLineWidth();
206 //----------------------------------------------------------------------------
211 if(myRepresentation == VTK_POINTS)
214 Superclass::SetShrink();
216 mySurfaceActor->SetShrink();
217 myEdgeActor->SetShrink();
224 Superclass::UnShrink();
226 mySurfaceActor->UnShrink();
227 myEdgeActor->UnShrink();
230 //----------------------------------------------------------------------------
233 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
235 Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
237 mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
242 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
244 Superclass::SetFeatureEdgesAngle(theValue);
246 mySurfaceActor->SetFeatureEdgesAngle(theValue);
251 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
252 bool theIsBoundaryEdges,
253 bool theIsManifoldEdges,
254 bool theIsNonManifoldEdges)
256 Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
259 theIsNonManifoldEdges);
261 mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
264 theIsNonManifoldEdges);
269 ::SetFeatureEdgesColoring(bool theIsColoring)
271 Superclass::SetFeatureEdgesColoring(theIsColoring);
273 mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
276 //----------------------------------------------------------------------------
279 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
281 if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
284 Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
286 mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
289 //----------------------------------------------------------------------------
292 ::SetRepresentation(int theMode)
294 Superclass::SetRepresentation(theMode);
296 if(theMode == SVTK::Representation::Insideframe)
297 myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
299 myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
302 //----------------------------------------------------------------------------
307 vtkDataSet* aDataSet;
308 unsigned long int aSize = Superclass::GetMemorySize();
310 aDataSet = mySurfaceActor->GetInput();
311 aSize += aDataSet->GetActualMemorySize() * 1024;
313 aDataSet = mySurfaceActor->GetMapper()->GetInput();
314 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
317 aDataSet = myEdgeActor->GetInput();
318 aSize += aDataSet->GetActualMemorySize() * 1024;
320 aDataSet = myEdgeActor->GetMapper()->GetInput();
321 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
324 aDataSet = myNodeActor->GetInput();
325 aSize += aDataSet->GetActualMemorySize() * 1024;
327 aDataSet = myNodeActor->GetMapper()->GetInput();
328 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
333 //----------------------------------------------------------------------------
336 ::RenderOpaqueGeometry(vtkViewport *ren)
338 GetMatrix(myNodeActor->GetUserMatrix());
339 GetMatrix(myEdgeActor->GetUserMatrix());
340 GetMatrix(mySurfaceActor->GetUserMatrix());
342 using namespace SVTK::Representation;
343 switch(GetRepresentation()){
345 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
346 myNodeActor->RenderOpaqueGeometry(ren);
350 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
351 myEdgeActor->RenderOpaqueGeometry(ren);
355 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
356 mySurfaceActor->RenderOpaqueGeometry(ren);
359 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
360 mySurfaceActor->RenderOpaqueGeometry(ren);
362 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
363 myEdgeActor->RenderOpaqueGeometry(ren);
371 #if (VTK_XVERSION < 0x050100)
372 ::RenderTranslucentGeometry(vtkViewport *ren)
374 ::RenderTranslucentPolygonalGeometry(vtkViewport *ren)
377 GetMatrix(myNodeActor->GetUserMatrix());
378 GetMatrix(myEdgeActor->GetUserMatrix());
379 GetMatrix(mySurfaceActor->GetUserMatrix());
381 using namespace SVTK::Representation;
382 switch(GetRepresentation()){
384 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
385 #if (VTK_XVERSION < 0x050100)
386 myNodeActor->RenderTranslucentGeometry(ren);
388 myNodeActor->RenderTranslucentPolygonalGeometry(ren);
393 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
394 #if (VTK_XVERSION < 0x050100)
395 myEdgeActor->RenderTranslucentGeometry(ren);
397 myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
402 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
403 #if (VTK_XVERSION < 0x050100)
404 mySurfaceActor->RenderTranslucentGeometry(ren);
406 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
410 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
411 #if (VTK_XVERSION < 0x050100)
412 mySurfaceActor->RenderTranslucentGeometry(ren);
414 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
417 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
418 #if (VTK_XVERSION < 0x050100)
419 myEdgeActor->RenderTranslucentGeometry(ren);
421 myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
428 #if (VTK_XVERSION >= 0x050100)
431 ::HasTranslucentPolygonalGeometry()
435 using namespace SVTK::Representation;
436 switch ( GetRepresentation() ) {
438 result |= myNodeActor->HasTranslucentPolygonalGeometry();
442 result |= myEdgeActor->HasTranslucentPolygonalGeometry();
446 result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
449 result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
450 result |= myEdgeActor->HasTranslucentPolygonalGeometry();
460 VISU_Actor::EQuadratic2DRepresentation
461 VISU_MeshAct::GetQuadratic2DRepresentation() const
463 bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
465 return VISU_Actor::eArcs;
468 return VISU_Actor::eLines;
471 void VISU_MeshAct::SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode )
473 Superclass::SetQuadratic2DRepresentation( theMode );
475 case VISU_Actor::eArcs:
476 mySurfaceActor->SetQuadraticArcMode(true);
477 myEdgeActor->SetQuadraticArcMode(true);
479 case VISU_Actor::eLines:
480 mySurfaceActor->SetQuadraticArcMode(false);
481 myEdgeActor->SetQuadraticArcMode(false);
488 void VISU_MeshAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
490 Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
491 myNodeActor->SetMarkerStd( theMarkerType, theMarkerScale );
494 void VISU_MeshAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
496 Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
497 myNodeActor->SetMarkerTexture( theMarkerId, theMarkerTexture );