4

I'm using

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

with an RTree defined as:

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

When I try to run a nearest neighbor query with this it fails to compile:

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

The error is:

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
        ]

It seems comparable_distance_result is missing specializations for vec3 vs boost::geometry::model::point and boost::geometry::model::box. I have tried adding them manually, but couldn't make it work. How can I add the required distance type specializations?

Note that I can use the same setup for spatial queries just fine, so it seems basically sound.

genpfault
  • 51,148
  • 11
  • 85
  • 139
BuschnicK
  • 5,304
  • 8
  • 37
  • 49

2 Answers2

4

I can not reproduce the problem with 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";
}

Prints

Nearest: # 3 (3, 3 3)

¹ Coliru doesn't have libglm

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Did it randomly help, or are you satisfied concluding it doesn't work on MSVC? – sehe Dec 05 '17 at 13:36
  • 2
    Thank you very much for the quick response and test program. The issue was that I did not include geometry.hpp, only rtree, box and point. I was trying to minimize my dependencies and obviously went too far. I feel a bit stupid now. OTOH: what would be the minimal set of headers to include for this program to work? – BuschnicK Dec 05 '17 at 13:37
  • Not too sure - I don't sweat it because the optimizer jots it away anyways, and all those boost headers don't count as "volatile" for most of my projects. Here's what IWYU gave: http://paste.ubuntu.com/26118710/ - that's not fully accurate though because it doesn't compile – sehe Dec 05 '17 at 13:57
  • a workaround if you have no glm: ``` namespace glm { struct vec3 { double x, y, z; vec3(double x_, double y_, double z_) { x = x_; y = y_; z = z_; } }; } ``` – dvorak4tzx Jul 11 '18 at 04:17
2

I just wanted to pull out the answer that actually solved this for me from a comment on the accepted answer (by @BuschnicK).

The issue was that I did not include geometry.hpp, only rtree, box and point.

Adding the following include to my header solved the problem shown above.

#include <boost/geometry.hpp>
William B.
  • 85
  • 5