OpenCASCADE BRepMesh - 2D Delaunay Triangulation
OpenCASCADE BRepMesh - 2D Delaunay Triangulation
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的更多相关文章
- Delaunay Triangulation in OpenCascade
Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...
- C++ version the delaunay triangulation
https://github.com/Bl4ckb0ne/delaunay-triangulation
- Delaunay triangulation
1,先花个圆: detail模式执行. #define XY 0x00 #define XZ 0x01 #define YZ 0x02 #define pi 3.1415926 #define clo ...
- CG&CAD resource
Computational Geometry The Geometry Center (UIUC) Computational Geometry Pages (UIUC) Geometry in Ac ...
- OpenCASCADE PCurve of Topological Face
OpenCASCADE PCurve of Topological Face eryar@163.com Abstract. OpenCASCADE provides a class BRepBuil ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- Representation Data in OpenCascade BRep
Representation Data in OpenCascade BRep eryar@163.com 摘要Abstract:现在的显示器大多数是光栅显示器,即可以看做一个像素的矩阵.在光栅显示器 ...
- Visualize Surface by Delaunay Triangulator
Visualize Surface by Delaunay Triangulator eryar@163.com Abstract. Delaunay Triangulation is the cor ...
- Mesh Algorithm in OpenCascade
Mesh Algorithm in OpenCascade eryar@163.com Abstract. Rendering a generic surface is a two steps pro ...
随机推荐
- nodejs+express+mongoose无法获取数据库数据问题解决
通过mongoose与mongodb进行操作.而mongoose是通过model来创建mongodb中对应的collection的,这样你通过如下的代码: mongoose.model('User', ...
- java猜数字(实验任务五)
1.程序设计思想: 先随机获取1-100之内的数字i: 在建立让用户输入数字的对话框,然后判断猜高了.低了还是猜对了: 用循环直到用户猜对了. 2.程序流程图: 3.源代码: package 实验任务 ...
- 定制自己的vue模版
前言 使用vue这个框架已经陆陆续续做了好几个项目了,不知不觉也已经在公司呆了4个月,转正了.时间如水...(省略一万字)./咳-不瞎扯了,公司是直接用的官方脚手架生成项目,官方模版没有vuex,ax ...
- ThinkJS框架入门详细教程(二)新手入门项目
一.准备工作 参考前一篇:ThinkJS框架入门详细教程(一)开发环境 安装thinkJS命令 npm install -g think-cli 监测是否安装成功 thinkjs -v 二.创建项目 ...
- zabbix灵活使用userparameters
userparameters介绍 官网文献:https://www.zabbix.com/documentation/2.0/manual/config/items/userparameters 当我 ...
- How to Add Columns to a DataGrid through Binding and Map Its Cell Values
How to Add Columns to a DataGrid through Binding and Map Its Cell Values Lance Contreras, 7 Nov 2013 ...
- 轻松几句搞定【Javascript中的this指向】问题
this关键字在JavaScript中扮演了至关重要的角色,每次它的出现都伴随着它的指向问题,这也是很多初学者容易出错的地方. 不过,这篇文章将会带你一次性搞定this指向的问题,望能给大家提供帮助! ...
- Python和SQL Server 2017的强大功能
Python和SQL Server 2017的强大功能 摘要: 源:https://www.red-gate.com/simple-talk/sql/sql-development/power-pyt ...
- vue-cli 自定义指令directive 添加验证滑块
vue项目注册登录页面遇到了一个需要滑块的功能,网上看了很多插件发现都不太好用,于是自己写了一个插件供大家参考: 用的是vue的自定义指令direcive,只需要在需要的组件里放入对应的标签嵌套即可: ...
- win10 uwp 绑定密码
win10 下,密码框无法绑定到ViewModel,Password是不可以绑定. 我们可以自己使用简单方法去绑定 我们之前在WPF 使用绑定密码框,我写了一篇,关于如何绑定,我提供一个我自己试了可以 ...