View Issue Details

IDProjectCategoryView StatusLast Update
0030722CommunityOCCT:Modeling Algorithmspublic2021-09-11 14:05
ReporterBenjaminBihler Assigned Tosmoskvin 
PrioritynormalSeverityminor 
Status closedResolutionfixed 
PlatformAOSL 
Product Version7.3.0 
Target Version7.7.0Fixed in Version7.6.0 
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 ReproduceTest case name: bugs modalg_7 bug30722

Draw 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 numberbugs/modalg_7/bug30722

Attached Files

  • Edge.brep (471 bytes)
  • Wire.brep (7,620 bytes)
  • bug30722_1.brep (7,620 bytes)
  • bug30722_2.brep (471 bytes)

Activities

BenjaminBihler

2019-05-21 15:37

developer  

Edge.brep (471 bytes)

BenjaminBihler

2019-05-21 15:37

developer  

Wire.brep (7,620 bytes)

BenjaminBihler

2019-05-21 15:41

developer   ~0084508

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.

msv

2019-05-21 16:33

developer   ~0084515

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.

git

2021-09-01 17:46

administrator   ~0103641

Branch CR30722 has been created by abulychev-ext.

SHA-1: 5425d4e36881ace5ed550081d1e7d49c20031c4d


Detailed log of new commits:

Author: abulyche
Date: Wed Sep 1 17:45:52 2021 +0300

    0030722: Modeling Algorithms - BRepExtrema_DistShapeShape computes wrong distances
    
    Updated the math_DirectPolynomialRoots.cxx
    Added the QA command for bug30722

git

2021-09-01 23:59

administrator   ~0103653

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: f54e2fd3d7270e8265ec075438bea83a1b204768

git

2021-09-02 12:25

administrator   ~0103667

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: 4ddbda1829c263e6b0e6d43e48943ea230a635d1

abulychev-ext

2021-09-02 16:46

developer  

bug30722_1.brep (7,620 bytes)

abulychev-ext

2021-09-02 16:46

developer  

bug30722_2.brep (471 bytes)

git

2021-09-02 19:03

administrator   ~0103692

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: ad0b5ca9b24d7d5e7bdef3773c4d688c46648c4b

kgv

2021-09-03 13:26

developer   ~0103714

+  const Standard_Real aGapCheckTol = (theArgNb >= 6) ? Draw::Atof(theArgVec[5]) : 0.1;

New command arguments have to be document in command's help.

ifv

2021-09-05 15:07

developer   ~0103818

It is not necessary to use special QA command QA30722, test can be created using Draw command distmini.

git

2021-09-05 17:54

administrator   ~0103819

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: afa3d9eb99f233bc42589185f2dc851b569ec524

git

2021-09-05 19:20

administrator   ~0103820

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: e67d0fe769e465e941efb3cb832462f1a02a3840

ifv

2021-09-06 10:32

developer   ~0103846

Most optimal test is using script with extrema command:

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

git

2021-09-06 10:54

administrator   ~0103851

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: 87470979c0a7fdc295d0a85d7f548a1694aded69

abulychev-ext

2021-09-06 11:14

developer   ~0103852

Dear kgv,
There isn't b2dclassify and many others commands from the BOPTest directory in the file: dox\user_guides\draw_test_harness, so it is advisable to create a special issue to add these commands to the documentation.

kgv

2021-09-06 11:26

developer   ~0103853

Last edited: 2021-09-06 11:27

> There isn't b2dclassify and many others commands from the BOPTest directory in the file: dox\user_guides\draw_test_harness
Draw Harness command help is defined within C++ code, not within user_guides (the latter is supplementary).
   theCommands.Add("b2dclassify"  , "use b2dclassify Face Point2d [Tol] ",
                   __FILE__, b2dclassify , g);


