【问题标题】:CGAL: adding features failsCGAL:添加功能失败
【发布时间】:2018-10-09 17:16:33
【问题描述】:

任务

很简单:我想创建一个四面体网格,我想向它添加几个特征。

示例

cube.off 文件作为输入,该文件可以在CGAL-4.11/examples/Mesh_3/data 中找到。我要添加的特征(只是立方体的十二条边)保存在cube.edges

2 -1 -1 -1 -1 1 -1
2 -1 -1 -1 1 -1 -1
2 -1 -1 -1 -1 -1 1
2 -1 1 -1 1 1 -1
2 -1 1 -1 -1 1 1
2 1 1 -1 1 -1 -1
2 1 1 -1 1 1 1
2 1 -1 -1 1 -1 1
2 -1 -1 1 -1 1 1
2 -1 -1 1 1 -1 1
2 -1 1 1 1 1 1
2 1 1 1 1 -1 1

代码的MWE:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>
#include <CGAL/Polyhedral_complex_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>

// From CGAL-4.11/examples/Mesh_3 but for simplicity copied to the current folder.
#include "read_polylines.h"

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Mesh_polyhedron_3<K>::type Polyhedron;
typedef CGAL::Polyhedral_complex_mesh_domain_3<K> Mesh_domain;
typedef CGAL::Sequential_tag Concurrency_tag;

typedef CGAL::Mesh_triangulation_3<Mesh_domain,CGAL::Default,Concurrency_tag>::type Tr;
typedef CGAL::Mesh_complex_3_in_triangulation_3<
  Tr,Mesh_domain::Corner_index,Mesh_domain::Curve_segment_index> C3t3;
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;

typedef K::Point_3 Point;
typedef std::vector<std::vector<Point> > Polylines;

int main()
{
  // Read the (one) patch.
  std::vector<Polyhedron> patches(1);
  std::ifstream input("cube.off");
  input >> patches[0];
  const std::pair<int, int> incident_subdomains[] = { std::make_pair(1,0) };
  Mesh_domain domain(patches.begin(), patches.end(), incident_subdomains, incident_subdomains+1);

  // Read the features.
  std::string feature_edges="cube.edges";
  Polylines polylines;
  read_polylines<Point>(feature_edges.c_str(), polylines);
  domain.add_features(polylines.begin(), polylines.end());

  // Create the mesh.
  Mesh_criteria criteria(CGAL::parameters::edge_size = 0.25);
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);

  // Write it (if it hasn't crashed before).
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file, false, true);
}

这(当使用选项 -DCGAL_MESH_3_VERBOSE 编译时)崩溃并显示以下错误消息:

Start volume scan...Scanning triangulation for bad cells (sequential)... terminate called after throwing an instance of 'CGAL::Assertion_exception'
  what():  CGAL ERROR: assertion violation!
Expr: patch_id > 0 && std::size_t(patch_id) < patch_id_to_polyhedron_id.size()
File: /yatmp/scr1/ya10813/cgal-install/include/CGAL/Polyhedral_complex_mesh_domain_3.h
Line: 457
Aborted

问题

我错过了什么?它一定是非常基本的东西。 CGAL 是一个非常可靠的库,可以很好地处理复杂的数据;我不相信一个有 12 个边的立方体足以阻止它。

我也尝试过的事情

  • 当我用domain.detect_features(); 替换行domain.add_features(polylines.begin(), polylines.end()); 时,程序正确终止。令人困惑的部分是检测到的特征正是我试图添加的那些(我知道因为我在Mesh_domain_with_polyline_features_3 中创建了一个为我打印边缘的函数;我可以在这里分享如有必要)。

  • 当我使用Polyhedral_mesh_domain_with_features_3 而不是Polyhedral_complex_mesh_domain_3 时,程序会正确终止。这些特征似乎保留在生成的几何图形中。但是,它只是一个补丁(out.mesh 中的所有三角形都具有相同的最后一个数字,而在这种情况下我希望它们具有数字 0 到 11)。 编辑:要实现这一点,必须使用detect_features(); 而不是add_features(...); 或将域拆分为补丁并让CGAL 从中创建复合体。感谢@lrineau 的澄清。

  • 我还尝试先将域拆分为几个补丁。但是,补丁的边界会发生变化。 编辑:保留它们的一种方法是将补丁边界添加为特征。

  • 反转表面的方向(并在incident_subdomains 中交换01):没有可见的变化。

  • 更改cube.edges 中特征线的顺序:没有可见的变化。

  • 与旧版本的 Boost 链接:无明显变化。

【问题讨论】:

    标签: c++ computational-geometry mesh cgal


    【解决方案1】:

    Polyhedral_complex_mesh_domain_3 类是一年前添加的新类in CGAL-4.11。你遇到的问题是没有调用domain.detect_features()就从来没有测试过,而且代码有个bug:数据成员patch_id_to_polyhedron_id只填detect_features()。这就解释了为什么当您调用 detect_features() 而不是 add_features(..) 时它会起作用。

    编辑:我今天已经修复了这个错误,请参阅PR #3393 of CGAL。该修复将在未来的错误修复版本 CGAL-4.12.2 和 CGAL-4.13.1 中发布。

    【讨论】:

    • 太好了,听到这个我真的放心了。
    • 我有一个解决办法。我修改了我的答案。在我看来,你现在可以接受了。
    • 亲爱的@lrineau,非常感谢您及时修复错误。我重新编译,我的程序现在正确终止。但是,我仍然感到困惑:当我添加 MWE 中的功能时,out.mesh 中的所有三角形都有标签2。当我将add_features(...); 替换为detect_features(); 时,网格看起来相同,但三角形有标签27(因此,medit 在按下“e”后显示为 6 种颜色而不是一种)。尽管检测到的特征与我手动添加的特征相同。哪种行为是正确的?
    • detect_features 检测尖锐的曲线,但它也检测表面斑块,并给它们编号。
    • 我明白了,我错误地认为add_features 也是如此。现在一切正常,非常感谢您的宝贵时间。我最近真的很绝望。 (=
    猜你喜欢
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2020-10-14
    • 1970-01-01
    相关资源
    最近更新 更多