1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_MeshAct.cxx
28 #include "VISU_MeshAct.h"
30 #include <vtkObjectFactory.h>
31 #include <vtkRenderer.h>
32 #include <vtkTexture.h>
34 #include <vtkFeatureEdges.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkDataSet.h>
37 #include <vtkMatrix4x4.h>
38 #include <vtkMapperCollection.h>
41 //----------------------------------------------------------------------------
42 vtkStandardNewMacro(VISU_MeshAct);
45 //----------------------------------------------------------------------------
50 m = vtkMatrix4x4::New();
52 mySurfaceActor = SVTK_DeviceActor::New();
53 mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
54 mySurfaceActor->SetUserMatrix(m);
56 myEdgeActor = SVTK_DeviceActor::New();
57 myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
58 myEdgeActor->SetUserMatrix(m);
60 myNodeActor = SVTK_DeviceActor::New();
61 myNodeActor->SetRepresentation(SVTK::Representation::Points);
62 myNodeActor->SetUserMatrix(m);
65 SetRepresentation(SVTK::Representation::Surface);
71 mySurfaceActor->Delete();
72 myEdgeActor->Delete();
73 myNodeActor->Delete();
77 //----------------------------------------------------------------------------
80 ::DeepCopy(VISU_Actor *theActor)
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());
91 //----------------------------------------------------------------------------
94 ::SetMapperInput(vtkDataSet* theDataSet)
96 Superclass::SetMapperInput(theDataSet);
98 mySurfaceActor->SetInput(theDataSet);
99 myEdgeActor->SetInput(theDataSet);
100 myNodeActor->SetInput(theDataSet);
104 //----------------------------------------------------------------------------
107 ::SetTransform(VTKViewer_Transform* theTransform)
109 Superclass::SetTransform(theTransform);
111 mySurfaceActor->SetTransform(theTransform);
112 myEdgeActor->SetTransform(theTransform);
113 myNodeActor->SetTransform(theTransform);
117 //----------------------------------------------------------------------------
120 ::SetShrinkable(bool theIsShrinkable)
122 Superclass::SetShrinkable(theIsShrinkable);
124 mySurfaceActor->SetShrinkable(theIsShrinkable);
125 myEdgeActor->SetShrinkable(theIsShrinkable);
130 ::SetShrinkFactor(vtkFloatingPointType theValue)
132 Superclass::SetShrinkFactor(theValue);
134 mySurfaceActor->SetShrinkFactor(theValue);
135 myEdgeActor->SetShrinkFactor(theValue);
139 //----------------------------------------------------------------------------
142 ::GetSurfaceProperty()
144 return mySurfaceActor->GetProperty();
151 return myEdgeActor->GetProperty();
158 return myNodeActor->GetProperty();
161 //----------------------------------------------------------------------------
164 ::SetOpacity(vtkFloatingPointType theValue)
166 GetSurfaceProperty()->SetOpacity(theValue);
173 return GetSurfaceProperty()->GetOpacity();
176 //----------------------------------------------------------------------------
179 ::SetLineWidth(vtkFloatingPointType theLineWidth)
181 GetEdgeProperty()->SetLineWidth(theLineWidth);
185 VISU_MeshAct::GetLineWidth()
187 return GetEdgeProperty()->GetLineWidth();
190 //----------------------------------------------------------------------------
195 if(myRepresentation == VTK_POINTS)
198 Superclass::SetShrink();
200 mySurfaceActor->SetShrink();
201 myEdgeActor->SetShrink();
208 Superclass::UnShrink();
210 mySurfaceActor->UnShrink();
211 myEdgeActor->UnShrink();
214 //----------------------------------------------------------------------------
217 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
219 Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
221 mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
226 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
228 Superclass::SetFeatureEdgesAngle(theValue);
230 mySurfaceActor->SetFeatureEdgesAngle(theValue);
235 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
236 bool theIsBoundaryEdges,
237 bool theIsManifoldEdges,
238 bool theIsNonManifoldEdges)
240 Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
243 theIsNonManifoldEdges);
245 mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
248 theIsNonManifoldEdges);
253 ::SetFeatureEdgesColoring(bool theIsColoring)
255 Superclass::SetFeatureEdgesColoring(theIsColoring);
257 mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
260 //----------------------------------------------------------------------------
263 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
265 if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
268 Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
270 mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
273 //----------------------------------------------------------------------------
276 ::SetRepresentation(int theMode)
278 Superclass::SetRepresentation(theMode);
280 if(theMode == SVTK::Representation::Insideframe)
281 myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
283 myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
286 //----------------------------------------------------------------------------
291 vtkDataSet* aDataSet;
292 unsigned long int aSize = Superclass::GetMemorySize();
294 aDataSet = mySurfaceActor->GetInput();
295 aSize += aDataSet->GetActualMemorySize() * 1024;
297 aDataSet = mySurfaceActor->GetMapper()->GetInput();
298 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
301 aDataSet = myEdgeActor->GetInput();
302 aSize += aDataSet->GetActualMemorySize() * 1024;
304 aDataSet = myEdgeActor->GetMapper()->GetInput();
305 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
308 aDataSet = myNodeActor->GetInput();
309 aSize += aDataSet->GetActualMemorySize() * 1024;
311 aDataSet = myNodeActor->GetMapper()->GetInput();
312 aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
317 //----------------------------------------------------------------------------
320 ::RenderOpaqueGeometry(vtkViewport *ren)
322 GetMatrix(myNodeActor->GetUserMatrix());
323 GetMatrix(myEdgeActor->GetUserMatrix());
324 GetMatrix(mySurfaceActor->GetUserMatrix());
326 using namespace SVTK::Representation;
327 switch(GetRepresentation()){
329 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
330 myNodeActor->RenderOpaqueGeometry(ren);
334 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
335 myEdgeActor->RenderOpaqueGeometry(ren);
338 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
339 mySurfaceActor->RenderOpaqueGeometry(ren);
342 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
343 mySurfaceActor->RenderOpaqueGeometry(ren);
345 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
346 myEdgeActor->RenderOpaqueGeometry(ren);
349 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
350 mySurfaceActor->RenderOpaqueGeometry(ren);
358 ::RenderTranslucentGeometry(vtkViewport *ren)
360 GetMatrix(myNodeActor->GetUserMatrix());
361 GetMatrix(myEdgeActor->GetUserMatrix());
362 GetMatrix(mySurfaceActor->GetUserMatrix());
364 using namespace SVTK::Representation;
365 switch(GetRepresentation()){
367 myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
368 myNodeActor->RenderTranslucentGeometry(ren);
372 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
373 myEdgeActor->RenderTranslucentGeometry(ren);
376 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
377 mySurfaceActor->RenderTranslucentGeometry(ren);
380 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
381 mySurfaceActor->RenderTranslucentGeometry(ren);
383 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
384 myEdgeActor->RenderTranslucentGeometry(ren);
387 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
388 mySurfaceActor->RenderTranslucentGeometry(ren);