Salome HOME
Issue 0019818: EDF 703 SMESH VISU : Display Mesh Groups names in viewer (as a caption)
[modules/visu.git] / src / PIPELINE / VISU_Plot3DPL.cxx
index a7e8287e0931b2bc34d1a9430c91c1e0fb21e6f1..8c3d9aeac9cfb9693c3e56e537d53b88805d3f4a 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  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
 //  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
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  VISU OBJECT : interactive object for VISU entities implementation
 // File:    VISU_PipeLine.cxx
 // Author:  Alexey PETROV
 // Module : VISU
-
-
+//
 #include "VISU_Plot3DPL.hxx"
 #include "VISU_CutPlanesPL.hxx"
 #include "VISU_PipeLineUtils.hxx"
 #include <vtkWarpScalar.h>
 #include <vtkOutlineFilter.h>
 
-using namespace std;
 
+//----------------------------------------------------------------------------
 vtkStandardNewMacro(VISU_Plot3DPL);
 
-VISU_Plot3DPL::VISU_Plot3DPL():
-  myCellDataToPointData(vtkCellDataToPointData::New(),true),
-  myAppendPolyData(vtkAppendPolyData::New(),true),
-  myGeometryFilter(vtkGeometryFilter::New(),true),
-  myContourFilter(vtkContourFilter::New(),true),
-  myWarpScalar(vtkWarpScalar::New(),true),
+
+//----------------------------------------------------------------------------
+VISU_Plot3DPL
+::VISU_Plot3DPL():
+  myCellDataToPointData(vtkCellDataToPointData::New()),
+  myAppendPolyData(vtkAppendPolyData::New()),
+  myGeometryFilter(vtkGeometryFilter::New()),
+  myContourFilter(vtkContourFilter::New()),
+  myWarpScalar(vtkWarpScalar::New()),
   myOrientation(VISU_CutPlanesPL::YZ),
   myIsRelative(true),
   myIsContour(false),
   myPosition(0.5),
-  myScaleFactor(1.)
+  myScaleFactor(1.0),
+  myMapScaleFactor(1.0)
 {
-  myAngle[0] = myAngle[1] = myAngle[2] = 0.;
+  SetIsShrinkable(false);
+  SetIsFeatureEdgesAllowed(false);
+
+  myCellDataToPointData->Delete();
+  myAppendPolyData->Delete();
+  myGeometryFilter->Delete();
+  myContourFilter->Delete();
+  myWarpScalar->Delete();
+
+  myAngle[0] = myAngle[1] = myAngle[2] = 0.0;
+
   SetNumberOfContours(32);
-  myIsShrinkable = false;
 }
 
-VISU_Plot3DPL::~VISU_Plot3DPL()
+
+//----------------------------------------------------------------------------
+VISU_Plot3DPL
+::~VISU_Plot3DPL()
+{}
+
+
+//----------------------------------------------------------------------------
+unsigned long int 
+VISU_Plot3DPL
+::GetMTime()
 {
+  unsigned long int aTime = Superclass::GetMTime();
+
+  aTime = std::max(aTime, myCellDataToPointData->GetMTime());
+  aTime = std::max(aTime, myAppendPolyData->GetMTime());
+  aTime = std::max(aTime, myGeometryFilter->GetMTime());
+  aTime = std::max(aTime, myContourFilter->GetMTime());
+  aTime = std::max(aTime, myWarpScalar->GetMTime());
+
+  return aTime;
 }
 
+
+//----------------------------------------------------------------------------
 void
-VISU_Plot3DPL::
-ShallowCopy(VISU_PipeLine *thePipeLine)
+VISU_Plot3DPL
+::DoShallowCopy(VISU_PipeLine *thePipeLine,
+               bool theIsCopyInput)
 {
-  VISU_ScalarMapPL::ShallowCopy(thePipeLine);
+  Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
+
   if(VISU_Plot3DPL *aPipeLine = dynamic_cast<VISU_Plot3DPL*>(thePipeLine)){
     SetOrientation (aPipeLine->GetPlaneOrientation(),
                     aPipeLine->GetRotateX(), aPipeLine->GetRotateY());
@@ -80,15 +115,17 @@ ShallowCopy(VISU_PipeLine *thePipeLine)
   }
 }
 
