Boost logo

Geometry :

Subject: [geometry] access to poligon point list
From: nicola81 (nicola_cavallini_at_[hidden])
Date: 2012-05-17 14:23:31


Hi all,

I'm kind of new to c++, and definitely new to boost geometry, this is why I
apologize in advance if my point is too ingenuous.

I would like to get the polygon points in a standard vector, or into some
other (simple :( ) structure I can access to.

I've spent several days trying to get something out of Google, but I
couldn't get anything useful. I cannot compile most of the code examples on
stackoverflow or on the geometry library website.

I run the last Intel compiler 12.something, and boost 1.49.

The example I was working on is attached, and is actually from the boost
website. My guess was trying to get a couple of standard vectors (Px, Py)
out object function “list_coordinates”.

Is there a smarter way to do so? I think so but I didn't manage to find it.

Let me say that I'm really looking forward to use Boost.Geometry,
especially because I believe it is going to be crucial in my project,
finite elements fluid-structure interaction.

Thanks a lot,
Nicola Cavallini

#include <iostream>
#include <deque>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>

#include <boost/foreach.hpp>

#include <boost/geometry/multi/geometries/register/multi_polygon.hpp>

typedef
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double>,false>
polygon;

BOOST_GEOMETRY_REGISTER_MULTI_POLYGON(std::deque<polygon>);

template <typename Point>
void list_coordinates(Point const& p)
{
    using boost::geometry::get;
    
    std::cout << "x = " << get<0>(p) << " y = " << get<0>(p) << std::endl;

}

int main()
{
    typedef
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy&lt;double>
> polygon;

    polygon green, blue;

    boost::geometry::read_wkt(
        "POLYGON((0 0,0 1.75,1.75 0,0 0))", green);

    boost::geometry::read_wkt(
        "POLYGON((.5 .5, .5 1, 1 1, 1 .5, .5 .5))", blue);

    std::deque<polygon> output;
    boost::geometry::intersection(green, blue, output);

    polygon red;

    red = output[0];

    typedef boost::geometry::model::d2::point_xy<double> point;

    boost::geometry::for_each_point(red, list_coordinates<point> );

    return 0;
}

--
View this message in context: http://boost-geometry.203548.n3.nabble.com/access-to-poligon-point-list-tp3999541.html
Sent from the Boost Geometry mailing list archive at Nabble.com.

Geometry list run by mateusz at loskot.net