Boost logo

Geometry :

Subject: [geometry] Coping with runtime dimension
From: Florian Lindner (mailinglists_at_[hidden])
Date: 2017-09-22 09:25:22


Hello,

I just started yesterday looking into boost.geometry to use on our own legacy system of Vertices (Points) in Meshes.

I'm quite impressed how easy it is to adapt to existing code and got it working (with some workarounds) really quick.
However, some problems remain.

We have a Vertex object, with a dimension determined at runtime. The actual position is saved as VECTOR_T (usually an
Eigen::VectorXd (double vector of arbitrary dimension)). One can get the coordinates using "const Eigen::VectorXd&
Vertex::getNormal()"

I was able to adapt to geometry by adding getters/setts for the dimensions: double getX() and getY() and

BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(mesh::Vertex, double, cs::cartesian, getX, getY, setX, setY)

and it works!

But in theory the vertices can be of arbitrary dimension, in practice it's usually 1, 2 or 3.

What is the best way to adapt our Vertex object to geometry?

- Change our Vertex so that it meets the model::point requirements. It worked so far, for the access I use:

template<size_t Dimension> struct access<Vertex, Dimension>
{
  static double get(Vertex const& p)
  {
    return p.getCoords()[Dimension];
  }

  static void set(Vertex& p, double const& value)
  {
    Eigen::VectorXd vec = p.getCoords();
    vec[Dimension] = value;
    p.setCoords(p);
  }
};

In our code we rarely set the entries of an vector, so the code is a but ugly. Will likely change that to a compile-time
get<Dim>() as a member of Vertex.

My biggest problem is the dimensionality

template<> struct dimension<Vertex> : boost::mpl::int_<2> {};

but I have no idea currently how to get that for an Eigen::VectorXd at compile-time?

Do you have any idea? We could just make all Vertex 3-dimensional and set the dimension to 0 if not used...

Thanks!
Florian


Geometry list run by mateusz at loskot.net