-// VISU OBJECT : interactive object for VISU entities implementation
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
+// VISU OBJECT : interactive object for VISU entities implementation
// File : VISU_MeshAct.hxx
// Author : Laurent CORNABE with the help of Nicolas REJNERI
// Module : VISU
// $Header$
-
+//
#include "VISU_ScalarMapAct.h"
#include "VISU_LookupTable.hxx"
#include "VISU_ScalarBarActor.hxx"
+#include "VISU_PipeLine.hxx"
+
+#include "VISU_OpenGLPointSpriteMapper.hxx"
+#include "VISU_GaussPtsDeviceActor.h"
+#include "VISU_DeformedShapePL.hxx"
+#include "VISU_PipeLineUtils.hxx"
+
+
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
+#include <SALOME_ExtractGeometry.h>
+#include <SALOME_ExtractPolyDataGeometry.h>
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
+#include <vtkProperty.h>
+#include <vtkMatrix4x4.h>
+#include <vtkMapper.h>
+#include <vtkDataSetMapper.h>
+
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkRenderWindow.h>
+#include <vtkImageData.h>
+
+//----------------------------------------------------------------------------
vtkStandardNewMacro(VISU_ScalarMapAct);
+static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
-VISU_ScalarMapAct::VISU_ScalarMapAct(){
+//----------------------------------------------------------------------------
+VISU_ScalarMapAct
+::VISU_ScalarMapAct()
+{
myScalarBar = VISU_ScalarBarActor::New();
vtkProperty* aProperty = GetProperty();
- //aProperty->SetAmbient(0.5);
- //aProperty->SetDiffuse(0.2);
- //aProperty->SetSpecular(0.2);
aProperty->SetAmbient(1.0);
aProperty->SetDiffuse(0.0);
aProperty->SetSpecular(0.0);
myProperty->DeepCopy(aProperty);
+
+ vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
+
+ mySurfaceActor= SVTK_DeviceActor::New();
+ mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
+ mySurfaceActor->SetProperty(aProperty);
+ mySurfaceActor->SetUserMatrix(aMatrix);
+
+ myEdgeActor = SVTK_DeviceActor::New();
+ myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
+ myEdgeActor->SetUserMatrix(aMatrix);
+ myEdgeActor->GetProperty()->SetColor(255.,255.,255.);
+
+ myPointsActor = SVTK_DeviceActor::New();
+ myPointsActor->SetRepresentation(SVTK::Representation::Points);
+ myPointsActor->SetProperty(aProperty);
+ myPointsActor->SetUserMatrix(aMatrix);
+
+ aMatrix->Delete();
+
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+ //Quadratic 2D elements representation
+ if(aResourceMgr) {
+ //----------------------------------------------------------------------------
+ int aQuadraticAngle = aResourceMgr->integerValue( "VISU", "max_angle", 2);
+ mySurfaceActor->SetQuadraticArcAngle(aQuadraticAngle);
+ myEdgeActor->SetQuadraticArcAngle(aQuadraticAngle);
+
+ int anElem0DSize = aResourceMgr->integerValue( "VISU", "elem0d_size", 5);
+ mySurfaceActor->GetProperty()->SetPointSize(anElem0DSize);
+ }
}
-VISU_ScalarMapAct::~VISU_ScalarMapAct(){
+//----------------------------------------------------------------------------
+VISU_ScalarMapAct
+::~VISU_ScalarMapAct()
+{
myScalarBar->Delete();
+
+ myPointsActor->Delete();
+
+ mySurfaceActor->Delete();
+ myEdgeActor->Delete();
+}
+
+void
+VISU_ScalarMapAct
+::ShallowCopyPL(VISU_PipeLine* thePipeLine)
+{
+ VISU_DataSetActor::ShallowCopyPL( thePipeLine );
+
+ myEdgeActor->GetMapper()->ScalarVisibilityOff();
+
+ VISU::CopyMapper( myPointsActor->GetMapper(), thePipeLine->GetMapper(), false );
+ VISU::CopyMapper( mySurfaceActor->GetMapper(), thePipeLine->GetMapper(), false );
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetMapperInput(vtkDataSet* theDataSet)
+{
+ Superclass::SetMapperInput( theDataSet );
+
+// myPointsActor->SetInput( theDataSet );
+// mySurfaceActor->SetInput( theDataSet );
+// myEdgeActor->SetInput( theDataSet );
+
+ if (theDataSet->IsA("vtkPolyData")) {
+ myPointsActor->SetInput( myPolyDataExtractor->GetOutput() );
+ mySurfaceActor->SetInput( myPolyDataExtractor->GetOutput() );
+ myEdgeActor->SetInput( myPolyDataExtractor->GetOutput() );
+ } else {
+ myPointsActor->SetInput( myExtractor->GetOutput() );
+ mySurfaceActor->SetInput( myExtractor->GetOutput() );
+ myEdgeActor->SetInput( myExtractor->GetOutput() );
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetTransform(VTKViewer_Transform* theTransform)
+{
+ Superclass::SetTransform(theTransform);
+
+ myPointsActor->SetTransform(theTransform);
+
+ mySurfaceActor->SetTransform(theTransform);
+ myEdgeActor->SetTransform(theTransform);
+}
+
+//----------------------------------------------------------------------------
+vtkProperty*
+VISU_ScalarMapAct
+::GetEdgeProperty()
+{
+ return myEdgeActor->GetProperty();
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetShrinkable(bool theIsShrinkable)
+{
+ Superclass::SetShrinkable(theIsShrinkable);
+
+ mySurfaceActor->SetShrinkable(theIsShrinkable);
+}
+
+void
+VISU_ScalarMapAct
+::SetShrinkFactor(vtkFloatingPointType theValue)
+{
+ Superclass::SetShrinkFactor(theValue);
+
+ mySurfaceActor->SetShrinkFactor(theValue);
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetShrink()
+{
+ if(myRepresentation == VTK_POINTS)
+ return;
+
+ Superclass::SetShrink();
+
+ mySurfaceActor->SetShrink();
+}
+
+void
+VISU_ScalarMapAct
+::UnShrink()
+{
+ Superclass::UnShrink();
+
+ mySurfaceActor->UnShrink();
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
+{
+ Superclass::SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
+
+ mySurfaceActor->SetFeatureEdgesAllowed(theIsFeatureEdgesAllowed);
+}
+
+void
+VISU_ScalarMapAct
+::SetFeatureEdgesAngle(vtkFloatingPointType theValue)
+{
+ Superclass::SetFeatureEdgesAngle(theValue);
+
+ mySurfaceActor->SetFeatureEdgesAngle(theValue);
+}
+
+void
+VISU_ScalarMapAct
+::SetFeatureEdgesFlags(bool theIsFeatureEdges,
+ bool theIsBoundaryEdges,
+ bool theIsManifoldEdges,
+ bool theIsNonManifoldEdges)
+{
+ Superclass::SetFeatureEdgesFlags(theIsFeatureEdges,
+ theIsBoundaryEdges,
+ theIsManifoldEdges,
+ theIsNonManifoldEdges);
+
+ mySurfaceActor->SetFeatureEdgesFlags(theIsFeatureEdges,
+ theIsBoundaryEdges,
+ theIsManifoldEdges,
+ theIsNonManifoldEdges);
+}
+
+void
+VISU_ScalarMapAct
+::SetFeatureEdgesColoring(bool theIsColoring)
+{
+ Superclass::SetFeatureEdgesColoring(theIsColoring);
+
+ mySurfaceActor->SetFeatureEdgesColoring(theIsColoring);
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
+{
+ if(theIsFeatureEdgesEnabled && myRepresentation == VTK_POINTS)
+ return;
+
+ Superclass::SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
+
+ mySurfaceActor->SetFeatureEdgesEnabled(theIsFeatureEdgesEnabled);
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetOpacity(vtkFloatingPointType theValue)
+{
+ mySurfaceActor->GetProperty()->SetOpacity(theValue);
+}
+
+vtkFloatingPointType
+VISU_ScalarMapAct
+::GetOpacity()
+{
+ return mySurfaceActor->GetProperty()->GetOpacity();
+}
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetLineWidth(vtkFloatingPointType theLineWidth)
+{
+ mySurfaceActor->GetProperty()->SetLineWidth(theLineWidth);
+}
+
+vtkFloatingPointType
+VISU_ScalarMapAct::GetLineWidth()
+{
+ return mySurfaceActor->GetProperty()->GetLineWidth();
}
-void VISU_ScalarMapAct::AddToRender(vtkRenderer* theRenderer){
- SALOME_Actor::AddToRender(theRenderer);
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::DeepCopy(VISU_Actor *theActor)
+{
+ if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
+ Superclass::DeepCopy(theActor);
+ SetBarVisibility(anActor->GetBarVisibility());
+ SetShading(anActor->IsShading());
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::AddToRender(vtkRenderer* theRenderer)
+{
+ Superclass::AddToRender(theRenderer);
+
if(myScalarBar)
theRenderer->AddActor2D(myScalarBar);
}
-void VISU_ScalarMapAct::RemoveFromRender(vtkRenderer* theRenderer){
- SALOME_Actor::RemoveFromRender(theRenderer);
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::RemoveFromRender(vtkRenderer* theRenderer)
+{
if(myScalarBar)
theRenderer->RemoveActor(myScalarBar);
+
+ if ( vtkWindow* aWindow = theRenderer->GetRenderWindow() ) {
+ myPointsActor->ReleaseGraphicsResources( aWindow );
+ mySurfaceActor->ReleaseGraphicsResources( aWindow );
+ myEdgeActor->ReleaseGraphicsResources( aWindow );
+ }
+
+ Superclass::RemoveFromRender(theRenderer);
}
-void VISU_ScalarMapAct::SetVisibility(int theMode){
- SALOME_Actor::SetVisibility(theMode);
- if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility && theMode);
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetVisibility(int theMode)
+{
+ Superclass::SetVisibility( theMode );
+
+ myPointsActor->SetVisibility( theMode );
+
+ if(myScalarBar)
+ myScalarBar->SetVisibility(myBarVisibility && theMode);
}
-int VISU_ScalarMapAct::GetVisibility(){
- return SALOME_Actor::GetVisibility();
+//----------------------------------------------------------------------------
+int
+VISU_ScalarMapAct
+::GetBarVisibility()
+{
+ return myBarVisibility;
}
-void VISU_ScalarMapAct::SetBarVisibility(bool theMode){
- myBarVisibility = theMode;
- if(myScalarBar) myScalarBar->SetVisibility(myBarVisibility);
+//----------------------------------------------------------------------------
+VISU_ScalarBarActor*
+VISU_ScalarMapAct
+::GetScalarBar()
+{
+ return myScalarBar;
}
-void VISU_ScalarMapAct::SetShading(bool theOn)
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetBarVisibility(bool theMode)
{
- vtkProperty* aProperty = GetProperty();
+ myBarVisibility = theMode;
+ if(myScalarBar)
+ myScalarBar->SetVisibility(myBarVisibility && GetVisibility());
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetRepresentation(int theMode)
+{
+ bool anIsShanding = IsShading();
- if (theOn)
- {
- aProperty->SetAmbient(0.0);
- aProperty->SetDiffuse(1.0);
- }
+ Superclass::SetRepresentation(theMode);
+
+ if(theMode == SVTK::Representation::Surfaceframe)
+ mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
else
- {
- aProperty->SetAmbient(1.0);
- aProperty->SetDiffuse(0.0);
- }
- myProperty->DeepCopy(aProperty);
+ mySurfaceActor->SetRepresentation(theMode);
+
+ myPointsActor->SetProperty( mySurfaceActor->GetProperty() );
+
+ SetShading(anIsShanding);
}
-bool VISU_ScalarMapAct::IsShading()
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapAct
+::SetShading(bool theOn)
{
- vtkProperty* aProperty = GetProperty();
+ vtkProperty* aProperty = mySurfaceActor->GetProperty();
+
+ if (theOn) {
+ aProperty->SetAmbient(0.0);
+ aProperty->SetDiffuse(1.0);
+ } else {
+ aProperty->SetAmbient(1.0);
+ aProperty->SetDiffuse(0.0);
+ }
+}
+
+//----------------------------------------------------------------------------
+bool
+VISU_ScalarMapAct
+::IsShading()
+{
+ vtkProperty* aProperty = mySurfaceActor->GetProperty();
+
+ return (fabs(aProperty->GetAmbient()) < EPS && fabs(aProperty->GetDiffuse() - 1.) < EPS);
+}
+
+int
+VISU_ScalarMapAct
+::RenderOpaqueGeometry(vtkViewport *ren)
+{
+ GetMatrix(myEdgeActor->GetUserMatrix());
+ GetMatrix(mySurfaceActor->GetUserMatrix());
+ GetMatrix(myPointsActor->GetUserMatrix());
+
+ using namespace SVTK::Representation;
+ switch ( GetRepresentation() ) {
+
+ case Surfaceframe:
+ mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
+ mySurfaceActor->RenderOpaqueGeometry(ren);
+
+ myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
+ myEdgeActor->RenderOpaqueGeometry(ren);
+ break;
+
+ case Points:
+ myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+ myPointsActor->RenderOpaqueGeometry(ren);
+ break;
+
+ default:
+ mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+ mySurfaceActor->RenderOpaqueGeometry(ren);
+ }
+
+ return 1;
+}
+
+int
+VISU_ScalarMapAct
+::RenderTranslucentGeometry(vtkViewport *ren)
+{
+ GetMatrix(myEdgeActor->GetUserMatrix());
+ GetMatrix(mySurfaceActor->GetUserMatrix());
+
+ using namespace SVTK::Representation;
+ switch ( GetRepresentation() ) {
+
+ case Surfaceframe:
+ mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+#if (VTK_XVERSION < 0x050100)
+ mySurfaceActor->RenderTranslucentGeometry(ren);
+#else
+ mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+
+ myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
+#if (VTK_XVERSION < 0x050100)
+ myEdgeActor->RenderTranslucentGeometry(ren);
+#else
+ myEdgeActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+ break;
+
+ case Points:
+ myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+#if (VTK_XVERSION < 0x050100)
+ myPointsActor->RenderTranslucentGeometry(ren);
+#else
+ myPointsActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+ break;
+
+ default:
+ mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+#if (VTK_XVERSION < 0x050100)
+ mySurfaceActor->RenderTranslucentGeometry(ren);
+#else
+ mySurfaceActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+ }
+
+ return 1;
+}
+
+//----------------------------------------------------------------------------
+
+VISU_Actor::EQuadratic2DRepresentation
+VISU_ScalarMapAct
+::GetQuadratic2DRepresentation() const
+{
+ bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
+ if(mode){
+ return VISU_Actor::eArcs;
+ }
+ else
+ return VISU_Actor::eLines;
+}
- return (aProperty->GetAmbient() == 0 && aProperty->GetDiffuse() == 1);
+void VISU_ScalarMapAct::SetQuadratic2DRepresentation( VISU_Actor::EQuadratic2DRepresentation theMode )
+{
+ Superclass::SetQuadratic2DRepresentation( theMode );
+ switch(theMode) {
+ case VISU_Actor::eArcs:
+ mySurfaceActor->SetQuadraticArcMode(true);
+ myEdgeActor->SetQuadraticArcMode(true);
+ break;
+ case VISU_Actor::eLines:
+ mySurfaceActor->SetQuadraticArcMode(false);
+ myEdgeActor->SetQuadraticArcMode(false);
+ break;
+ default:
+ break;
+ }
+}
+
+void VISU_ScalarMapAct::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
+{
+ Superclass::SetMarkerStd( theMarkerType, theMarkerScale );
+ myPointsActor->SetMarkerStd( theMarkerType, theMarkerScale );
+}
+
+void VISU_ScalarMapAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
+{
+ Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
+ myPointsActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
}