? 1. 簡介
OCC官方在2022年10月3日發布 7.7 Beta 版,并于今天2022年11月7日正式發布 Open Cascade 7.7.0 版本,其中一個更新為:一個用于生成拓撲模型上的點集的工具方法,
Introduced new tool BRepLib_PointCloudShape generating a point set for a
topological shape.
參考新功能說明檔案和用戶檔案,其主要功能:在距離模型表面指定距離內生成點集,可以用來模擬激光掃描模型所得到的點云,提供兩種生成方式:
- 根據設定的點集密度值自動生成點集;
- 根據模型三角形網格頂點生成,[檔案特別注明該方法非執行緒安全]
2. 測驗效果
使用三個模型進行測驗,效果如下:
圖1:模型1. 正方體,邊長為10mm, 指定距離 設定為 2mm
圖2:模型1. 正方體,將 指定距離 設定為 20mm, 按密度生成
圖3:模型2. nist_ctc_05,模型來自 NIST, 按密度生成
圖4:模型2. nist_ctc_05, Use Triangulation 按三角形網格頂點生成
圖5:模型3. Schenkel,模型來自 FreeCAD, 按密度生成
3. 功能詳解
通過以上圖示,可進一步理解其具體功能是在模型周圍指定距離內以某種隨機演算法生成點集,輸入引數包括:模型、指定距離、指定密度值、是否按三角形網格頂點生成以及計算精度,
當按密度生成 時,需指定密度值;此時生成的點集接近均勻,但生成原理還有待進一步探究;如上圖1所示,
當按三角形網格頂點生成 時,將使用模型的顯示網格頂點生成點集,如上圖4所示,此時不同的指定距離所得的點集完全相同,據此可以推測點集由網格頂點直接生成,不同指定距離的生成效果如下:

因此可以推測,對已顯示模型(已具有三角網格模型)生成點集時,效率將非常快,
4. 代碼
該工具 BRepLib_PointCloudShape 是一個抽象類,但只需要實作一個接收生成點結果的介面即可:
//! Method to add point, normal to surface in this point and face for which point computed.
//! @param[in] thePoint 3D point on the surface
//! @param[in] theNorm surface normal at this point
//! @param[in] theUV surface UV parameters
//! @param[in] theFace surface (face) definition
Standard_EXPORT virtual void addPoint (const gp_Pnt& thePoint,
const gp_Vec& theNorm,
const gp_Pnt2d& theUV,
const TopoDS_Shape& theFace) = 0;

class PointCloudPntFiller : public BRepLib_PointCloudShape
{
public:
PointCloudPntFiller (Standard_Real theTol) : BRepLib_PointCloudShape (TopoDS_Shape(), theTol) {}
void SetPointArray (const Handle(Graphic3d_ArrayOfPoints)& thePoints) { myPoints = thePoints; }
protected:
virtual void addPoint (const gp_Pnt& thePoint,
const gp_Vec& theNorm,
const gp_Pnt2d& theUV,
const TopoDS_Shape& ) Standard_OVERRIDE
{
const Standard_Integer aPntIndex = myPoints->AddVertex (thePoint, theUV);
if (theNorm.SquareMagnitude() > gp::Resolution())
{
myPoints->SetVertexNormal (aPntIndex, theNorm);
}
if (myPoints->HasVertexColors())
{
Quantity_Color aColor (360.0 * Standard_Real(aPntIndex) / Standard_Real(myPoints->VertexNumberAllocated()),
1.0, 0.5, Quantity_TOC_HLS);
myPoints->SetVertexColor (aPntIndex, aColor);
}
}
private:
Handle(Graphic3d_ArrayOfPoints) myPoints;
};
PointCloudPntFiller 記錄工具生成的點集,并用于后續顯示之中,本文截圖均基于 PointCloudPntFiller 實作,
最后,仍有幾個疑問需要解決,隨機生成點演算法原理是什么、隨機距離的原理是什么?當然最重要的是該工具的具體應用場景是什么?
對此感興趣的同學可一起交流,本文源代碼地址本文源代碼,
參考資料
1. 官方博客:OCCT 7.7.0 beta version is available - Forum Open Cascade Technology
2. 用戶檔案:BRepLib_PointCloudShape Class Reference - Open CASCADE Technology Documentation
3. Open Cascade 7.7.0 Beta 源代碼:User account | OPEN CASCADE
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/528816.html
標籤:其他