欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > CGAL Surface_Mesh 示例

CGAL Surface_Mesh 示例

2025/3/17 23:14:42 来源:https://blog.csdn.net/mrbaolong/article/details/142593721  浏览:    关键词:CGAL Surface_Mesh 示例

CGAL Surface_Mesh 示例

创建一个简单的网格曲面Surface_Mesh对象,然后通过半边结构遍历某个面的顶点以及遍历整个网格对象的所有顶点,最后计算网格所有顶点的3D凸包网格。

项目

project

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

效果

创建的网格:

m

生成的凸包网格:

ch

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词