You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CGAL生成.obj格式三角网格遇两类问题求解决方案

问题:GDAL读取单要素SHP生成OBJ三角网格时的CGAL报错

我用GDAL读取包含单个要素的SHP文件,提取所有点后尝试生成OBJ格式三角网格,遇到两个问题:

1. PMP三角化触发运行时预条件违反错误

调用PMP::triangulate_faces(mesh)进行三角化时,出现CGAL运行时错误,信息如下:

CGAL error: precondition violation!
Expression : vaa != vbb
File : D:\Programs\dev\CGAL-5.5.1\include\CGAL\Constrained_triangulation_2.h
Line : 813
Explanation: Refer to the bug-reporting instructions at https://www.cgal.org/bug_report.html

源代码1

namespace PMP = CGAL::Polygon_mesh_processing;
typedef K::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;

Mesh mesh;
for (int k = 0; k < num; k++)
{
  double x = poline->getX(k);
  double y = poline->getY(k);
  double z = poline->getZ(k);
  coordTransform->Transform(1, &x, &y, 0);
  mesh.add_vertex(Point(y - *(center + 1), x - *center, 0 - *(center + 2)));
}                    
string filename = "E:/point/output/泰森多边形/";
filename = filename + "_" + to_string(i)+".obj";
char* path = new char[strlen(filename.c_str()) + 1];
strcpy(path, filename.c_str());
            
mesh.add_face(mesh.vertices());
if (!CGAL::is_triangle_mesh(mesh))//未三角化的三角化
{   
  std::cout << "Input mesh is not triangulated." << std::endl;
  PMP::triangulate_faces(mesh);
}
CGAL::IO::write_polygon_mesh(path, outmesh2, CGAL::parameters::stream_precision(17));

2. convex_hull_3方法触发编译错误

改用CGAL::convex_hull_3()生成Polyhedron_3时,出现编译错误,信息如下:

C2530 "v": References must be initialized property_map.hpp 304
C2678 Binary "[": no operator found that accepts a left operand of type "const PropertyMap" (or no acceptable conversion) property_map.h 304
C2678 Binary "[": no operator found that accepts a left operand of type "const PropertyMap" (or no acceptable conversion) property_map.h 311

源代码2

typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K>  PHD;

PHD mesh;
vector<Point> points;
for (int k = 0; k < num; k++)
{
  double x = poline->getX(k);
  double y = poline->getY(k);
  double z = poline->getZ(k);
  coordTransform->Transform(1, &x, &y, 0);
  points.push_back(Point(y - *(center + 1), x - *center, 0 - *(center + 2)));

}
CGAL::convex_hull_3(points.begin(), points.end(), mesh);
CGAL::IO::write_polygon_mesh(path, outmesh2, CGAL::parameters::stream_precision(17));

环境信息

  • Windows 64位操作系统
  • Visual Studio 2019编译器(Debug模式)
  • CGAL版本5.5.1
  • Boost版本1.71.0
  • Eigen 3

补充提示

  • 代码已基于主头文件编写,若因缺失头文件报错请详细说明
  • 可提供实验数据

内容的提问来源于stack exchange,提问作者DwightJavaScript

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 02:16:07