如何用自定义标签扩充CGAL AABB树中的对象?

时间:2017-04-14 19:26:07

标签: c++ cgal

对于固定点,我想从(固定的)线段集中有效地找到最接近的项目。为此,我一直在试验CGAL example

#include <iostream>
#include <list>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_segment_primitive.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::FT FT;
typedef K::Point_3 Point;
typedef K::Segment_3 Segment;

typedef std::list<Segment>::iterator Iterator;
typedef CGAL::AABB_segment_primitive<K, Iterator> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
int main()
{
    Point a(1.0, 0.0, 0.0);
    Point b(0.0, 1.0, 0.0);
    Point c(0.0, 0.0, 1.0);

    std::list<Segment> segments;
    segments.push_back(Segment(a,b));
    segments.push_back(Segment(a,c));

    Tree tree(segments.begin(),segments.end());
    tree.accelerate_distance_queries();

    Point point_query(2.0, 2.0, 2.0);
    Point closest = tree.closest_point(point_query);
    std::cerr << "closest point is: " << closest << std::endl;
    return EXIT_SUCCESS;
}

现在,我需要识别特定的线段(此点所属的线段),而不是最近的点。如果我使用例如:

auto closest = tree.closest_point_and_primitive(point_query);
auto it = closest.second;

然后it确实指向特定的细分。但是,我更愿意以某种方式用自定义ID标记每个段,然后检索此id / tag而不是段本身。这可以通过合理无痛的方式实现吗?我一直试图在another CGAL example中寻找灵感,但遗憾的是还没有结果......

0 个答案:

没有答案