OCCT icon indicating copy to clipboard operation
OCCT copied to clipboard

Geom2dAPI_InterCurveCurve has 2 repeated intersection points

Open xuzhongxing opened this issue 8 months ago • 1 comments

Description

The two curves in 2d should have only one intersection point. But Geom2dAPI_InterCurveCurve gives two.

Please see the attached source files and data files to reproduce this issue.

Expected Behavior

There should be one intersection point.

Actual Behavior

Geom2dAPI_InterCurveCurve gives two repeated intersection points.

intsections: 2
param on guide:850
param on spine: 0.85874
param on guide:850
param on spine: 0.85874

Sample Code or DRAW Tcl Script

#include "TopoDS_Shape.hxx"
#include "BinTools.hxx"
#include "BRepTools.hxx"
#include "TopoDS.hxx"
#include "BRepTools_WireExplorer.hxx"
#include "BRep_TEdge.hxx"
#include "BRep_CurveOnSurface.hxx"
#include "Geom2dAPI_InterCurveCurve.hxx"
#include "Geom2d_Curve.hxx"

#include <fstream>
#include <filesystem>

int main(int argc, char** argv) {
    std::filesystem::path file1("D:/temp/Body_93.brep");
    std::ifstream ifs1(file1, std::ios::binary | std::ios::in);
    TopoDS_Shape shape1;
    BinTools::Read(shape1, ifs1);

    std::filesystem::path file2("D:/temp/Body_127.brep");
    std::ifstream ifs2(file2, std::ios::binary | std::ios::in);
    TopoDS_Shape shape2;
    BinTools::Read(shape2, ifs2);

    const TopoDS_Edge& edge2 = TopoDS::Edge(shape2);

    BRepTools_WireExplorer we;
    const TopoDS_Wire& wire = TopoDS::Wire(shape1);
    we.Init(wire);
    we.More();

    const TopoDS_Edge& edge1 = we.Current();

    const BRep_TEdge* te1 = static_cast<const BRep_TEdge*>(edge1.TShape().get());
    const BRep_TEdge* te2 = static_cast<const BRep_TEdge*>(edge2.TShape().get());

    BRep_ListIteratorOfListOfCurveRepresentation itcr1(te1->Curves());

    while (itcr1.More()) {
        const Handle(BRep_CurveRepresentation)& cr1 = itcr1.Value();

        if (cr1->IsCurveOnSurface()) {
            const BRep_CurveOnSurface* cos1 = static_cast<const BRep_CurveOnSurface*>(cr1.get());
            const Handle(Geom_Surface)& surface1 = cos1->Surface();

            BRep_ListIteratorOfListOfCurveRepresentation itcr2(te2->Curves());

            while (itcr2.More()) {
                const Handle(BRep_CurveRepresentation)& cr2 = itcr2.Value();

                if (cr2->IsCurveOnSurface()) {
                    const BRep_CurveOnSurface* cos2 = static_cast<const BRep_CurveOnSurface*>(cr2.get());
                    const Handle(Geom_Surface)& surface2 = cos2->Surface();

                    
                    const Handle(Geom2d_Curve)& pcurve1 = cos1->PCurve();
                    const Handle(Geom2d_Curve)& pcurve2 = cos2->PCurve();

                    Geom2dAPI_InterCurveCurve inter(pcurve1, pcurve2);

                    std::cerr << "intsections: " << inter.NbPoints() << "\n";
                    if (inter.NbPoints() >= 1) {
                        double t1, t2;
                        t1 = pcurve1->FirstParameter();
                        t2 = pcurve1->LastParameter();

                        t1 = pcurve2->FirstParameter();
                        t2 = pcurve2->LastParameter();

                        const Geom2dInt_GInter& intersector = inter.Intersector();
                        const IntRes2d_IntersectionPoint& intPoint = intersector.Point(1);

                        std::cerr << "param on guide:" << intPoint.ParamOnFirst() << "\n";
                        std::cerr << "param on spine: " << intPoint.ParamOnSecond() << "\n";

                        const IntRes2d_IntersectionPoint& intPoint2 = intersector.Point(2);
                        std::cerr << "param on guide:" << intPoint2.ParamOnFirst() << "\n";
                        std::cerr << "param on spine: " << intPoint2.ParamOnSecond() << "\n";
                    }
                }

                itcr2.Next();
            }
        }

        itcr1.Next();
    }

    return 0;
}

Operating System

Windows

Compiler

MSVC

Bitness

64-bit

OCCT Version

7.9.0

Additional Files

temp.zip

Image

xuzhongxing avatar Mar 03 '25 09:03 xuzhongxing