From 1fae7cdaf1d04b0e935d04990caf9c6d35b48bff Mon Sep 17 00:00:00 2001 From: jgv Date: Fri, 2 Jun 2017 17:26:10 +0300 Subject: [PATCH] 0028784: [HLR] Crash while getting hidden lines for a compound Method HLRBRep_PolyHLRToShape::InternalCompound is modified: avoid creation an edge with null length. Add testing Draw command. --- src/HLRBRep/HLRBRep_PolyHLRToShape.cxx | 11 +++++++--- src/QABugs/QABugs_20.cxx | 29 ++++++++++++++++++++++++++ tests/bugs/modalg_7/bug28784 | 20 ++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 tests/bugs/modalg_7/bug28784 diff --git a/src/HLRBRep/HLRBRep_PolyHLRToShape.cxx b/src/HLRBRep/HLRBRep_PolyHLRToShape.cxx index b91d1e6f20..771e082913 100644 --- a/src/HLRBRep/HLRBRep_PolyHLRToShape.cxx +++ b/src/HLRBRep/HLRBRep_PolyHLRToShape.cxx @@ -132,8 +132,13 @@ HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ, if (todraw) if (!S.IsNull()) todraw = Map.Contains(BP.Shape()); if (todraw) { - B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2())); - added = Standard_True; + const gp_Pnt2d& FirstP2d = BP.P1(); + const gp_Pnt2d& LastP2d = BP.P2(); + if (FirstP2d.SquareDistance(LastP2d) > 1.e-20) + { + B.Add(Result,BRepLib_MakeEdge2d(BP.P1(),BP.P2())); + added = Standard_True; + } } } } @@ -156,7 +161,7 @@ HLRBRep_PolyHLRToShape::InternalCompound (const Standard_Integer typ, const gp_XY aSta2D(aSta.X(), aSta.Y()); const gp_XY aEnd2D(aEnd.X(), aEnd.Y()); const gp_XY aD = aEnd2D - aSta2D; - if (aD.Modulus() > 1.e-10) { + if (aD.SquareModulus() > 1.e-20) { B.Add(Result,BRepLib_MakeEdge2d(aSta2D, aEnd2D)); added = Standard_True; } diff --git a/src/QABugs/QABugs_20.cxx b/src/QABugs/QABugs_20.cxx index 6bb12714ef..dfeaecc7a9 100644 --- a/src/QABugs/QABugs_20.cxx +++ b/src/QABugs/QABugs_20.cxx @@ -56,6 +56,8 @@ #include #include +#include +#include //======================================================================= //function : SurfaceGenOCC26675_1 @@ -2305,6 +2307,32 @@ static Standard_Integer OCC28594(Draw_Interpretor& di, Standard_Integer argc, co return 0; } +static Standard_Integer OCC28784(Draw_Interpretor&, Standard_Integer argc, const char** argv) +{ + if (argc < 3) + return 1; + + TopoDS_Shape aShape = DBRep::Get(argv[2]); + if (aShape.IsNull()) + return 1; + + gp_Ax2 aPlane (gp::Origin(), gp::DX(), -gp::DZ()); + HLRAlgo_Projector aProjector(aPlane); + + Handle(HLRBRep_PolyAlgo) aHLR = new HLRBRep_PolyAlgo(aShape); + aHLR->Projector(aProjector); + aHLR->Update(); + + HLRBRep_PolyHLRToShape aHLRtoShape; + aHLRtoShape.Update(aHLR); + + TopoDS_Shape aHidden = aHLRtoShape.HCompound(); + + DBRep::Set(argv[1], aHidden); + + return 0; +} + void QABugs::Commands_20(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -2326,6 +2354,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) { theCommands.Add("OCC27875", "OCC27875 curve", __FILE__, OCC27875, group); theCommands.Add("OCC28389", "OCC28389", __FILE__, OCC28389, group); theCommands.Add("OCC28594", "OCC28594", __FILE__, OCC28594, group); + theCommands.Add("OCC28784", "OCC28784 result shape", __FILE__, OCC28784, group); return; } diff --git a/tests/bugs/modalg_7/bug28784 b/tests/bugs/modalg_7/bug28784 new file mode 100755 index 0000000000..5289bd6460 --- /dev/null +++ b/tests/bugs/modalg_7/bug28784 @@ -0,0 +1,20 @@ +puts "========" +puts "OCC28784" +puts "========" +puts "" +####################################################### +# [HLR] Crash while getting hidden lines for a compound +####################################################### + +pload QAcommands + +restore [locate_data_file bug28784_MHX_SKG_MS_Pos1_simplified.brep] a +OCC28784 result a + +checknbshapes result -edge 236 + +smallview +top +donly result +fit +checkview -screenshot -2d -path ${imagedir}/${test_image}.png