使用CGAL进行四面体网格划分时保留补丁号 [英] Keep patch numbers during tetrahedral meshing with CGAL

查看:163
本文介绍了使用CGAL进行四面体网格划分时保留补丁号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 .off 格式的网格物体,它们一起包围了一个体积.例如,获取CGAL-4.11中提供的 patch-01.off patch-20.off patch-30.off examples/Mesh_3/data/patches .

I have several meshes in the .off format that together enclose a volume. For instance, take patch-01.off, patch-20.off and patch-30.off that are available with CGAL-4.11 in examples/Mesh_3/data/patches.

我想获得此体积的四面体网格并将其保存为 .mesh 格式.困难的部分是我希望与三角形相对应的每一行都以数字0、1或2结尾,以指示该三角形对应于哪个输入色块.目前,我不在乎顶点或四面体的标签.

I would like to get a tetrahedral mesh of this volume and save it in the .mesh format. The difficult part is that I want each line corresponding to a triangle to end with a number 0, 1 or 2 indicating to which of the input patches the triangle corresponds. Currently, I don't care about the tags of the vertices or tetrahedra.

我尝试修改CGAL示例 examples/Mesh_3/mesh_polyhedral_complex.cpp (已修改的部分已标记):

I tried modifying the CGAL example examples/Mesh_3/mesh_polyhedral_complex.cpp (the modified portion is marked):

#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>

#include <cstdlib>

// Domain
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;


#ifdef CGAL_CONCURRENT_MESH_3
typedef CGAL::Parallel_tag Concurrency_tag;
#else
typedef CGAL::Sequential_tag Concurrency_tag;
#endif

// Triangulation
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;

// Criteria
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;

// To avoid verbose function and named parameters call
using namespace CGAL::parameters;

// THE MODIFICATION STARTS HERE
const char* const filenames[] = {
  "data/patches/patch-01.off",
  "data/patches/patch-20.off",
  "data/patches/patch-30.off",
};

const std::pair<int, int> incident_subdomains[] = {
  std::make_pair(0, 1),
  std::make_pair(1, 0),
  std::make_pair(1, 0),
};
// THE REMAINDER OF THE FILE IS UNCHANGED.

int main()
{
  const std::size_t nb_patches = sizeof(filenames) / sizeof(const char*);
  CGAL_assertion(sizeof(incident_subdomains) ==
                 nb_patches * sizeof(std::pair<int, int>));
  std::vector<Polyhedron> patches(nb_patches);
  for(std::size_t i = 0; i < nb_patches; ++i) {
    std::ifstream input(filenames[i]);
    if(!(input >> patches[i])) {
      std::cerr << "Error reading " << filenames[i] << " as a polyhedron!\n";
      return EXIT_FAILURE;
    }
  }
  // Create domain
  Mesh_domain domain(patches.begin(), patches.end(),
                     incident_subdomains, incident_subdomains+nb_patches);

  domain.detect_features(); //includes detection of borders

  // Mesh criteria
  Mesh_criteria criteria(edge_size = 8,
                         facet_angle = 25, facet_size = 8, facet_distance = 0.2,
                         cell_radius_edge_ratio = 3, cell_size = 10);

  // Mesh generation
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return EXIT_SUCCESS;
}

这将创建一个外观良好的四面体网格并将其保存到 out.mesh .但是,所有三角形都有一个标记1,如以下摘录所示(out.mesh中的1318--1328行).

This creates a well-looking tetrahedral mesh and saves it to out.mesh. However, all the triangles have a tag 1, as shown in the following excerpt (lines 1318--1328 in out.mesh).

52.527837077556413 58.272620021324407 30.13290265121827 1
0.06169736357779243 30.258121963438846 69.405198139655852 1
Triangles
2944
923 898 888 1
923 898 888 1
905 903 890 1
905 903 890 1
354 385 375 1
354 385 375 1

当我在medit中显示结果时,所有三角形都具有相同的颜色,而(换句话说),我希望每个输入色块具有不同的颜色.

When I display the result in medit, all the triangles have the same colour, while (to put the question other way) I would like each of the input patches to be of different colour.

在上面的示例中我需要修改什么?

What do I need to modify in the example above?

我注意到out.mesh似乎包含每个三角形的两个副本.这与问题有关吗?如何清除副本?

I noticed that out.mesh seems to contain two copies of each triangle. Is this related to the problem? How can I get rid of the copies?

已经有一个类似的问题.区别在于它们只有一个文件,并尝试通过颜色传达补丁信息,而我的补丁位于单独的文件中.

There already is a similar question. The difference is that they have a single file and try to convey the patch info through colour, whereas my patches are in separate files.

推荐答案

感谢您提出确切的问题.

thanks for you precise question.

您的问题有一个非常简单的解决方案,但这涉及到 output_to_medit()的未记录功能.只需替换行:

There is a very easy solution for your question, but that involves an undocumented feature of output_to_medit(). Just replace the line:

c3t3.output_to_medit(medit_file);

作者

c3t3.output_to_medit(medit_file, false, true);

,这将使用表面补丁ID标记这些方面.

and that will tag the facets with surface patches IDs.

这篇关于使用CGAL进行四面体网格划分时保留补丁号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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