【问题标题】:CGAL surface_mesh cover exampleCGAL surface_mesh 覆盖示例
【发布时间】:2025-11-28 13:40:01
【问题描述】:

在 CGAL 网页上,您会看到这个简短的示例:

 CGAL::AABB_tree tree(faces(surface_mesh));

在所有 surface_mesh 和 AABBTree 文档示例中,未使用此行,所以我想知道如何配置 AABB 特征以使该示例成为可能。我自己的方法不编译:

    #include <CGAL/AABB_face_graph_triangle_primitive.h>
    #include <CGAL/AABB_traits.h>
    #include <CGAL/AABB_tree.h>
    #include <CGAL/AABB_triangle_primitive.h>
    #include <CGAL/Simple_cartesian.h>
    #include <CGAL/Surface_mesh.h>
    #include <fstream>
    #include <iostream>
    #include <list>

    typedef CGAL::Simple_cartesian<double> Kernel;
    typedef Kernel::FT FT;
    typedef Kernel::Ray_3 Ray;
    typedef Kernel::Line_3 Line;
    typedef Kernel::Point_3 Point;

    typedef CGAL::Surface_mesh<Point> SMesh;
    typedef CGAL::AABB_face_graph_triangle_primitive<SMesh> Primitive;
    typedef CGAL::AABB_traits<Kernel, Primitive> AABB_Mesh_Traits;
    typedef CGAL::AABB_tree<AABB_Mesh_Traits> AABBTree;

    int main( const int argc, const char* argv[] )
    {
        const char* filename = ( argc > 1 ) ? argv[1] : "model.obj";
        std::ifstream input( filename );
        SMesh mesh;
        input >> mesh;
        AABBTree tree( faces( mesh ) );

        Point a( 1.0, 0.0, 0.0 );
        Point b( 0.0, 1.0, 0.0 );
        Ray ray_query( a, b );
        std::cout << tree.number_of_intersected_primitives( ray_query )
           << " intersections(s) with ray query" << std::endl;

        return EXIT_SUCCESS;
    }

编译错误是:

 no matching constructor for initialization of 'AABBTree' 
 (aka 'AABB_tree<AABB_traits<Simple_cartesian<double>, 
   AABB_face_graph_triangle_primitive<
    Surface_mesh<Point_3<CGAL::Simple_cartesian<double> > > > > >')

【问题讨论】:

  • 网站撒谎 :) 过于简化,应该是tree(faces(mesh).first, faces(mesh).second, mesh)
  • 确实;那个单一的改变使它编译。谢谢!您能否@sloriot 请将其添加为解决方案?然后我可以将其标记为已解决。

标签: compiler-errors cgal aabb


【解决方案1】:

应该是tree(faces(mesh).first, faces(mesh).second, mesh)

请注意,在User Manual 中,您会找到一个使用的真实示例 完整的语法。此示例随库中的 目录examples/AABB_tree

【讨论】: