@版權(quán)聲明:本文版權(quán)歸作者所有,歡迎轉(zhuǎn)載讼庇,但未經(jīng)作者同意必須保留此段聲明绎巨,且在文章頁(yè)面明顯位置給出,
本文鏈接http://www.reibang.com/p/92ede833b8bc
如有問(wèn)題, 可郵件(yumxuanyi@qq.com)咨詢(xún)蠕啄。
關(guān)鍵字:OpenCASCADE场勤、OpenGL、曲線離散化歼跟、GCPnts
一和媳、概要
計(jì)算機(jī)圖形學(xué)中繪制曲線,無(wú)論是繪制參數(shù)曲線還是非參數(shù)曲線哈街,都需要先將參數(shù)曲線進(jìn)行離散化留瞳,通過(guò)離散化得到一組離散化的點(diǎn)集,然后再將點(diǎn)集發(fā)送給圖形渲染管線進(jìn)行處理骚秦,最終生成我們想要的曲線她倘。
OpenCASCADE中提供了GCPnts包。利用GCPnts包中提供的類(lèi)作箍,我們可以很方便的將三維曲線進(jìn)行離散化帝牡。
二、GCPnts包中各種類(lèi)說(shuō)明
1. GCPnts_AbscissaPoint 弧長(zhǎng)點(diǎn)算法
a. 可以用來(lái)計(jì)算曲線長(zhǎng)度蒙揣。
b. 用來(lái)計(jì)算曲線上與給定參數(shù)位置間隔一定弧長(zhǎng)的位置點(diǎn)靶溜。
其中b很有用,后面均勻弧長(zhǎng)算法內(nèi)部就用到了
通過(guò)函數(shù)積分來(lái)計(jì)算曲線弧長(zhǎng)
math_GaussSingleIntegration: 該類(lèi)使用高斯勒讓得積分算法,實(shí)現(xiàn)了對(duì)只有一個(gè)自變量的函數(shù)求積分
算法如下:
- 微元弧長(zhǎng) ds
已知曲線Adaptor3d_Curve adaptorCurve,可以求得任意一點(diǎn)的切向量
gp_Pnt curentPnt; gp_Vec curVec;
adaptorCurve.D1(parameter,curentPnt,curVec);
切向量的兩個(gè)坐標(biāo)就是dx 和 dy,
所以對(duì)于曲線有微元弧長(zhǎng) ds = sqrt(dx^2 + dy^2) =curVec.Magnitude(); - 根據(jù)高斯-勒讓得積分公式進(jìn)行積分求解懒震。
根據(jù)積分點(diǎn)和權(quán)重近似計(jì)算函數(shù)積分罩息。這個(gè)近似精度非常高
“”
2. GCPnts_QuasiUniformAbscissa 準(zhǔn)均勻弧長(zhǎng)分布算法
功能:計(jì)算的曲線上的一組離散點(diǎn),這些點(diǎn)按弧長(zhǎng)均勻分布个扰。
說(shuō)明: 該方法需要指定一個(gè)期望的離散點(diǎn)的個(gè)數(shù)瓷炮。
算法:每?jī)蓚€(gè)連續(xù)的離散點(diǎn)之間的弧長(zhǎng)相等。
事例代碼:
//GCPnts_QuasiUniformAbscissa 準(zhǔn)均勻弧長(zhǎng)分布算法 也就是等弧長(zhǎng)分布
// 計(jì)算一組按弧長(zhǎng)均勻分布的離散點(diǎn)
// 可以根據(jù)指定的弧長(zhǎng) 或者指定的多少個(gè)點(diǎn)
//Abscissa is the curvilinear distance between two consecutive points of the distribution
//Abscissa 表示連續(xù)的兩個(gè)分布點(diǎn)之間的弧長(zhǎng)
//算法 兩點(diǎn)之間的弧長(zhǎng)等于的弧長(zhǎng)
GCPnts_QuasiUniformAbscissa QUATooler;
//curveLength 可以由GCPnts_AbscissaPoint求得這里取曲線總長(zhǎng)的兩倍
Standard_Integer needPointsCount = curveLength * 2.0; //表示期望的點(diǎn)數(shù)量
QUATooler.Initialize(adaptorCurve, needPointsCount);//取兩倍曲線長(zhǎng)度的點(diǎn) 也就是0.5mm弧長(zhǎng)一個(gè)點(diǎn)
Standard_Integer pointsCount = QUATooler.NbPoints();
TColgp_SequenceOfPnt SeqP;
for (int i = 1; i <= pointsCount; i++)
{
SeqP.Append(adaptorCurve.Value(QUATooler.Parameter(i)));
}
注:半徑50圓 GCPnts_QuasiUniformAbscissa計(jì)算的點(diǎn)有628個(gè)递宅。
3. GCPnts_UniformAbscissa 均勻弧長(zhǎng)分布算法
功能:同方法GCPnts_QuasiUniformAbscissa娘香,用于計(jì)算的曲線上的一組離散點(diǎn)苍狰,這些點(diǎn)按弧長(zhǎng)均勻分布。
但是提供兩種方式: a. 指定期望點(diǎn)的個(gè)數(shù) b. 指定弧長(zhǎng)烘绽。
事例代碼:
GCPnts_UniformAbscissa UATooler;
//a 指定期望點(diǎn)的個(gè)數(shù)
//同GCPnts_QuasiUniformAbscissa 這里不舉例
//UATooler.Initialize(adaptorCurve, needPointsCount);
//b 指定弧長(zhǎng)
Standard_Real abscissa = 10;//弧長(zhǎng)10mm
UATooler.Initialize(adaptorCurve, abscissa);
Standard_Integer pntCount = UATooler.NbPoints(); TColgp_SequenceOfPnt SeqP;
for (int i = 1; i <= pntCount; i++)
{
SeqP.Append(adaptorCurve.Value(UATooler.Parameter(i)));
}
注:半徑50圓 弧長(zhǎng) 0.5mm 計(jì)算的點(diǎn)有630個(gè)
2 * 3.1415926 * 50 / 0.5 = 628.31852
半徑50圓 弧長(zhǎng) 10mm 計(jì)算的點(diǎn)有33個(gè)
2 * 3.1415926 * 50 / 10 = 31.415926
4. GCPnts_QuasiUniformDeflection 準(zhǔn)均勻偏差分布算法
功能:計(jì)算的曲線上的一組離散點(diǎn)淋昭。
算法說(shuō)明:
假定 Pi 和 Pj為 分布的兩連續(xù)的離散點(diǎn) ,它們的參數(shù)為ui和uj。
計(jì)算偏差deflection :Pi和Pj連線(弦長(zhǎng))的中點(diǎn)和曲線上中間參數(shù) [(ui+uj) / 2 ] 位置點(diǎn)之間的距離安接。
則兩連續(xù)的離散點(diǎn)的計(jì)算偏差deflection必須小于給定的偏差Deflection值翔忽。
事例代碼:
GCPnts_QuasiUniformDeflection QUDTooler;
QUDTooler.Initialize(adaptorCurve, 1.e-5);//這里我們要求 deflection <= 1.e-5
Standard_Integer pointsLength = QUDTooler.NbPoints(); TColgp_SequenceOfPnt SeqP;
for (int i = 1; i <= pointsLength; i++)
{
SeqP.Append(QUDTooler.Value(i));
}
注:半徑50圓 準(zhǔn)均勻偏差分布算法計(jì)算的點(diǎn)有4969個(gè)。
5. GCPnts_UniformDeflection 均勻偏差算法
功能:用于計(jì)算C2連續(xù)的曲線上的一組離散點(diǎn)盏檐。
該算法比較耗時(shí)歇式。請(qǐng)使用GCPnts_QuasiUniformDeflection算法。
GCPnts_QuasiUniformDeflection方法可以用于計(jì)算非C2連續(xù)的曲線胡野。
6. GCPnts_TangentialDeflection 切矢量偏離算法
功能:計(jì)算的曲線上的一組離散點(diǎn)材失。
算法原理:如果P1(u1)和 P2(u2) 曲線上兩個(gè)連續(xù)的離散點(diǎn)。
P3 表示曲線上中間參數(shù) ((u1+u2)/2)點(diǎn)硫豆。
則P3需要滿足如下條件:
條件1: ||P1P3^P3P2||/||P1P3||*||P3P2||<AngularDeflection
偏轉(zhuǎn)角度小于給定的角度AngularDeflection
a * b = |a||b|cosθ 也就是 cosθ < AngularDeflection
條件2 : ||P1P2^P1P3||/||P1P2||<CurvatureDeflection
表示曲線切線 與 弦長(zhǎng)夾角要小于 給定的曲線偏離率CurvatureDeflection
|a|cosθ < CurvatureDeflection
事例代碼:
GCPnts_TangentialDeflection TDTooler; //聲明算法類(lèi)
Standard_Real AngularDeflection = 1 / M_PI_4; //這里去角度偏差1 / M_PI_4
Standard_Real CurvatureDeflection = 1.e-5; //這里去曲率偏差 1.e-5
TDTooler.Initialize(adaptorCurve, AngularDeflection, CurvatureDeflection); //算法初始化
Standard_Integer PLength = TDTooler.NbPoints();
TColgp_SequenceOfPnt SeqP
for (int i = 1; i <= PLength; i++)
{
SeqP.Append(TDTooler.Value(i));
}
注:半徑50圓 使用切矢量偏離算法計(jì)算的點(diǎn)有4969個(gè)豺憔。