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. 记2017问鼎杯预赛的wp---来自一个小菜鸡的感想

    这次准备写一下几个misc和密码题目..很坑. 打了一整天的比赛,越来越觉得自己很菜了. 有一道题目叫做"真真假假",这道题目只有一个提示--Xor.第一眼知道是异或,也就知道这一 ...

  2. Webx项目的获取与验证

    在JavaWeb环境配置后就可进行Webx实例项目的获取与研读了. 1.创建一个初始的Demo工程. 1)下载 Webx Maven 项目的目录结构Artifact插件. archetype-webx ...

  3. Kia's Calculation hdu4726

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. 使用python实现后台系统的JWT认证(转)

    今天的文章介绍一种适用于restful+json的API认证方法,这个方法是基于jwt,并且加入了一些从oauth2.0借鉴的改良. 1. 常见的几种实现认证的方法 首先要明白,认证和鉴权是不同的.认 ...

  5. SqlServer和Oracle中一些常用的sql语句5 流程控制语句

    --在sql语句中 begin...end 用来设定一个程序块 相关于c#中的{} declare @yz real,@w int --声明变量 set @w=120 --为变量赋值 if @w< ...

  6. SSM框架整合项目 :投票系统

    框架: Spring SpringMVC MyBatis 题目: 投票系统 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastjson 5, aspe ...

  7. 我的第一个python web开发框架(7)——本地部署前端访问服务器

    PS:本系列内容进度节奏会放的很慢,每次知识点都尽量少一点,这样大家接触的知识点少了,会更容易理解,因为少即是多.另外,对于后面代码部分,虽然尽量不用那些复杂的封装和类,但它并不表示看了就能全部记住, ...

  8. python3.6安装pyspider

    win10下安装pyspider 1.pip 我在安装pip的时候默认安装了Pip. 如果没有的话:pip安装 2.PhantomJS PhantomJS 是一个基于 WebKit 的服务器端 Jav ...

  9. JIRA-6.3.6安装与破解

    首先下载JIRA-6.3.6的安装包: wget http://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-6.3. ...

  10. Visual Studio 自定义项目模板

    经常我们需要新建一个项目,然后新建我们的View文件夹,ViewModel文件夹,Model文件夹,还有把我们的ViewModelBase放入我们的VIewModel,如果还用框架,还需要加上好多. ...