Part: Geometry functionality extension

======================================

Added for curves:
getFirstParameter
getLastParameter
curvatureAt
length

Modified:
normalAt(double u, Base::Vector3d& dir)

as it was not working properly.
This commit is contained in:
Abdullah Tahiri 2017-02-09 00:05:46 +01:00 committed by wmayer
parent 1bac54e63e
commit 9c10b3219d
2 changed files with 90 additions and 7 deletions

View File

@ -93,6 +93,7 @@
# include <GC_MakeArcOfHyperbola.hxx> # include <GC_MakeArcOfHyperbola.hxx>
# include <GC_MakeLine.hxx> # include <GC_MakeLine.hxx>
# include <GC_MakeSegment.hxx> # include <GC_MakeSegment.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <Precision.hxx> # include <Precision.hxx>
# include <GeomAPI_ProjectPointOnCurve.hxx> # include <GeomAPI_ProjectPointOnCurve.hxx>
# include <ShapeConstruct_Curve.hxx> # include <ShapeConstruct_Curve.hxx>
@ -375,14 +376,24 @@ Base::Vector3d GeomCurve::secondDerivativeAtParameter(double u) const
return Base::Vector3d(vec.X(),vec.Y(),vec.Z()); return Base::Vector3d(vec.X(),vec.Y(),vec.Z());
} }
bool GeomCurve::normal(double u, gp_Dir& dir) const bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const
{ {
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle()); Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
GeomLProp_CLProps prop(c,u,1,Precision::Confusion());
if (prop.IsTangentDefined()) { try {
prop.Normal(dir); if (!c.IsNull()) {
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
gp_Dir gdir;
prop.Normal(gdir);
dir = Base::Vector3d(gdir.X(), gdir.Y(), gdir.Z());
return true; return true;
} }
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
return false; return false;
} }
@ -433,6 +444,74 @@ bool GeomCurve::closestParameterToBasicCurve(const Base::Vector3d& point, double
} }
} }
double GeomCurve::getFirstParameter() const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
try {
if (!c.IsNull()) {
// pending check for RealFirst RealLast in case of infinite curve
return c->FirstParameter();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}
double GeomCurve::getLastParameter() const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
try {
if (!c.IsNull()) {
// pending check for RealFirst RealLast in case of infinite curve
return c->LastParameter();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}
double GeomCurve::curvatureAt(double u) const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
try {
if (!c.IsNull()) {
GeomLProp_CLProps prop(c,u,2,Precision::Confusion());
return prop.Curvature();
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}
double GeomCurve::length(double u, double v) const
{
Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(handle());
try {
if (!c.IsNull()) {
GeomAdaptor_Curve adaptor(c);
return GCPnts_AbscissaPoint::Length(adaptor,u,v,Precision::Confusion());
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::RuntimeError(e->GetMessageString());
}
}
// ------------------------------------------------- // -------------------------------------------------
TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomBoundedCurve, Part::GeomCurve) TYPESYSTEM_SOURCE_ABSTRACT(Part::GeomBoundedCurve, Part::GeomCurve)

View File

@ -139,9 +139,13 @@ public:
Base::Vector3d pointAtParameter(double u) const; Base::Vector3d pointAtParameter(double u) const;
Base::Vector3d firstDerivativeAtParameter(double u) const; Base::Vector3d firstDerivativeAtParameter(double u) const;
Base::Vector3d secondDerivativeAtParameter(double u) const; Base::Vector3d secondDerivativeAtParameter(double u) const;
bool normal(double u, gp_Dir& dir) const;
bool closestParameter(const Base::Vector3d& point, double &u) const; bool closestParameter(const Base::Vector3d& point, double &u) const;
bool closestParameterToBasicCurve(const Base::Vector3d& point, double &u) const; bool closestParameterToBasicCurve(const Base::Vector3d& point, double &u) const;
double getFirstParameter() const;
double getLastParameter() const;
double curvatureAt(double u) const;
double length(double u, double v) const;
bool normalAt(double u, Base::Vector3d& dir) const;
}; };
class PartExport GeomBoundedCurve : public GeomCurve class PartExport GeomBoundedCurve : public GeomCurve