+
+//----------------------------------------------------------------------------
 VISU_CutPlanesPL::PlaneOrientation
-VISU_Plot3DPL::
-GetOrientation(vtkDataSet* theDataSet)
+VISU_Plot3DPL
+::GetOrientation(vtkDataSet* theDataSet)
 {
   theDataSet->Update();
 
-  float aBounds[6];
+  vtkFloatingPointType aBounds[6];
   theDataSet->GetBounds(aBounds);
-  float aDelta[3] = {aBounds[1] - aBounds[0], aBounds[3] - aBounds[2], aBounds[5] - aBounds[4]};
+  vtkFloatingPointType aDelta[3] = {aBounds[1] - aBounds[0], aBounds[3] - aBounds[2], aBounds[5] - aBounds[4]};
 
   if(aDelta[0] >= aDelta[1] && aDelta[0] >= aDelta[2])
     if(aDelta[1] >= aDelta[2])
@@ -111,58 +148,66 @@ GetOrientation(vtkDataSet* theDataSet)
   return VISU_CutPlanesPL::XY;
 }
 
-float
-VISU_Plot3DPL::
-GetScaleFactor(vtkDataSet* theDataSet)
+
+//----------------------------------------------------------------------------
+vtkFloatingPointType
+VISU_Plot3DPL
+::GetScaleFactor( VISU_ColoredPL* theColoredPL,
+                 vtkDataSet* theDataSet )
 {
   theDataSet->Update();
-  float aLength = theDataSet->GetLength(); // diagonal length
+  vtkFloatingPointType aLength = theDataSet->GetLength(); // diagonal length
 
-  float aScalarRange[2];
-  GetSourceRange(aScalarRange);
+  vtkFloatingPointType aScalarRange[2];
+  theColoredPL->GetSourceRange(aScalarRange);
 
-  static float EPS = 0.3;
-  float aRange = aScalarRange[1];
+  static vtkFloatingPointType EPS = 0.3;
+  vtkFloatingPointType aRange = aScalarRange[1];
   if(aRange > 0.0)
     return aLength / aRange * EPS;
 
   return 0.0;
 }
 
+
+//----------------------------------------------------------------------------
 void
-VISU_Plot3DPL::
-Init()
+VISU_Plot3DPL
+::Init()
 {
-  VISU_ScalarMapPL::Init();
+  Superclass::Init();
 
-  myOrientation = GetOrientation(GetInput2());
-  SetScaleFactor(GetScaleFactor(GetInput2()));
+  myOrientation = GetOrientation(GetMergedInput());
+  SetScaleFactor( GetScaleFactor( this, GetMergedInput() ) );
 }
 
-VISU_ScalarMapPL::THook*
-VISU_Plot3DPL::
-DoHook()
+
+//----------------------------------------------------------------------------
+vtkDataSet*
+VISU_Plot3DPL
+::InsertCustomPL()
 {
   return myAppendPolyData->GetOutput();
 }
 
+
+//----------------------------------------------------------------------------
 void
