1 // Copyright (C) 2007-2010 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.hxx
25 // Author : Laurent CORNABE with the help of Nicolas REJNERI
29 #include "VISU_ScalarMapAct.h"
30 #include "VISU_LookupTable.hxx"
31 #include "VISU_ScalarBarActor.hxx"
32 #include "VISU_PipeLine.hxx"
34 #include "VISU_OpenGLPointSpriteMapper.hxx"
35 #include "VISU_GaussPtsDeviceActor.h"
36 #include "VISU_DeformedShapePL.hxx"
37 #include "VISU_PipeLineUtils.hxx"
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Session.h>
43 #include <SALOME_ExtractGeometry.h>
44 #include <SALOME_ExtractPolyDataGeometry.h>
46 #include <vtkObjectFactory.h>
47 #include <vtkRenderer.h>
48 #include <vtkProperty.h>
49 #include <vtkMatrix4x4.h>
50 #include <vtkMapper.h>
51 #include <vtkDataSetMapper.h>
53 #include <vtkRenderWindowInteractor.h>
54 #include <vtkCallbackCommand.h>
55 #include <vtkRenderWindow.h>
56 #include <vtkImageData.h>
59 //----------------------------------------------------------------------------
60 vtkStandardNewMacro(VISU_ScalarMapAct);
61 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
63 //----------------------------------------------------------------------------
67 myScalarBar = VISU_ScalarBarActor::New();
69 vtkProperty* aProperty = GetProperty();
70 aProperty->SetAmbient(1.0);
71 aProperty->SetDiffuse(0.0);
72 aProperty->SetSpecular(0.0);
74 myProperty->DeepCopy(aProperty);
76 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
78 mySurfaceActor= SVTK_DeviceActor::New();
79 mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
80 mySurfaceActor->SetProperty(aProperty);
81 mySurfaceActor->SetUserMatrix(aMatrix);
83 myEdgeActor = SVTK_DeviceActor::New();
84 myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
85 myEdgeActor->SetUserMatrix(aMatrix);
86 myEdgeActor->GetProperty()->SetColor(255.,255.,255.);
88 myPointsActor = SVTK_DeviceActor::New();
89 myPointsActor->SetRepresentation(SVTK::Representation::Points);
90 myPointsActor->SetProperty(aProperty);
91 myPointsActor->SetUserMatrix(aMatrix);
95 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
96 //Quadratic 2D elements representation
98 //----------------------------------------------------------------------------
99 int aQuadraticAngle = aResourceMgr->integerValue( "VISU", "max_angle", 2);
100 mySurfaceActor->SetQuadraticArcAngle(aQuadraticAngle);
101 myEdgeActor->SetQuadraticArcAngle(aQuadraticAngle);
103 int anElem0DSize = aResourceMgr->integerValue( "VISU", "elem0d_size", 5);
104 mySurfaceActor->GetProperty()->SetPointSize(anElem0DSize);
108 //----------------------------------------------------------------------------
110 ::~VISU_ScalarMapAct()
112 myScalarBar->Delete();
114 myPointsActor->Delete();
116 mySurfaceActor->Delete();
117 myEdgeActor->Delete();
122 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
124 VISU_DataSetActor::ShallowCopyPL( thePipeLine );
126 myEdgeActor->GetMapper()->ScalarVisibilityOff();
128 VISU::CopyMapper( myPointsActor->GetMapper(), thePipeLine->GetMapper(), false );
129 VISU::CopyMapper( mySurfaceActor->GetMapper(), thePipeLine->GetMapper(), false );
132 //----------------------------------------------------------------------------
135 ::SetMapperInput(vtkDataSet* theDataSet)
137 Superclass::SetMapperInput( theDataSet );
139 // myPointsActor->SetInput( theDataSet );
140 // mySurfaceActor->SetInput( theDataSet );
141 // myEdgeActor->SetInput( theDataSet );
143 if (theDataSet->IsA("vtkPolyData")) {
144 myPointsActor->SetInput( myPolyDataExtractor->GetOutput() );
145 mySurfaceActor->SetInput( myPolyDataExtractor->GetOutput() );
146 myEdgeActor->SetInput( myPolyDataExtractor->GetOutput() );
148 myPointsActor->SetInput( myExtractor->GetOutput() );
149 mySurfaceActor->SetInput( myExtractor->GetOutput() );
150 myEdgeActor->SetInput( myExtractor->GetOutput() );
154 //----------------------------------------------------------------------------
157 ::SetTransform(VTKViewer_Transform* theTransform)
159 Superclass::SetTransform(theTransform);
161 myPointsActor->SetTransform(theTransform);
163 mySurfaceActor->SetTransform(theTransform);
164 myEdgeActor->SetTransform(theTransform);
167 //----------------------------------------------------------------------------
172 return myEdgeActor->GetProperty();
175 //----------------------------------------------------------------------------
178 ::SetShrinkable(bool theIsShrinkable)
180 Superclass::SetShrinkable(theIsShrinkable);
182 mySurfaceActor->SetShrinkable(theIsShrinkable);
187 ::SetShrinkFactor(vtkFloatingPointType theValue)
189 Superclass::SetShrinkFactor(theValue);
191 mySurfaceActor->SetShrinkFactor(theValue);
194 //----------------------------------------------------------------------------
199 if(myRepresentation == VTK_POINTS)
202 Superclass::SetShrink();
204 mySurfaceActor->SetShrink();
211 Superclass::UnShrink();
213 mySurfaceActor->UnShrink();
216 //----------------------------------------------------------------------------
219 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
221 Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
223 mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
228 ::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
230 Superclass::SetFeatureEdgesAngle(theValue);
232 mySurfaceActor->SetFeatureEdgesAngle(theValue);
237 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
238 bool theIsBoundaryEdges,
239 bool theIsManifoldEdges,
240 bool theIsNonManifoldEdges)
242 Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
245 theIsNonManifoldEdges);
247 mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
250 theIsNonManifoldEdges);
255 ::SetFeatureEdgesColoring(bool theIsColoring)
257 Superclass::SetFeatureEdgesColoring(theIsColoring);
259 mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
262 //----------------------------------------------------------------------------
265 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
267 if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
270 Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
272 mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
275 //----------------------------------------------------------------------------
278 ::SetOpacity(vtkFloatingPointType theValue)
280 mySurfaceActor->GetProperty()->SetOpacity(theValue);
287 return mySurfaceActor->GetProperty()->GetOpacity();
290 //----------------------------------------------------------------------------
293 ::SetLineWidth(vtkFloatingPointType theLineWidth)
295 mySurfaceActor->GetProperty()->SetLineWidth(theLineWidth);
299 VISU_ScalarMapAct::GetLineWidth()
301 return mySurfaceActor->GetProperty()->GetLineWidth();
304 //----------------------------------------------------------------------------
307 ::DeepCopy(VISU_Actor *theActor)
309 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
310 Superclass::DeepCopy(theActor);
311 SetBarVisibility(anActor->GetBarVisibility());
312 SetShading(anActor->IsShading());
317 //----------------------------------------------------------------------------
320 ::AddToRender(vtkRenderer* theRenderer)
322 Superclass::AddToRender(theRenderer);
325 theRenderer->AddActor2D(myScalarBar);
328 //----------------------------------------------------------------------------
331 ::RemoveFromRender(vtkRenderer* theRenderer)
334 theRenderer->RemoveActor(myScalarBar);
336 if ( vtkWindow* aWindow = theRenderer->GetRenderWindow() ) {
337 myPointsActor->ReleaseGraphicsResources( aWindow );
338 mySurfaceActor->ReleaseGraphicsResources( aWindow );
339 myEdgeActor->ReleaseGraphicsResources( aWindow );
342 Superclass::RemoveFromRender(theRenderer);
345 //----------------------------------------------------------------------------
348 ::SetVisibility(int theMode)
350 Superclass::SetVisibility( theMode );
352 myPointsActor->SetVisibility( theMode );
355 myScalarBar->SetVisibility(myBarVisibility && theMode);
358 //----------------------------------------------------------------------------
363 return myBarVisibility;
366 //----------------------------------------------------------------------------
374 //----------------------------------------------------------------------------
377 ::SetBarVisibility(bool theMode)
379 myBarVisibility = theMode;
381 myScalarBar->SetVisibility(myBarVisibility && GetVisibility());
385 //----------------------------------------------------------------------------
388 ::SetRepresentation(int theMode)
390 bool anIsShanding = IsShading();
392 Superclass::SetRepresentation(theMode);
394 if(theMode == SVTK::Representation::Surfaceframe)
395 mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
397 mySurfaceActor->SetRepresentation(theMode);
399 myPointsActor->SetProperty( mySurfaceActor->GetProperty() );
401 SetShading(anIsShanding);
405 //----------------------------------------------------------------------------
408 ::SetShading(bool theOn)
410 vtkProperty* aProperty = mySurfaceActor->GetProperty();
413 aProperty->SetAmbient(0.0);
414 aProperty->SetDiffuse(1.0);
416 aProperty->SetAmbient(1.0);
417 aProperty->SetDiffuse(0.0);
421 //----------------------------------------------------------------------------
426 vtkProperty* aProperty = mySurfaceActor->GetProperty();
428 return (fabs(aProperty->GetAmbient()) < EPS && fabs(aProperty->GetDiffuse() - 1.) < EPS);
433 ::RenderOpaqueGeometry(vtkViewport *ren)
435 GetMatrix(myEdgeActor->GetUserMatrix());
436 GetMatrix(mySurfaceActor->GetUserMatrix());
437 GetMatrix(myPointsActor->GetUserMatrix());
439 using namespace SVTK::Representation;
440 switch ( GetRepresentation() ) {
443 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
444 mySurfaceActor->RenderOpaqueGeometry(ren);
446 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
447 myEdgeActor->RenderOpaqueGeometry(ren);
451 myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
452 myPointsActor->RenderOpaqueGeometry(ren);
456 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
457 mySurfaceActor->RenderOpaqueGeometry(ren);
465 ::RenderTranslucentGeometry(vtkViewport *ren)
467 GetMatrix(myEdgeActor->GetUserMatrix());
468 GetMatrix(mySurfaceActor->GetUserMatrix());
470 using namespace SVTK::Representation;
471 switch ( GetRepresentation() ) {
474 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
475 #if (VTK_XVERSION < 0x050100)
476 mySurfaceActor->RenderTranslucentGeometry(ren);
478 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
481 myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
482 #if (VTK_XVERSION < 0x050100)
483 myEdgeActor->RenderTranslucentGeometry(ren);
485 myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
490 myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
491 #if (VTK_XVERSION < 0x050100)
492 myPointsActor->RenderTranslucentGeometry(ren);
494 myPointsActor->RenderTranslucentPolygonalGeometry(ren);
499 mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
500 #if (VTK_XVERSION < 0x050100)
501 mySurfaceActor->RenderTranslucentGeometry(ren);
503 mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
510 //----------------------------------------------------------------------------
512 VISU_Actor::EQuadratic2DRepresentation
514 ::GetQuadratic2DRepresentation() const
516 bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
518 return VISU_Actor::eArcs;
521 return VISU_Actor::eLines;
524 void VISU_ScalarMapAct::SetQuadratic2DRepresentation( VISU_Actor::EQuadratic2DRepresentation theMode )
526 Superclass::SetQuadratic2DRepresentation( theMode );
528 case VISU_Actor::eArcs:
529 mySurfaceActor->SetQuadraticArcMode(true);
530 myEdgeActor->SetQuadraticArcMode(true);
532 case VISU_Actor::eLines:
533 mySurfaceActor->SetQuadraticArcMode(false);
534 myEdgeActor->SetQuadraticArcMode(false);
541 void VISU_ScalarMapAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
543 Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
544 myPointsActor->SetMarkerStd( theMarkerType, theMarkerScale );
547 void VISU_ScalarMapAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
549 Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
550 myPointsActor->SetMarkerTexture( theMarkerId, theMarkerTexture );