Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / PIPELINE / VISU_CutPlanesPL.cxx
index 8bd5837f093a88f734ab8053e3a09c8a2dd26e9e..ca90de17199298b574eea11196a3356400ac8093 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_CutPlanesPL.hxx"
+#include "VISU_FieldTransform.hxx"
 #include "VISU_PipeLineUtils.hxx"
 #include "VTKViewer_GeometryFilter.h"
+#include "VISU_MapperHolder.hxx"
+#include "VISU_DeformationPL.hxx"
 
 #include <vtkAppendPolyData.h>
 #include <vtkCutter.h>
 #include <vtkPlane.h>
 
-using namespace std;
+//#include <vtkUnstructuredGrid.h>
 
 static vtkFloatingPointType EPS = 1.0E-3;
 
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//----------------------------------------------------------------------------
 vtkStandardNewMacro(VISU_CutPlanesPL);
 
+
+//----------------------------------------------------------------------------
 VISU_CutPlanesPL
-::VISU_CutPlanesPL()
+::VISU_CutPlanesPL():
+  VISU_OptionalDeformationPL()
 {
+  if(MYDEBUG) MESSAGE("VISU_CutPlanesPL()::VISU_CutPlanesPL() - "<<this);
+  
+  SetIsShrinkable(false);
+  SetIsFeatureEdgesAllowed(false);
+
+  SetElnoDisassembleState( true );
+
   myAppendPolyData = vtkAppendPolyData::New();
-  myIsShrinkable = false;
 
   myNbParts = 10;
 
@@ -54,65 +73,151 @@ VISU_CutPlanesPL
 
   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
+  UseDeformation(false);
 }
 
+
+//----------------------------------------------------------------------------
 VISU_CutPlanesPL
 ::~VISU_CutPlanesPL()
 {
+  if(MYDEBUG) MESSAGE("VISU_CutPlanesPL()::~VISU_CutPlanesPL() - "<<this);
   myAppendPolyData->Delete();
+  myAppendPolyData = NULL;
 }
 
+
+//----------------------------------------------------------------------------
+unsigned long int 
+VISU_CutPlanesPL
+::GetMTime()
+{
+  unsigned long int aTime = Superclass::GetMTime();
+  
+  if(IsDeformed()) {
+    aTime = std::max(aTime, VISU_OptionalDeformationPL::GetMTime());
+  }
+  
+  aTime = std::max(aTime, myAppendPolyData->GetMTime());
+
+  return aTime;
+}
+
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::ShallowCopy(VISU_PipeLine *thePipeLine)
+::DoShallowCopy(VISU_PipeLine *thePipeLine,
+               bool theIsCopyInput)
 {
+  Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
+
   if(VISU_CutPlanesPL *aPipeLine = dynamic_cast<VISU_CutPlanesPL*>(thePipeLine)){
+
     SetOrientation(aPipeLine->GetPlaneOrientation(),
-                  aPipeLine->GetRotateX(),aPipeLine->GetRotateY());
+                  aPipeLine->GetRotateX(),
+                  aPipeLine->GetRotateY());
+
     SetDisplacement(aPipeLine->GetDisplacement());
+
     SetNbParts(aPipeLine->GetNbParts());
-    for (int i = 0, iend = GetNbParts(); i < iend; i++)
-      if(!aPipeLine->IsPartDefault(i))         SetPartPosition(i, aPipeLine->GetPartPosition(i));
+    for (int i = 0, iEnd = GetNbParts(); i < iEnd; i++)
+      if(!aPipeLine->IsPartDefault(i))         
+       SetPartPosition(i, aPipeLine->GetPartPosition(i));
   }
-  VISU_ScalarMapPL::ShallowCopy(thePipeLine);
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::Init()
 {
-  VISU_ScalarMapPL::Init();
-
+  Superclass::Init();
   SetNbParts(10);
   myBasePlane[0] = YZ;
   myDisplacement[0] = 0.5;
   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
+  SetScale(VISU_DeformationPL::GetDefaultScaleFactor(this));
 }
 
