Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_Plot3DPL.cxx
index 2b87e56f32ba96130af4c7a0868ce2f8f0164a7b..d4fc2bd3593ef8685f6e357fb2e1a6292a1d50a2 100644 (file)
-//  VISU OBJECT : interactive object for VISU entities implementation
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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.
+// 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.
+// 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
+// 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_PipeLine.cxx
 // Author:  Alexey PETROV
 // Module : VISU
-
-
+//
 #include "VISU_Plot3DPL.hxx"
 #include "VISU_CutPlanesPL.hxx"
 #include "VISU_PipeLineUtils.hxx"
 
 #include <vtkAppendPolyData.h>
-#include <vtkCutter.h>
+#include <vtkEDFCutter.h>
 #include <vtkPlane.h>
 
-#include <vtkCellDataToPointData.h>
 #include <vtkGeometryFilter.h>
 #include <vtkContourFilter.h>
 #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(VISU_CellDataToPointData::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)
 {
+  Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
+
   if(VISU_Plot3DPL *aPipeLine = dynamic_cast<VISU_Plot3DPL*>(thePipeLine)){
     SetOrientation (aPipeLine->GetPlaneOrientation(),
                     aPipeLine->GetRotateX(), aPipeLine->GetRotateY());
@@ -77,12 +113,13 @@ ShallowCopy(VISU_PipeLine *thePipeLine)
     SetContourPrs( aPipeLine->GetIsContourPrs() );
     SetNumberOfContours( aPipeLine->GetNumberOfContours() );
   }
-  VISU_ScalarMapPL::ShallowCopy(thePipeLine);
 }
 
+
+//----------------------------------------------------------------------------
 VISU_CutPlanesPL::PlaneOrientation
