From 83b0f13a587b158b31b95a5ab173910334ed7ba7 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 31 May 2016 16:18:36 +0300 Subject: [PATCH] 0027555: Visualization, AIS_Shape - own deviation coefficient change is not considered by Wireframe presentation mode --- src/AIS/AIS_ColoredShape.cxx | 12 +++----- src/AIS/AIS_Shape.cxx | 20 +++--------- src/AIS/AIS_TexturedShape.cxx | 18 ++--------- src/Prs3d/Prs3d_Drawer.hxx | 18 +++++++++++ src/StdPrs/StdPrs_ToolTriangulatedShape.cxx | 34 +++++++++++++++++++++ src/StdPrs/StdPrs_ToolTriangulatedShape.hxx | 12 ++++++++ 6 files changed, 75 insertions(+), 39 deletions(-) diff --git a/src/AIS/AIS_ColoredShape.cxx b/src/AIS/AIS_ColoredShape.cxx index 4d312437fc..6a639f9aa1 100644 --- a/src/AIS/AIS_ColoredShape.cxx +++ b/src/AIS/AIS_ColoredShape.cxx @@ -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); diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 170cc28714..c53664025f 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -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); diff --git a/src/AIS/AIS_TexturedShape.cxx b/src/AIS/AIS_TexturedShape.cxx index b370b76ea4..a5b6593fcb 100644 --- a/src/AIS/AIS_TexturedShape.cxx +++ b/src/AIS/AIS_TexturedShape.cxx @@ -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); diff --git a/src/Prs3d/Prs3d_Drawer.hxx b/src/Prs3d/Prs3d_Drawer.hxx index 7f8595cd48..a114f12194 100644 --- a/src/Prs3d/Prs3d_Drawer.hxx +++ b/src/Prs3d/Prs3d_Drawer.hxx @@ -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. diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx index 96fb16d2b2..e5ba469c55 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.cxx @@ -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(); + } +} diff --git a/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx b/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx index 31710fe009..22c3e6617a 100644 --- a/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx +++ b/src/StdPrs/StdPrs_ToolTriangulatedShape.hxx @@ -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