使用 Lloyd 优化和 Mesh_domain::create_labeled_image_mesh_domain 的问题

Problem using Lloyd optimization and Mesh_domain::create_labeled_image_mesh_domain

我正在使用 CGAL 4.13 (Linux Fedora 29) 从分割的解剖图像生成 3D 网格。我想使用 Lloyd 优化,但我以可重现的方式遇到了运行时错误。

为了说明我的问题,我通过添加 Lloyd 优化步骤修改了示例 mesh_3D_image.cpp,如下所示。程序编译时没有 error/warning 消息。

#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/Labeled_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/Image_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Labeled_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> C3t3;
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria; 

using namespace CGAL::parameters;

int main(int argc, char* argv[])
{
  const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
  CGAL::Image_3 image;
  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }
  Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);
  Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=4,
                     cell_radius_edge_ratio=3, cell_size=8);

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

  // !!! THE FOLLOWING LINE MAKES THE PROGRAM CRASH !!!
  CGAL::lloyd_optimize_mesh_3(c3t3, domain, time_limit=30); 

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

  return 0;
}

我使用下面的CMakeLists.txt文件编译它:

# Created by the script cgal_create_CMakeLists

project( executables )
cmake_minimum_required(VERSION 2.8.11)
find_package( CGAL QUIET COMPONENTS  )

# !!! I had to add manually the following line !!!    
find_package(CGAL COMPONENTS ImageIO)

include( ${CGAL_USE_FILE} )
find_package( Boost REQUIRED )
add_executable( executables  lloyd.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS executables )    
target_link_libraries(executables   ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )

没有生成网格。我收到以下消息:

$ ./build/mesh_3D_image terminate called after throwing an instance of 'CGAL::Precondition_exception' what(): CGAL ERROR: precondition violation! Expr: std::distance(first,last) >= 3 File: /usr/include/CGAL/Mesh_3/Lloyd_move.h Line: 419 Aborted (core dumped)

我的代码哪里错了,如何触发对 3D 图像生成的网格的优化?

您删除了部分:

  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }

来自示例,这实际上是从文件中读取图像。

实际上,当CGAL::make_mesh_3()被这样调用时:

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

它在内部启动 CGAL::perturb_mesh_3()CGAL::exude_mesh_3()。 latest 改变了 Regular triangulation 中顶点的权重,并且应该总是最后调用(参见 documentation of CGAL::exude_mesh_3().

中的警告

唯一的顺序限制是应该最后调用 exuder。所以你可以调用

C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, lloyd(time_limit=30));

C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_exude());
CGAL::lloyd_optimize_mesh_3(c3t3, domain, time_limit = 30);
CGAL::exude_mesh_3(c3t3);