]> SALOME platform Git repositories - modules/visu.git/blobdiff - src/OBJECT/VISU_ScalarMapAct.cxx
Salome HOME
Note 0009977 of the issue 0013178: EDF243 VISU : post_processing for fields at nodes
[modules/visu.git] / src / OBJECT / VISU_ScalarMapAct.cxx
index 908165049a5b59754e0f9898a5ec74905c6b22aa..d26381de01fee6fe9aaf2082bf05f4d7e5e95c80 100644 (file)
@@ -1,31 +1,31 @@
-//  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
 //
-//  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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.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_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>
@@ -81,8 +88,8 @@ class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
     
     if(theInteractor)
       theInteractor->AddObserver(vtkCommand::CharEvent, 
-                                myEventCallbackCommand, 
-                                0.0);
+                                 myEventCallbackCommand, 
+                                 0.0);
 
     myInteractor = theInteractor;
   }
@@ -91,7 +98,7 @@ class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
   //----------------------------------------------------------------------------
   void
   DoMapperShallowCopy( vtkMapper* theMapper,
-                      bool theIsCopyInput )
+                       bool theIsCopyInput )
   {
     Superclass::DoMapperShallowCopy( theMapper, theIsCopyInput );
 
@@ -153,9 +160,9 @@ class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
   static
   void
   ProcessEvents(vtkObject* theObject, 
-               unsigned long theEvent,
-               void* theClientData, 
-               void* theCallData)
+                unsigned long theEvent,
+                void* theClientData, 
+                void* theCallData)
   {
     if ( VISU_PointsDeviceActor* self = reinterpret_cast<VISU_PointsDeviceActor*>( theClientData ) )
       self->OnInteractorEvent( theEvent );
@@ -171,20 +178,20 @@ class VISU_PointsDeviceActor: public VISU_GaussDeviceActorBase
       switch( myInteractor->GetKeyCode() ) {
       case 'M' :
       case 'm' : {
-       if ( !GetVisibility() )
-         return;
+        if ( !GetVisibility() )
+          return;
 
-       static vtkFloatingPointType anIncrement = 2;
-       vtkFloatingPointType aMagnification = GetPointSpriteMapper()->GetPointSpriteMagnification();
-       vtkFloatingPointType coefficient = myInteractor->GetShiftKey() ? anIncrement : 1 / anIncrement;
+        static vtkFloatingPointType anIncrement = 2;
+        vtkFloatingPointType aMagnification = GetPointSpriteMapper()->GetPointSpriteMagnification();
+        vtkFloatingPointType coefficient = myInteractor->GetShiftKey() ? anIncrement : 1 / anIncrement;
 
-       GetPointSpriteMapper()->SetPointSpriteMagnification( aMagnification * coefficient );
+        GetPointSpriteMapper()->SetPointSpriteMagnification( aMagnification * coefficient );
 
-       myInteractor->CreateTimer(VTKI_TIMER_UPDATE);
-       break;
+        myInteractor->CreateTimer(VTKI_TIMER_UPDATE);
+        break;
       }
       default:
-       return;
+        return;
       }
       break;
     }
@@ -235,11 +242,30 @@ VISU_ScalarMapAct
   myEdgeActor->SetUserMatrix(aMatrix);
   myEdgeActor->GetProperty()->SetColor(255.,255.,255.);
 
-  myPointsActor = VISU_PointsDeviceActor::New();
+  myPointsActor = SVTK_DeviceActor::New();
+  myPointsActor->SetRepresentation(SVTK::Representation::Points);
   myPointsActor->SetProperty(aProperty);
   myPointsActor->SetUserMatrix(aMatrix);
 
+  myPointSpriteActor = VISU_PointsDeviceActor::New();
+  myPointSpriteActor->SetProperty(aProperty);
+  myPointSpriteActor->SetUserMatrix(aMatrix);
+
   aMatrix->Delete();
+
+  myIsPointSpriteMode = false;
+
+  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);
+  }
 }
 
 //----------------------------------------------------------------------------
@@ -249,6 +275,7 @@ VISU_ScalarMapAct
   myScalarBar->Delete();
 
   myPointsActor->Delete();
+  myPointSpriteActor->Delete();
 
   mySurfaceActor->Delete();
   myEdgeActor->Delete();
@@ -258,12 +285,13 @@ void
 VISU_ScalarMapAct
 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
 {
-  VISU_Actor::ShallowCopyPL( thePipeLine );
+  VISU_DataSetActor::ShallowCopyPL( thePipeLine );
 
   myEdgeActor->GetMapper()->ScalarVisibilityOff();
 
-  myPointsActor->DoMapperShallowCopy( thePipeLine->GetMapper(), false );
+  myPointSpriteActor->DoMapperShallowCopy( thePipeLine->GetMapper(), false );
 
+  VISU::CopyMapper( myPointsActor->GetMapper(), thePipeLine->GetMapper(), false );
   VISU::CopyMapper( mySurfaceActor->GetMapper(), thePipeLine->GetMapper(), false );
 }
 
