#pragma once #include #include #include #include namespace mesh_utils { template void cgal_to_eigen(CGAL::Surface_mesh& mesh, Eigen::MatrixXd& V, Eigen::MatrixXi& F) { V.resize(mesh.num_vertices(), 3); F.resize(mesh.num_faces(), 3); for (auto v : mesh.vertices()) { auto p = mesh.point(v); V.row(v.idx()) << p.x(), p.y(), p.z(); } Eigen::Index face_idx = 0; for (auto f : mesh.faces()) { int vertex_count = 0; for (auto h : CGAL::halfedges_around_face(mesh.halfedge(f), mesh)) { auto v = mesh.target(h); F(face_idx, vertex_count) = v.idx(); ++vertex_count; } face_idx++; } } template void simple_visualize_mesh( CGAL::Surface_mesh& mesh, bool triangulate = true) { if(!CGAL::is_triangle_mesh(mesh)) { std::cerr << "Warning: Mesh is not triangulated. Visualizer expects triangles.\n"; if(triangulate){ std::cout << "Triangulating mesh for visualization...\n"; CGAL::Polygon_mesh_processing::triangulate_faces(mesh); } else{ std::cout << " exit without visualizetion.\n"; return; } } Eigen::MatrixXd V; Eigen::MatrixXi F; cgal_to_eigen(mesh, V, F); igl::opengl::glfw::Viewer viewer; viewer.data().set_mesh(V, F); viewer.launch(); } // Zero-Copy Map für V (optional) template Eigen::Map> get_vertex_map(CGAL::Surface_mesh& mesh) { auto& points = mesh.points(); double* data = reinterpret_cast(&points[0][0]); return {data, static_cast(points.size()), 3}; } } // namespace