如何使用boost ::几何:: rtree with glm :: vec3作为自定义点类型
How to use boost::geometry::rtree with glm::vec3 as a custom point type?
我正在使用
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
]
似乎companable_distance_result缺少VEC3 vs boost :: geomegotry :: model :: point and boost :: gemost :: mode :: model :: box。我尝试过手动添加它们,但无法使其起作用。如何添加所需的距离类型专业?
请注意,我可以将相同的设置用于空间查询,因此基本上是听起来的。
我无法用GCC/BOOST 1.65.1重现问题:
live �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
我只是想从对所接受的答案的评论(@buschnick)的评论中拿出真正解决此问题的答案。
问题是我不包括几何hpp。
添加以下内容包括我的标题解决了上面显示的问题。
#include <boost/geometry.hpp>
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 自定义先决条件对移动分配运算符有效吗
- 使用VS Code和CMake Tools运行自定义命令
- 如何创建从Maya(或类似程序)到虚幻引擎的自定义数据导出插件
- std::ranges::elements_view,用于自定义类似元组的数据
- 跟随整数索引列表的自定义类迭代器
- 参数化自定义CMake工具链
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 如何在自定义类中启用'auto loops'?
- 使用QJsEngine在Qt中注册自定义类型
- Qt自定义QPush按钮未显示在布局上
- 自定义对象的dlib序列化在gcc中失败
- 如何为数据类型 vector<glm::vec3> (opengl 数据类型) 编写 std::minmax 函数的自定义比较器
- 如何使用boost ::几何:: rtree with glm :: vec3作为自定义点类型