从表面减去封闭的网格(CGAL?) [英] Substract closed mesh from surface (CGAL?)

查看:160
本文介绍了从表面减去封闭的网格(CGAL?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题,最好用下图描述。

I have the following problem, best described with the picture below.

我有3D曲面,因此它可以垂直重叠并且是非封闭的网格。我有一个要从中减去的对象。绿色+黄色区域是原始表面,红色线勾勒出一个球体(作为三角网格,而不是图元)。黄色区域是与球相交的表面部分,需要从原始表面移除。绿色区域是相减的结果:所需的表面。

I have a surface in 3D, so it can have vertical overlap and is a non-closed mesh. And I have an object which I want to subtract from it. The green+yellow area is the original surface, the red lines outline a sphere (as triangulated mesh, not a primitive). The yellow area is the part of the surface intersecting the sphere that needs to be removed from the original surface. The green area is the result of the subtraction: the surface that is needed.

我已经在使用CGAL库,但是它仍然是新的,因此使用CGAL的解决方案将是最优选的。但是,如果有人也提供了没有CGAL的解决方案,那也将受到欢迎。

I am already using the CGAL library, but still new to it, so a solution using CGAL would be the most preferred. However if somebody has a solution without CGAL that would be welcome as well.

我能看到的最好方法是使表面略微厚度(保持当前表面作为底部)。然后使用Nef_polyhedron_3减去另一个对象,然后转换为Polyhedron_3并仅保留底面。但这似乎有点hack。

The best way I can see would be to give the surface a slight thickness (keeping the current surface as the bottom). And then use Nef_polyhedron_3 to substract the other object, then convert to Polyhedron_3 and only keep the bottom faces. But this seems like a bit of a hack.

编辑:
使用提议的解决方案,我非常接近,但是我无法使用提议的反向法线使用以下代码将剪辑固定到正确的一侧。
我还尝试查看面顶点排序(顺时针/逆时针)是否有效,但似乎没有任何作用。

Using the proposed solution I get very close, but I am unable to clip to the correct side using the reversed normals as proposed, using the following code. I also tried to see if face vertex ordering (clockwise / counter clockwise) has any effect, but it seems not to have any.

typedef CGAL::Simple_cartesian<double>                  SC;
typedef CGAL::Surface_mesh<SC::Point_3>                 SurfaceMesh;
typedef SurfaceMesh::Property_map<SM_fid, SC::Vector_3> SM_fnormals;
typedef SurfaceMesh::Vertex_index                       SM_vid;
typedef SurfaceMesh::Face_index                         SM_fid;

namespace PMP = CGAL::Polygon_mesh_processing;
namespace params = PMP::parameters;

void clip(SurfaceMesh P&, SurfaceMesh& Q) {        
    SM_fnormals fnormals = CGALobstacle->add_property_map<SM_fid, SC::Vector_3>
        ("f:normals", CGAL::NULL_VECTOR).first;

    PMP::compute_face_normals(Q, fnormals);

    PMP::clip(P, Q, false, params::all_default(), params::face_normal_map(fnormals));
}


推荐答案

有一个未记录的函数开始从CGAL 4.10中的 Polygon_mesh_processing / include / CGAL / Polygon_mesh_processing / internal / clip.h 开始。函数签名为:

There is an undocumented function starting from CGAL 4.10 in Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/clip.h. The function signature is :

/// requires face_index_map, vertex_index_map for np_tm
/// requires face_index_map for np_c
/// if edge_is_constrained_map is not provided in np_tm a default one is
/// provided using boost::unordered_set<edge_descriptor>
template <class TriangleMesh,
          class NamedParameters1,
          class NamedParameters2>
bool
clip(      TriangleMesh& tm,
 /*const*/ TriangleMesh& clipper,
           bool close,
     const NamedParameters1& np_tm,
     const NamedParameters2& np_c)

第二个参数是您的球体,第一个是您的曲面。第三个指示是否要关闭输出表面(在您的情况下为false)。请注意,该函数是裁剪的,因此,如果需要球体的外部,则需要反转球体的方向(向内法线)。

The second parameter would be your sphere and the first your surface. The third indicates if you want the output surface to be closed (so false in your case). Note that the function is clipping so if you want the outside part of the sphere you need to reverse the orientation of your sphere (inward normals).

有一个用法示例此处

我建议使用 Surface_mesh 而不是 Polyhedron_3

请注意,该函数未记录在文档中,并且标头可能会在即将发布的版本中消失(如果这样做,则表明它已正式记录在文档中。)

Note that the function is not documented and the header might disappear in an upcoming release (if it does it means that it got officially documented).

编辑:自CGAL 4.13起正式记录的功能是这里

EDIT: The officially documented function since CGAL 4.13 is here.

这篇关于从表面减去封闭的网格(CGAL?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