CGAL:添加功能失败 [英] CGAL: adding features fails

查看:77
本文介绍了CGAL:添加功能失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单:我想创建一个四面体网格,并想为其添加一些功能.

is simple: I want to create a tetrahedral mesh and I want to add several features to it.

作为输入,获取文件 cube.off ,该文件可在 CGAL-4.11/examples/Mesh_3/data 中找到.我要添加的功能(仅多维数据集的十二个边)保存在 cube.edges :

As an input, take the file cube.off that can be found in CGAL-4.11/examples/Mesh_3/data. The features I would like to add (just the twelve edges of the cube) are saved in 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 进行编译时)会崩溃,并显示以下错误消息:

This (when compiled with the option -DCGAL_MESH_3_VERBOSE) crashes with the following error message:

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条边的立方体足以阻止它.

Question

What am I missing? It must be something really basic. CGAL is a very reliable library that works well on complex data; I don't believe that a cube with 12 edges is enough to stop it.

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

  • When I replace the line domain.add_features(polylines.begin(), polylines.end()); with domain.detect_features();, the program terminates correctly. The confusing part is that the detected features are exactly those that I am trying to add (I know that because I have made a function in Mesh_domain_with_polyline_features_3 that printed the edges for me; I can share it here if necessary).

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

When I use Polyhedral_mesh_domain_with_features_3 instead of Polyhedral_complex_mesh_domain_3, the program terminates correctly. The features seem to be preserved in the resulting geometry. However, it is just one patch (all of the triangles in out.mesh have the same last number, whereas I want them to have numbers 0 to 11 in this case). To achieve that, one would have to either use detect_features(); instead of add_features(...); or split the domain into patches and let CGAL create the complex from them. Thanks to @lrineau for the clarification.

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

I also tried splitting the domain into several patches first. However, then the boundaries of the patches change. One way to keep them is to add the patch boundaries as features.

反转表面方向(并在 incident_subdomains 中交换 0 1 ):无明显变化.

Reversing the orientation of the surface (and swapping 0 and 1 in incident_subdomains): no visible change.

更改 cube.edges 中要素线的顺序:无明显变化.

Changing the order of the feature lines in cube.edges: no visible change.

与旧版Boost链接:没有明显变化.

Linking with older version of Boost: no visible change.

推荐答案

code> Polyhedral_complex_mesh_domain_3 是一年前添加的新类,在CGAL-4.11 中.您遇到的问题是,从未调用 domain.detect_features()从未对其进行过测试,并且该代码存在错误:数据成员 patch_id_to_polyhedron_id 仅填充了detect_features().这就解释了为什么在调用 detect_features()而不是 add_features(..)时有效.

The class Polyhedral_complex_mesh_domain_3 is a new class added one year ago in CGAL-4.11. The problem you got is that it was never tested without calling domain.detect_features(), and the code has a bug: the data member patch_id_to_polyhedron_id is only filled in detect_features(). That explains why it works when you call detect_features() instead of add_features(..).

编辑:我已经修复了该错误,请参见 PR#3393 CGAL .该修补程序将在将来的bug修复版本CGAL-4.12.2和CGAL-4.13.1中提供.

Edit: I have fixed that bug today, see the PR #3393 of CGAL. The fix will be in the future bug-fix releases CGAL-4.12.2 and CGAL-4.13.1.

这篇关于CGAL:添加功能失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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