-VISU_Plot3DPL::
-GetOrientation(vtkDataSet* theDataSet)
+VISU_Plot3DPL
+::GetOrientation(vtkDataSet* theDataSet)
 {
   theDataSet->Update();
 
@@ -111,15 +148,18 @@ GetOrientation(vtkDataSet* theDataSet)
   return VISU_CutPlanesPL::XY;
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType
-VISU_Plot3DPL::
-GetScaleFactor(vtkDataSet* theDataSet)
+VISU_Plot3DPL
+::GetScaleFactor( VISU_ColoredPL* theColoredPL,
+                  vtkDataSet* theDataSet )
 {
   theDataSet->Update();
   vtkFloatingPointType aLength = theDataSet->GetLength(); // diagonal length
 
   vtkFloatingPointType aScalarRange[2];
-  GetSourceRange(aScalarRange);
+  theColoredPL->GetSourceRange(aScalarRange);
 
   static vtkFloatingPointType EPS = 0.3;
   vtkFloatingPointType aRange = aScalarRange[1];
@@ -129,40 +169,48 @@ GetScaleFactor(vtkDataSet* theDataSet)
   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()
 {
+  vtkDataSet* aMergedInput = GetMergedInput();
+  if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
+    throw std::runtime_error("Impossible to build presentation");
+
   vtkFloatingPointType aPlaneNormal[3];
   vtkFloatingPointType anOrigin[3];
   GetBasePlane( anOrigin, aPlaneNormal );
 
   vtkPolyData* aPolyData = 0;
-  vtkCutter *aCutPlane = 0;
-  vtkUnstructuredGrid* anUnstructuredGrid =
-    myFieldTransform->GetUnstructuredGridOutput();
+  vtkEDFCutter *aCutPlane = 0;
 
   if ( !IsPlanarInput() )
   {
-    aCutPlane = vtkCutter::New();
-    aCutPlane->SetInput(anUnstructuredGrid);
+    aCutPlane = vtkEDFCutter::New();
+    aCutPlane->SetInput(aMergedInput);
 
     vtkPlane *aPlane = vtkPlane::New();
     aPlane->SetOrigin(anOrigin);
@@ -176,13 +224,13 @@ Update()
   }
 
   if ( !aPolyData || aPolyData->GetNumberOfCells() == 0 ) {
-    myGeometryFilter->SetInput(anUnstructuredGrid);
+    myGeometryFilter->SetInput(aMergedInput);
     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,7 +239,7 @@ Update()
   }
   else // contour prs
   {
-    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+    if(VISU::IsDataOnCells(aPolyData)) {
       myCellDataToPointData->SetInput(aPolyData);
       myCellDataToPointData->PassCellDataOn();
       myContourFilter->SetInput(myCellDataToPointData->GetOutput());
@@ -205,7 +253,7 @@ Update()
     myWarpScalar->SetInput(myContourFilter->GetOutput());
   }
 
-  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData);
+  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData.GetPointer());
   myAppendPolyData->AddInput(myWarpScalar->GetPolyDataOutput());
 
   if ( aCutPlane )
@@ -213,62 +261,135 @@ 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(vtkFloatingPointType theScaleFactor)
+VISU_Plot3DPL
+::SetScaleFactor(vtkFloatingPointType theScaleFactor)
 {
   myScaleFactor = theScaleFactor;
-  myWarpScalar->SetScaleFactor(theScaleFactor);
+  myWarpScalar->SetScaleFactor(theScaleFactor*myMapScaleFactor);
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType
-VISU_Plot3DPL::
-GetScaleFactor() const
+VISU_Plot3DPL
+::GetScaleFactor()
 {
   return myScaleFactor;
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_Plot3DPL::
-SetPlanePosition(vtkFloatingPointType 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;
 }
 
 
+//----------------------------------------------------------------------------
 vtkFloatingPointType
 VISU_Plot3DPL::
 GetRotateX()
@@ -281,6 +402,8 @@ GetRotateX()
   return 0;
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType
 VISU_Plot3DPL::
 GetRotateY(){
@@ -292,28 +415,41 @@ GetRotateY(){
   return 0;
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_Plot3DPL::
 SetOrientation(VISU_CutPlanesPL::PlaneOrientation theOrientation,
-              vtkFloatingPointType theXAngle,
-              vtkFloatingPointType 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();
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType
-VISU_Plot3DPL::
-GetPlanePosition() const
+VISU_Plot3DPL
+::GetPlanePosition()
 {
   return myPosition;
 }
@@ -322,10 +458,11 @@ GetPlanePosition() const
 //function : GetBasePlane
 //purpose  :
 //=======================================================================
-
-void VISU_Plot3DPL::GetBasePlane(vtkFloatingPointType theOrigin[3],
-                                 vtkFloatingPointType theNormal[3],
-                                 bool  theCenterOrigine ) const
+void
+VISU_Plot3DPL
+::GetBasePlane(vtkFloatingPointType theOrigin[3],
+               vtkFloatingPointType theNormal[3],
+               bool  theCenterOrigine )
 {
   VISU_CutPlanesPL::GetDir(theNormal,myAngle,myOrientation);
 
@@ -341,7 +478,7 @@ void VISU_Plot3DPL::GetBasePlane(vtkFloatingPointType theOrigin[3],
 
   if ( theCenterOrigine ) {
     // move theOrigin to the center of aBounds projections to the plane
-    GetInput2()->GetBounds(aBounds);
+    GetMergedInput()->GetBounds(aBounds);
     vtkFloatingPointType boundPoints[8][3] = {
       {aBounds[0],aBounds[2],aBounds[4]},
       {aBounds[1],aBounds[2],aBounds[4]},
@@ -369,9 +506,10 @@ void VISU_Plot3DPL::GetBasePlane(vtkFloatingPointType theOrigin[3],
 //function : GetMinMaxPosition
 //purpose  : return absolute position range
 //=======================================================================
-
-void VISU_Plot3DPL::GetMinMaxPosition( vtkFloatingPointType& minPos, 
-                                      vtkFloatingPointType& maxPos ) const
+void
+VISU_Plot3DPL
+::GetMinMaxPosition( vtkFloatingPointType& minPos, 
+                     vtkFloatingPointType& maxPos )
 {
   vtkFloatingPointType aBounds[6], aBoundPrj[3], aNormal[3];
   VISU_CutPlanesPL::GetDir(aNormal,myAngle,myOrientation);
@@ -386,9 +524,12 @@ void VISU_Plot3DPL::GetMinMaxPosition( vtkFloatingPointType& minPos,
 //purpose  :
 //=======================================================================
 
-void VISU_Plot3DPL::SetMapScale(vtkFloatingPointType theMapScale)
+void 
+VISU_Plot3DPL
+::SetMapScale(vtkFloatingPointType theMapScale)
 {
-  VISU_ScalarMapPL::SetMapScale(theMapScale);
+  myMapScaleFactor = theMapScale;
+  Superclass::SetMapScale(theMapScale);
 
   if ( myIsContour ) {
     vtkFloatingPointType aRange[2];