-VISU_ScalarMapPL::THook* 
+
+//----------------------------------------------------------------------------
+vtkDataSet* 
 VISU_CutPlanesPL
-::DoHook()
+::InsertCustomPL()
 {
-  return myAppendPolyData->GetOutput();
+  return GetWarpVectorOutput();
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::Update()
 {
   ClearAppendPolyData(myAppendPolyData);
+
+
+  if(!myVectorialField || !IsDeformed()){
+    SetMergeFilterInput(GetMergedInput(),GetMergedInput());
+  }
+  
+
+  if(VISU::IsDataOnCells(GetMergedInput()))
+    GetMapper()->SetScalarModeToUseCellData();
+  else
+    GetMapper()->SetScalarModeToUsePointData();
+
   SetPartPosition();
+  
   vtkFloatingPointType aDir[3];
-  GetDir(aDir,myAng[0],myBasePlane[0]);
+  GetDir(aDir, 
+        myAng[0], 
+        myBasePlane[0]);
+  
   vtkFloatingPointType aBounds[6];
-  GetInput2()->GetBounds(aBounds);
-  vtkDataSet* aDataSet = myFieldTransform->GetUnstructuredGridOutput();
-  CutWithPlanes(myAppendPolyData,aDataSet,myNbParts,aDir,aBounds,
-               myPartPosition,myPartCondition,myDisplacement[0]);
 
-  VISU_ScalarMapPL::Update();
+  vtkDataSet* aFilterOutput = GetMergeFilterOutput();
+  
+  aFilterOutput->GetBounds(aBounds);
+
+  CutWithPlanes(myAppendPolyData,
+                aFilterOutput,
+               myNbParts,
+               aDir,
+               aBounds,
+               myPartPosition, 
+               myPartCondition, 
+               myDisplacement[0]);
+
+  
+
+  SetWarpVectorInput(myAppendPolyData->GetOutput());
+  Superclass::Update();
 }
 
+
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_CutPlanesPL
+::GetMemorySize()
+{
+  unsigned long int aSize = Superclass::GetMemorySize();
+
+  if(vtkDataSet* aDataSet = myAppendPolyData->GetOutput())
+    aSize += aDataSet->GetActualMemorySize() * 1024;
+  
+  int anEnd = myAppendPolyData->GetNumberOfInputConnections(0);
+  for(int anId = 0; anId < anEnd; anId++)
+    if(vtkDataSet* aDataSet = myAppendPolyData->GetInput(anId))
+      aSize += aDataSet->GetActualMemorySize() * 1024;
+
+  return aSize;
+}
+
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::SetPartPosition(int theNum)
@@ -125,11 +230,11 @@ void
 VISU_CutPlanesPL
 ::ClearAppendPolyData(vtkAppendPolyData *theAppendPolyData)
 {
-  int iEnd = theAppendPolyData->GetNumberOfInputs();
-  for(int i = iEnd-1; i >= 0; i--)
-    theAppendPolyData->RemoveInput(theAppendPolyData->GetInput(i));
+  theAppendPolyData->RemoveAllInputs();
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType* 
 VISU_CutPlanesPL::
 GetRx(vtkFloatingPointType theRx[3][3], 
@@ -142,6 +247,8 @@ GetRx(vtkFloatingPointType theRx[3][3],
 }
 
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType* 
 VISU_CutPlanesPL
 ::GetRy(vtkFloatingPointType theRy[3][3], 
@@ -154,6 +261,7 @@ VISU_CutPlanesPL
 }
 
 
+//----------------------------------------------------------------------------
 vtkFloatingPointType* 
 VISU_CutPlanesPL
 ::GetRz(vtkFloatingPointType theRz[3][3], 
@@ -166,6 +274,7 @@ VISU_CutPlanesPL
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::CorrectPnt(vtkFloatingPointType thePnt[3], 
@@ -177,6 +286,8 @@ VISU_CutPlanesPL
   }
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::GetBoundProject(vtkFloatingPointType BoundPrj[3], 
@@ -204,6 +315,7 @@ VISU_CutPlanesPL
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::SetOrientation(const VISU_CutPlanesPL::PlaneOrientation& theOrient,
@@ -225,6 +337,7 @@ VISU_CutPlanesPL
 }
 
 
+//----------------------------------------------------------------------------
 const VISU_CutPlanesPL::PlaneOrientation& 
 VISU_CutPlanesPL
 ::GetPlaneOrientation(int theNum)
@@ -244,6 +357,8 @@ VISU_CutPlanesPL
   return 0;
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType 
 VISU_CutPlanesPL
 ::GetRotateY(int theNum)
@@ -257,41 +372,99 @@ VISU_CutPlanesPL
 }
 
 
+//----------------------------------------------------------------------------
+vtkFloatingPointType 
+VISU_CutPlanesPL
+::GetDisplacement(int theNum)
+{
+  return myDisplacement[theNum];
+}
+
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::SetNbParts(int theNb) 
+::SetDisplacement(vtkFloatingPointType theDisp, 
+                 int theNum) 
 {
-  myNbParts = theNb;
-  myPartPosition.resize(myNbParts);
-  myPartCondition.resize(myNbParts,1);
+  if(VISU::CheckIsSameValue(myDisplacement[theNum], theDisp))
+    return;
+
+  myDisplacement[theNum] = theDisp;
   Modified();
 }
 
 
+//----------------------------------------------------------------------------
+void
+VISU_CutPlanesPL
+::SetNbParts(int theNbParts) 
+{
+  if(theNbParts > 0 && GetNbParts() != theNbParts){
+    myPartPosition.resize(theNbParts);
+    myPartCondition.resize(theNbParts, 1);
+    myNbParts = theNbParts;
+    Modified();
+  }
+}
+
+
+//----------------------------------------------------------------------------
+int
+VISU_CutPlanesPL
+::GetNbParts() 
+{
+  return myPartPosition.size();
+}
+
+
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::SetPartPosition(int thePartNumber, 
                  vtkFloatingPointType thePartPosition)
 {
-  if(thePartNumber >= myNbParts) return;
+  if(thePartNumber >= myNbParts) 
+    return;
+
+  bool anIsSameValue = VISU::CheckIsSameValue(myPartPosition[thePartNumber], thePartPosition);
+  anIsSameValue &= VISU::CheckIsSameValue(myPartCondition[thePartNumber], 0);
+  if(anIsSameValue)
+    return;
+
   myPartPosition[thePartNumber] = thePartPosition;
   myPartCondition[thePartNumber] = 0;
   Modified();
 }
 
+
+//----------------------------------------------------------------------------
 vtkFloatingPointType 
 VISU_CutPlanesPL
 ::GetPartPosition(int thePartNumber, 
                  int theNum)
 {
-  if(thePartNumber >= myNbParts) return 0;
+  if(thePartNumber >= myNbParts) 
+    return 0;
+
   vtkFloatingPointType aPosition = myPartPosition[thePartNumber];
   if(myPartCondition[thePartNumber]){
       vtkFloatingPointType aDir[3], aBounds[6], aBoundPrj[3];
-      GetInput2()->GetBounds(aBounds);
-      GetDir(aDir,myAng[theNum],myBasePlane[theNum]);
-      GetBoundProject(aBoundPrj,aBounds,aDir);
-      if (myNbParts > 1){
+      if(!IsDeformed()) 
+        GetMergedInput()->GetBounds(aBounds);
+      else
+        GetMergeFilterOutput()->GetBounds(aBounds);
+
+
+      GetDir(aDir,
+            myAng[theNum],
+            myBasePlane[theNum]);
+
+      GetBoundProject(aBoundPrj,
+                     aBounds,
+                     aDir);
+
+      if(myNbParts > 1){
        vtkFloatingPointType aDBoundPrj = aBoundPrj[2]/(myNbParts - 1);
        vtkFloatingPointType aDisplacement = aDBoundPrj * myDisplacement[theNum];
        vtkFloatingPointType aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement;
@@ -299,28 +472,43 @@ VISU_CutPlanesPL
       }else
        aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[theNum];
   }
+
   return aPosition;
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::SetPartDefault(int thePartNumber)
 {
-  if(thePartNumber >= myNbParts) return;
+  if(thePartNumber >= myNbParts) 
+    return;
+
+  bool anIsSameValue = VISU::CheckIsSameValue(myPartPosition[thePartNumber], GetPartPosition(thePartNumber));
+  anIsSameValue &= VISU::CheckIsSameValue(myPartCondition[thePartNumber], 1);
+  if(anIsSameValue)
+    return;
+
   myPartPosition[thePartNumber] = GetPartPosition(thePartNumber);
   myPartCondition[thePartNumber] = 1;
   Modified();
 }
+
+
+//----------------------------------------------------------------------------
 int
 VISU_CutPlanesPL
 ::IsPartDefault(int thePartNumber)
 {
-  if(thePartNumber >= myNbParts) return 1;
+  if(thePartNumber >= myNbParts) 
+    return 1;
+
   return myPartCondition[thePartNumber];
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::GetDir(vtkFloatingPointType theDir[3],
@@ -349,11 +537,13 @@ VISU_CutPlanesPL
     iPlane = 1;
     break;
   }
+
   for(int i = 0; i < 3; i++)
     theDir[i] = aRotation[i][iPlane];
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::CutWithPlane(vtkAppendPolyData* theAppendPolyData,
@@ -370,11 +560,11 @@ VISU_CutPlanesPL
   aCutPlane->SetCutFunction(aPlane);
   aPlane->Delete();
   theAppendPolyData->AddInput(aCutPlane->GetOutput());
-  aCutPlane->Register(theAppendPolyData);
   aCutPlane->Delete();
 }
 
 
+//----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
@@ -382,8 +572,8 @@ VISU_CutPlanesPL
                int theNbPlanes, 
                vtkFloatingPointType theDir[3], 
                vtkFloatingPointType theBounds[6],
-               const vector<vtkFloatingPointType>& thePlanePosition,
-               const vector<int>& thePlaneCondition,
+               const std::vector<vtkFloatingPointType>& thePlanePosition,
+               const std::vector<int>& thePlaneCondition,
                vtkFloatingPointType theDisplacement)
 {
   vtkFloatingPointType aBoundPrj[3], aOrig[3], aPosition;
@@ -413,3 +603,36 @@ VISU_CutPlanesPL
   aPolyData->Update();
   theAppendPolyData->Update();
 }
+
+
+//----------------------------------------------------------------------------
+void
+VISU_CutPlanesPL::SetVectorialField(VISU::PUnstructuredGridIDMapper theMapper)
+{  
+  if(myVectorialField == theMapper)
+    return;
+
+  if(CheckCanDeformate(theMapper->GetOutput())){
+    myVectorialField = theMapper;
+    
+    SetMergeFilterInput(GetMergedInput(),theMapper->GetOutput());
+  }
+  else
+    UseDeformation(false);
+  
+  Modified();
+}
+
+//----------------------------------------------------------------------------
+VISU::PUnstructuredGridIDMapper VISU_CutPlanesPL::
+getVectorialField()
+{
+  return myVectorialField;
+}
+
+//----------------------------------------------------------------------------
+void VISU_CutPlanesPL::SetMapScale(vtkFloatingPointType theMapScale){
+  Superclass::SetMapScale(theMapScale);
+  if(IsDeformed())
+    VISU_OptionalDeformationPL::SetMapScale(theMapScale);
+}