MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030367Community[OCCT] OCCT:Modeling Algorithmspublic2018-11-13 13:302018-11-13 13:30
ReporterBenjaminBihler 
Assigned Tomsv 
PrioritynormalSeverityminor 
StatusnewResolutionopen 
Platformg++OSWindowsOS Version7
Product Version[OCCT] 7.3.0 
Target Version[OCCT] 7.4.0*Fixed in Version 
Summary0030367: Modeling Algorithms - Distance Computation for Wire and Edge Gives Wrong Result
DescriptionThe C++ program pasted into "Steps To Reproduce" computes the distance between an edge and a wire and compares it to the distances of the edge and wire start and stop points. The value computed by BRepExtrema_DistShapeShape is obviously too large.

On my computer the output is:

Computation has given a wrong result!
The distance is computed as 1.06335, but it cannot be larger than 1.
Steps To Reproduce#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 <iostream>

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

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

TopoDS_Shape shape2;
BRepTools::Read(shape2, "Distance2.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);
}

const double distance = distanceComputer.Value();

BRepAdaptor_Curve edgeAdaptor(edge);
BRepAdaptor_CompCurve wireAdaptor(wire);

const double startPointDistance = edgeAdaptor.Value(
    edgeAdaptor.FirstParameter()).Distance(
    wireAdaptor.Value(wireAdaptor.FirstParameter()));
const double stopPointDistance = edgeAdaptor.Value(
    edgeAdaptor.LastParameter()).Distance(
    wireAdaptor.Value(wireAdaptor.LastParameter()));
const double mixedDistance1 =
    edgeAdaptor.Value(edgeAdaptor.LastParameter()).Distance(
            wireAdaptor.Value(wireAdaptor.FirstParameter()));
const double mixedDistance2 =
    edgeAdaptor.Value(edgeAdaptor.FirstParameter()).Distance(
            wireAdaptor.Value(wireAdaptor.LastParameter()));

const double alternativeDistanceValue = std::min(
    std::min(std::min(startPointDistance, stopPointDistance), mixedDistance1),
    mixedDistance2);

if (alternativeDistanceValue < distance - Precision::Confusion())
{
std::cerr << "Computation has given a wrong result!" << std::endl
        << "The distance is computed as " << distance
        << ", but it cannot be larger than " << alternativeDistanceValue << "."
        << std::endl;
}

return 0;
}
TagsNo tags attached.
Test case number
Attached Files? file icon Distance1.brep (472 bytes) 2018-11-13 13:30
? file icon Distance2.brep (3,937 bytes) 2018-11-13 13:30

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2018-11-13 13:30 BenjaminBihler New Issue
2018-11-13 13:30 BenjaminBihler Assigned To => msv
2018-11-13 13:30 BenjaminBihler File Added: Distance1.brep
2018-11-13 13:30 BenjaminBihler File Added: Distance2.brep


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker