手动插入网格到CGAL与点和单元



我在一张纸上写了一个三角形网格,上面有一堆节点和它们的连接。我想把这个网格放入CGAL,例如,玩劳埃德平滑,计算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));

但不包括单元格(三角形)。

有提示从哪里开始吗?

我也遇到过类似的情况。警告:我不需要使用那些特定的算法,所以我不确定这个解决方案如何与那些工作。

您可以使用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;
}

如果你有多于一张脸,你可以设置脸邻居

    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})

相关内容

  • 没有找到相关文章

最新更新