【问题标题】:Boost Geometry/Spatial Query Shapes提升几何/空间查询形状
【发布时间】:2013-10-21 09:15:20
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: c++ boost spatial boost-geometry


    【解决方案1】:

    简而言之:它不受支持,因为目前在 Boost.Geometry OOB 中,金字塔和平截头体概念不可用/不支持。

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

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

    内部

    bg::intersects(xxx, my_geometry);
    

    被调用,其中xxx 是节点的边界框或值的可索引(从用户传递到bgi::rtreeValueType 提取的几何图形,例如也是一个框或一个点)。因此,如果您实施例如

    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

    【讨论】:

    • 感谢您的提示。您发布的代码不会立即为我工作。不确定它到底缺少什么。查看 intersects.hpp 源码,我也觉得应该...
    • 我试过了,这个函数按预期调用了。我没有实现一个真实的,工作的例子。你能分享什么不起作用吗?
    • 我为我的类型“cg::Frustum”尝试了这个,只是写了一个总是返回true的函数。我收到以下错误:/usr/include/boost/geometry/core/point_type.hpp:45:5: error: no matching function for call to 'assertion_failed(mpl_::failed********** ** (boost::geometry::traits::point_type<:frustum>::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE::************)(mpl_::assert_::types<:frustum mpl_::na>))' - 有什么建议吗?
    【解决方案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>
    

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

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

    【讨论】:

      【解决方案3】:

      这里的其他答案很好,但是我在 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;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2015-06-14
        • 2020-09-15
        • 2012-05-18
        • 1970-01-01
        • 2017-05-26
        • 1970-01-01
        • 1970-01-01
        • 2011-06-05
        • 1970-01-01
        相关资源
        最近更新 更多