“使用CGAL计算曲率”

huangapple go评论103阅读模式
英文:

Computing curvatures with CGAL

问题

我试图理解如何使用CGAL计算SurfaceMesh(以及高斯曲率)的主曲率。

首先,我没有看到是否有一个函数可以计算网格中所有顶点的曲率?

Jet_fitting_3中似乎有一个示例,但它非常复杂,涉及到多个附加的类...

据我了解,对于每个顶点,我需要:

  1. 收集周围的点
  2. 使用monge_fit获得蒙日形式

但示例然后使用comply_wrt_given_normal修改法线,我不完全理解为什么需要这样做。

我可能也会忽略一个非常明显的函数,可以计算这个,正如我之前所说...毕竟这是一个非常重要的属性。

我成功编写的代码如下:

for (auto v : result.vertices())
{
    adj.clear();
    
    auto h = result.halfedge(v);
    
    // 找到所有相邻的顶点
    for (HalfedgeDescriptor he : result.halfedges_around_target(h))
        adj.push_back(result.point(result.source(he)));
            
    CGAL::Monge_via_jet_fitting<Kernel> monge_fit;
    CGAL::Monge_via_jet_fitting<Kernel>::Monge_form monge_form;
    
    monge_form = monge_fit(adj.begin(), adj.end(), 2, 1);
    monge_form.comply_wrt_given_normal(vn.first[v]);
    
    // 获取主曲率
    double k1 = monge_form.principal_curvatures(0);
    double k2 = monge_form.principal_curvatures(1);
}

然而,它在调用monge_fit时引发异常,异常消息如下:

CGAL error: precondition violation!
Expression: nb_input_pts >= nb_d_jet_coeff
File: /opt/homebrew/include/CGAL/Monge_via_jet_fitting.h
Line: 297
Explanation: 
Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html
libc++abi: terminating due to uncaught exception of type CGAL::Precondition_exception: CGAL ERROR: precondition violation!
Expr: nb_input_pts >= nb_d_jet_coeff
File: /opt/homebrew/include/CGAL/Monge_via_jet_fitting.h
Line: 297

所以,点的数量不足,我猜是这个问题?

然而,我不知道如何纠正这个问题... 任何提示都将不胜感激。

英文:

I am trying to understand how I can compute the principal curvatures of a SurfaceMesh (and so the gaussian one) using CGAL.

First of all, since I didn't see it, is there any function that computes a curvature for all vertices in a mesh?

There seems to be an example in Jet_fitting_3, but it's really convoluted, with several additional classes...

As far as I understand, I have to, for each vertex:

  1. gather points around it
  2. use monge_fit on them obtaining a monge form

But the example then modifies the normal with comply_wrt_given_normal which I do not understand completely why it would be needed.

I might also be skipping over a quite obvious function that computes this, as I said before... after all it's really an important property.

The code I have succeeded to write is this:

for (auto v : result.vertices())
{
    adj.clear();
    
    auto h = result.halfedge(v);
    
    // find all adjacent vertices
    for (HalfedgeDescriptor he : result.halfedges_around_target(h))
        adj.push_back(result.point(result.source(he)));
            
    CGAL::Monge_via_jet_fitting&lt;Kernel&gt; monge_fit;
    CGAL::Monge_via_jet_fitting&lt;Kernel&gt;::Monge_form monge_form;
    
    monge_form = monge_fit(adj.begin(), adj.end(), 2, 1);
    monge_form.comply_wrt_given_normal(vn.first[v]);
    
    // get the principal curvatures
    double k1 = monge_form.principal_curvatures(0);
    double k2 = monge_form.principal_curvatures(1);
}

However, it raises an exception in calling monge_fit, with the following text:

CGAL error: precondition violation!
Expression : nb_input_pts &gt;= nb_d_jet_coeff
File       : /opt/homebrew/include/CGAL/Monge_via_jet_fitting.h
Line       : 297
Explanation: 
Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html
libc++abi: terminating due to uncaught exception of type CGAL::Precondition_exception: CGAL ERROR: precondition violation!
Expr: nb_input_pts &gt;= nb_d_jet_coeff
File: /opt/homebrew/include/CGAL/Monge_via_jet_fitting.h
Line: 297

So the number of points are not sufficient, I guess?

I don't know, however, how to correct this... any hints are more than welcome.

答案1

得分: 1

The method comply_wrt_given_normal 'orients' the fitted jet.
使用方法 comply_wrt_given_normal 用于调整拟合的曲线。

Fitting a jet by only giving points gives curvatures values and a normal vector that are valid up to a sign.
仅通过提供点来拟合曲线会产生曲率值和法向量,这些值有效,但带有符号。

If you care about the sign of the Gaussian curvature then you must call comply_wrt_given_normal, else you can avoid calling it and use the absolute value of the curvature.
如果你关心高斯曲率的符号,那么你必须调用 comply_wrt_given_normal,否则你可以避免调用它并使用曲率的绝对值。

Internally, comply_wrt_given_normal just swap and multiply by -1 some coefficients of the jet.
在内部,comply_wrt_given_normal 只是交换并将曲线的一些系数乘以 -1。

Fitting a jet requires to solve a system of equations where the dimensions depend on the number of points and the order of the jet.
拟合曲线需要解决一个方程组,其维度取决于点的数量和曲线的阶数。

With a mesh, you have very few adjacent vertices so the system of equation is under-determined and cannot be solved, hence the error you get.
使用网格时,相邻顶点很少,因此方程组是欠定的,无法解决,这就是你遇到的错误。

I see 4 solutions
我看到有4种解决方案

英文:

The method comply_wrt_given_normal 'orients' the fitted jet.
Fitting a jet by only giving points gives curvatures values and a normal vector that are valid up to a sign.
If you care about the sign of the Gaussian curvature then you must call comply_wrt_given_normal, else you can avoid calling it and use the absolute value of the curvature.
Internally, comply_wrt_given_normal just swap and multiply by -1 some coefficients of the jet.

Fitting a jet requires to solve a system of equations where the dimensions depend on the number of points and the order of the jet.
With a mesh, you have very few adjacent vertices so the system of equation is under-determined and cannot be solved, hence the error you get.

I see 4 solutions

huangapple
  • 本文由 发表于 2023年8月4日 20:40:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836003.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定