From f0144633d9477689dcda93d7ea9e40e79c273924 Mon Sep 17 00:00:00 2001 From: jgv Date: Fri, 25 Mar 2016 17:40:07 +0300 Subject: [PATCH] 0027271: Unifysamedomain invalid result Prevent merging of faces along periodic direction. Test case "bugs heal bug27000_1" has been corrected to actual state of the algorithm. --- .../ShapeUpgrade_UnifySameDomain.cxx | 74 +++++++++++++++---- tests/bugs/heal/bug27000_1 | 2 +- tests/bugs/modalg_6/bug27271 | 11 +++ 3 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 tests/bugs/modalg_6/bug27271 diff --git a/src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx b/src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx index d6d435fecd..b36a1f79f8 100644 --- a/src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx +++ b/src/ShapeUpgrade/ShapeUpgrade_UnifySameDomain.cxx @@ -86,6 +86,8 @@ #include #include #include +#include +#include IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_UnifySameDomain,MMgt_TShared) @@ -95,6 +97,42 @@ struct SubSequenceOfEdges TopoDS_Edge UnionEdges; }; +static Standard_Boolean IsLikeSeam(const TopoDS_Edge& anEdge, + const TopoDS_Face& aFace, + const Handle(Geom_Surface)& aBaseSurface) +{ + if (!aBaseSurface->IsUPeriodic() && !aBaseSurface->IsVPeriodic()) + return Standard_False; + + BRepAdaptor_Curve2d BAcurve2d(anEdge, aFace); + gp_Pnt2d FirstPoint, LastPoint; + gp_Vec2d FirstDir, LastDir; + BAcurve2d.D1(BAcurve2d.FirstParameter(), FirstPoint, FirstDir); + BAcurve2d.D1(BAcurve2d.LastParameter(), LastPoint, LastDir); + Standard_Real Length = FirstDir.Magnitude(); + if (Length <= gp::Resolution()) + return Standard_False; + else + FirstDir /= Length; + Length = LastDir.Magnitude(); + if (Length <= gp::Resolution()) + return Standard_False; + else + LastDir /= Length; + + Standard_Real Tol = 1.e-7; + if (aBaseSurface->IsUPeriodic() && + (Abs(FirstDir.X()) < Tol) && + (Abs(LastDir.X()) < Tol)) + return Standard_True; + + if (aBaseSurface->IsVPeriodic() && + (Abs(FirstDir.Y()) < Tol) && + (Abs(LastDir.Y()) < Tol)) + return Standard_True; + + return Standard_False; +} //======================================================================= //function : AddOrdinaryEdges @@ -641,11 +679,11 @@ static Standard_Boolean MergeSubSeq(const TopTools_SequenceOfShape& aChain, Topo } if (Abs(FP) < Precision::PConfusion()) { - B.MakeEdge (E,Cir,Precision::Confusion()); - B.Add(E,V1); - B.Add(E,V2); - E.Orientation(FE.Orientation()); - } + B.MakeEdge (E,Cir, Precision::Confusion()); + B.Add(E,V1); + B.Add(E,V2); + E.Orientation(FE.Orientation()); + } else { GC_MakeCircle MC1 (adef.Value(FP), adef.Value((FP + LP) * 0.5), adef.Value(LP)); @@ -869,7 +907,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges, if (!aMapVE.Contains(aV)) aMapVE.Add(aV, TopTools_ListOfShape()); aMapVE.ChangeFromKey(aV).Append(anEdge); - } + } } } } @@ -891,7 +929,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges, // make chain for unite TopTools_SequenceOfShape aChain; - aChain.Append(edge); + aChain.Append(edge); aUsedEdges.Add(edge); TopoDS_Vertex V[2]; TopExp::Vertices(edge, V[0], V[1], Standard_True); @@ -912,7 +950,7 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges, if (!aUsedEdges.Contains(edge)) { if (j == 0) - aChain.Prepend(edge); + aChain.Prepend(edge); else aChain.Append(edge); aUsedEdges.Add(edge); @@ -921,17 +959,17 @@ static Standard_Boolean MergeEdges(TopTools_SequenceOfShape& SeqEdges, V[j] = (VF2.IsSame(V[j]) ? VL2 : VF2); isAdded = Standard_True; break; - } - } } } + } + } if (aChain.Length() < 2) continue; - Standard_Boolean IsClosed = Standard_False; + Standard_Boolean IsClosed = Standard_False; if (V[0].IsSame ( V[1] )) - IsClosed = Standard_True; + IsClosed = Standard_True; // split chain by vertices at which merging is not possible NCollection_Sequence aOneSeq; @@ -1200,6 +1238,10 @@ void ShapeUpgrade_UnifySameDomain::UnifyFaces() if (IsSameDomain(aFace,anCheckedFace)) { + // hotfix for 27271: prevent merging along periodic direction. + if (IsLikeSeam(edge, aFace, aBaseSurface)) + continue; + // replacing pcurves TopoDS_Face aMockUpFace; BRep_Builder B; @@ -1483,11 +1525,11 @@ void ShapeUpgrade_UnifySameDomain::UnifyFaces() } else { - Handle(ShapeExtend_WireData) sbwd = + Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData (aWire); - ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED ); - wires.Append(seg); - } + ShapeFix_WireSegment seg ( sbwd, TopAbs_REVERSED ); + wires.Append(seg); + } } CompShell.DispatchWires ( parts,wires ); diff --git a/tests/bugs/heal/bug27000_1 b/tests/bugs/heal/bug27000_1 index 066ee4f1a8..d9472c1639 100644 --- a/tests/bugs/heal/bug27000_1 +++ b/tests/bugs/heal/bug27000_1 @@ -1,4 +1,4 @@ restore [locate_data_file bug27000_1.brep] shape unifysamedom result shape checkshape result -checknbshapes result -vertex 60 -edge 87 -wire 35 -face 33 -shell 2 -solid 2 -compsolid 0 -compound 1 -shape 220 \ No newline at end of file +checknbshapes result -vertex 62 -edge 90 -wire 36 -face 34 -shell 2 -solid 2 -compsolid 0 -compound 1 -shape 227 \ No newline at end of file diff --git a/tests/bugs/modalg_6/bug27271 b/tests/bugs/modalg_6/bug27271 new file mode 100644 index 0000000000..467e30695b --- /dev/null +++ b/tests/bugs/modalg_6/bug27271 @@ -0,0 +1,11 @@ +puts "============" +puts "OCC27271" +puts "============" +puts "" +########################################################################################################### +# Unifysamedomain invalid result +########################################################################################################### + +restore [locate_data_file bug27271_Shape.brep] a +unifysamedom result a +checkshape result \ No newline at end of file -- 2.20.1