Search code examples
c++boostpolygonboost-geometry

Boost Polygon with indexed geometry


I need to make some polygon computation on 2D plan. Typically, isInside operation.

I found boost::Polygon API but my points are inside a single big array. That's I call indexed geometry. See http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/

So my best way is just to boost::Polygon and give to it my array + indices of points to use.

The objective is just to don't copy my million of points (because they are shared at least by two polygons).

I don't know if API allows it ( or I need to inherit my own class :-( ). Maybe, someone know another API (inside boost or other).

Thanks

Documentation


Solution

  • Boost Geometry allows for adapted user-defined data types.

    Specifically, C arrays are adapted here: https://www.boost.org/doc/libs/1_68_0/boost/geometry/geometries/adapted/c_array.hpp

    I have another answer up where I show how to use Boost Geometry algorithms on a direct C array of structs (in that case I type punned using tuple as the point type): How to calculate the convex hull with boost from arrays instead of setting each point separately? (the other answers show alternatives that may be easier if you can afford to copy some data).

    The relevant algorithms would be: