cgal - 使用 Lloyd 优化和 Mesh_domain::create_labeled_image_mesh_domain 的问题
问题描述
我正在使用 CGAL 4.13 (Linux Fedora 29) 从分段解剖图像生成 3D 网格。我想使用 Lloyd 优化,但我以一种可重现的方式遇到了运行时错误。
为了说明我的问题,我通过添加 Lloyd 优化步骤修改了示例mesh_3D_image.cpp ,如下所示。程序编译时没有错误/警告消息。
#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 在抛出 'CGAL::Precondition_exception' 的实例后调用终止 what(): CGAL ERROR: precondition violation!Expr: std::distance(first,last) >= 3 文件: /usr/include/CGAL/Mesh_3/Lloyd_move.h 行: 419 Aborted (core dumped)
我的代码哪里出错了,如何触发对 3D 图像生成的网格的优化?
解决方案
实际上,当CGAL::make_mesh_3()
这样调用时:
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
它在内部启动CGAL::perturb_mesh_3()
和CGAL::exude_mesh_3()
. latest 更改了正则三角剖分中顶点的权重,并且应始终最后调用(请参阅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);
推荐阅读
- sql - 如何根据用户对具有特定条件的特定记录的权限有效地过滤大量记录?
- android - Recyclerview 实际上并不回收视图?
- swift - UINavigationBar 未正确加载
- javascript - TypeScript 中的 querySelectorAll 等效项
- scala - 是否有维护插入顺序的 Scala 集合?
- php - 我想获取两个表数据然后获取百分比金额
- python - 长测试用例超时,子字符串游戏
- bash - 在 bash 中在三元运算符 ($var -eq 0 ? 1 : 0) 中使用 -eq 时出错
- android - 将 SearchView 添加到 RecyclerView 列表
- vue.js - Vue-cli-service 服务构建完成回调?