我在一张纸上写下了一个三角形网格,上面有一堆节点及其连接。我想将这个网格放入CGAL,例如,玩Lloyd平滑,计算Voronoi图等。
我正在查看显然允许插入点的Mesh_2/mesh_optimization.cpp
CDT cdt;
Vertex_handle va = cdt.insert(Point(-2,0));
Vertex_handle vb = cdt.insert(Point(0,-2));
Vertex_handle vc = cdt.insert(Point(2,0));
Vertex_handle vd = cdt.insert(Point(0,1));
但不是细胞(三角形)。
有关从哪里开始的任何提示?
答案 0 :(得分:1)
我遇到了类似的情况。警告:我不需要使用那些特定的算法,所以我不确定这个解决方案是如何工作的。
您可以使用CGAL::Triangulation_data_structure_2
(wiki)手动指定面,邻居和顶点。
#include <CGAL/Triangulation_2.h>
#include <CGAL/Projection_traits_xy_3.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_ds_face_base_2.h>
#include <iostream>
int main()
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef CGAL::Projection_traits_xy_3<K> Gt; //allows for using 2D algorithms on the 3D points (good for terrain)
typedef CGAL::Triangulation_vertex_base_2<Gt> Vb;
typedef CGAL::Constrained_triangulation_face_base_2<Gt> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> triangulation;
triangulation tri;
//read in x,y,z from a file here
//create a new vertex and insert into a 2D triangulation
//vertex 0
int x,y,z;
x = 0;
y = 0;
z=0;
Point_3 pt0( x,y,z);
auto Vh0 = tri.create_vertex(); // type of Vh0 is triangulation::Vertex_handle
Vh0->set_point(pt0);
//vertex 1
x = 1;
y = 0;
z=0;
Point_3 pt1( x,y,z);
auto Vh1 = tri.create_vertex();
Vh1->set_point(pt1);
//vertex 2
x = 0.5;
y = 0.5;
z=0;
Point_3 pt2( x,y,z);
auto Vh2= tri.create_vertex();
Vh2->set_point(pt2);
auto face = tri.create_face(Vh0,Vh1,Vh1); // type of face is triangulation::Face_handle
Vh0->set_face(face);
Vh1->set_face(face);
Vh2->set_face(face);
std::cout << "#veterx=" << tri.number_of_vertices() << std::endl;
std::cout << "#faces=" << tri.faces().size() << std::endl;
}
如果你有超过1张脸,你可以设置面对面
face->set_neighbors(face0,face1,face2);
CMakeLists.txt构建示例:
cmake_minimum_required (VERSION 3.12)
project (tri)
find_package(CGAL REQUIRED)
include(${CGAL_USE_FILE})
include_directories(
${CGAL_INCLUDE_DIRS}
${CGAL_3RD_PARTY_INCLUDE_DIRS})
add_executable(main
main.cpp)
target_link_libraries(main ${CGAL_3RD_PARTY_LIBRARIES})