0027555: Visualization, AIS_Shape - own deviation coefficient change is not considere...
authorkgv <kgv@opencascade.com>
Tue, 31 May 2016 13:18:36 +0000 (16:18 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 9 Jun 2016 09:18:49 +0000 (12:18 +0300)
src/AIS/AIS_ColoredShape.cxx
src/AIS/AIS_Shape.cxx
src/AIS/AIS_TexturedShape.cxx
src/Prs3d/Prs3d_Drawer.hxx
src/StdPrs/StdPrs_ToolTriangulatedShape.cxx
src/StdPrs/StdPrs_ToolTriangulatedShape.hxx

index 4d31243..6a639f9 100644 (file)
@@ -310,14 +310,8 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
     if (myDrawer->IsAutoTriangulation())
     {
       // compute mesh for entire shape beforehand to ensure consistency and optimizations (parallelization)
-      Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
-      Standard_Boolean isOwnDeviationAngle       = OwnDeviationAngle      (anAngleNew, anAnglePrev);
-      Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew,  aCoeffPrev);
-      if ((isOwnDeviationAngle       && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
-       || (isOwnDeviationCoefficient && Abs (aCoeffNew  - aCoeffPrev)  > Precision::Confusion()))
-      {
-        BRepTools::Clean (myshape);
-      }
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
+
       // After this call if type of deflection is relative
       // computed deflection coefficient is stored as absolute.
       Standard_Boolean wasRecomputed = StdPrs_ToolTriangulatedShape::Tessellate (myshape, myDrawer);
@@ -331,6 +325,8 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& ,
   }
   else // WireFrame mode
   {
+    StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
+
     // After this call if type of deflection is relative
     // computed deflection coefficient is stored as absolute.
     Prs3d::GetDeflection (myshape, myDrawer);
index 170cc28..c536640 100644 (file)
@@ -122,7 +122,7 @@ Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
 //=======================================================================
 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
                         const Handle(Prs3d_Presentation)& aPrs,
-                        const Standard_Integer aMode)
+                        const Standard_Integer theMode)
 {  
   aPrs->Clear();
   if(myshape.IsNull()) return;
@@ -144,13 +144,14 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
 
   if (IsInfinite())
   {
-    aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
+    aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
   }
 
-  switch (aMode)
+  switch (theMode)
   {
     case AIS_WireFrame:
     {
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       try
       {
         OCC_CATCH_SIGNALS
@@ -169,18 +170,7 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
     }
     case AIS_Shaded:
     {
-      if (myDrawer->IsAutoTriangulation())
-      {
-        Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
-        Standard_Boolean isOwnDeviationAngle       = OwnDeviationAngle      (anAngleNew, anAnglePrev);
-        Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew,  aCoeffPrev);
-        if ((isOwnDeviationAngle       && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
-         || (isOwnDeviationCoefficient && Abs (aCoeffNew  - aCoeffPrev)  > Precision::Confusion()))
-        {
-          BRepTools::Clean (myshape);
-        }
-      }
-
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       if ((Standard_Integer) myshape.ShapeType() > 4)
       {
         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
index b370b76..a5b6593 100644 (file)
@@ -440,28 +440,14 @@ void AIS_TexturedShape::Compute (const Handle(PrsMgr_PresentationManager3d)& /*t
   {
     case AIS_WireFrame:
     {
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       StdPrs_WFShape::Add (thePrs, myshape, myDrawer);
       break;
     }
     case AIS_Shaded:
     case 3: // texture mapping on triangulation
     {
-      if (myDrawer->IsAutoTriangulation())
-      {
-        Standard_Real aPrevAngle;
-        Standard_Real aNewAngle;
-        Standard_Real aPrevCoeff;
-        Standard_Real aNewCoeff;
-
-        Standard_Boolean isOwnDeviationAngle       = OwnDeviationAngle (aNewAngle, aPrevAngle);
-        Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient (aNewCoeff,aPrevCoeff);
-        if (((Abs (aNewAngle - aPrevAngle) > Precision::Angular()) && isOwnDeviationAngle) ||
-            ((Abs (aNewCoeff - aPrevCoeff) > Precision::Confusion()) && isOwnDeviationCoefficient))
-        {
-          BRepTools::Clean (myshape);
-        }
-      }
-
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       if (myshape.ShapeType() > TopAbs_FACE)
       {
         StdPrs_WFShape::Add (thePrs, myshape, myDrawer);
index 7f8595c..a114f12 100644 (file)
@@ -202,6 +202,15 @@ public:
          : 0.0;
   }
 
+  //! Updates the previous value used for the chordal deviation coefficient to the current state.
+  void UpdatePreviousDeviationCoefficient()
+  {
+    if (myHasOwnDeviationCoefficient)
+    {
+      myPreviousDeviationCoefficient = DeviationCoefficient();
+    }
+  }
+
   //! Sets the deviation coefficient aCoefficient for removal
   //! of hidden lines created by different viewpoints in
   //! different presentations. The Default value is 0.02.
@@ -282,6 +291,15 @@ public:
          : 0.0;
   }
 
+  //! Updates the previous deviation angle to the current value
+  void UpdatePreviousDeviationAngle()
+  {
+    if (myHasOwnDeviationAngle)
+    {
+      myPreviousDeviationAngle = DeviationAngle();
+    }
+  }
+
   //! Sets anAngle, the angle of maximum chordal deviation for removal of hidden lines created by
   //! different viewpoints in different presentations.
   //! The default value is 20 * M_PI / 180.
index 96fb16d..e5ba469 100644 (file)
@@ -252,3 +252,37 @@ Standard_Boolean StdPrs_ToolTriangulatedShape::Tessellate (const TopoDS_Shape&
 
   return wasRecomputed;
 }
+
+// =======================================================================
+// function : ClearOnOwnDeflectionChange
+// purpose  :
+// =======================================================================
+void StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (const TopoDS_Shape&         theShape,
+                                                               const Handle(Prs3d_Drawer)& theDrawer,
+                                                               const Standard_Boolean      theToResetCoeff)
+{
+  if (!theDrawer->IsAutoTriangulation()
+    || theShape.IsNull())
+  {
+    return;
+  }
+
+  const Standard_Boolean isOwnDeviationAngle       = theDrawer->HasOwnDeviationAngle();
+  const Standard_Boolean isOwnDeviationCoefficient = theDrawer->HasOwnDeviationCoefficient();
+  const Standard_Real anAngleNew  = theDrawer->DeviationAngle();
+  const Standard_Real anAnglePrev = theDrawer->PreviousDeviationAngle();
+  const Standard_Real aCoeffNew   = theDrawer->DeviationCoefficient();
+  const Standard_Real aCoeffPrev  = theDrawer->PreviousDeviationCoefficient();
+  if ((!isOwnDeviationAngle       || Abs (anAngleNew - anAnglePrev) <= Precision::Angular())
+   && (!isOwnDeviationCoefficient || Abs (aCoeffNew  - aCoeffPrev)  <= Precision::Confusion()))
+  {
+    return;
+  }
+
+  BRepTools::Clean (theShape);
+  if (theToResetCoeff)
+  {
+    theDrawer->UpdatePreviousDeviationAngle();
+    theDrawer->UpdatePreviousDeviationCoefficient();
+  }
+}
index 31710fe..22c3e66 100644 (file)
@@ -59,6 +59,18 @@ public:
   //! @return true if tesselation was recomputed and false otherwise.
   Standard_EXPORT static Standard_Boolean Tessellate (const TopoDS_Shape& theShape,
                                                       const Handle(Prs3d_Drawer)& theDrawer);
+
+  //! If presentation has own deviation coefficient and IsAutoTriangulation() is true,
+  //! function will compare actual coefficients with previous values and will clear triangulation on their change
+  //! (regardless actual tessellation quality).
+  //! Function is placed here for compatibility reasons - new code should avoid using IsAutoTriangulation().
+  //! @param theShape  [in] the shape
+  //! @param theDrawer [in] the display settings
+  //! @param theToResetCoeff [in] updates coefficients in theDrawer to actual state to avoid redundant recomputations
+  Standard_EXPORT static void ClearOnOwnDeflectionChange (const TopoDS_Shape& theShape,
+                                                          const Handle(Prs3d_Drawer)& theDrawer,
+                                                          const Standard_Boolean theToResetCoeff);
+
 };
 
 #endif