Example implementation

This commit is contained in:
Abdullah Tahiri
2018-11-18 02:36:57 +01:00
committed by wmayer
parent 9a34a93db1
commit b6a37e153f
6 changed files with 99 additions and 126 deletions

View File

@@ -462,14 +462,14 @@ bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const
return false;
}
bool GeomCurve::intersect( GeomCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
bool GeomCurve::intersect( GeomCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
double tol) const
{
Handle(Geom_Curve) curve1 = Handle(Geom_Curve)::DownCast(handle());
Handle(Geom_Curve) curve2 = Handle(Geom_Curve)::DownCast(c->handle());
if(!curve1.IsNull() && !curve2.IsNull()) {
if(!curve1.IsNull() && !curve2.IsNull()) {
return intersect(curve1,curve2,points, tol);
}
else
@@ -477,38 +477,38 @@ bool GeomCurve::intersect( GeomCurve * c,
}
bool GeomCurve::intersect(const Handle(Geom_Curve) curve1, const Handle(Geom_Curve) curve2,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
bool GeomCurve::intersect(const Handle(Geom_Curve) curve1, const Handle(Geom_Curve) curve2,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
double tol) const
{
// https://forum.freecadweb.org/viewtopic.php?f=10&t=31700
if (curve1->IsKind(STANDARD_TYPE(Geom_BoundedCurve)) &&
curve2->IsKind(STANDARD_TYPE(Geom_BoundedCurve))){
Handle(Geom_BoundedCurve) bcurve1 = Handle(Geom_BoundedCurve)::DownCast(curve1);
Handle(Geom_BoundedCurve) bcurve2 = Handle(Geom_BoundedCurve)::DownCast(curve2);
gp_Pnt c1s = bcurve1->StartPoint();
gp_Pnt c2s = bcurve2->StartPoint();
gp_Pnt c1e = bcurve1->EndPoint();
gp_Pnt c2e = bcurve2->EndPoint();
auto checkendpoints = [&points,tol]( gp_Pnt p1, gp_Pnt p2) {
if(p1.Distance(p2) < tol)
points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z()));
};
checkendpoints(c1s,c2s);
checkendpoints(c1s,c2e);
checkendpoints(c1e,c2s);
checkendpoints(c1e,c2e);
}
try {
GeomAPI_ExtremaCurveCurve intersector(curve1, curve2);
if (intersector.NbExtrema() == 0 || intersector.LowerDistance() > tol) {
// No intersection
return false;
@@ -517,7 +517,7 @@ bool GeomCurve::intersect(const Handle(Geom_Curve) curve1, const Handle(Geom_Cur
for (int i = 1; i <= intersector.NbExtrema(); i++) {
if (intersector.Distance(i) > tol)
continue;
gp_Pnt p1, p2;
intersector.Points(i, p1, p2);
points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z()));
@@ -530,7 +530,7 @@ bool GeomCurve::intersect(const Handle(Geom_Curve) curve1, const Handle(Geom_Cur
else
THROWM(Base::CADKernelError,e.GetMessageString())
}
return points.size()>0?true:false;
}
@@ -547,7 +547,7 @@ bool GeomCurve::closestParameter(const Base::Vector3d& point, double &u) const
}
}
catch (StdFail_NotDone& e) {
if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))){
Base::Vector3d firstpoint = this->pointAtParameter(c->FirstParameter());
Base::Vector3d lastpoint = this->pointAtParameter(c->LastParameter());
@@ -620,7 +620,7 @@ double GeomCurve::getLastParameter() const
catch (Standard_Failure& e) {
THROWM(Base::CADKernelError,e.GetMessageString())
}
}
}
double GeomCurve::curvatureAt(double u) const
@@ -849,7 +849,7 @@ void GeomBezierCurve::Restore(Base::XMLReader& reader)
THROWM(Base::CADKernelError,"BezierCurve restore failed")
}
catch (Standard_Failure& e) {
THROWM(Base::CADKernelError,e.GetMessageString())
}
}
@@ -1530,24 +1530,24 @@ PyObject *GeomTrimmedCurve::getPyObject(void)
return 0;
}
bool GeomTrimmedCurve::intersectBasisCurves( const GeomTrimmedCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
bool GeomTrimmedCurve::intersectBasisCurves( const GeomTrimmedCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& points,
double tol) const
{
Handle(Geom_TrimmedCurve) curve1 = Handle(Geom_TrimmedCurve)::DownCast(handle());
Handle(Geom_TrimmedCurve) curve2 = Handle(Geom_TrimmedCurve)::DownCast(c->handle());
Handle(Geom_Curve) bcurve1 = curve1->BasisCurve();
Handle(Geom_Curve) bcurve2 = curve2->BasisCurve();
if(!bcurve1.IsNull() && !bcurve2.IsNull()) {
return intersect(bcurve1, bcurve2, points, tol);
}
else
return false;
}
// -------------------------------------------------
@@ -3661,7 +3661,7 @@ void GeomLineSegment::setPoints(const Base::Vector3d& Start, const Base::Vector3
// Create line out of two points
if (p1.Distance(p2) < gp::Resolution())
THROWM(Base::ValueError,"Both points are equal");
GC_MakeSegment ms(p1, p2);
if (!ms.IsDone()) {
THROWM(Base::CADKernelError,gce_ErrorStatusText(ms.Status()))
@@ -3723,21 +3723,20 @@ void GeomLineSegment::Restore (Base::XMLReader &reader)
EndY = reader.getAttributeAsFloat("EndY");
EndZ = reader.getAttributeAsFloat("EndZ");
Base::Vector3d start(StartX,StartY,StartZ);
Base::Vector3d start(StartX,StartY,StartZ);
Base::Vector3d end(EndX,EndY,EndZ);
// set the read geometry
try {
setPoints(start, end);
}
catch(Base::ValueError &e) {
// for a line segment construction, the only possibility of a value error is that
// for a line segment construction, the only possibility of a value error is that
// the points are too close. The best try to restore is incrementing the distance.
// for other objects, the best effort may be just to leave default values.
reader.setPartialRestore(true);
end = start + Base::Vector3d(start.x*DBL_EPSILON,0,0);
setPoints(start, end);
THROWM(Base::RestoreError, e.getMessage());
}
}