Add planar embedding to EdgeWalker

This commit is contained in:
WandererFan
2016-11-13 10:15:44 -05:00
committed by wmayer
parent b6448d26d0
commit 78de266aa3
5 changed files with 330 additions and 32 deletions

View File

@@ -54,6 +54,7 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include <Base/Vector3D.h>
#include "DrawUtil.h"
@@ -138,6 +139,92 @@ bool DrawUtil::isZeroEdge(TopoDS_Edge e)
return result;
}
//! assumes 2d on XY
//! quick angle for straight edges
double DrawUtil::angleWithX(TopoDS_Edge e, bool reverse)
{
double result = 0;
gp_Pnt gstart = BRep_Tool::Pnt(TopExp::FirstVertex(e));
Base::Vector3d start(gstart.X(),gstart.Y(),gstart.Z());
gp_Pnt gend = BRep_Tool::Pnt(TopExp::LastVertex(e));
Base::Vector3d end(gend.X(),gend.Y(),gend.Z());
Base::Vector3d u;
if (reverse) {
u = start - end;
} else {
u = end - start;
}
result = atan2(u.y,u.x);
return result;
}
double DrawUtil::angleWithX(TopoDS_Edge e, TopoDS_Vertex v)
{
double result = 0;
double param = 0;
//find tangent @ v
double adjust = 1.0; //occ tangent points in direction of curve. at lastVert we need to reverse it.
BRepAdaptor_Curve adapt(e);
if (isFirstVert(e,v)) {
param = adapt.FirstParameter();
} else if (isLastVert(e,v)) {
param = adapt.LastParameter();
adjust = -1;
} else {
//TARFU
Base::Console().Message("Error: DU::angleWithX - v is neither first nor last \n");
//must be able to get non-terminal point parm from curve/
}
Base::Vector3d uVec(0.0,0.0,0.0);
gp_Dir uDir;
BRepLProp_CLProps prop(adapt,param,2,Precision::Confusion());
if (prop.IsTangentDefined()) {
prop.Tangent(uDir);
uVec = Base::Vector3d(uDir.X(),uDir.Y(),uDir.Z()) * adjust;
} else {
//this bit is a little sketchy
gp_Pnt gstart = BRep_Tool::Pnt(TopExp::FirstVertex(e));
Base::Vector3d start(gstart.X(),gstart.Y(),gstart.Z());
gp_Pnt gend = BRep_Tool::Pnt(TopExp::LastVertex(e));
Base::Vector3d end(gend.X(),gend.Y(),gend.Z());
if (isFirstVert(e,v)) {
uVec = end - start;
} else if (isLastVert(e,v)) {
uVec = end - start;
} else {
gp_Pnt errPnt = BRep_Tool::Pnt(v);
Base::Console().Warning("angleWithX: Tangent not defined at (%.3f,%.3f,%.3f)\n",errPnt.X(),errPnt.Y(),errPnt.Z());
//throw ??????
}
}
result = atan2(uVec.y,uVec.x);
return result;
}
bool DrawUtil::isFirstVert(TopoDS_Edge e, TopoDS_Vertex v)
{
bool result = false;
TopoDS_Vertex first = TopExp::FirstVertex(e);
if (isSamePoint(first,v)) {
result = true;
}
return result;
}
bool DrawUtil::isLastVert(TopoDS_Edge e, TopoDS_Vertex v)
{
bool result = false;
TopoDS_Vertex last = TopExp::LastVertex(e);
if (isSamePoint(last,v)) {
result = true;
}
return result;
}
//based on Function provided by Joe Dowsett, 2014
double DrawUtil::sensibleScale(double working_scale)
{