I am currently trying to implement a motion-planning algorithm and have been using Boost's RTree to do so. Up until now, the RTree has stored std::pair<boost::geometry::model::point<double, 2, bg::cs::cartesian>, unsigned int> and has worked just fine in answering nearest neighbor queries.
Externally, I make use of a custom struct called Node, each of which corresponds to a point in the RTree. I maintain a vector of Nodes so that the ids of the output pairs from the RTree queries can be used as indices to be looked up in the vector.
However, I want to eliminate the use of this large vector to see its results on time and space performance of my algorithm. To do this, I want to replace the use of point in the pairs with Nodes, so that the Nodes are directly output in the query results. To do this I have used boost geometry 2d point registering, with the following code:
#include <algorithm>
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#include <boost/geometry.hpp>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <chrono>
using namespace std;
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
typedef bg::model::point<double, 2, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
struct Node
{
Node *parent;
point pos;
};
typedef pair<Node, unsigned int> ptval;
typedef pair<box, unsigned int> boxval;
BOOST_GEOMETRY_REGISTER_POINT_2D(Node, double, bg::cs::cartesian, pos.get<0>(), pos.get<1>());
int main() {
cout << "hi" << endl; return 0;
}
However, a strange error results:
In file included from rrt.cpp:13:
rrt.cpp: In static member function 'static void boost::geometry::traits::access<Node, 0>::set(Node&, const double&)':
rrt.cpp:45:1: error: assignment of read-only location 'p.Node::pos.boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>::get<0>()'
BOOST_GEOMETRY_REGISTER_POINT_2D(Node, double, bg::cs::cartesian, pos.get<0>(), pos.get<1>());
This is odd as there are no const declarations anywhere here. I'm guessing it has to do with something inside of the hood of the get<>() functions, but I'm not sure exactly what it is.
Any help is appreciated, as I've not found this issue anywhere online.