Modifications of a command should be always done in sync with updating command "help" description ("help b2dclassify").
When you see some (old) command having a poor description, it is also advisable improving description in general, while you are modifying this command (for instance, "b2dclassify" lacks elaboration of it's purpose).

git

2021-09-06 12:48

administrator   ~0103860

Branch CR30722 has been updated forcibly by abulychev-ext.

SHA-1: b487a5aeaed02c702006993ec8e2ee881bc5debe

ifv

2021-09-06 15:17

developer   ~0103867

Branch seems to be valid

Branches for integration:
OCCT - CR30722
Products - not

smoskvin

2021-09-11 13:23

administrator   ~0104000

Combination -
OCCT branch : IR-2021-09-10
master SHA - 9ae883970dd77a39d856b49e6883ed5d0e60d20f
49e51745631c52b6c452c65adae4d6dfa21a1b1e
Products branch : IR-2021-09-10 SHA - 2d2bc879e2da9d770a1938ab3410f5885c8555e7
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 17358.54000000042 / 17496.500000000422 [-0.79%]
Products
Total CPU difference: 11397.800000000112 / 11567.680000000111 [-1.47%]
Windows-64-VC14:
OCCT
Total CPU difference: 19328.109375 / 19307.609375 [+0.11%]
Products
Total CPU difference: 12733.328125 / 12920.953125 [-1.45%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention

git

2021-09-11 14:05

administrator   ~0104026

Branch CR30722 has been deleted by mnt.

SHA-1: b487a5aeaed02c702006993ec8e2ee881bc5debe

Related Changesets

occt: master 41e2eed0

2021-09-01 14:45:52

abulyche


Committer: smoskvin Details Diff
0030722: Modeling Algorithms - BRepExtrema_DistShapeShape computes wrong distances

Updated the math_DirectPolynomialRoots.cxx
Added the test case "bug30722"
Updated the command "b2dclassify" in the BOPTest_LowCommands.cxx
Affected Issues
0030722
mod - src/BOPTest/BOPTest_LowCommands.cxx Diff File
mod - src/math/math_DirectPolynomialRoots.cxx Diff File
add - tests/bugs/modalg_7/bug30722 Diff File

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
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
2020-09-14 22:53 msv Target Version 7.5.0 => 7.6.0
2021-06-01 17:15 ifv Assigned To ifv => abulychev-ext
2021-08-29 19:55 msv Target Version 7.6.0 => 7.7.0
2021-09-01 17:46 git Note Added: 0103641
2021-09-01 23:59 git Note Added: 0103653
2021-09-02 12:25 git Note Added: 0103667
2021-09-02 16:46 abulychev-ext File Added: bug30722_1.brep
2021-09-02 16:46 abulychev-ext File Added: bug30722_2.brep
2021-09-02 19:03 git Note Added: 0103692
2021-09-03 09:26 abulychev-ext Assigned To abulychev-ext => ifv
2021-09-03 09:26 abulychev-ext Status assigned => resolved
2021-09-03 09:26 abulychev-ext Steps to Reproduce Updated
2021-09-03 13:26 kgv Note Added: 0103714
2021-09-05 15:03 ifv Assigned To ifv => abulychev-ext
2021-09-05 15:07 ifv Note Added: 0103818
2021-09-05 15:07 ifv Status resolved => assigned
2021-09-05 17:54 git Note Added: 0103819
2021-09-05 19:20 git Note Added: 0103820
2021-09-05 21:34 abulychev-ext Assigned To abulychev-ext => ifv
2021-09-05 21:34 abulychev-ext Status assigned => resolved
2021-09-06 10:32 ifv Note Added: 0103846
2021-09-06 10:32 ifv Assigned To ifv => abulychev-ext
2021-09-06 10:32 ifv Status resolved => assigned
2021-09-06 10:54 git Note Added: 0103851
2021-09-06 11:14 abulychev-ext Note Added: 0103852
2021-09-06 11:26 kgv Note Added: 0103853
2021-09-06 11:27 kgv Note Edited: 0103853
2021-09-06 12:48 git Note Added: 0103860
2021-09-06 14:56 abulychev-ext Assigned To abulychev-ext => ifv
2021-09-06 14:56 abulychev-ext Status assigned => resolved
2021-09-06 15:13 ifv Test case number => bugs/modalg_7/bug30722
2021-09-06 15:17 ifv Note Added: 0103867
2021-09-06 15:17 ifv Assigned To ifv => bugmaster
2021-09-06 15:17 ifv Status resolved => reviewed
2021-09-11 13:23 smoskvin Note Added: 0104000
2021-09-11 13:23 smoskvin Status reviewed => tested
2021-09-11 13:43 smoskvin Changeset attached => occt master 41e2eed0
2021-09-11 13:43 smoskvin Assigned To bugmaster => smoskvin
2021-09-11 13:43 smoskvin Status tested => verified
2021-09-11 13:43 smoskvin Resolution open => fixed
2021-09-11 14:05 git Note Added: 0104026