Opened 2 years ago

Last modified 2 years ago

#12725 new Feature Requests

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

Reported by: Arturo Blas <arturoblas@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.60.0 Severity: Showstopper
Keywords: rtree, geometry, distance Cc: arturoblas@…


When trying to calculate the nearest segment from another segment in a 3-dimensional space using the boost::geometry::index::nearest query on a boost:: boost::geometry::index::rtree but I get the following compilation error on VS2010:

> error C2664: 'boost::mpl::assertion_failed' : cannot convert parameter
> 1 from 'boost::mpl::failed ************(__cdecl
> boost::geometry::nyi::not_implemented_error<Term1,Term2,Term3>::THIS_OPERATION_IS_NOT_OR_NOT_YET_IMPLEMENTED::*
> ***********)(boost::mpl::assert_::types<T1,T2,T3>)' to 'boost::mpl::assert<false>::type'

I have managed to narrow down the same issue to using just the boost::geometry::distance function:

    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));

According to the documentation of the version of Boost I'm using (1.60) this should be supported, however it works just fine when using two dimensions.

I could not find anything in the docs either about how to extend the functionality or whether it's possible at all and could not find any relevant changes regarding this issue since this version.

Is this a bug or something in the roadmap that hasn't yet been addressed?

Change History (6)

comment:1 Changed 2 years ago by Arturo Blas <arturoblas@…>

Cc: arturoblas@… added
Severity: ProblemShowstopper
Version: Boost 1.61.0Boost 1.60.0

comment:2 Changed 2 years ago by Arturo Blas <arturoblas@…>

Can you please give some feedback about this ticket to know whether to rely on Boost for this functionality or try to find other options?

comment:3 Changed 2 years ago by awulkiew

Type: BugsFeature Requests

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.

comment:4 Changed 2 years ago by Arturo Blas <arturoblas@…>

Thanks for your feedback, this is what I had in mind but I was hoping I could just hook in my own intersection/distance function providing segment distance in 3D space.

Also, the main issue from a user's perspective is the lack of an statement in the documentation so it's explicitly stated that algorithms may not work for primitives with 2+ dimensions.

Is there an ETA for implementing this?

comment:5 Changed 2 years ago by awulkiew

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. But you could consider contributing your own implementation. :)

comment:6 in reply to:  5 Changed 2 years ago by Arturo Blas <arturoblas@…>

Thanks again for your help. That looks like a good way to test things actually work but not a long term solution obviously.

I could share with you my 3D segment distance implementation if that would help in any way.


Note: See TracTickets for help on using tickets.