OpenCASCADE BRepMesh - 2D Delaunay Triangulation

eryar@163.com

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.

Key Words. BRepMesh, Delaunay Triangulation,

1.Introduction

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

https://www.opencascade.com/content/brepmeshincremental-mesh-algorithm

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即可看到剖分结果,如下图所示:

3.Conclusion

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

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

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

OpenCASCADE BRepMesh - 2D Delaunay Triangulation的更多相关文章

  1. Delaunay Triangulation in OpenCascade

    Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...

  2. C++ version the delaunay triangulation

    https://github.com/Bl4ckb0ne/delaunay-triangulation

  3. Delaunay triangulation

    1,先花个圆: detail模式执行. #define XY 0x00 #define XZ 0x01 #define YZ 0x02 #define pi 3.1415926 #define clo ...

  4. CG&CAD resource

    Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...

  5. OpenCASCADE PCurve of Topological Face

    OpenCASCADE PCurve of Topological Face eryar@163.com Abstract. OpenCASCADE provides a class BRepBuil ...

  6. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

  7. Representation Data in OpenCascade BRep

    Representation Data in OpenCascade BRep eryar@163.com 摘要Abstract:现在的显示器大多数是光栅显示器,即可以看做一个像素的矩阵.在光栅显示器 ...

  8. Visualize Surface by Delaunay Triangulator

    Visualize Surface by Delaunay Triangulator eryar@163.com Abstract. Delaunay Triangulation is the cor ...

  9. Mesh Algorithm in OpenCascade

    Mesh Algorithm in OpenCascade eryar@163.com Abstract. Rendering a generic surface is a two steps pro ...

随机推荐

  1. 基于NIO的Socket通信

    一.NIO模式的基本原理: 服务端: 首先,服务端打开一个通道(ServerSocketChannel),并向通道中注册一个通道调度器(Selector):然后向通道调度器注册感兴趣的事件Select ...

  2. Collecting Bugs poj2096 概率DP

                                                                Collecting Bugs Time Limit: 10000MS   Me ...

  3. httpd网页身份认证

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  4. 用MXNet实现mnist的生成对抗网络(GAN)

    用MXNet实现mnist的生成对抗网络(GAN) 生成式对抗网络(Generative Adversarial Network,简称GAN)由一个生成网络与一个判别网络组成.生成网络从潜在空间(la ...

  5. RobotFramework自动化测试框架-移动手机自动化测试Click Element关键字的使用

    Click Element关键字用来模拟点击APP界面上的一个元素,该关键字接收一个参数[ locator ] ,这里的locator指的是界面元素的定位方式. 示例1:使用Click Element ...

  6. pgpool-II主备流复制的架设

    1.环境 OS: CentOS release 6.4 (Final) DB: postgresql 9.3.6 pgpool服务器: pgpool 172.16.0.240 数据库主服务器:mast ...

  7. 【转】Windows自动连接、断开无线网络

    前提是先连接到指定的WiFi网络上. 然后通过 netsh wlan export profile 将网络配置文件导出,然后使用如下命令添加配置文件到指定的网络接口上,再执行连接命令即可. netsh ...

  8. windows2008(64位)下iis7.5中的url伪静态化重写(urlrewrite)

    以前在windows2003里,使用的是iis6.0,那时常使用的URL重写组件是iisrewrite,当服务器升级到windows2008R2时,IIS成了64位的7.5,结果iisreite组件是 ...

  9. 利用python生成交换机的VRF配置文件

    为了快速生成有规律的VRF,写了一个python脚本,可以快速生成如下的VRF配置. ip vpn-instance  vpn0ipv4-family  route-distinguisher 600 ...

  10. git的使用(进阶篇)

    如何处理代码冲突 冲突合并一般是因为自己的本地做的提交和服务器上的提交有差异,并且这些差异中的文件改动,Git不能自动合并,那么就需要用户手动进行合并 如我这边执行git pull origin ma ...