-VISU_Plot3DPL::
-Update()
+VISU_Plot3DPL
+::Update()
 {
-  float aPlaneNormal[3];
-  float anOrigin[3];
+  vtkFloatingPointType aPlaneNormal[3];
+  vtkFloatingPointType anOrigin[3];
   GetBasePlane( anOrigin, aPlaneNormal );
 
   vtkPolyData* aPolyData = 0;
   vtkCutter *aCutPlane = 0;
-  vtkUnstructuredGrid* anUnstructuredGrid =
-    myFieldTransform->GetUnstructuredGridOutput();
+  vtkDataSet* aDataSet = GetMergedInput();
 
   if ( !IsPlanarInput() )
   {
     aCutPlane = vtkCutter::New();
-    aCutPlane->SetInput(anUnstructuredGrid);
+    aCutPlane->SetInput(aDataSet);
 
     vtkPlane *aPlane = vtkPlane::New();
     aPlane->SetOrigin(anOrigin);
@@ -176,13 +221,13 @@ Update()
   }
 
   if ( !aPolyData || aPolyData->GetNumberOfCells() == 0 ) {
-    myGeometryFilter->SetInput(anUnstructuredGrid);
+    myGeometryFilter->SetInput(aDataSet);
     aPolyData = myGeometryFilter->GetOutput();
     aPolyData->Update();
   }
   if ( !myIsContour ) // surface prs
   {
-    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+    if(VISU::IsDataOnCells(aPolyData)) {
       myCellDataToPointData->SetInput(aPolyData);
       myCellDataToPointData->PassCellDataOn();
       myWarpScalar->SetInput(myCellDataToPointData->GetPolyDataOutput());
@@ -191,21 +236,21 @@ Update()
   }
   else // contour prs
   {
-    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+    if(VISU::IsDataOnCells(aPolyData)) {
       myCellDataToPointData->SetInput(aPolyData);
       myCellDataToPointData->PassCellDataOn();
       myContourFilter->SetInput(myCellDataToPointData->GetOutput());
     }else
       myContourFilter->SetInput(aPolyData);
 
-    float aScalarRange[2];
+    vtkFloatingPointType aScalarRange[2];
     GetSourceRange(aScalarRange);
 
     myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange);
     myWarpScalar->SetInput(myContourFilter->GetOutput());
   }
 
-  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData);
+  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData.GetPointer());
   myAppendPolyData->AddInput(myWarpScalar->GetPolyDataOutput());
 
   if ( aCutPlane )
@@ -213,63 +258,136 @@ Update()
 
   myWarpScalar->SetNormal(aPlaneNormal);
 
-  VISU_ScalarMapPL::Update();
+  Superclass::Update();
 }
 
+
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_Plot3DPL
+::GetMemorySize()
+{
+  unsigned long int aSize = Superclass::GetMemorySize();
+
+  if(vtkDataObject* aDataObject = myGeometryFilter->GetInput())
+    aSize += aDataObject->GetActualMemorySize() * 1024;
+  
+  if(myCellDataToPointData->GetInput())
+    if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
+      aSize += aDataSet->GetActualMemorySize() * 1024;
+
+  if(vtkDataObject* aDataObject = myContourFilter->GetInput())
+    aSize += aDataObject->GetActualMemorySize() * 1024;
+
+  if(vtkDataObject* aDataObject = myWarpScalar->GetInput())
+    aSize += aDataObject->GetActualMemorySize() * 1024;
+
+  int anEnd = myAppendPolyData->GetNumberOfInputConnections(0);
+  for(int anId = 0; anId < anEnd; anId++){
+    if(vtkDataObject* aDataObject = myAppendPolyData->GetInput(anId))
+      aSize += aDataObject->GetActualMemorySize() * 1024;
+  }
+
+  return aSize;
+}
+
+
+//----------------------------------------------------------------------------
 void
-VISU_Plot3DPL::
-SetNumberOfContours(int theNumber)
+VISU_Plot3DPL
+::SetNumberOfContours(int theNumber)
 {
   myContourFilter->SetNumberOfContours(theNumber);
 }
 
+
+//----------------------------------------------------------------------------
 int
-VISU_Plot3DPL::
-GetNumberOfContours() const
+VISU_Plot3DPL
+::GetNumberOfContours()
 {
   return myContourFilter->GetNumberOfContours();
 }
 
+
+//----------------------------------------------------------------------------
 void
