Salome HOME
Porting to VTK 6.
[modules/visu.git] / src / PIPELINE / VISU_CutPlanesPL.cxx
index 22493a104f8b33e3ceb508f0d4579ff7479ce4af..06ab525d24040255c5358799a88575e4c6b98404 100644 (file)
@@ -1,40 +1,50 @@
-//  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_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 <vtkEDFCutter.h>
 #include <vtkPlane.h>
 
-static vtkFloatingPointType EPS = 1.0E-3;
+//#include <vtkUnstructuredGrid.h>
+
+static double EPS = 1.0E-3;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
 
 
 //----------------------------------------------------------------------------
@@ -43,9 +53,15 @@ 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();
 
@@ -58,6 +74,7 @@ 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);
 }
 
 
@@ -65,6 +82,7 @@ VISU_CutPlanesPL
 VISU_CutPlanesPL
 ::~VISU_CutPlanesPL()
 {
+  if(MYDEBUG) MESSAGE("VISU_CutPlanesPL()::~VISU_CutPlanesPL() - "<<this);
   myAppendPolyData->Delete();
   myAppendPolyData = NULL;
 }
@@ -76,7 +94,11 @@ 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;
@@ -87,22 +109,25 @@ VISU_CutPlanesPL
 void
 VISU_CutPlanesPL
 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
-               bool theIsCopyInput)
+                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));
+      else 
+        SetPartDefault(i);
+    }          
   }
 }
 
@@ -113,20 +138,20 @@ VISU_CutPlanesPL
 ::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));
 }
 
 
 //----------------------------------------------------------------------------
-vtkDataSet* 
+vtkAlgorithmOutput* 
 VISU_CutPlanesPL
 ::InsertCustomPL()
 {
-  return myAppendPolyData->GetOutput();
+  return GetWarpVectorOutputPort();
 }
 
 
@@ -135,27 +160,48 @@ void
 VISU_CutPlanesPL
 ::Update()
 {
+  vtkDataSet* aMergedInput = GetMergedInput();
+  if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
+    throw std::runtime_error("Impossible to build presentation");
+
   ClearAppendPolyData(myAppendPolyData);
 
-  SetPartPosition();
 
-  vtkFloatingPointType aDir[3];
+  if(!myVectorialField || !IsDeformed()){
+    SetMergeFilterInput(aMergedInput,aMergedInput);
+  }
+  
+
+  if(VISU::IsDataOnCells(aMergedInput))
+    GetMapper()->SetScalarModeToUseCellData();
+  else
+    GetMapper()->SetScalarModeToUsePointData();
+
+  SetPartPosition();
+  
+  double aDir[3];
   GetDir(aDir, 
-        myAng[0], 
-        myBasePlane[0]);
+         myAng[0], 
+         myBasePlane[0]);
+  
+  double aBounds[6];
 
-  vtkFloatingPointType aBounds[6];
-  GetMergedInput()->GetBounds(aBounds);
+  vtkDataSet* aFilterOutput = GetMergeFilterOutput();
+  
+  aFilterOutput->GetBounds(aBounds);
 
   CutWithPlanes(myAppendPolyData,
-               GetMergedInput(),
-               myNbParts,
-               aDir,
-               aBounds,
-               myPartPosition, 
-               myPartCondition, 
-               myDisplacement[0]);
+                aFilterOutput,
+                myNbParts,
+                aDir,
+                aBounds,
+                myPartPosition, 
+                myPartCondition, 
+                myDisplacement[0]);
+
+  
 
+  SetWarpVectorInput(myAppendPolyData->GetOutput());
   Superclass::Update();
 }
 
@@ -197,10 +243,10 @@ VISU_CutPlanesPL
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointType* 
+double* 
 VISU_CutPlanesPL::
-GetRx(vtkFloatingPointType theRx[3][3], 
-      vtkFloatingPointType thaAng)
+GetRx(double theRx[3][3], 
+      double thaAng)
 {
   theRx[0][0] = 1.0;            theRx[0][1] = 0.0;            theRx[0][2] = 0.0;
   theRx[1][0] = 0.0;            theRx[1][1] = cos(thaAng);    theRx[1][2] = -sin(thaAng);
@@ -211,10 +257,10 @@ GetRx(vtkFloatingPointType theRx[3][3],
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointType* 
+double* 
 VISU_CutPlanesPL
-::GetRy(vtkFloatingPointType theRy[3][3], 
-       vtkFloatingPointType thaAng)
+::GetRy(double theRy[3][3], 
+        double thaAng)
 {
   theRy[0][0] = cos(thaAng);    theRy[0][1] = 0.0;            theRy[0][2] = sin(thaAng);
   theRy[1][0] = 0.0;            theRy[1][1] = 1.0;            theRy[1][2] = 0.0;
@@ -224,10 +270,10 @@ VISU_CutPlanesPL
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointType* 
+double* 
 VISU_CutPlanesPL
-::GetRz(vtkFloatingPointType theRz[3][3], 
-       vtkFloatingPointType thaAng)
+::GetRz(double theRz[3][3], 
+        double thaAng)
 {
   theRz[0][0] = cos(thaAng);    theRz[0][1] = -sin(thaAng);   theRz[0][2] = 0.0;
   theRz[1][0] = sin(thaAng);    theRz[1][1] = cos(thaAng);    theRz[1][2] = 0.0;
@@ -239,8 +285,8 @@ VISU_CutPlanesPL
 //----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::CorrectPnt(vtkFloatingPointType thePnt[3], 
-            const vtkFloatingPointType BoundPrj[6])
+::CorrectPnt(double thePnt[3], 
+             const double BoundPrj[6])
 {
   for(int i = 0, j = 0; i < 3; ++i, j=2*i){
     if(thePnt[i] < BoundPrj[j]) thePnt[i] = BoundPrj[j];
@@ -252,21 +298,21 @@ VISU_CutPlanesPL
 //----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::GetBoundProject(vtkFloatingPointType BoundPrj[3], 
-                 const vtkFloatingPointType BoundBox[6], 
-                 const vtkFloatingPointType Dir[3])
+::GetBoundProject(double BoundPrj[3], 
+                  const double BoundBox[6], 
+                  const double Dir[3])
 {
-  vtkFloatingPointType BoundPoints[8][3] = { {BoundBox[0],BoundBox[2],BoundBox[4]},
-                                            {BoundBox[1],BoundBox[2],BoundBox[4]},
-                                            {BoundBox[0],BoundBox[3],BoundBox[4]},
-                                            {BoundBox[1],BoundBox[3],BoundBox[4]},
-                                            {BoundBox[0],BoundBox[2],BoundBox[5]},
-                                            {BoundBox[1],BoundBox[2],BoundBox[5]},
-                                            {BoundBox[0],BoundBox[3],BoundBox[5]},
-                                            {BoundBox[1],BoundBox[3],BoundBox[5]}};
+  double BoundPoints[8][3] = { {BoundBox[0],BoundBox[2],BoundBox[4]},
+                                             {BoundBox[1],BoundBox[2],BoundBox[4]},
+                                             {BoundBox[0],BoundBox[3],BoundBox[4]},
+                                             {BoundBox[1],BoundBox[3],BoundBox[4]},
+                                             {BoundBox[0],BoundBox[2],BoundBox[5]},
+                                             {BoundBox[1],BoundBox[2],BoundBox[5]},
+                                             {BoundBox[0],BoundBox[3],BoundBox[5]},
+                                             {BoundBox[1],BoundBox[3],BoundBox[5]}};
   BoundPrj[0] = vtkMath::Dot(Dir,BoundPoints[0]), BoundPrj[1] = BoundPrj[0];
   for(int i = 1; i < 8; i++){
-    vtkFloatingPointType tmp = vtkMath::Dot(Dir,BoundPoints[i]);
+    double tmp = vtkMath::Dot(Dir,BoundPoints[i]);
     if(BoundPrj[1] < tmp) BoundPrj[1] = tmp;
     if(BoundPrj[0] > tmp) BoundPrj[0] = tmp;
   }
@@ -281,9 +327,9 @@ VISU_CutPlanesPL
 void
 VISU_CutPlanesPL
 ::SetOrientation(const VISU_CutPlanesPL::PlaneOrientation& theOrient,
-                vtkFloatingPointType theXAng, 
-                vtkFloatingPointType theYAng, 
-                int theNum)
+                 double theXAng, 
+                 double theYAng, 
+                 int theNum)
 {
   myBasePlane[theNum] = theOrient;
   switch(myBasePlane[theNum]){
@@ -307,7 +353,7 @@ VISU_CutPlanesPL
   return myBasePlane[theNum];
 }
 
-vtkFloatingPointTyp
+doubl
 VISU_CutPlanesPL
 ::GetRotateX(int theNum)
 {
@@ -321,7 +367,7 @@ VISU_CutPlanesPL
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointTyp
+doubl
 VISU_CutPlanesPL
 ::GetRotateY(int theNum)
 {
@@ -335,7 +381,7 @@ VISU_CutPlanesPL
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointTyp
+doubl
 VISU_CutPlanesPL
 ::GetDisplacement(int theNum)
 {
@@ -346,8 +392,8 @@ VISU_CutPlanesPL
 //----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::SetDisplacement(vtkFloatingPointType theDisp, 
-                 int theNum) 
+::SetDisplacement(double theDisp, 
+                  int theNum) 
 {
   if(VISU::CheckIsSameValue(myDisplacement[theNum], theDisp))
     return;
@@ -384,7 +430,7 @@ VISU_CutPlanesPL
 void
 VISU_CutPlanesPL
 ::SetPartPosition(int thePartNumber, 
-                 vtkFloatingPointType thePartPosition)
+                  double thePartPosition)
 {
   if(thePartNumber >= myNbParts) 
     return;
@@ -401,34 +447,38 @@ VISU_CutPlanesPL
 
 
 //----------------------------------------------------------------------------
-vtkFloatingPointTyp
+doubl
 VISU_CutPlanesPL
 ::GetPartPosition(int thePartNumber, 
-                 int theNum)
+                  int theNum)
 {
   if(thePartNumber >= myNbParts) 
     return 0;
 
-  vtkFloatingPointType aPosition = myPartPosition[thePartNumber];
+  double aPosition = myPartPosition[thePartNumber];
   if(myPartCondition[thePartNumber]){
-      vtkFloatingPointType aDir[3], aBounds[6], aBoundPrj[3];
-      GetMergedInput()->GetBounds(aBounds);
+      double aDir[3], aBounds[6], aBoundPrj[3];
+      if(!IsDeformed()) 
+        GetMergedInput()->GetBounds(aBounds);
+      else
+        GetMergeFilterOutput()->GetBounds(aBounds);
+
 
       GetDir(aDir,
-            myAng[theNum],
-            myBasePlane[theNum]);
+             myAng[theNum],
+             myBasePlane[theNum]);
 
       GetBoundProject(aBoundPrj,
-                     aBounds,
-                     aDir);
+                      aBounds,
+                      aDir);
 
       if(myNbParts > 1){
-       vtkFloatingPointType aDBoundPrj = aBoundPrj[2]/(myNbParts - 1);
-       vtkFloatingPointType aDisplacement = aDBoundPrj * myDisplacement[theNum];
-       vtkFloatingPointType aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement;
-       aPosition = aStartPosition + thePartNumber*aDBoundPrj;
+        double aDBoundPrj = aBoundPrj[2]/(myNbParts - 1);
+        double aDisplacement = aDBoundPrj * myDisplacement[theNum];
+        double aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement;
+        aPosition = aStartPosition + thePartNumber*aDBoundPrj;
       }else
-       aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[theNum];
+        aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[theNum];
   }
 
   return aPosition;
@@ -469,12 +519,12 @@ VISU_CutPlanesPL
 //----------------------------------------------------------------------------
 void
 VISU_CutPlanesPL
-::GetDir(vtkFloatingPointType theDir[3],
-        const vtkFloatingPointType theAng[3],
-        const PlaneOrientation& theBasePlane)
+::GetDir(double theDir[3],
+         const double theAng[3],
+         const PlaneOrientation& theBasePlane)
 {
   int iPlane = 0;
-  vtkFloatingPointType aRx[3][3], aRy[3][3], aRz[3][3], aRotation[3][3];
+  double aRx[3][3], aRy[3][3], aRz[3][3], aRotation[3][3];
   switch(theBasePlane){
   case XY:
     if(fabs(theAng[0]) > EPS) GetRx(aRx,theAng[0]); else vtkMath::Identity3x3(aRx);
@@ -505,19 +555,19 @@ VISU_CutPlanesPL
 void
 VISU_CutPlanesPL
 ::CutWithPlane(vtkAppendPolyData* theAppendPolyData,
-              vtkDataSet* theDataSet,
-              vtkFloatingPointType theDir[3], 
-              vtkFloatingPointType theOrig[3])
+               vtkDataSet* theDataSet,
+               double theDir[3], 
+               double theOrig[3])
 {
-  vtkCutter *aCutPlane = vtkCutter::New();
-  aCutPlane->SetInput(theDataSet);
+  vtkEDFCutter *aCutPlane = vtkEDFCutter::New();
+  aCutPlane->SetInputData(theDataSet);
   vtkPlane *aPlane = vtkPlane::New();
   aPlane->SetOrigin(theOrig);
 
   aPlane->SetNormal(theDir);
   aCutPlane->SetCutFunction(aPlane);
   aPlane->Delete();
-  theAppendPolyData->AddInput(aCutPlane->GetOutput());
+  theAppendPolyData->AddInputConnection(aCutPlane->GetOutputPort());
   aCutPlane->Delete();
 }
 
@@ -526,26 +576,26 @@ VISU_CutPlanesPL
 void
 VISU_CutPlanesPL
 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
-               vtkDataSet* theDataSet,
-               int theNbPlanes, 
-               vtkFloatingPointType theDir[3], 
-               vtkFloatingPointType theBounds[6],
-               const std::vector<vtkFloatingPointType>& thePlanePosition,
-               const std::vector<int>& thePlaneCondition,
-               vtkFloatingPointType theDisplacement)
+                vtkDataSet* theDataSet,
+                int theNbPlanes, 
+                double theDir[3], 
+                double theBounds[6],
+                const std::vector<double>& thePlanePosition,
+                const std::vector<int>& thePlaneCondition,
+                double theDisplacement)
 {
-  vtkFloatingPointType aBoundPrj[3], aOrig[3], aPosition;
+  double aBoundPrj[3], aOrig[3], aPosition;
   GetBoundProject(aBoundPrj, theBounds, theDir);
   if(theNbPlanes > 1){
-    vtkFloatingPointType aDBoundPrj = aBoundPrj[2]/(theNbPlanes - 1);
-    vtkFloatingPointType aDisplacement = aDBoundPrj*theDisplacement;
-    vtkFloatingPointType aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement;
+    double aDBoundPrj = aBoundPrj[2]/(theNbPlanes - 1);
+    double aDisplacement = aDBoundPrj*theDisplacement;
+    double aStartPosition = aBoundPrj[0] - 0.5*aDBoundPrj + aDisplacement;
     for (int i = 0; i < theNbPlanes; i++){
       aPosition = aStartPosition + i*aDBoundPrj;
       if(thePlaneCondition[i]){
-       aPosition = aStartPosition + i*aDBoundPrj;
+        aPosition = aStartPosition + i*aDBoundPrj;
       }else
-       aPosition = thePlanePosition[i];
+        aPosition = thePlanePosition[i];
       VISU::Mul(theDir,aPosition,aOrig);
       CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig);
     }
@@ -558,9 +608,38 @@ VISU_CutPlanesPL
     CutWithPlane(theAppendPolyData,theDataSet,theDir,aOrig);
   }
   vtkPolyData *aPolyData = theAppendPolyData->GetOutput();
-  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(double theMapScale){
+  Superclass::SetMapScale(theMapScale);
+  if(IsDeformed())
+    VISU_OptionalDeformationPL::SetMapScale(theMapScale);
+}