CGAL曲面网格最短路径演示程序的输入网格变换问题问询
问题描述
我有一个用于路径规划的网格,正在基于CGAL的Surface_mesh_shortest_path模块开发。使用官方演示程序计算两点间路径时,控制台输出的选中面索引(如5428、4813)及重心坐标为小数值,但我输入的网格顶点坐标数值极大(示例:{334746, 1165, 66225})。请问该演示程序对输入网格文件执行了何种变换?
相关代码
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Surface_mesh.h> #include <CGAL/Surface_mesh_shortest_path.h> #include <CGAL/AABB_face_graph_triangle_primitive.h> #include <CGAL/AABB_traits.h> #include <CGAL/AABB_tree.h> #include <cstdlib> #include <iostream> #include <fstream> typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef Kernel::Point_3 Point_3; typedef Kernel::Ray_3 Ray_3; typedef CGAL::Surface_mesh<Point_3> Triangle_mesh; typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Triangle_mesh> Traits; typedef CGAL::Surface_mesh_shortest_path<Traits> Surface_mesh_shortest_path; typedef boost::graph_traits<Triangle_mesh> Graph_traits; typedef Graph_traits::vertex_iterator vertex_iterator; typedef Graph_traits::face_iterator face_iterator; typedef typename Surface_mesh_shortest_path::Barycentric_coordinates Barycentric_coordinates; typedef typename Surface_mesh_shortest_path::Face_location Face_location; typedef CGAL::AABB_face_graph_triangle_primitive<Triangle_mesh> AABB_face_graph_primitive; typedef CGAL::AABB_traits<Kernel, AABB_face_graph_primitive> AABB_face_graph_traits; typedef CGAL::AABB_tree<AABB_face_graph_traits> AABB_tree; typedef CGAL::Surface_mesh<Point_3> Mesh; typedef Mesh::Vertex_index vertex_descriptor; int main(int argc, char** argv) { const std::string filename = (argc>1) ? argv[1] : CGAL::data_file_path("meshes/elephant.off"); Triangle_mesh tmesh; if(!CGAL::IO::read_polygon_mesh(filename, tmesh) || !CGAL::is_triangle_mesh(tmesh)) { std::cerr << "Invalid input file." << std::endl; return EXIT_FAILURE; } // or the C++11 for loop. Note that there is a ':' and not a ',' as in BOOST_FOREACH for(vertex_descriptor vd : tmesh.vertices()){ std::cout << tmesh.point(vd) << std::endl; } Surface_mesh_shortest_path shortest_paths(tmesh); const Point_3 source_pt(334746, 1165, 66225); Face_location source_loc = shortest_paths.locate<AABB_face_graph_traits>(source_pt); // this builds an AABB tree of the mesh shortest_paths.add_source_point(source_loc.first, source_loc.second); AABB_tree tree; shortest_paths.build_aabb_tree(tree); const Point_3 target_pt(370364, 809, 66265.6); Face_location target_loc = shortest_paths.locate<AABB_face_graph_traits>(target_pt); std::vector<Point_3> points; shortest_paths.shortest_path_points_to_source_points(target_loc.first, target_loc.second, std::back_inserter(points)); // Print the points std::cout << points.size() << " "; for (std::size_t i = 0; i < points.size(); ++i) std::cout << " |----| " << points[i] << "\n"; std::cout << std::endl; return EXIT_SUCCESS; }
解答
CGAL的Surface_mesh_shortest_path演示程序没有对输入网格的顶点坐标执行任何缩放或变换,你看到的现象是由数据本身的属性决定的:
- 面索引是网格的拓扑属性,仅用于标识网格中的三角面,和顶点坐标的数值大小完全无关,输出的5428、4813就是输入网格中对应面的原始编号。
- 重心坐标是三角面内部的局部坐标表示,用来定位面内的点,其取值范围始终在[0,1]之间(三个坐标之和为1),这是重心坐标的定义特性,和顶点的全局大数值坐标没有关联。
- 从代码逻辑来看,
CGAL::IO::read_polygon_mesh仅负责读取网格数据,不会修改原始顶点坐标;locate方法只是通过AABB树查找点所在的面并计算局部重心坐标,也不会对网格做任何变换。
内容的提问来源于stack exchange,提问作者GPrathap
相关产品推荐
相关产品推荐

