OpenCASCADE BRepMesh - 2D Delaunay Triangulation

OpenCASCADE BRepMesh - 2D Delaunay Triangulation

eryar@163.com文章来源地址:https://www.yii666.com/article/758080.html

Abstract. OpenCASCADE package BRepMesh can compute the Delaunay’s triangulation with the algorithm of Watson. It can be used for 2d plane or on surface by meshing in UV parametric space. The blog focus on the usage of the triangulation tool to triangulate 2d points.文章来源地址https://www.yii666.com/article/758080.html

Key Words. BRepMesh, Delaunay Triangulation,

1.Introduction

点集的三角剖分Triangulation主要用于几何数据的可视化,在所有的造型内核中都有三角剖分的功能,用来生成模型的网格数据交给图形接口,如OpenGL等来显示。OpenCASCADE中使用类BRepMesh_IncrementalMesh来将TopoDS_Shape进行三角剖分得到显示数据。其原理根据其名字可以这样解释,使用了增量算法,不停的剖分直到结果的三角形满足精度要求。

https://www.opencascade.com/content/brepmeshincremental-mesh-algorithm文章地址https://www.yii666.com/article/758080.html网址:yii666.com<

OpenCASCADE的BRepMesh只能用于二维点集的三角剖分,所以对于任意曲面的三角剖分,可以对其参数空间UV使用增量算法进行剖分,直到最终的三角剖分满足显示精度要求,最后将参数空间UV映射回实际的三维模型空间。所以三角剖分的关键就成了寻找合理的剖分点,在尽量少的剖分点情况下,使剖分满足显示精度要求。

本文主要介绍如何使用OpenCASCADE中BRepMesh来对二维点集进行三角剖分,最后将剖分结果在Draw Test Harness中进行可视化,便于实时查看剖分结果。

2.Code Example

使用BRepMesh直接对二维点集进行三角剖分,代码如下所示:

/*
Copyright(C) 2017 Shing Liu(eryar@163.com) Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions : The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/ #include <math_BullardGenerator.hxx> #include <BRepMesh.hxx>
#include <BRepMesh_Delaun.hxx>
#include <BRepMesh_DataStructureOfDelaun.hxx> #pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib") #pragma comment(lib, "TKG2d.lib")
#pragma comment(lib, "TKG3d.lib")
#pragma comment(lib, "TKGeomBase.lib")
#pragma comment(lib, "TKGeomAlgo.lib") #pragma comment(lib, "TKBRep.lib")
#pragma comment(lib, "TKTopAlgo.lib")
#pragma comment(lib, "TKMesh.lib") void testMesh(Standard_Integer thePointCount)
{
std::ofstream aTclFile("d:/mesh.tcl"); math_BullardGenerator aRandom; BRepMesh::Array1OfVertexOfDelaun aVertices(, thePointCount); for (Standard_Integer i = aVertices.Lower(); i <= aVertices.Upper(); ++i)
{
gp_XY aPoint;
aPoint.SetX(aRandom.NextReal() * aVertices.Upper());
aPoint.SetY(aRandom.NextReal() * aVertices.Upper()); BRepMesh_Vertex aVertex(aPoint, i, BRepMesh_Frontier); aVertices.SetValue(i, aVertex); // output point to Draw Test Harness.
aTclFile << "vpoint p" << i << " " << aPoint.X() << " " << aPoint.Y() << "" << std::endl;
} BRepMesh_Delaun aDelaunay(aVertices);
Handle(BRepMesh_DataStructureOfDelaun) aMeshStructure = aDelaunay.Result(); const BRepMesh::MapOfInteger& aTriangles = aMeshStructure->ElementsOfDomain();
BRepMesh::MapOfInteger::Iterator aTriangleIt(aTriangles);
for (aTriangleIt; aTriangleIt.More(); aTriangleIt.Next())
{
const Standard_Integer aTriangleId = aTriangleIt.Key();
const BRepMesh_Triangle& aCurrentTriangle = aMeshStructure->GetElement(aTriangleId); if (aCurrentTriangle.Movability() == BRepMesh_Deleted)
{
continue;
} Standard_Integer aTriangleVerts[];
aMeshStructure->ElementNodes(aCurrentTriangle, aTriangleVerts); // output line to Draw Test Harness.
aTclFile << "vline l" << aTriangleId << "1 p" << aTriangleVerts[] << " p" << aTriangleVerts[] << std::endl;
aTclFile << "vline l" << aTriangleId << "2 p" << aTriangleVerts[] << " p" << aTriangleVerts[] << std::endl;
aTclFile << "vline l" << aTriangleId << "3 p" << aTriangleVerts[] << " p" << aTriangleVerts[] << std::endl;
} aTclFile.close();
} int main(int argc, char* argv[])
{
testMesh(); return ;
}

程序使用随机数据生成的点集进行三角剖分并将三角剖分结果输出到D盘mesh.tcl文件,在Draw Test Harness中导入mesh.tcl即可看到剖分结果,如下图所示:

OpenCASCADE BRepMesh - 2D Delaunay Triangulation

OpenCASCADE BRepMesh - 2D Delaunay Triangulation

3.Conclusion

BRepMesh可以对二维点集进行三角剖分,使用简单,只需要将点集传入类BRepMesh_Delaun即可。

将三角剖分结果生成Draw Test Harness脚本的方法,可以用来方便地将剖分结果可视化。自己开发程序的时候也可采用这个方法将造型的模型数据在Draw Test Harness中显示。网址:yii666.com

如果三角剖分的点集中有孔需要去除,OpenCASCADE应该也提供了这个功能,有待发掘。

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png