From 14ea8abd0a78f3d216ee35ce1e473faade4bbfb1 Mon Sep 17 00:00:00 2001 From: msv Date: Thu, 8 Sep 2016 22:57:50 +0300 Subject: [PATCH] 0027830: Infinite HLR looping Make protection of HLR algo against garbage data in faces. In particular case, there are faces built on a periodical surfaces, which U bounds exceed period thousands times. Such faces are excluded from the process of edges hiding. In addition, while fitting the intersection point in period for periodical faces, replace looping with the single call to AdjustPeriodic method. - Add new test case. - Update tests of HLR according to new numbers of subshapes. Update of test cases according to the new behavior --- src/HLRBRep/HLRBRep_Data.cxx | 77 +++++++++++++++++++------------- src/HLRBRep/HLRBRep_Data.hxx | 5 ++- src/HLRBRep/HLRBRep_Hider.cxx | 2 + tests/bugs/modalg_6/bug27341_301 | 2 +- tests/bugs/modalg_6/bug27341_306 | 2 +- tests/bugs/modalg_6/bug27341_307 | 2 +- tests/bugs/modalg_6/bug27341_308 | 4 +- tests/bugs/modalg_6/bug27341_313 | 2 +- tests/bugs/modalg_6/bug27341_317 | 4 +- tests/bugs/modalg_6/bug27341_320 | 2 +- tests/bugs/modalg_6/bug27341_324 | 2 +- tests/bugs/modalg_6/bug27341_328 | 2 +- tests/bugs/modalg_6/bug27830 | 17 +++++++ 13 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 tests/bugs/modalg_6/bug27830 diff --git a/src/HLRBRep/HLRBRep_Data.cxx b/src/HLRBRep/HLRBRep_Data.cxx index 63e7ee0ef4..0167524a04 100644 --- a/src/HLRBRep/HLRBRep_Data.cxx +++ b/src/HLRBRep/HLRBRep_Data.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -2093,39 +2094,24 @@ HLRBRep_Data::Classify (const Standard_Integer E, IntCurveSurface_TransitionOnCurve Tr; for (i = 1; i <= nbPoints; i++) { - Standard_Boolean InsideRestriction = Standard_False; myIntersector.CSPoint(i).Values(PInter,u,v,w,Tr); if (w < wLim) { - if (PeriodU) - while (u > UMin) - u -= PeriodU; - if (PeriodV) - while (v > VMin) - v -= PeriodV; -// Standard_Real UInit = u; - Standard_Real VInit = v; + Standard_Real aDummyShift; + if (PeriodU > 0.) + GeomInt::AdjustPeriodic(u, UMin, UMax, PeriodU, u, aDummyShift); + if (PeriodV > 0.) + GeomInt::AdjustPeriodic(v, VMin, VMax, PeriodV, v, aDummyShift); - do { - v = VInit; - - do { - gp_Pnt2d pnt2d(u,v); - if (myClassifier->Classify(pnt2d,Precision::PConfusion()) - != TopAbs_OUT) - { - InsideRestriction = Standard_True; - state = TopAbs_IN; - Level++; - if (!LevelFlag) { - return state; - } - } - v += PeriodV; - } - while (PeriodV && v < VMax && !InsideRestriction); - u += PeriodU; - } - while (PeriodU && u < UMax && !InsideRestriction); + gp_Pnt2d pnt2d(u, v); + if (myClassifier->Classify(pnt2d, Precision::PConfusion()) + != TopAbs_OUT) + { + state = TopAbs_IN; + Level++; + if (!LevelFlag) { + return state; + } + } } } } @@ -2444,3 +2430,34 @@ HLRBRep_Data::SameVertex (const Standard_Boolean h1, } return SameV; } + +//======================================================================= +//function : IsBadFace +//purpose : +//======================================================================= + +Standard_Boolean HLRBRep_Data::IsBadFace() const +{ + if (iFaceGeom) + { + // check for garbage data - if periodic then bounds must not exceed period + HLRBRep_Surface *pGeom = (HLRBRep_Surface*)iFaceGeom; + if (pGeom->IsUPeriodic()) + { + Standard_Real aPeriod = pGeom->UPeriod(); + Standard_Real aMin = pGeom->FirstUParameter(); + Standard_Real aMax = pGeom->LastUParameter(); + if (aPeriod * 2 < aMax - aMin) + return Standard_True; + } + if (pGeom->IsVPeriodic()) + { + Standard_Real aPeriod = pGeom->VPeriod(); + Standard_Real aMin = pGeom->FirstVParameter(); + Standard_Real aMax = pGeom->LastVParameter(); + if (aPeriod * 2 < aMax - aMin) + return Standard_True; + } + } + return Standard_False; +} diff --git a/src/HLRBRep/HLRBRep_Data.hxx b/src/HLRBRep/HLRBRep_Data.hxx index 72ee999565..f5371143a8 100644 --- a/src/HLRBRep/HLRBRep_Data.hxx +++ b/src/HLRBRep/HLRBRep_Data.hxx @@ -173,7 +173,10 @@ public: //! Classification of an edge. Standard_EXPORT TopAbs_State Classify (const Standard_Integer E, const HLRBRep_EdgeData& ED, const Standard_Boolean LevelFlag, Standard_Integer& Level, const Standard_Real param); - + + //! Returns true if the current face is bad. + Standard_EXPORT Standard_Boolean IsBadFace() const; + Standard_EXPORT void Destroy(); ~HLRBRep_Data() { diff --git a/src/HLRBRep/HLRBRep_Hider.cxx b/src/HLRBRep/HLRBRep_Hider.cxx index 86b7513787..6162996feb 100644 --- a/src/HLRBRep/HLRBRep_Hider.cxx +++ b/src/HLRBRep/HLRBRep_Hider.cxx @@ -103,6 +103,8 @@ void HLRBRep_Hider::Hide(const Standard_Integer FI, myDS->InitEdge(FI,MST); if (!myDS->MoreEdge()) // there is nothing to do return; // ********************** + if (myDS->IsBadFace()) + return; HLRBRep_EdgeInterferenceTool EIT(myDS); // List of Intersections HLRBRep_Array1OfEData& myEData = myDS->EDataArray(); diff --git a/tests/bugs/modalg_6/bug27341_301 b/tests/bugs/modalg_6/bug27341_301 index a278496272..e1634e7285 100644 --- a/tests/bugs/modalg_6/bug27341_301 +++ b/tests/bugs/modalg_6/bug27341_301 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 1030.62 -checknbshapes result -vertex 258 -edge 130 +checknbshapes result -vertex 256 -edge 129 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_306 b/tests/bugs/modalg_6/bug27341_306 index 7698f2a1fc..f673547bd5 100644 --- a/tests/bugs/modalg_6/bug27341_306 +++ b/tests/bugs/modalg_6/bug27341_306 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 2893.98 -checknbshapes result -vertex 705 -edge 353 +checknbshapes result -vertex 699 -edge 350 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_307 b/tests/bugs/modalg_6/bug27341_307 index 1ca4fedeec..7cb2f09310 100644 --- a/tests/bugs/modalg_6/bug27341_307 +++ b/tests/bugs/modalg_6/bug27341_307 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 2282.11 -checknbshapes result -vertex 947 -edge 476 +checknbshapes result -vertex 945 -edge 475 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_308 b/tests/bugs/modalg_6/bug27341_308 index b8e0622a22..3bff8b8736 100644 --- a/tests/bugs/modalg_6/bug27341_308 +++ b/tests/bugs/modalg_6/bug27341_308 @@ -22,7 +22,7 @@ build3d result fit -checkprops result -l 1249.94 -checknbshapes result -vertex 490 -edge 245 +checkprops result -l 1170.46 +checknbshapes result -vertex 486 -edge 243 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_313 b/tests/bugs/modalg_6/bug27341_313 index a947ba4138..69f4eed1c3 100644 --- a/tests/bugs/modalg_6/bug27341_313 +++ b/tests/bugs/modalg_6/bug27341_313 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 9662.5 -checknbshapes result -vertex 4429 -edge 2221 +checknbshapes result -vertex 4423 -edge 2218 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_317 b/tests/bugs/modalg_6/bug27341_317 index cfa5701fd7..95e54f9cec 100644 --- a/tests/bugs/modalg_6/bug27341_317 +++ b/tests/bugs/modalg_6/bug27341_317 @@ -22,7 +22,7 @@ build3d result fit -checkprops result -l 2774.53 -checknbshapes result -vertex 614 -edge 307 +checkprops result -l 2704.1 +checknbshapes result -vertex 594 -edge 297 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_320 b/tests/bugs/modalg_6/bug27341_320 index 01beeddc94..ca1b112227 100644 --- a/tests/bugs/modalg_6/bug27341_320 +++ b/tests/bugs/modalg_6/bug27341_320 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 1726.77 -checknbshapes result -vertex 811 -edge 406 +checknbshapes result -vertex 803 -edge 402 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_324 b/tests/bugs/modalg_6/bug27341_324 index cfd3304ab5..dad9044f34 100644 --- a/tests/bugs/modalg_6/bug27341_324 +++ b/tests/bugs/modalg_6/bug27341_324 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 211.007 -checknbshapes result -vertex 106 -edge 53 +checknbshapes result -vertex 102 -edge 51 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27341_328 b/tests/bugs/modalg_6/bug27341_328 index 383ea1aba9..4aef177764 100644 --- a/tests/bugs/modalg_6/bug27341_328 +++ b/tests/bugs/modalg_6/bug27341_328 @@ -23,6 +23,6 @@ build3d result fit checkprops result -l 40.3211 -checknbshapes result -vertex 62 -edge 31 +checknbshapes result -vertex 60 -edge 30 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_6/bug27830 b/tests/bugs/modalg_6/bug27830 new file mode 100644 index 0000000000..66b2398254 --- /dev/null +++ b/tests/bugs/modalg_6/bug27830 @@ -0,0 +1,17 @@ +puts "============" +puts "OCC27830" +puts "============" +puts "" +###################################################### +# Infinite HLR looping +###################################################### + +restore [locate_data_file bug27830_body1.brep] result + +vinit +vdisplay result +vfit +vhlr on +vhlrtype algo result + +# no screenshot since the shape is a garbage, the test is just to check performance