boost::geometry::distance 3D 图元编译错误

boost::geometry::distance compile errors with 3D primitives

我正在尝试使用 boost:: boost::geometry::index::rtree 上的 boost::geometry::index::nearest 查询来计算 3 维 space 中距离另一个线段最近的线段,但出现以下编译错误:

error C2664: 'boost::mpl::assertion_failed' : cannot convert parameter 1 from 'boost::mpl::failed ************(__cdecl boost::geometry::nyi::not_implemented_error::THIS_OPERATION_IS_NOT_OR_NOT_YET_IMPLEMENTED::* ***********)(boost::mpl::assert_::types)' to 'boost::mpl::assert::type'

我已经设法将同一问题缩小到仅使用 boost::geometry::distance 函数:

typedef boost::geometry::model::point <float, 3, boost::geometry::cs::cartesian> point;
typedef boost::geometry::model::segment <point> segment;

point pa = point(x1, y1, z1);
point pc = point(x2, y2, z2);
point pb = point(x3, y3, z3);

float dist = boost::geometry::distance(segment(pa, pb), segment(pa, pc));

根据我使用的 Boost 版本 (1.60) 的文档,这应该是受支持的,但是在使用二维时它工作得很好。

http://www.boost.org/doc/libs/1_60_0/libs/geometry/doc/html/geometry/reference/algorithms/distance/distance_2.html#geometry.reference.algorithms.distance.distance_2.supported_geometries

我在文档中找不到任何有关如何扩展功能或是否可能的信息。

在与来自 Boost 开发的 @awulkiew 交换了几条消息后,您可以在 this ticket.

中看到当前的解决方法

此时 N-dimensional 段的一些内部函数没有实现:

Yes, it seems that disjoint/intersects is not yet implemented for N-dimensional segments. And distance() calls this algorithm.

As a workaround you could store bounding boxes of segments in the R-tree, then search for Boxes nearest to some query Box using iterative query, in each iteration check the actual distance between segments using your own implementation and stop if your k-th found segment is closer than the distance between the bounding box passed into the query and the bounding box found in the current iteration. So basically use the index how you'd use it for any other Geometry.

还有另一种涉及覆盖内部 Boost 函数的解决方法,但不鼓励这样做,因为这些方法将来可能会发生变化:

I'd discourage you from hooking in your own functions in case something changed in the future internally in the rtree (e.g. different functions were used). But if you'd like to try it you could overload bg::comparable_distance(segment, segment) and bg::comparable_distance(segment, box), e.g. like that:

namespace boost { namespace geometry {
    template <typename Box>
    float comparable_distance(segment const& s, Box const& b) { return 0; }
    float comparable_distance(segment const& s1, segment const& s2) { return 0; }
}}

Box would be of type internally used in the R-tree to represent nodes, so bg::model::box<...>.

此外,目前还没有添加对此功能的支持的预计到达时间。

No ETA, currently we're adding support for 2d geographic CS.

在我的例子中,解决方案是实现我自己的距离函数并使用第一个解决方法中建议的算法。