From: Paul RASCLE Date: Sat, 28 Nov 2020 17:34:31 +0000 (+0100) Subject: fix on split polylines X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d6dfded8b000d3443e70aac5bab1838098dae45;p=modules%2Fhydro.git fix on split polylines --- diff --git a/src/HYDROData/HYDROData_TopoCurve.cxx b/src/HYDROData/HYDROData_TopoCurve.cxx index 54888d1c..dc6ba8fb 100644 --- a/src/HYDROData/HYDROData_TopoCurve.cxx +++ b/src/HYDROData/HYDROData_TopoCurve.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,9 @@ #include #include +#include +#include + #define _DEVDEBUG_ #include "HYDRO_trace.hxx" #include @@ -309,6 +313,98 @@ static int IntersectCurve( return aIntCount; } +static int IntersectShape( + const TopoDS_Edge& theEdge1, + const TopoDS_Edge& theEdge2, + std::list& theParameters) +{ + if (theEdge1.IsSame(theEdge2)) + Standard_ConstructionError::Raise("The lines to make intersection must be different"); + +// std::ostringstream oshp1, oshp2; +// BRepTools::Write(theEdge1, oshp1); +// BRepTools::Write(theEdge2, oshp2); +// BRep_Builder aBuilder; +// std::istringstream ishp1(oshp1.str()); +// std::istringstream ishp2(oshp2.str()); +// TopoDS_Shape aShape1, aShape2; +// DEBTRACE("oshp1.str() " << oshp1.str()); +// DEBTRACE("oshp2.str() " << oshp2.str()); +// try +// { +// BRepTools::Read(aShape1, ishp1, aBuilder); +// } catch (Standard_Failure) +// { +// DEBTRACE("Error Brep conversion"); +// return 0; +// } +// try +// { +// BRepTools::Read(aShape2, ishp2, aBuilder); +// } catch (Standard_Failure) +// { +// DEBTRACE("Error Brep conversion"); +// return 0; +// } + + int nbSols = 0; + BRepAdaptor_Curve aCurve1 = BRepAdaptor_Curve(theEdge1); + //BRepAdaptor_Curve aCurve2 = BRepAdaptor_Curve(theEdge2); + + // --- Calculate Lines Intersections Points: two times, changing the order (sometimes intersections not detected) + + BRepExtrema_DistShapeShape dst(theEdge1, theEdge2); // first + if (dst.IsDone()) + { + DEBTRACE("nb solutions found: " << dst.NbSolution()); + gp_Pnt P1, P2; + for (int i = 1; i <= dst.NbSolution(); i++) + { + P1 = dst.PointOnShape1(i); + P2 = dst.PointOnShape2(i); + Standard_Real Dist = P1.Distance(P2); + DEBTRACE("distance solution "<< i << " : " << Dist); + if (Dist <= Precision::Confusion()) + { + double par1; + dst.ParOnEdgeS1(i, par1); + DEBTRACE("parameter: " << par1); + nbSols += AddParameter(aCurve1, par1, theParameters); // add only new parameters + } + else + { + DEBTRACE("not an Intersection Point"); + } + } + } + + BRepExtrema_DistShapeShape dst2(theEdge2, theEdge1); // second + if (dst2.IsDone()) + { + DEBTRACE("nb solutions found: " << dst.NbSolution()); + gp_Pnt P1, P2; + for (int i = 1; i <= dst2.NbSolution(); i++) + { + P1 = dst2.PointOnShape1(i); + P2 = dst2.PointOnShape2(i); + Standard_Real Dist = P1.Distance(P2); + DEBTRACE("distance solution "<< i << " : " << Dist); + if (Dist <= Precision::Confusion()) + { + double par1; + dst2.ParOnEdgeS2(i, par1); + DEBTRACE("parameter: " << par1); + nbSols += AddParameter(aCurve1, par1, theParameters); // add only new parameters + } + else + { + DEBTRACE("not an Intersection Point"); + } + } + } + return nbSols; +} + // Intersects the first edge by the second one and // adds the intersection parameters to the ordered list. static int IntersectEdge( @@ -316,9 +412,10 @@ static int IntersectEdge( const TopoDS_Edge& theEdge2, std::list& theParameters) { - BRepAdaptor_Curve aCurve1 = BRepAdaptor_Curve(theEdge1); - BRepAdaptor_Curve aCurve2 = BRepAdaptor_Curve(theEdge2); - return IntersectCurve(aCurve1, aCurve2, theParameters); + return IntersectShape(theEdge1, theEdge2, theParameters); +// BRepAdaptor_Curve aCurve1 = BRepAdaptor_Curve(theEdge1); +// BRepAdaptor_Curve aCurve2 = BRepAdaptor_Curve(theEdge2); +// return IntersectCurve(aCurve1, aCurve2, theParameters); } // Returns the curve tangent in the position: 0 - start, 1 - end.