GeomFill_Frenet继承自GeomFill_TrihedronLaw类。GeomFill_Frenet类主要用于实现Frenet标架的计算。Frenet标架是一个沿曲线移动的局部坐标系,它由切向量、法向量和副法向量组成,常用于机器人学、计算机图形学等领域。
class GeomFill_Frenet : public GeomFill_TrihedronLaw
{
public:
Standard_EXPORT GeomFill_Frenet();
Standard_EXPORT virtual Handle(GeomFill_TrihedronLaw) Copy() const Standard_OVERRIDE;
Standard_EXPORT void Init();
Standard_EXPORT virtual Standard_Boolean SetCurve (const Handle(Adaptor3d_Curve)& C) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean D0 (const Standard_Real Param, gp_Vec& Tangent, gp_Vec& Normal, gp_Vec& BiNormal) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean D1 (const Standard_Real Param, gp_Vec& Tangent, gp_Vec& DTangent, gp_Vec& Normal, gp_Vec& DNormal, gp_Vec& BiNormal, gp_Vec& DBiNormal) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean D2 (const Standard_Real Param, gp_Vec& Tangent, gp_Vec& DTangent, gp_Vec& D2Tangent, gp_Vec& Normal, gp_Vec& DNormal, gp_Vec& D2Normal, gp_Vec& BiNormal, gp_Vec& DBiNormal, gp_Vec& D2BiNormal) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Integer NbIntervals (const GeomAbs_Shape S) const Standard_OVERRIDE;
Standard_EXPORT virtual void Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const Standard_OVERRIDE;
Standard_EXPORT virtual void GetAverageLaw (gp_Vec& ATangent, gp_Vec& ANormal, gp_Vec& ABiNormal) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean IsConstant() const Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean IsOnlyBy3dCurve() const Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(GeomFill_Frenet,GeomFill_TrihedronLaw)
protected:
private:
Standard_EXPORT Standard_Boolean IsSingular (const Standard_Real U, Standard_Integer& Index) const;
Standard_EXPORT Standard_Boolean DoSingular (const Standard_Real U, const Standard_Integer Index, gp_Vec& Tangent, gp_Vec& BiNormal, Standard_Integer& n, Standard_Integer& k, Standard_Integer& TFlag, Standard_Integer& BNFlag, Standard_Real& Delta);
Standard_EXPORT Standard_Boolean SingularD0 (const Standard_Real Param, const Standard_Integer Index, gp_Vec& Tangent, gp_Vec& Normal, gp_Vec& BiNormal, Standard_Real& Delta);
Standard_EXPORT Standard_Boolean SingularD1 (const Standard_Real Param, const Standard_Integer Index, gp_Vec& Tangent, gp_Vec& DTangent, gp_Vec& Normal, gp_Vec& DNormal, gp_Vec& BiNormal, gp_Vec& DBiNormal, Standard_Real& Delta);
Standard_EXPORT Standard_Boolean SingularD2 (const Standard_Real Param, const Standard_Integer Index, gp_Vec& Tangent, gp_Vec& DTangent, gp_Vec& D2Tangent, gp_Vec& Normal, gp_Vec& DNormal, gp_Vec& D2Normal, gp_Vec& BiNormal, gp_Vec& DBiNormal, gp_Vec& D2BiNormal, Standard_Real& Delta);
Standard_EXPORT Standard_Boolean RotateTrihedron (gp_Vec& Tangent, gp_Vec& Normal, gp_Vec& BiNormal, const gp_Vec& NewTangent) const;
gp_Pnt P;
Handle(TColStd_HArray1OfReal) mySngl;
Handle(TColStd_HArray1OfReal) mySnglLen;
Standard_Boolean isSngl;
GeomFill_Frenet():构造函数,用于初始化GeomFill_Frenet对象。
Copy():返回当前对象的副本。
Init():初始化函数,用于初始化GeomFill_Frenet对象的状态。
SetCurve(const Handle(Adaptor3d_Curve)& C):设置曲线,Adaptor3d_Curve是一个适配器,用于将不同类型的曲线统一到一个接口。
D0, D1, D2函数:这些函数是Frenet标架计算的核心,用于获取曲线在不同阶数下的导数信息。D0:计算给定参数Param处的Frenet标架的零阶导数,即切向量(Tangent)、法向量(Normal)和副法向量(BiNormal)。D1:计算一阶导数,除了切向量(Tangent)外,还包括切向量的导数(DTangent)、法向量的导数(DNormal)和副法向量的导数(DBiNormal)。D2:计算二阶导数,包括切向量的二阶导数(D2Tangent)、法向量的二阶导数(D2Normal)和副法向量的二阶导数(D2BiNormal)。
NbIntervals和Intervals函数:这两个函数用于处理曲线分段的情况,当曲线不是单调或连续时,可能需要将其拆分成多个区间来单独处理。
NbIntervals:返回给定形状S的区间数量。Intervals:将形状S的区间填充到数组T中。
GetAverageLaw函数:计算Frenet标架的平均值,包括平均切向量(ATangent)、平均法向量(ANormal)和平均副法向量(ABiNormal)。
IsConstant和IsOnlyBy3dCurve函数:这两个函数用于查询Frenet标架的某些特定属性。IsConstant:检查Frenet标架是否是常数,即是否不随参数变化。IsOnlyBy3dCurve:检查Frenet标架是否仅由3D曲线决定,与其他因素无关。
RTTI宏:DEFINE_STANDARD_RTTIEXT(GeomFill_Frenet,GeomFill_TrihedronLaw):定义运行时类型信息,使得在运行时可以准确识别GeomFill_Frenet对象的类型。
受保护和私有成员函数:IsSingular:检查给定参数U处的Frenet标架是否奇异(即无法定义或计算不稳定)。DoSingular:处理奇异点的情况,计算奇异点处的Frenet标架及其相关属性。SingularD0:可能是处理奇异点处的零阶导数的函数,但代码片段不完整,无法提供完整解释。
以下代码的主要目的是生成一组随机点,拟合一个B样条曲线,对曲线进行采样,并计算每个采样点的Frenet标架。
#include <TColgp_Array1OfPnt.hxx>
#include <math_BullardGenerator.hxx>
#include <GCPnts_UniformAbscissa.hxx>
#include <GCPnts_UniformDeflection.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#include <GeomFill_Fixed.hxx>
#include <GeomFill_Frenet.hxx>
#include <GeomFill_ConstantBiNormal.hxx>
#include <GeomFill_CorrectedFrenet.hxx>
#include <GeomFill_Darboux.hxx>
#include <GeomFill_DiscreteTrihedron.hxx>
#include <GeomFill_GuideTrihedronAC.hxx>
#include <GeomFill_GuideTrihedronPlan.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepTools.hxx>
#include <GeomAdaptor_Curve.hxx>
void test()
{
TColgp_Array1OfPnt aPoints(1, 6);
math_BullardGenerator aBullardGenerator;
for (Standard_Integer i = aPoints.Lower(); i <= aPoints.Upper(); ++i)
{
Standard_Real aX = aBullardGenerator.NextReal() * 50.0;
Standard_Real aY = aBullardGenerator.NextReal() * 50.0;
Standard_Real aZ = aBullardGenerator.NextReal() * 50.0;
aPoints.SetValue(i, gp_Pnt(aX, aY, aZ));
}
GeomAPI_PointsToBSpline aBSplineFitter(aPoints);
if (!aBSplineFitter.IsDone())
{
return;
}
Handle(Geom_BSplineCurve) aBSplineCurve = aBSplineFitter.Curve();
Handle(GeomAdaptor_Curve) aCurveAdaptor = new GeomAdaptor_Curve(aBSplineCurve);
BRepBuilderAPI_MakeEdge anEdgeMaker(aBSplineCurve);
Handle(GeomFill_Frenet) aFrenet = new GeomFill_Frenet();
aFrenet->SetCurve(aCurveAdaptor);
GeomAdaptor_Curve GAC(aBSplineCurve);
GCPnts_UniformAbscissa aPointSampler(GAC, 5.0);
for (Standard_Integer i = 1; i <= aPointSampler.NbPoints(); ++i)
{
Standard_Real aParam = aPointSampler.Parameter(i);
gp_Pnt aP = aCurveAdaptor->Value(aParam);
gp_Vec aT;
gp_Vec aN;
gp_Vec aB;
aFrenet->D0(aParam, aT, aN, aB);
std::cout << "vtrihedron vt" << i << " -origin " << aP.X() << " " << aP.Y() << " " << aP.Z() << " "
<< " -zaxis " << aB.X() << " " << aB.Y() << " " << aB.Z() << " "
<< " -xaxis " << aT.X() << " " << aT.Y() << " " << aT.Z() << std::endl;
std::cout << "vtrihedron vt" << i << " -labels xaxis T 1" << std::endl;
std::cout << "vtrihedron vt" << i << " -labels yaxis N 1" << std::endl;
std::cout << "vtrihedron vt" << i << " -labels zaxis B 1" << std::endl;
std::cout << "vsize vt" << i << " 2" << std::endl;
}
}
int main(int argc, char* argv[])
{
test();
return 0;
}
部分输出:
vtrihedron vt1 -origin 14.3321 39.5759 36.4378 -zaxis 0.603904 -0.215816 -0.767283 -xaxis 0.245889 -0.865249 0.436902
vtrihedron vt1 -labels xaxis T 1
vtrihedron vt1 -labels yaxis N 1
vtrihedron vt1 -labels zaxis B 1
vsize vt1 2
vtrihedron vt2 -origin 15.5482 35.2417 38.614 -zaxis 0.606185 -0.214462 -0.765862 -xaxis 0.240416 -0.868495 0.433493
vtrihedron vt2 -labels xaxis T 1
vtrihedron vt2 -labels yaxis N 1
vtrihedron vt2 -labels zaxis B 1
vsize vt2 2
vtrihedron vt3 -origin 16.7352 30.8904 40.772 -zaxis 0.608637 -0.213027 -0.764317 -xaxis 0.234266 -0.872095 0.429616
vtrihedron vt3 -labels xaxis T 1
vtrihedron vt3 -labels yaxis N 1
vtrihedron vt3 -labels zaxis B 1
vsize vt3 2
vtrihedron vt4 -origin 17.8894 26.52 42.9092 -zaxis 0.611285 -0.211501 -0.762626 -xaxis 0.227273 -0.876125 0.42515
vtrihedron vt4 -labels xaxis T 1
vtrihedron vt4 -labels yaxis N 1
vtrihedron vt4 -labels zaxis B 1
标签:Frenet,GeomFill,const,gp,Standard,CASCADE,Vec,include,Open From: https://blog.csdn.net/T20151470/article/details/137197284