@@ -274,10 +302,21 @@ VISU_ScalarMapAct
 {
   Superclass::SetMapperInput( theDataSet );
 
-  myPointsActor->SetInput( theDataSet );
+//    myPointsActor->SetInput( theDataSet );
+//    mySurfaceActor->SetInput( theDataSet );
+//    myEdgeActor->SetInput( theDataSet );
 
-  mySurfaceActor->SetInput( theDataSet );
-  myEdgeActor->SetInput( theDataSet );
+  if (theDataSet->IsA("vtkPolyData")) {
+    myPointSpriteActor->SetInput( myPolyDataExtractor->GetOutput() );
+    myPointsActor->SetInput( myPolyDataExtractor->GetOutput() );
+    mySurfaceActor->SetInput( myPolyDataExtractor->GetOutput() );
+    myEdgeActor->SetInput( myPolyDataExtractor->GetOutput() );
+  } else {
+    myPointSpriteActor->SetInput( myExtractor->GetOutput() );
+    myPointsActor->SetInput( myExtractor->GetOutput() );
+    mySurfaceActor->SetInput( myExtractor->GetOutput() );
+    myEdgeActor->SetInput( myExtractor->GetOutput() );
+  }
 }
 
 //----------------------------------------------------------------------------
@@ -288,11 +327,20 @@ VISU_ScalarMapAct
   Superclass::SetTransform(theTransform);
 
   myPointsActor->SetTransform(theTransform);
+  myPointSpriteActor->SetTransform(theTransform);
 
   mySurfaceActor->SetTransform(theTransform);
   myEdgeActor->SetTransform(theTransform);
 }
 
+//----------------------------------------------------------------------------
+vtkProperty* 
+VISU_ScalarMapAct
+::GetEdgeProperty()
+{
+  return myEdgeActor->GetProperty();
+}
+
 //----------------------------------------------------------------------------
 void
 VISU_ScalarMapAct
@@ -334,12 +382,74 @@ VISU_ScalarMapAct
   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 aPointSpriteOpacity = theValue > 0.0 ? 1.0 : 0.0;
+  myPointSpriteActor->GetPointSpriteMapper()->SetPointSpriteOpacity(aPointSpriteOpacity);
 }
 
 vtkFloatingPointType
@@ -371,7 +481,7 @@ VISU_ScalarMapAct
   if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor)){
     Superclass::DeepCopy(theActor);
     SetBarVisibility(anActor->GetBarVisibility());
-    myPointsActor->DeepCopy( anActor->myPointsActor );
+    myPointSpriteActor->DeepCopy( anActor->myPointSpriteActor );
     SetShading(anActor->IsShading());
   }
 }
