From: Konstantin Leontev Date: Fri, 25 Oct 2024 15:44:53 +0000 (+0100) Subject: [bos #43278][EDF 25230] MakeVertexInsideFace too long. Added ShapeFix for result... X-Git-Tag: V9_14_0a1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fkleontev%2F43278_MakeVertexInsideFace_too_long;p=modules%2Fshaper.git [bos #43278][EDF 25230] MakeVertexInsideFace too long. Added ShapeFix for result created by ShapeUpgrade_ShapeDivideArea. Added check for created curve related to [bos #37951][EDF 25230] - SIGSEGV with MakeVertexInsideFace --- diff --git a/src/FeaturesPlugin/Test/TestPointCloud_Cone.py b/src/FeaturesPlugin/Test/TestPointCloud_Cone.py new file mode 100644 index 000000000..abe256a09 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestPointCloud_Cone.py @@ -0,0 +1,47 @@ +# Copyright (C) 2014-2024 CEA, EDF +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +""" + Unit test of makeVertexInsideFace with a cone +""" + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 50, 100, 50) + +# Make a cloud of given number of points in range 1-30 on the cone face +for i in range(1, 31): + model.do() + PC_1 = model.makeVertexInsideFace(Part_1_doc, model.selection("FACE", "Cone_1_1/Face_1"), i) + + ### Check result + err = PC_1.feature().error() + if err != "": + print(err) + # this test should not fail with old OCCT + assert("Improper OCCT version" in err) + break + else: + assert(model.checkPythonDump()) + +model.end() diff --git a/src/FeaturesPlugin/tests.set b/src/FeaturesPlugin/tests.set index 2611fad2e..25a67737e 100644 --- a/src/FeaturesPlugin/tests.set +++ b/src/FeaturesPlugin/tests.set @@ -525,6 +525,7 @@ SET(TEST_NAMES_PARA Test20247.py Test22847.py TestPointCoordinates.py + TestPointCloud_Cone.py TestPointCloud.py TestGeometryCalculation.py TestBoundingBox.py diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointCloudOnFace.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointCloudOnFace.cpp index 8a49805cd..fefb1645b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointCloudOnFace.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointCloudOnFace.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,13 @@ gp_Pnt GetMidPnt2d(const TopoDS_Face& theFace, const TopoDS_Edge& anEdge = aWexp.Current(); if (!aUsedEmap.Add(anEdge)) continue; BRepAdaptor_Curve2d aBAcurve2d (anEdge, theFace); + // Initialization of curve could fail in constructor, + // so we need to check if we actually have a curve here. + if (!aBAcurve2d.Curve()) + { + continue; + } + Standard_Real aDelta = (aBAcurve2d.LastParameter() - aBAcurve2d.FirstParameter())/aNbSamples; for (Standard_Integer ii = 0; ii < aNbSamples; ii++) { @@ -426,6 +434,12 @@ void ModifyFacesForGlobalResult(const TopoDS_Face& theInputFace, aLocalTool.SetNumbersUVSplits (1, aNumberToSplit); aLocalTool.Perform(); aLocalResult = aLocalTool.Result(); + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(aLocalResult, Standard_False); + aNbFacesInLocalResult = aNumberToSplit; #endif } @@ -505,6 +519,11 @@ void ModifyFacesForGlobalResult(const TopoDS_Face& theInputFace, aLocalTool.SetNumbersUVSplits (1, aNumberToSplit); aLocalTool.Perform(); aLocalResult = aLocalTool.Result(); + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(aLocalResult, Standard_False); #endif } else @@ -553,6 +572,13 @@ bool GeomAlgoAPI_PointCloudOnFace::PointCloud(GeomShapePtr theFace, tool.NbParts() = theNumberOfPoints; tool.Perform(); TopoDS_Shape res = tool.Result(); + if (res.IsNull()) + return -1; + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(res, Standard_False); BRep_Builder aBB; TopoDS_Compound aGlobalRes; diff --git a/src/GeomAlgoImpl/GEOMAlgo_AlgoTools.cxx b/src/GeomAlgoImpl/GEOMAlgo_AlgoTools.cxx index e79ecdffb..c3eaf8edc 100644 --- a/src/GeomAlgoImpl/GEOMAlgo_AlgoTools.cxx +++ b/src/GeomAlgoImpl/GEOMAlgo_AlgoTools.cxx @@ -102,6 +102,7 @@ #include #include +#include #include @@ -1016,6 +1017,13 @@ Standard_Integer GEOMAlgo_AlgoTools::PointCloudInFace(const TopoDS_Face& theFace tool.NbParts() = theNbPnts; tool.Perform(); TopoDS_Shape res = tool.Result(); + if (res.IsNull()) + return -1; + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(res, Standard_False); BRep_Builder aBB; TopoDS_Compound aGlobalRes; @@ -1236,6 +1244,13 @@ gp_Pnt GetMidPnt2d(const TopoDS_Face& theFace, { const TopoDS_Edge& anEdge = aWexp.Current(); BRepAdaptor_Curve2d aBAcurve2d (anEdge, theFace); + // Initialization of curve could fail in constructor, + // so we need to check if we actually have a curve here. + if (!aBAcurve2d.Curve()) + { + continue; + } + Standard_Real aDelta = (aBAcurve2d.LastParameter() - aBAcurve2d.FirstParameter())/aNbSamples; for (Standard_Integer ii = 0; ii < aNbSamples; ii++) { @@ -1497,6 +1512,12 @@ void ModifyFacesForGlobalResult(const TopoDS_Face& theInputFace, aLocalTool.SetNumbersUVSplits (1, aNumberToSplit); aLocalTool.Perform(); aLocalResult = aLocalTool.Result(); + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(aLocalResult, Standard_False); + aNbFacesInLocalResult = aNumberToSplit; #endif } @@ -1575,6 +1596,11 @@ void ModifyFacesForGlobalResult(const TopoDS_Face& theInputFace, aLocalTool.SetNumbersUVSplits (1, aNumberToSplit); aLocalTool.Perform(); aLocalResult = aLocalTool.Result(); + + // Splitting algorithm can produces invalid shapes that results in + // infinite loop on ShapeUpgrade_UnifySameDomain::build() call. + // Here is a fix from OCCT DRAW: SWDRAW_ShapeUpgrade: splitbynumber(). + ShapeFix::SameParameter(aLocalResult, Standard_False); #endif } else