MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030722Community[OCCT] OCCT:Modeling Algorithmspublic2019-05-21 15:372019-08-12 18:01
ReporterBenjaminBihler 
Assigned Toifv 
PrioritynormalSeverityminor 
StatusassignedResolutionopen 
PlatformAOSLOS VersionL
Product Version[OCCT] 7.3.0 
Target Version[OCCT] 7.5.0*Fixed in Version 
Summary0030722: Modeling Algorithms - BRepExtrema_DistShapeShape computes wrong distances
DescriptionWhen computing the intersections of a wire and an edge, the result is wrong. Checking the wire's edges against the given edge shows that there is a major computation error.
Steps To ReproduceDraw script:

restore Wire.brep w
restore Edge.brep e
explode w
mkcurve c1 w_1
mkcurve c2 e
extrema c1 c2

Original steps:

Please check the following program with the two uploaded files:

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

#include <iostream>

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

    TopoDS_Shape shape1;
    BRepTools::Read(shape1, "Edge.brep", builder);

    TopoDS_Shape shape2;
    BRepTools::Read(shape2, "Wire.brep", builder);

    TopoDS_Edge edge;
    TopoDS_Wire wire;

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

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

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

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

    BRepCheck_Analyzer edgeAnalyzer(edge);

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

    BRepCheck_Analyzer wireAnalyzer(wire);

    if (!wireAnalyzer.IsValid())
    {
        std::cerr << "Wire 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);
    }

    if (2 != distanceComputer.NbSolution())
    {
        std::cout << "Two solutions are expected, but there are "
                << distanceComputer.NbSolution() << " solutions." << std::endl;
    }

    for (TopExp_Explorer edgeExplorer(wire, TopAbs_EDGE); edgeExplorer.More();
            edgeExplorer.Next())
    {
        TopoDS_Edge wireEdge = TopoDS::Edge(edgeExplorer.Current());

        BRepExtrema_DistShapeShape wireEdgeDistanceComputer;
        wireEdgeDistanceComputer.SetFlag(Extrema_ExtFlag_MIN);
        wireEdgeDistanceComputer.LoadS1(wireEdge);
        wireEdgeDistanceComputer.LoadS2(edge);
        wireEdgeDistanceComputer.Perform();

        double smallestDistance = std::numeric_limits<double>::max();

        BRepAdaptor_Curve adaptor(wireEdge);

        for (double parameter = adaptor.FirstParameter();
                parameter <= adaptor.LastParameter(); parameter += 0.01)
        {
            BRepExtrema_DistShapeShape edgePointDistanceComputer;
            edgePointDistanceComputer.SetFlag(Extrema_ExtFlag_MIN);
            edgePointDistanceComputer.LoadS1(edge);

            TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(
                    adaptor.Value(parameter));

            edgePointDistanceComputer.LoadS2(vertex);
            edgePointDistanceComputer.Perform();

            const double pointDistance = edgePointDistanceComputer.Value();

            if (pointDistance < smallestDistance)
            {
                smallestDistance = pointDistance;
            }
        }

        if (smallestDistance
                < wireEdgeDistanceComputer.Value() - Precision::Confusion())
        {
            std::cout << "Error in distance computation: "
                    << wireEdgeDistanceComputer.Value()
                    << " has been computed but the distance is " << smallestDistance
                    << " at most!" << std::endl;
        }
    }

    return 0;
}
TagsNo tags attached.
Test case number
Attached Files? file icon Edge.brep (471 bytes) 2019-05-21 15:37
? file icon Wire.brep (7,620 bytes) 2019-05-21 15:37

- Relationships

-  Notes
(0084508)
BenjaminBihler (developer)
2019-05-21 15:41

There are quite a lot of similar issues like 0030164, 0030367, 0027087. After having been using Open CASCADE for several years, I would claim that BRepExtrema_DistShapeShape errors are a major quality issue of Open CASCADE.
(0084515)
msv (developer)
2019-05-21 16:33

There is a real issue in extrema computation between the trimmed ellipse (first edge of the wire) and the trimmed line. It finds no solution, but must find the single solution.
I have provided the Draw script in steps to reproduce.

- Issue History
Date Modified Username Field Change
2019-05-21 15:37 BenjaminBihler New Issue
2019-05-21 15:37 BenjaminBihler Assigned To => msv
2019-05-21 15:37 BenjaminBihler File Added: Edge.brep
2019-05-21 15:37 BenjaminBihler File Added: Wire.brep
2019-05-21 15:41 BenjaminBihler Note Added: 0084508
2019-05-21 16:33 msv Note Added: 0084515
2019-05-21 16:34 msv Steps to Reproduce Updated View Revisions
2019-05-21 16:37 msv Assigned To msv => ifv
2019-05-21 16:37 msv Status new => assigned
2019-08-12 18:01 msv Target Version 7.4.0 => 7.5.0*


Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker