Boost logo

Geometry :

Subject: [ggl] Derived classes and traits
From: Barend Gehrels (barend)
Date: 2011-08-20 04:11:33


Hi,

> Hello, I am starting to play with bg and I want to derive/abstract a
> couple of things using it.
>
> For example, a derived point class:
>
> namespace bg = boost::geometry;
>
> template <typename CoordinateType, std::size_t DimensionCount,
> typename CoordinateSystem>
> class MyPointType : public bg::model::point<CoordinateType,
> DimensionCount, CoordinateSystem >
> {
> // Add possible new functionality here.
> };
>
> typedef MyPointType<int32_t, 2, bg::cs::cartesian> MyIntPoint2;
> typedef MyPointType<int32_t, 3, bg::cs::cartesian> MyIntPoint3;
>
>
> This works fine.

Eehhm, I don't think it works fine in combination with Boost.Geometry
algorithms. If you derive a class, you still have to registrate it by
either a macro, or specialize the necessary traits classes...

E.g. using BOOST_GEOMETRY_REGISTER_POINT_2D

And that is also the answer to your next question:

> However, when trying to derive one more level, I'm facing a problem:
>
> class SomethingDerivedAgain : MyIntPoint3
> {
> public:
> SomethingDerivedAgain(...) // How to access MyIntPoint3's
> CoordinateType (abstractly of course, without assuming it's int32_t)
> so that I can override the (v0,v1,v2) constructor of bg::model::point ??
>
> private:
> // Incredible new stuff here
> };
>
> Would "traits" help me achieve this ? Could you provide a snippet of
> usage example ? That would be very appreciated.

Inside SomethingDerivedAgain you can use the type
bg::point_type<MyIntPoint3>::coordinate_type and this will map to
int32_t indeed.

(After this, you again have to register SomethingDerivedAgain as a
point type as well).

Regards, Barend

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/ggl/attachments/20110818/246b66d0/attachment-0001.html


Geometry list run by mateusz at loskot.net