CGAL Surface_Mesh 示例
创建一个简单的网格曲面Surface_Mesh
对象,然后通过半边结构遍历某个面的顶点以及遍历整个网格对象的所有顶点,最后计算网格所有顶点的3D凸包网格。
项目
sm_points.cpp
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/draw_surface_mesh.h>typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
typedef Mesh::Vertex_index vertex_descriptor;
typedef Mesh::Face_index face_descriptor;int main()
{Mesh m;vertex_descriptor v0 = m.add_vertex(K::Point_3(0,0,0));vertex_descriptor v1 = m.add_vertex(K::Point_3(1,0,0));vertex_descriptor v2 = m.add_vertex(K::Point_3(0,1,0));vertex_descriptor v3 = m.add_vertex(K::Point_3(0,0,1));face_descriptor fd = m.add_face(v0, v1, v2);m.add_face(v1, v0, v3);// Access the point for a given vertexfor(vertex_descriptor vd : vertices_around_face(m.halfedge(fd), m)){std ::cout << m.point(vd) << std::endl;}/* 输出0 0 01 0 00 1 0*/// Access the range of all points of the meshfor( const K::Point_3& p : m.points()){std::cout << p << std::endl;}/* 输出0 0 01 0 00 1 00 0 1*/Mesh ch;CGAL::convex_hull_3(m.points().begin(), m.points().end(), ch);CGAL::draw(m);//CGAL::draw(ch);return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.1...3.23)
project(sm)
find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt5)
create_single_source_cgal_program("sm_points.cpp")
if(CGAL_Qt5_FOUND)#link it with the required CGAL librariestarget_link_libraries(sm_points PUBLIC CGAL::CGAL_Basic_viewer)
endif()
构建编译运行
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake
cmake --build build --config Debug.\build\Debug\sm_points.exe
效果
创建的网格:
生成的凸包网格: