]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
fix on split polylines
authorPaul RASCLE <paul.rascle@openfields.fr>
Sat, 28 Nov 2020 17:34:31 +0000 (18:34 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
src/HYDROData/HYDROData_TopoCurve.cxx

index 54888d1c532d6d60b2f30e7a69e0a17933b14f72..dc6ba8fb279fc3348bcee5733c4f4d1c7c44eaf2 100644 (file)
@@ -25,6 +25,7 @@
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <Extrema_ExtCC.hxx>
 #include <Extrema_ExtPC.hxx>
+#include <BRepExtrema_DistShapeShape.hxx>
 #include <GeomAPI_Interpolate.hxx>
 #include <Geom_BSplineCurve.hxx>
 #include <Precision.hxx>
@@ -39,6 +40,9 @@
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
 
+#include <iostream>
+#include <sstream>
+
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 #include <BRepTools.hxx>
@@ -309,6 +313,98 @@ static int IntersectCurve(
   return aIntCount;
 }
 
+static int IntersectShape(
+    const TopoDS_Edge& theEdge1,
+    const TopoDS_Edge& theEdge2,
+    std::list<double>& 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<double>& 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.