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 vertex
  for(vertex_descriptor vd : vertices_around_face(m.halfedge(fd), m)){
    std ::cout << m.point(vd) << std::endl;
  }
  /* 输出
    0 0 0
    1 0 0
    0 1 0
  */

  // Access the range of all points of the mesh
  for( const K::Point_3& p : m.points()){
    std::cout << p << std::endl;
  }
  /* 输出
    0 0 0
    1 0 0
    0 1 0
    0 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 libraries
  target_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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值