# [geometry] Runtime dimensionality

9 messages
Open this post in threaded view
|

## [geometry] Runtime dimensionality

 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 struct access {   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() as a member of Vertex. My biggest problem is the dimensionality template<> struct dimension : 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? Thanks! Florian _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 On 26 September 2017 at 04:02, Florian Lindner via Boost-users <[hidden email]> wrote: > > We have a Vertex object, with a dimension determined at runtime. T This is not possible. Dimension is compile-time trait of any model in the Geometry, intrinsic or adapted. Unless my info is outdated. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net_______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 Mateusz Loskot Via Boost-users wrote: ```On 26 September 2017 at 04:02, Florian Lindner via Boost-users [hidden email] wrote: ``` ```We have a Vertex object, with a dimension determined at runtime. T ``` ```This is not possible. Dimension is compile-time trait of any model in the Geometry, intrinsic or adapted. Unless my info is outdated. ``` Nothing've  changed. Dimension has to be known at compile time. The way how this could be handled depends on the use case. What are you using Boost.Geometry for? Adam _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 This was presented at BoostCon I attended a number of years back. Pablo is a great guy to talk to about this.On Tue, Sep 26, 2017 at 12:19 PM, Adam Wulkiewicz via Boost-users wrote: Mateusz Loskot Via Boost-users wrote: ```On 26 September 2017 at 04:02, Florian Lindner via Boost-users [hidden email] wrote: ``` ```We have a Vertex object, with a dimension determined at runtime. T ``` ```This is not possible. Dimension is compile-time trait of any model in the Geometry, intrinsic or adapted. Unless my info is outdated. ``` Nothing've  changed. Dimension has to be known at compile time. The way how this could be handled depends on the use case. What are you using Boost.Geometry for? Adam _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 The Maschine Via Boost-users wrote: This was presented at BoostCon I attended a number of years back.  Pablo is a great guy to talk to about this. Thanks for the link, that's interesting but I don't have time right now to watch the whole talk. Let me be more specific. What's a set of Boost.Geometry operations that you'd like to use? E.g. would you like to do spatial indexing using the rtree, perform set operations, perform relational operations, etc? What's the maximum dimension? The most generic approach would be to set dimension to the highest dimension you support and then as Florian pointed out return 0 for dimensions higher than the actual dimension. Depending on the actuall use case the unneeded dimensions could be processed by the library anyway so this could harm the performance. But maybe it would be good enough for you. In some cases it would be possible to optimize the code, e.g. if you wanted to use the rtree you could pass your own equal_to getter checking only the important dimensions or overload e.g. boost::geometry::intersects() which is used by the rtree while performing boost::geometry::index::intersects() spatial query, etc. Regarding set and relational operations for polygons AFAIR only the first 2 dimensions are used in the most part of the algorithm anyway (besides actual points comparison I think). If the operation you'd like to perform was CPU-bounded, had the complexity worse or equal to linear, the max dimension was high but the actual dimension was low then it could be worth converting your geometry to e.g. one of the Boost.Geometry model having compile-time dimension. The conversion would have linear complexity so the overall complexity would stay the same and it could speed up the overall operation because you'd avoid processing the unnecessary dimensions. Converting the data could also increase performance if the fact that purely dynamic Eigen::VectorXd have data pointer to dynamically allocated memory caused cache misses while accessing data. This probably would be the case if the operation had complexity higher than linear because the conversion would be linear itself and I'm assuming that most of the time the program would wait for the data while copying or processing using linear algorithm. And so on... Adam _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 In reply to this post by Boost - Users mailing list Am 26.09.2017 um 14:40 schrieb Mateusz Loskot: > On 26 September 2017 at 04:02, Florian Lindner via Boost-users > <[hidden email]> wrote: >> >> We have a Vertex object, with a dimension determined at runtime. T > > This is not possible. > Dimension is compile-time trait of any model in the Geometry, > intrinsic or adapted. > Unless my info is outdated. Ok, I expected that. Is there maybe a way to define the rtree's dimensionality upon creation? So that I can do: rtree<3, size_t, RTreeParameters, VertexIndexGetter>; 3 beging the dimension. Thanks, Florian _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
Open this post in threaded view
|

## Re: [geometry] Runtime dimensionality

 On 27 September 2017 at 03:57, Florian Lindner <[hidden email]> wrote: > Am 26.09.2017 um 14:40 schrieb Mateusz Loskot: >> On 26 September 2017 at 04:02, Florian Lindner via Boost-users >> <[hidden email]> wrote: >>> >>> We have a Vertex object, with a dimension determined at runtime. T >> >> This is not possible. >> Dimension is compile-time trait of any model in the Geometry, >> intrinsic or adapted. >> Unless my info is outdated. > > Ok, I expected that. Is there maybe a way to define the rtree's dimensionality upon creation? So that I can do: > > rtree<3, size_t, RTreeParameters, VertexIndexGetter>; > > 3 beging the dimension. The only run-time parameters rtree can take are for balancing configuration. http://www.boost.org/doc/libs/1_65_1/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.htmlUnless, again, something has changed and rtree can swallow-adapt `Value` type of any dimension. I'm sure Adam will chime in with further clarifications. Best regards, -- Mateusz Loskot, http://mateusz.loskot.net_______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users
 Mateusz Loskot Via Boost-users wrote: ```On 27 September 2017 at 03:57, Florian Lindner [hidden email] wrote: ``` ```Am 26.09.2017 um 14:40 schrieb Mateusz Loskot: ``` ```On 26 September 2017 at 04:02, Florian Lindner via Boost-users [hidden email] wrote: ``` ```We have a Vertex object, with a dimension determined at runtime. T ``` ```This is not possible. Dimension is compile-time trait of any model in the Geometry, intrinsic or adapted. Unless my info is outdated. ``` ```Ok, I expected that. Is there maybe a way to define the rtree's dimensionality upon creation? So that I can do: rtree<3, size_t, RTreeParameters, VertexIndexGetter>; 3 beging the dimension. ``` ``` The only run-time parameters rtree can take are for balancing configuration. http://www.boost.org/doc/libs/1_65_1/libs/geometry/doc/html/geometry/spatial_indexes/creation_and_modification.html Unless, again, something has changed and rtree can swallow-adapt `Value` type of any dimension. I'm sure Adam will chime in with further clarifications. ``` The rtree takes dimension from geometry::dimension of Value's Indexable Geometry in compile-time. But I don't fully understand the problem. In the code above the dimension 3 is compile-time parameter, not run-time. The equivalent of the code above could therefore be e.g.: typedef bg::model::box> box_type; rtree, RTreeParameters, ValueIndexableGetter> rt; Adam _______________________________________________ Boost-users mailing list [hidden email] https://lists.boost.org/mailman/listinfo.cgi/boost-users