eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 603, comments - 590, trackbacks - 0, articles - 0

Boolean operations between triangle meshes

Posted on 2018-05-17 23:18 eryar 阅读(2157) 评论(0)  编辑 收藏 引用 所属分类: 2.OpenCASCADE

Boolean operations between triangle meshes

eryar@163.com

Abstract. Boolean operations is one of basic and well known on 3D models. The operations are widely used in computer graphics, game, CAD, EDA. The blog introduce the function in some open source program. 

Key Words. Boolean Operations, Mesh, Triangle Mesh Boolean Operations,

1.Introduction

OpenCASCADE提供了基于BREP体的Boolean Operations,但是如果Topo体中只包含三角网格信息的话,是不支持布尔运算的。典型的例子就是由STL导入生成的模型在OpenCASCADE中是不能进行布尔运算。

有一些开源库提供了基于三角网格的布尔运算的功能。如MeshLab、Cork等。本文主要就来介绍一下这两个库中的基于三角网格的布尔运算功能。

wps_clip_image-6945

Figure 1. Boolean Operation cut between Cylinder and Torus mesh

基于网格有布尔运算主要应用于没有几何信息的模型,如游戏、3D打印中的网格模型。

2.MeshLab CSG

MeshLab中提供了网格的布尔运算功能,源码在filter_csg中。程序界面如下图所示:

wps_clip_image-25211

Figure 2. CSG Operation in MeshLab

下图所示为两个网格球的公共部分Intersection的结果:

wps_clip_image-31437

Figure 3. Intersection between sphere meshes

由上图可以看出,经过布尔运算后,网格变密了。

wps_clip_image-5546

Figure 4. Union between sphere meshes

上图所示为两个网格球的合并union结果。合并后的网格也变密了。

wps_clip_image-19657

Figure 5. Difference between sphere meshes

3.Cork 

Cork是一个小巧的用于网格布尔运算的开源库(LGPL),可以从如下地址下载:

https://github.com/gilbo/cork

下面使用cork编译出来的程序来测试下前面两个球的网格。在Windows中可以编译一个测试的应用程序,可以输入命令来测试效果:

wps_clip_image-14008

Figure 6. Cork help info

将测试文件ballA.off和ballB.off复制到编译出来的程序wincork相同的文件夹中,分别输入以下命令来得到相应的布尔运算结果:

F:\Mesh\cork\win\wincork\>wincork -union balla.off ballb.off union.off
F:\Mesh\cork\win\wincork\>wincork -diff balla.off ballb.off diff.off
F:\Mesh\cork\win\wincork\>wincork -isct balla.off ballb.off isct.off

然后将生成的union.off、diff.off和isct.off在MeshLab中打开如下图所示:

wps_clip_image-6071

Figure 7. Union between two sphere meshes

wps_clip_image-29249

Figure 8. Difference between two sphere meshes

wps_clip_image-7233

Figure 9. Intersection between two sphere meshes

从上面结果可以看出cork库得到的结果网格效果好,没有加密。

4. Conclusion

基于网格的布尔运算也是三维建模中一个基本功能,一些开源库提供了对网格进行布尔运算的支持。如MeshLab, Cork, CGAL等。

本文通过在MeshLab和Cork中对两个球的网格进行布尔运算,对比运算的结果,发现使用Cork得到的网格没有加密,数据量会小一些。

由于OpenCASCADE目前的版本不支持基于网格的布尔运算,在其官网上提供了一个功能请求:https://tracker.dev.opencascade.org/view.php?id=29776

wps_clip_image-7484


为了方便大家在移动端也能看到我的博文和讨论交流,现已注册微信公众号,欢迎大家扫描下方二维码关注。
Shing Liu(eryar@163.com)

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理