Archived issue #0030367
Modeling Algorithms - Distance Computation for Wire and Edge Gives Wrong Result
Description
The 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.
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, "Attachment 1 (BREP)", builder);
TopoDS_Shape shape2;
BRepTools::Read(shape2, "Attachment 2 (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;
}
#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, "Attachment 1 (BREP)", builder);
TopoDS_Shape shape2;
BRepTools::Read(shape2, "Attachment 2 (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;
}
Public activity
No public notes
Participants are labeled by their role within this record.