]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
PostPro 2005, T1.5: 2D fields displayed in 3D. Add GetBasePlane(), GetMinMaxPosition...
authoreap <eap@opencascade.com>
Tue, 3 May 2005 12:53:26 +0000 (12:53 +0000)
committereap <eap@opencascade.com>
Tue, 3 May 2005 12:53:26 +0000 (12:53 +0000)
src/PIPELINE/VISU_Plot3DPL.cxx
src/PIPELINE/VISU_Plot3DPL.hxx

index 2f78d530261122c1265eb9a86c4fb8fdc5a745a4..920e6427a1df735f7a346273f5aed8e27ede91cf 100644 (file)
@@ -52,9 +52,10 @@ VISU_Plot3DPL::VISU_Plot3DPL():
   myWarpScalar(vtkWarpScalar::New(),true),
   myOrientation(VISU_CutPlanesPL::YZ),
   myIsRelative(true),
+  myIsContour(false),
   myPosition(0.5)
 {
-  myAngle[0] = myAngle[1] = myAngle[2];
+  myAngle[0] = myAngle[1] = myAngle[2] = 0.;
   SetNumberOfContours(32);
 }
 
@@ -67,8 +68,15 @@ VISU_Plot3DPL::
 ShallowCopy(VISU_PipeLine *thePipeLine)
 {
   VISU_ScalarMapPL::ShallowCopy(thePipeLine);
-  //if(VISU_Plot3DPL *aPipeLine = dynamic_cast<VISU_Plot3DPL*>(thePipeLine)){
-  //}
+  if(VISU_Plot3DPL *aPipeLine = dynamic_cast<VISU_Plot3DPL*>(thePipeLine)){
+    SetOrientation (aPipeLine->GetPlaneOrientation(),
+                    aPipeLine->GetRotateX(), aPipeLine->GetRotateY());
+    SetPlanePosition (aPipeLine->GetPlanePosition(),
+                      aPipeLine->IsPositionRelative() );
+    SetScaleFactor( aPipeLine->GetScaleFactor() );
+    SetContourPrs( aPipeLine->GetIsContourPrs() );
+    SetNumberOfContours( aPipeLine->GetNumberOfContours() );
+  }
 }
 
 VISU_CutPlanesPL::PlaneOrientation 
@@ -107,13 +115,13 @@ VISU_Plot3DPL::
 GetScaleFactor(vtkDataSet* theDataSet)
 {
   theDataSet->Update();
-  float aLength = theDataSet->GetLength();
+  float aLength = theDataSet->GetLength(); // diagonal length
 
   float aScalarRange[2];
   GetSourceRange(aScalarRange);
 
   static float EPS = 0.3;
-  float aRange = aScalarRange[1] - aScalarRange[0];
+  float aRange = aScalarRange[1];
   if(aRange > 0.0)
     return aLength / aRange * EPS;
 
@@ -141,19 +149,9 @@ void
 VISU_Plot3DPL::
 Update()
 {
-  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData);
-
-  float aDir[3];
-  VISU_CutPlanesPL::GetDir(aDir,myAngle,myOrientation);
-
-  float aBounds[6];
-  GetInput2()->GetBounds(aBounds);
-
-  float aBoundPrj[3];
-  VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aDir);
-
+  float aPlaneNormal[3];
   float anOrigin[3];
-  VISU::Mul(aDir,GetPlanePosition(),anOrigin);
+  GetBasePlane( anOrigin, aPlaneNormal );
 
   vtkUnstructuredGrid* anUnstructuredGrid = 
     myFieldTransform->GetUnstructuredGridOutput();
@@ -162,36 +160,44 @@ Update()
 
   vtkPlane *aPlane = vtkPlane::New();
   aPlane->SetOrigin(anOrigin); 
-  aPlane->SetNormal(aDir);
+  aPlane->SetNormal(aPlaneNormal);
 
   aCutPlane->SetCutFunction(aPlane);
   aPlane->Delete();
 
+  VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData);
+
   vtkPolyData* aPolyData = aCutPlane->GetOutput();
   aPolyData->Update();
+
   if(aPolyData->GetNumberOfCells() == 0){
     myGeometryFilter->SetInput(anUnstructuredGrid);
     aPolyData = myGeometryFilter->GetOutput();
   }
-  myWarpScalar->SetInput(aPolyData);
+  if ( !myIsContour ) // surface prs
+  {
+    myWarpScalar->SetInput(aPolyData);
+  }
+  else // contour prs
+  {
+    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+      myCellDataToPointData->SetInput(aPolyData);
+      myCellDataToPointData->PassCellDataOn();
+      myContourFilter->SetInput(myCellDataToPointData->GetOutput());
+    }else
+      myContourFilter->SetInput(aPolyData);
+
+    float aScalarRange[2];
+    GetSourceRange(aScalarRange);
+
+    myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange);
+    myWarpScalar->SetInput(myContourFilter->GetOutput());
+  }
   myAppendPolyData->AddInput(myWarpScalar->GetPolyDataOutput());
-  
-  float aScalarRange[2];
-  GetSourceRange(aScalarRange);
-  
-  if(aPolyData->GetCellData()->GetNumberOfArrays()){
-    myCellDataToPointData->SetInput(aPolyData);
-    myCellDataToPointData->PassCellDataOn();
-    myContourFilter->SetInput(myCellDataToPointData->GetOutput());
-  }else
-    myContourFilter->SetInput(aPolyData);
-  
-  myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange);
-  myAppendPolyData->AddInput(myContourFilter->GetOutput());
 
   aCutPlane->Delete();
 
-  myWarpScalar->SetNormal(aDir);
+  myWarpScalar->SetNormal(aPlaneNormal);
 
   VISU_ScalarMapPL::Update();
 }
@@ -294,17 +300,68 @@ float
 VISU_Plot3DPL::
 GetPlanePosition() const
 {
-  if(!myIsRelative)
-    return myPosition;
+  return myPosition;
+}
 
-  float aBounds[6];
-  GetInput2()->GetBounds(aBounds);
+//=======================================================================
+//function : GetBasePlane
+//purpose  : 
+//=======================================================================
 
-  float aDir[3];
-  VISU_CutPlanesPL::GetDir(aDir,myAngle,myOrientation);
+void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
+                                 float theNormal[3],
+                                 bool  theCenterOrigine ) const
+{
+  VISU_CutPlanesPL::GetDir(theNormal,myAngle,myOrientation);
+
+  float aPosition = myPosition;
+  float aBounds[6], aBoundPrj[3];
+  if ( myIsRelative )
+  {
+    GetInput()->GetBounds(aBounds);
+    VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,theNormal);
+    aPosition = aBoundPrj[0] + aBoundPrj[2]*myPosition;
+  }
+  VISU::Mul(theNormal,aPosition,theOrigin);
+
+  if ( theCenterOrigine ) {
+    // move theOrigin to the center of aBounds projections to the plane
+    GetInput2()->GetBounds(aBounds);
+    float boundPoints[8][3] = {
+      {aBounds[0],aBounds[2],aBounds[4]},
+      {aBounds[1],aBounds[2],aBounds[4]},
+      {aBounds[0],aBounds[3],aBounds[4]},
+      {aBounds[1],aBounds[3],aBounds[4]},
+      {aBounds[0],aBounds[2],aBounds[5]},
+      {aBounds[1],aBounds[2],aBounds[5]}, 
+      {aBounds[0],aBounds[3],aBounds[5]}, 
+      {aBounds[1],aBounds[3],aBounds[5]}};
+    float newOrigin[3] = { 0,0,0 };
+    for(int i = 0; i < 8; i++) {
+      float proj[3];
+      vtkPlane::ProjectPoint( boundPoints[i], theOrigin, theNormal, proj );
+      newOrigin[0] += proj[0];
+      newOrigin[1] += proj[1];
+      newOrigin[2] += proj[2];
+    }
+    theOrigin[0] = newOrigin[0] / 8.;
+    theOrigin[1] = newOrigin[1] / 8.;
+    theOrigin[2] = newOrigin[2] / 8.;
+  }
+}
 
-  float aBoundPrj[3];
-  VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aDir);
+//=======================================================================
+//function : GetMinMaxPosition
+//purpose  : return absolute position range
+//=======================================================================
 
-  return aBoundPrj[0] + aBoundPrj[2]*myPosition;
+void VISU_Plot3DPL::GetMinMaxPosition( float& minPos, float& maxPos ) const
+{
+  float aBounds[6], aBoundPrj[3], aNormal[3];
+  VISU_CutPlanesPL::GetDir(aNormal,myAngle,myOrientation);
+  GetInput()->GetBounds(aBounds);
+  VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aNormal);
+  minPos = aBoundPrj[0];
+  maxPos = aBoundPrj[1];
 }
+
index 1e40692881ce3e4d3661f1291fdda904f182f2e1..467e81ebd7bb1cff6f3ef2ab7927501c55f30a18 100644 (file)
@@ -79,12 +79,24 @@ public:
   float 
   GetScaleFactor() const;
 
+  void
+  SetContourPrs (bool theIsContourPrs ) { myIsContour = theIsContourPrs; }
+
+  bool
+  GetIsContourPrs() { return myIsContour; }
+
   void
   SetNumberOfContours(int theNumber);
 
   int
   GetNumberOfContours() const;
 
+  void GetBasePlane (float theOrigin[3],
+                     float theNormal[3],
+                     bool  theCenterOrigine = false ) const;
+
+  void GetMinMaxPosition( float& minPos, float& maxPos ) const;
+
 public:
   virtual void Init();
   virtual void Update();
@@ -100,7 +112,7 @@ protected:
   virtual THook* DoHook();
 
   float myAngle[3];
-  bool myIsRelative;
+  bool myIsRelative, myIsContour;
   float myPosition;
   VISU_CutPlanesPL::PlaneOrientation myOrientation;