I am struggling to define and fill a point in d dimensions. To be exact, I exploited that letting Boost.Geometry handle any dimension by the user, is impossible (that is what I saw from the docs and their mailing list). So, I am trying to define a 100D or 10000D dimension point.
Here is the code, where my attempts and the help from their list developed:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/index/rtree.hpp>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
template <int CompileTimeDimension>
void do_something()
{
typedef bg::model::point<float, CompileTimeDimension, bg::cs::cartesian> point;
bgi::rtree<point, bgi::linear<8> > rt;
}
template <std::size_t D, std::size_t N>
struct fill
{
template <typename Point>
static void apply(Point& p, typename bg::coordinate_type<Point>::type const& v)
{
bg::set<D>(p, v);
fill<D + 1, N>::apply(p, v);
}
};
template <std::size_t N>
struct fill<N, N>
{
template <typename Point>
static void apply(Point&, typename bg::coordinate_type<Point>::type const&) {}
};
int main()
{
int M;
M = 100;
if ( M == 100 )
do_something<100>();
else if ( M == 10000 )
do_something<10000>();
else
std::cerr << "invalid dimension!";
point p;
if ( M == 100 )
fill<0, 100>::apply(p, 5);
else if ( M == 10000 )
fill<0, 10000>::apply(p, 5);
else
std::cerr << "invalid dimension!";
return 0;
}
The error is that the compiler can not see the typedef of "point". On the other hand, I can not make dimension of the typedef to be a run-time variable (Boost won't let me(!)). What can I do? Except from using another library, since this is the worst interface I have ever seen in higher dimensions geometry. :/
Compiled as: c++ -I ../ bla.cpp -std=c++0x -ftemplate-depth-170001 -o bla