MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0031047Community[OCCT] OCCT:Modeling Algorithmspublic2019-10-08 17:392019-10-15 10:01
ReporterBenjaminBihler 
Assigned Toifv 
PrioritynormalSeverityminor 
StatusassignedResolutionopen 
Platformg++ 9.2.0OSWindowsOS Version7
Product Version[OCCT] 7.4.0 
Target Version[OCCT] 7.5.0*Fixed in Version 
Summary0031047: BRepExtrema_DistShapeShape gives wrong result
DescriptionThe distance of a vertex to a face is computed. It should be zero, but it is computed to be 47.1989. I use mingw-w64 with g++ 9.2.0, but this actually shouldn't make a difference. Please see the code in "Steps To Reproduce".
Steps To Reproduce#script 1 - test DistShapeShape

restore Face.brep f
vertex v1 -79 -282.7 0
copy v1 v2
ttranslate v2 0 0.1 0
distmini d1 f v1
distmini d2 f v2
set dist1 [dval d1_val]
set dist2 [dval d2_val]
puts "dist1=$dist1"
puts "dist2=$dist2"
if {$dist1 != $dist2} {
  puts "Error: both distances must be equal to 0"
}

#script 2 - test BRepClass_FaceClassifier

restore Face.brep f
point p1 -79 -282.7
point p2 -79 -282.6
if ![regexp "IN" [b2dclassify f p1]] {
  puts "Error: inner point p1 is classified as OUT"
}
if ![regexp "IN" [b2dclassify f p2]] {
  puts "Error: inner point p2 is classified as OUT"
}
TagsNo tags attached.
Test case number
Attached Files? file icon Face.brep (118,509 bytes) 2019-10-08 17:39

- Relationships

-  Notes
(0087997)
BenjaminBihler (developer)
2019-10-10 08:28

A slight translation of the test point makes the distance measurement work. At least I can use this here to detect whether my measurement is wrong in a special test case. See this code for the disturbed (and therefore correct) calculation:

#include <TopoDS_Face.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <TopoDS.hxx>
#include <Precision.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>

#include <string>
#include <vector>
#include <iostream>

int main(int, char*[])
{
    BRep_Builder builder;
    TopoDS_Shape face;

    BRepTools::Read(face, "Face.brep", builder);

    gp_Pnt testPoint1(-79.14602309143586467143904883414507,
            -282.66130124109884036442963406443596,
            0.00000000000000000000000000000000);

    BRepExtrema_DistShapeShape distanceComputer1(
            BRepBuilderAPI_MakeVertex(testPoint1), face);

    if (distanceComputer1.IsDone())
    {
        std::cout << "Calculated Distance = " << distanceComputer1.Value()
                << std::endl;
        if (distanceComputer1.Value() > Precision::Confusion())
        {
            std::cout << "This is wrong! The distance should be (close to) zero."
                    << std::endl;
        }
    }
    else
    {
        std::cout << "Calculation failed." << std::endl;
    }

    std::cout << std::endl << "Translating test point..." << std::endl;

    gp_Pnt testPoint2 = testPoint1.Translated(gp_Vec(0.0, 0.1, 0.0));

    BRepExtrema_DistShapeShape distanceComputer2(
            BRepBuilderAPI_MakeVertex(testPoint2), face);

    if (distanceComputer2.IsDone())
    {
        std::cout << "Calculated Distance = " << distanceComputer2.Value()
                << std::endl;
        if (distanceComputer2.Value() > Precision::Confusion())
        {
            std::cout << "This is wrong! The distance should be (close to) zero."
                    << std::endl;
        }
    }
    else
    {
        std::cout << "Calculation failed." << std::endl;
    }

    return 0;
}
(0088107)
msv (developer)
2019-10-14 16:06

I have updated steps to reproduce with a simple draw script.
It gives the error in the current OCCT version.
(0088108)
msv (developer)
2019-10-14 16:28

The cause of the bug is incorrect work of BRepClass_FaceClassifier. See script 2 in steps to reproduce.

The possible fix is to use BRepTopAdaptor_FClass2d for classification.
(0088128)
Mechanicoder (reporter)
2019-10-15 09:33

我在求两个曲面的距离时遇到了相似的问题。
两个曲面均是周期曲面且相交,第一个曲面在周期方向曲率存在较大的波动,第二个曲面为回转面。
调用过程:BrepExtrema_DistShapeShape->BrepExtrema_DistSS->BrepExt_ExtFF->Extrema_GenExtSS, 最后一个步骤中,均匀取了20*20个离散点并求最近点对,进而确定Extrema_FunDistSS, math_BFGS的初始值,进行求解。根据该步骤所求的结果,计算对应曲面上的法向量,发现两个法向量夹角为180.005°。
我猜测是这里出了问题。

版本:7.3.0
(0088129)
msv (developer)
2019-10-15 09:47
edited on: 2019-10-15 09:49

Dear Mechanocider,
Very few people who uses this bugtracker can read Chinese. Please use English for your posts.

亲爱的机械编码器,
使用此bugtracker的人很少能读中文。 请使用英文撰写您的帖子。

(0088130)
BenjaminBihler (developer)
2019-10-15 09:51

Dear msv,

are BRepClass_FaceClassifier and BRepTopAdaptor_FClass2d serving the same purpose? Is BRepTopAdaptor_FClass2d more correct/stable? This post https://www.opencascade.com/content/classify-point-given-face [^] seems to indicate that it is faster. But I have found no more information on that.

Thank you,
Benjamin
(0088131)
msv (developer)
2019-10-15 10:01

BRepTopAdaptor_FClass2d tries to use discrete representation of the boundary to solve the problem using just intersections of linear segments. In case of point located too close to bounds it calls geometric classifier BRepClass_FaceClassifier.

- Issue History
Date Modified Username Field Change
2019-10-08 17:39 BenjaminBihler New Issue
2019-10-08 17:39 BenjaminBihler Assigned To => msv
2019-10-08 17:39 BenjaminBihler File Added: Face.brep
2019-10-10 08:28 BenjaminBihler Note Added: 0087997
2019-10-14 16:06 msv Note Added: 0088107
2019-10-14 16:06 msv Steps to Reproduce Updated View Revisions
2019-10-14 16:28 msv Note Added: 0088108
2019-10-14 16:28 msv Steps to Reproduce Updated View Revisions
2019-10-14 16:29 msv Assigned To msv => ifv
2019-10-14 16:29 msv Status new => assigned
2019-10-15 09:33 Mechanicoder Note Added: 0088128
2019-10-15 09:47 msv Note Added: 0088129
2019-10-15 09:49 msv Note Edited: 0088129 View Revisions
2019-10-15 09:51 BenjaminBihler Note Added: 0088130
2019-10-15 10:01 msv Note Added: 0088131


Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker