首页 > 解决方案 > CGAL:添加功能失败

问题描述

任务

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

例子

作为输入,获取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 个边的立方体足以阻止它。

我也尝试过的事情

标签: c++computational-geometrymeshcgal

解决方案


该课程Polyhedral_complex_mesh_domain_3是一年前在 CGAL-4.11 中添加的新课程。你遇到的问题是,它从来没有在没有调用的情况下测试过domain.detect_features(),并且代码有一个错误:数据成员patch_id_to_polyhedron_id只填写了detect_features(). 这就解释了为什么当您调用detect_features()而不是add_features(..).

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


推荐阅读