DiscussionsIssue archiveOCCT:Modeling Algorithms

Archived issue #0031319

Modeling Algorithms - BRepExtrema_DistShapeShape won't find all intersections

CommunityOCCT:Modeling Algorithmsnew2 public notes

Search issues

Description

I have an example of a wire and an edge that intersect two times (with their intersection positions being far away from each other), but BRepExtrema_DistShapeShape finds only one of the intersections.

Please see the code in "Steps To Reproduce".

Steps to reproduce

#include <BRepAdaptor_CompCurve.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <Precision.hxx>
#include <ShapeFix_Edge.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>

#include <iostream>

int main(int, char**)
{
    BRep_Builder builder;

    TopoDS_Wire wire;

    {
        TopoDS_Shape shape;
        BRepTools::Read(shape, "Attachment 2 (BREP)", builder);

        for (TopExp_Explorer wireExplorer(shape, TopAbs_WIRE); wireExplorer.More();
                 wireExplorer.Next())
        {
            wire = TopoDS::Wire(wireExplorer.Current());
            break;
        }

        if (wire.IsNull())
        {
            std::cerr << "Wire is null." << std::endl;
            exit(1);
        }

        BRepCheck_Analyzer wireAnalyzer(wire);

        if (!wireAnalyzer.IsValid())
        {
            std::cerr << "Wire is invalid." << std::endl;
            exit(1);
        }
    }

    TopoDS_Edge edge;

    {
        TopoDS_Shape shape;
        BRepTools::Read(shape, "Attachment 1 (BREP)", builder);

        for (TopExp_Explorer edgeExplorer(shape, TopAbs_EDGE); edgeExplorer.More();
                 edgeExplorer.Next())
        {
            edge = TopoDS::Edge(edgeExplorer.Current());
            break;
        }

        if (edge.IsNull())
        {
            std::cerr << "Edge is null." << std::endl;
            exit(1);
        }

        BRepCheck_Analyzer edgeAnalyzer(edge);

        if (!edgeAnalyzer.IsValid())
        {
            std::cerr << "Edge is invalid." << std::endl;
            exit(1);
        }
    }

    BRepExtrema_DistShapeShape distanceComputer;
    distanceComputer.SetFlag(Extrema_ExtFlag_MIN);
    distanceComputer.LoadS1(wire);
    distanceComputer.LoadS2(edge);
    distanceComputer.Perform();

    if (!distanceComputer.IsDone())
    {
        std::cerr << "Calculation failed." << std::endl;
        exit(1);
    }

    std::cout << "There are " << distanceComputer.NbSolution()
                        << " solutions, two solutions are expected!" << std::endl;

    return 0;
}

Public activity

2 archived notes

Participants are labeled by their role within this record.

01Author
The described problem appears quite often with the given wire. If necessary I can show more edges whose intersections are partially missed.
02Commenter 2
If we make the edge shorter (in bounds of the wire) then both solutions are found.
If we change the order of arguments then also both solutions are found.
It is obviously the bug in extrema algo.