c++ - 如何将 boost::geometry::rtree 与 glm::vec3 一起用作自定义点类型?

标签 c++ templates boost glm-math boost-geometry

我在用

BOOST_GEOMETRY_REGISTER_POINT_3D(glm::vec3, float, boost::geometry::cs::cartesian, x, y, z);

RTree 定义为:

  using IndexedPoint = std::pair<glm::vec3, uint32_t>;
  using RTree = boost::geometry::index::rtree<IndexedPoint, boost::geometry::index::rstar<8>>;

当我尝试用它运行最近邻查询时,它无法编译:

auto it = rtree.qbegin(boost::geometry::index::nearest(glm::vec3(), 3))

错误是:

error C2664: 'int boost::mpl::assertion_failed<false>(boost::mpl::assert<false>::type)': cannot convert argument 1 from 'boost::mpl::failed ************(__cdecl boost::geometry::strategy::distance::services::default_strategy<boost::geometry::point_tag,boost::geometry::box_tag,glm::vec<3,float,0>,boost::geometry::model::point<float,3,boost::geometry::cs::cartesian>,boost::geometry::cartesian_tag,boost::geometry::cartesian_tag,void>::NOT_IMPLEMENTED_FOR_THIS_POINT_TYPE_COMBINATION::* ***********)(boost::mpl::assert_::types<Point1,Point2,CsTag1,CsTag2>)' to 'boost::mpl::assert<false>::type'
        with
        [
            Point1=glm::vec<3,float,0>,
            Point2=boost::geometry::model::point<float,3,boost::geometry::cs::cartesian>,
            CsTag1=boost::geometry::cartesian_tag,
            CsTag2=boost::geometry::cartesian_tag
        ]

comparable_distance_result 似乎缺少 vec3 与 boost::geometry::model::point 和 boost::geometry::model::box 的特化。我试过手动添加它们,但无法正常工作。如何添加所需的距离类型特化?

请注意,我可以对空间查询使用相同的设置,所以它看起来基本上是合理的。

最佳答案

我无法用 GCC/Boost 1.65.1 重现问题:

Live¹ On Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>

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

#include <glm/vec3.hpp>
BOOST_GEOMETRY_REGISTER_POINT_3D(glm::vec3, float, bg::cs::cartesian, x, y, z)

#include <iostream>
int main() {

    using IndexedPoint = std::pair<glm::vec3, uint32_t>;
    using RTree = boost::geometry::index::rtree<IndexedPoint, boost::geometry::index::rstar<8>>;

    RTree rtree;
    rtree.insert({glm::vec3(1,1,1), 1});
    rtree.insert({glm::vec3(2,2,2), 2});
    rtree.insert({glm::vec3(3,3,3), 3});
    rtree.insert({glm::vec3(4,4,4), 4});

    auto it = rtree.qbegin(bgi::nearest(glm::vec3(2.9, 2.9, 2.9), 99));

    auto p = it->first;
    std::cout << "Nearest: # " << it->second << " (" << p.x << ", " << p.y << " " << p.z << ")\n";
}

打印

Nearest: # 3 (3, 3 3)

¹ Coliru 没有 libglm

关于c++ - 如何将 boost::geometry::rtree 与 glm::vec3 一起用作自定义点类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47653386/

相关文章:

c++ - 无法使用大小和类型参数调用 OpenCV 的 Mat::zeros

c++ - 将字节数组从 utf-16 转换为 utf-8

c++ - 未定义的构造函数引用,泛型类

c++ - 在opengl中绘制图形

c++ - 构建 C++ 字符串时如何处理未终止的字符数组?

javascript - 在 Backbone 模板中使用 _.each

jquery - 在页面模板中使用自定义 jquery

c++ - 使用 OS X 核心音频播放/输出体验音频丢失

C++ boost 库 local_time_period

c++ - 这种情况下有什么样的多线程保护?