MantisBT - Community
View Issue Details
0031319Community[OCCT] OCCT:Modeling Algorithmspublic2020-01-24 12:342020-09-15 12:36
BenjaminBihler 
msv 
normalminor 
newopen 
ALL
[OCCT] 7.4.0 
[OCCT] 7.6.0* 
0031319: Modeling Algorithms - BRepExtrema_DistShapeShape won't find all intersections
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".
#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, "Wire.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, "Edge.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;
}
No tags attached.
? Edge.brep (470) 2020-01-24 12:34
https://tracker.dev.opencascade.org/
? Wire.brep (23,454) 2020-01-24 12:34
https://tracker.dev.opencascade.org/
Issue History
2020-01-24 12:34BenjaminBihlerNew Issue
2020-01-24 12:34BenjaminBihlerAssigned To => msv
2020-01-24 12:34BenjaminBihlerFile Added: Edge.brep
2020-01-24 12:34BenjaminBihlerFile Added: Wire.brep
2020-01-27 14:13BenjaminBihlerNote Added: 0090074
2020-01-27 17:18msvNote Added: 0090077
2020-09-15 12:36msvTarget Version7.5.0 => 7.6.0*

Notes
(0090074)
BenjaminBihler   
2020-01-27 14:13   
The described problem appears quite often with the given wire. If necessary I can show more edges whose intersections are partially missed.
(0090077)
msv   
2020-01-27 17:18   
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.