@@ -384,7 +494,7 @@ VISU_ScalarMapAct
 {
   Superclass::AddToRender(theRenderer);
 
-  myPointsActor->SetInteractor( myInteractor );
+  myPointSpriteActor->SetInteractor( myInteractor );
 
   if(myScalarBar)
     theRenderer->AddActor2D(myScalarBar);
@@ -399,6 +509,7 @@ VISU_ScalarMapAct
     theRenderer->RemoveActor(myScalarBar);
 
   if ( vtkWindow* aWindow = theRenderer->GetRenderWindow() ) {
+    myPointSpriteActor->ReleaseGraphicsResources( aWindow );
     myPointsActor->ReleaseGraphicsResources( aWindow );
     mySurfaceActor->ReleaseGraphicsResources( aWindow );
     myEdgeActor->ReleaseGraphicsResources( aWindow );
@@ -414,6 +525,7 @@ VISU_ScalarMapAct
 {
   Superclass::SetVisibility( theMode );
 
+  myPointSpriteActor->SetVisibility( theMode );
   myPointsActor->SetVisibility( theMode );
 
   if(myScalarBar) 
@@ -443,7 +555,7 @@ VISU_ScalarMapAct
 {
   myBarVisibility = theMode;
   if(myScalarBar) 
-    myScalarBar->SetVisibility(myBarVisibility);
+    myScalarBar->SetVisibility(myBarVisibility && GetVisibility());
 }
 
 
@@ -461,6 +573,7 @@ VISU_ScalarMapAct
   else
     mySurfaceActor->SetRepresentation(theMode);
 
+  myPointSpriteActor->SetProperty( mySurfaceActor->GetProperty() );
   myPointsActor->SetProperty( mySurfaceActor->GetProperty() );
 
   SetShading(anIsShanding);
@@ -500,6 +613,7 @@ VISU_ScalarMapAct
   GetMatrix(myEdgeActor->GetUserMatrix());
   GetMatrix(mySurfaceActor->GetUserMatrix());
   GetMatrix(myPointsActor->GetUserMatrix());
+  GetMatrix(myPointSpriteActor->GetUserMatrix());
 
   using namespace SVTK::Representation;
   switch ( GetRepresentation() ) {
@@ -513,8 +627,13 @@ VISU_ScalarMapAct
     break;
 
   case Points:
-    myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
-    myPointsActor->RenderOpaqueGeometry(ren);
+    if( myIsPointSpriteMode ) {
+      myPointSpriteActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+      myPointSpriteActor->RenderOpaqueGeometry(ren);
+    } else {
+      myPointsActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+      myPointsActor->RenderOpaqueGeometry(ren);
+    }
     break;
 
   default:
@@ -527,7 +646,11 @@ VISU_ScalarMapAct
 
 int
 VISU_ScalarMapAct
+#if (VTK_XVERSION < 0x050100)
 ::RenderTranslucentGeometry(vtkViewport *ren)
+#else
+::RenderTranslucentPolygonalGeometry(vtkViewport *ren)
+#endif
 {
   GetMatrix(myEdgeActor->GetUserMatrix());
   GetMatrix(mySurfaceActor->GetUserMatrix());
@@ -537,25 +660,78 @@ VISU_ScalarMapAct
 
   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);
-    myPointsActor->RenderTranslucentGeometry(ren);
+    if( myIsPointSpriteMode ) {
+      myPointSpriteActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
+#if (VTK_XVERSION < 0x050100)
+      myPointSpriteActor->RenderTranslucentGeometry(ren);
+#else
+      myPointSpriteActor->RenderTranslucentPolygonalGeometry(ren);
+#endif
+    } else {
+      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;
 }
 
+//----------------------------------------------------------------------------
+#if (VTK_XVERSION >= 0x050100)
+int
+VISU_ScalarMapAct
+::HasTranslucentPolygonalGeometry()
+{
+  int result = 0; 
+
+  using namespace SVTK::Representation;
+  switch ( GetRepresentation() ) {
+  case Surfaceframe:
+    result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
+    result |= myEdgeActor->HasTranslucentPolygonalGeometry();
+    break;
+  case Points:
+    if( myIsPointSpriteMode )
+      result |= myPointSpriteActor->HasTranslucentPolygonalGeometry();
+    else
+      result |= myPointsActor->HasTranslucentPolygonalGeometry();
+    break;
+  default:
+    result |= mySurfaceActor->HasTranslucentPolygonalGeometry();
+  }
+
+  return result;
+}
+#endif
+
 //----------------------------------------------------------------------------
 unsigned long int
 VISU_ScalarMapAct
@@ -563,9 +739,69 @@ VISU_ScalarMapAct
 {
   unsigned long int aSize = Superclass::GetMemorySize();
 
-  aSize += myPointsActor->GetMemorySize();
+  aSize += myPointSpriteActor->GetMemorySize();
 
   return aSize;
 }
 
 //----------------------------------------------------------------------------
+
+VISU_Actor::EQuadratic2DRepresentation 
+VISU_ScalarMapAct
+::GetQuadratic2DRepresentation() const
+{
+  bool mode = (mySurfaceActor->GetQuadraticArcMode() && myEdgeActor->GetQuadraticArcMode());
+  if(mode){
+    return VISU_Actor::eArcs;
+  }
+  else
+    return VISU_Actor::eLines;
+}
+  
+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 );
+
+  myIsPointSpriteMode = theMarkerType == VTK::MT_POINT_SPRITE;
+}
+
+void VISU_ScalarMapAct::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
+{
+  Superclass::SetMarkerTexture( theMarkerId, theMarkerTexture );
+  myPointsActor->SetMarkerTexture( theMarkerId, theMarkerTexture );
+
+  myIsPointSpriteMode = false;
+}
+
+/**
+ * Set size of the 0D elements.
+ */
+void VISU_ScalarMapAct::Set0DElemSize(vtkFloatingPointType theValue) {
+  mySurfaceActor->GetProperty()->SetPointSize(theValue);
+}
+
+/**
+ * Get size of the 0D elements.
+ */
+vtkFloatingPointType VISU_ScalarMapAct::Get0DElemSize() {
+  return mySurfaceActor->GetProperty()->GetPointSize();
+}
+