[TD]fix null shape in GeometryMatcher

This commit is contained in:
wandererfan
2023-04-20 14:16:06 -04:00
committed by WandererFan
parent 4c57de5614
commit 6a8eca135b
2 changed files with 57 additions and 21 deletions

View File

@@ -55,10 +55,14 @@ bool GeometryMatcher::compareGeometry(Part::TopoShape shape1, Part::TopoShape s
{
// Base::Console().Message("GM::compareGeometry()\n");
if (shape1.isNull() || shape2.isNull()) {
Base::Console().Message("GM::compareGeometry - one or more shapes are null\n");
Base::Console().Message("GM::compareGeometry - one or more TopoShapes are null\n");
}
TopoDS_Shape geom1 = shape1.getShape();
TopoDS_Shape geom2 = shape2.getShape();
if (geom1.IsNull() || geom2.IsNull()) {
Base::Console().Message("GM::compareGeometry - one or more TopoDS_Shapes are null\n");
}
if (geom1.ShapeType() == TopAbs_VERTEX) {
return comparePoints(geom1, geom2);
}
@@ -68,7 +72,7 @@ bool GeometryMatcher::compareGeometry(Part::TopoShape shape1, Part::TopoShape s
return false;
}
bool GeometryMatcher::comparePoints(TopoDS_Shape shape1, TopoDS_Shape shape2)
bool GeometryMatcher::comparePoints(TopoDS_Shape &shape1, TopoDS_Shape &shape2)
{
// Base::Console().Message("GM::comparePoints()\n");
if (shape1.ShapeType() != TopAbs_VERTEX ||
@@ -86,7 +90,7 @@ bool GeometryMatcher::comparePoints(TopoDS_Shape shape1, TopoDS_Shape shape2)
return false;
}
bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2)
bool GeometryMatcher::compareEdges(TopoDS_Shape &shape1, TopoDS_Shape &shape2)
{
// Base::Console().Message("GM::compareEdges()\n");
if (shape1.ShapeType() != TopAbs_EDGE ||
@@ -97,6 +101,10 @@ bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2)
}
TopoDS_Edge edge1 = TopoDS::Edge(shape1);
TopoDS_Edge edge2 = TopoDS::Edge(shape2);
if (edge1.IsNull() || edge2.IsNull()) {
Base::Console().Message("GM::compareEdges - an input edge is null\n");
}
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
@@ -132,9 +140,14 @@ bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2)
return compareDifferent(edge1, edge2);
}
bool GeometryMatcher::compareLines(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareLines(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
// Base::Console().Message("GM::compareLines()\n");
// how does the edge that was NOT null in compareEdges become null here?
if (edge1.IsNull() || edge2.IsNull()) {
// Base::Console().Message("GM::compareLine - an input edge is null\n");
return false;
}
auto start1 = DU::toVector3d(BRep_Tool::Pnt(TopExp::FirstVertex(edge1)));
auto end1 = DU::toVector3d(BRep_Tool::Pnt(TopExp::LastVertex(edge1)));
auto start2 = DU::toVector3d(BRep_Tool::Pnt(TopExp::FirstVertex(edge2)));
@@ -147,9 +160,15 @@ bool GeometryMatcher::compareLines(TopoDS_Edge edge1, TopoDS_Edge edge2)
return false;
}
bool GeometryMatcher::compareCircles(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareCircles(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
// Base::Console().Message("GM::compareCircles()\n");
// how does the edge that was NOT null in compareEdges become null here?
if (edge1.IsNull() || edge2.IsNull()) {
// Base::Console().Message("GM::compareCircles - an input edge is null\n");
return false;
}
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
gp_Circ circle1 = adapt1.Circle();
@@ -166,8 +185,14 @@ bool GeometryMatcher::compareCircles(TopoDS_Edge edge1, TopoDS_Edge edge2)
return false;
}
bool GeometryMatcher::compareEllipses(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareEllipses(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
// how does the edge that was NOT null in compareEdges become null here?
if (edge1.IsNull() || edge2.IsNull()) {
// Base::Console().Message("GM::compareEllipses - an input edge is null\n");
return false;
}
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
gp_Elips ellipse1 = adapt1.Ellipse();
@@ -188,8 +213,13 @@ bool GeometryMatcher::compareEllipses(TopoDS_Edge edge1, TopoDS_Edge edge2)
}
// for our purposes, only circles masquerading as bsplines are of interest
bool GeometryMatcher::compareBSplines(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareBSplines(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
// how does the edge that was NOT null in compareEdges become null here?
if (edge1.IsNull() || edge2.IsNull()) {
// Base::Console().Message("GM::compareBSplines - an input edge is null\n");
return false;
}
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
bool isArc1(false);
@@ -217,27 +247,33 @@ bool GeometryMatcher::compareBSplines(TopoDS_Edge edge1, TopoDS_Edge edge2)
}
// this is a weak comparison. we should also check center & radius?
bool GeometryMatcher::compareCircleArcs(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareCircleArcs(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
return compareEndPoints(edge1, edge2);
}
bool GeometryMatcher::compareEllipseArcs(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareEllipseArcs(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
return compareEndPoints(edge1, edge2);
}
// this is where we would try to match a bspline against a line or a circle.
// not sure how successful this would be. For now, we just say it doesn't match
bool GeometryMatcher::compareDifferent(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareDifferent(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
return false;
}
bool GeometryMatcher::compareEndPoints(TopoDS_Edge edge1, TopoDS_Edge edge2)
bool GeometryMatcher::compareEndPoints(TopoDS_Edge &edge1, TopoDS_Edge &edge2)
{
// how does the edge that was NOT null in compareEdges become null here?
if (edge1.IsNull() || edge2.IsNull()) {
// Base::Console().Message("GM::compareLine - an input edge is null\n");
return false;
}
BRepAdaptor_Curve adapt1(edge1);
BRepAdaptor_Curve adapt2(edge2);
double pFirst1 = adapt1.FirstParameter();