2

我目前正在使用 boost 几何/空间索引库,以便对 3d 边界框执行范围查询。例如,我可以获得与查询边界框重叠的所有边界框的列表。

文档(http://www.boost.org/doc/libs/1_54_0_beta1/libs/geometry/doc/html/geometry/spatial_indexes/queries.html)显示,至少在 2d 中可以使用多边形而不是将边界框作为查询对象。是否也可以在 3d 中使用更高级的查询形状?我正在考虑诸如定向边界框、金字塔或相机平截头体之类的对象。如果是这样:我该怎么做/我在哪里可以找到一个例子?

谢谢

4

3 回答 3

3

简而言之:它不受支持,因为目前在 Boost.Geometry OOB 中,Pyramid 和 Frustum 概念不可用/不支持。

但是,理论上应该可以执行这样的查询。在查询期间,bgi::rtree调用命名空间中定义的适当布尔算法boost::geometry,例如,如果您调用

rtree.query(bgi::intersects(my_geometry), out_it);

内部

bg::intersects(xxx, my_geometry);

被调用,其中节点的边界框或值的可索引(从用户传递到xxx中提取的几何图形,例如,也是一个框或一个点)。所以如果你实现了例如ValueTypebgi::rtree

namespace boost { namespace geometry {

template <typename Box> inline
bool intersects(Box const& b, MyFrustum const& f)
{
    // your implementation
}

}}

理论上它应该工作。虽然没有测试它。

以上:

namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;

此外,如果您想直接联系开发人员,您可以考虑订阅 Boost.Geometry 邮件列表:http ://lists.boost.org/mailman/listinfo.cgi/geometry

于 2013-10-21T20:27:27.953 回答
2

我遇到了同样的问题,在与@Adam 聊天后,他提出了以下解决方案,为我解决了这个问题(我在 GCC 上构建我的代码,上面的解决方案似乎只能在 Visual Studio 上编译)。

#include <boost/geometry.hpp>

struct MyFrustum
{
    MyFrustum(int d) : dummy(d) {}
    int dummy;
};

namespace boost { namespace geometry {

// This will be called for Nodes and Values!

template <typename Box> inline
bool intersects(Box const& b, MyFrustum const& f)
{
    std::cout << "checking the intersection with " << f.dummy << std::endl;
    return true;
}

}}

#include <boost/geometry/index/rtree.hpp>

显然,定义事物的顺序很重要,这样编译器就不会退回到其默认实现(这会产生尚未实现的错误)。

希望对您有所帮助,再次感谢亚当!

于 2014-04-01T06:57:40.143 回答
1

这里的其他答案很好,但是我在 Xcode 中仍然遇到了麻烦,无论我包含/声明的东西是什么顺序。我正在为其他无法在他们的环境中工作的人发布这个答案。这里的其他解决方案在 Visual Studio 2013 中对我来说很好,但在 Xcode 5.1.1 中却不行。该编译器中似乎存在重载解决问题。解决方案是避免对“Box”使用模板类型,直接使用所有具体类型,如下所示:

#include <boost/geometry.hpp>

namespace bg = boost::geometry;
using point3d = bg::model::point<float, 3, bg::cs::cartesian>;
using box3d = bg::model::box<point3d>;

namespace boost { namespace geometry {

    template <> inline
    bool intersects(box3d const& b, MyFrustum const& p) {
        // your implementation
        return true;
    }
}
于 2014-11-04T21:02:13.820 回答