#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>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
+#include <iostream>
+#include <sstream>
+
#define _DEVDEBUG_
#include "HYDRO_trace.hxx"
#include <BRepTools.hxx>
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(
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.