-VISU_Plot3DPL::
-SetScaleFactor(float theScaleFactor)
+VISU_Plot3DPL
+::SetScaleFactor(vtkFloatingPointType theScaleFactor)
 {
   myScaleFactor = theScaleFactor;
-  myWarpScalar->SetScaleFactor(theScaleFactor);
+  myWarpScalar->SetScaleFactor(theScaleFactor*myMapScaleFactor);
 }
 
-float
-VISU_Plot3DPL::
-GetScaleFactor() const
+
+//----------------------------------------------------------------------------
+vtkFloatingPointType
+VISU_Plot3DPL
+::GetScaleFactor()
 {
   return myScaleFactor;
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_Plot3DPL::
-SetPlanePosition(float thePosition,
-                bool theIsRelative)
+SetContourPrs(bool theIsContourPrs )
+{
+  if(myIsContour == theIsContourPrs)
+    return;
+
+  myIsContour = theIsContourPrs;
+  Modified();
+}
+
+
+//----------------------------------------------------------------------------
+bool
+VISU_Plot3DPL
+::GetIsContourPrs()
+{
+  return myIsContour;
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_Plot3DPL
+::SetPlanePosition(vtkFloatingPointType thePosition,
+                  bool theIsRelative)
 {
+  bool anIsSameValue = VISU::CheckIsSameValue(myIsRelative, theIsRelative);
+  anIsSameValue &= (myPosition == thePosition);
+  if(anIsSameValue)
+    return;
+
   myIsRelative = theIsRelative;
   myPosition = thePosition;
+  Modified();
 }
 
+
+//----------------------------------------------------------------------------
 bool
-VISU_Plot3DPL::
-IsPositionRelative() const
+VISU_Plot3DPL
+::IsPositionRelative()
 {
   return myIsRelative;
 }
 
+
+//----------------------------------------------------------------------------
 VISU_CutPlanesPL::PlaneOrientation
-VISU_Plot3DPL::
-GetPlaneOrientation() const
+VISU_Plot3DPL
+::GetPlaneOrientation()
 {
   return myOrientation;
 }
 
 
-float
+//----------------------------------------------------------------------------
+vtkFloatingPointType
 VISU_Plot3DPL::
 GetRotateX()
 {
@@ -281,7 +399,9 @@ GetRotateX()
   return 0;
 }
 
-float
+
+//----------------------------------------------------------------------------
+vtkFloatingPointType
 VISU_Plot3DPL::
 GetRotateY(){
   switch(myOrientation){
@@ -292,28 +412,41 @@ GetRotateY(){
   return 0;
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_Plot3DPL::
 SetOrientation(VISU_CutPlanesPL::PlaneOrientation theOrientation,
-              float theXAngle,
-              float theYAngle)
+              vtkFloatingPointType theXAngle,
+              vtkFloatingPointType theYAngle)
 {
+  bool anIsSameValue = VISU::CheckIsSameValue(GetRotateX(), theXAngle);
+  anIsSameValue &= VISU::CheckIsSameValue(GetRotateY(), theYAngle);
+  anIsSameValue &= (myOrientation == theOrientation);
+  if(anIsSameValue)
+    return;
+
   switch(theOrientation){
   case VISU_CutPlanesPL::XY: myAngle[0] = theXAngle; break;
   case VISU_CutPlanesPL::YZ: myAngle[1] = theXAngle; break;
   case VISU_CutPlanesPL::ZX: myAngle[2] = theXAngle; break;
   }
+
   switch(theOrientation){
   case VISU_CutPlanesPL::XY: myAngle[1] = theYAngle; break;
   case VISU_CutPlanesPL::YZ: myAngle[2] = theYAngle; break;
   case VISU_CutPlanesPL::ZX: myAngle[0] = theYAngle; break;
   }
+
   myOrientation = theOrientation;
+  Modified();
 }
 
-float
-VISU_Plot3DPL::
-GetPlanePosition() const
+
+//----------------------------------------------------------------------------
+vtkFloatingPointType
+VISU_Plot3DPL
+::GetPlanePosition()
 {
   return myPosition;
 }
@@ -322,15 +455,16 @@ GetPlanePosition() const
 //function : GetBasePlane
 //purpose  :
 //=======================================================================
-
-void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
-                                 float theNormal[3],
-                                 bool  theCenterOrigine ) const
+void
+VISU_Plot3DPL
+::GetBasePlane(vtkFloatingPointType theOrigin[3],
+              vtkFloatingPointType theNormal[3],
+              bool  theCenterOrigine )
 {
   VISU_CutPlanesPL::GetDir(theNormal,myAngle,myOrientation);
 
-  float aPosition = myPosition;
-  float aBounds[6], aBoundPrj[3];
+  vtkFloatingPointType aPosition = myPosition;
+  vtkFloatingPointType aBounds[6], aBoundPrj[3];
   if ( myIsRelative )
   {
     GetInput()->GetBounds(aBounds);
@@ -341,8 +475,8 @@ void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
 
   if ( theCenterOrigine ) {
     // move theOrigin to the center of aBounds projections to the plane
-    GetInput2()->GetBounds(aBounds);
-    float boundPoints[8][3] = {
+    GetMergedInput()->GetBounds(aBounds);
+    vtkFloatingPointType boundPoints[8][3] = {
       {aBounds[0],aBounds[2],aBounds[4]},
       {aBounds[1],aBounds[2],aBounds[4]},
       {aBounds[0],aBounds[3],aBounds[4]},
@@ -351,9 +485,9 @@ void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
       {aBounds[1],aBounds[2],aBounds[5]},
       {aBounds[0],aBounds[3],aBounds[5]},
       {aBounds[1],aBounds[3],aBounds[5]}};
-    float newOrigin[3] = { 0,0,0 };
+    vtkFloatingPointType newOrigin[3] = { 0,0,0 };
     for(int i = 0; i < 8; i++) {
-      float proj[3];
+      vtkFloatingPointType proj[3];
       vtkPlane::ProjectPoint( boundPoints[i], theOrigin, theNormal, proj );
       newOrigin[0] += proj[0];
       newOrigin[1] += proj[1];
@@ -369,10 +503,12 @@ void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
 //function : GetMinMaxPosition
 //purpose  : return absolute position range
 //=======================================================================
-
-void VISU_Plot3DPL::GetMinMaxPosition( float& minPos, float& maxPos ) const
+void
+VISU_Plot3DPL
+::GetMinMaxPosition( vtkFloatingPointType& minPos, 
+                    vtkFloatingPointType& maxPos )
 {
-  float aBounds[6], aBoundPrj[3], aNormal[3];
+  vtkFloatingPointType aBounds[6], aBoundPrj[3], aNormal[3];
   VISU_CutPlanesPL::GetDir(aNormal,myAngle,myOrientation);
   GetInput()->GetBounds(aBounds);
   VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aNormal);
@@ -385,14 +521,17 @@ void VISU_Plot3DPL::GetMinMaxPosition( float& minPos, float& maxPos ) const
 //purpose  :
 //=======================================================================
 
-void VISU_Plot3DPL::SetMapScale(float theMapScale)
+void 
+VISU_Plot3DPL
+::SetMapScale(vtkFloatingPointType theMapScale)
 {
-  VISU_ScalarMapPL::SetMapScale(theMapScale);
+  myMapScaleFactor = theMapScale;
+  Superclass::SetMapScale(theMapScale);
 
   if ( myIsContour ) {
-    float aRange[2];
+    vtkFloatingPointType aRange[2];
     GetSourceRange(aRange);
-    float aNewRange[] = { aRange[1] - theMapScale*(aRange[1]-aRange[0]), aRange[1] };
+    vtkFloatingPointType aNewRange[] = { aRange[1] - theMapScale*(aRange[1]-aRange[0]), aRange[1] };
     myContourFilter->GenerateValues(GetNumberOfContours(),aNewRange);
   }
   myWarpScalar->SetScaleFactor(myScaleFactor*theMapScale);