Boost logo

Boost Users :

Subject: Re: [Boost-users] Polygon, accessing Points_Data
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2011-04-13 12:19:42


AmandaLind wrote:
> This is the last time I bump this in hope of help...

You should be a little more patient, I read the list every day and search for Polygon in the subject line.

> namespace gtl = boost::polygon;
> using namespace boost::polygon::operators;
> using namespace gtl;
>
> //lets construct the two polygons
> typedef gtl::polygon_data Polygon;
> typedef gtl::polygon_traits::point_type Point;

Both polygon_data and polygon_traits are templates, so the above code doesn't appear legal. You need to specify the coordinate type for polygon data and the polygon type for polygon traits.

...
> Polygon poly1;
> gtl::set_points(poly1, pts1, pts1+numcorners1);
...
> Polygon poly2;
> gtl::set_points(poly2, pts2, pts2+numcorners2);
>
> using namespace boost::polygon::operators;
>
> Polygon poly3;
> poly3 = poly1 & poly2;

The above code should not compile because the result of a boolean AND between two polygons can be zero, one or many polygons. It must be stored to a model of polygon set concept. The polygon_data assignment operator should not accept the operator template produced by &.

> Point pts3[poly3.size()];
>
> //how does one use iterators ?!
> std::vector<point_data<int> >::iterator itr ;
> itr= poly3.begin();
> int index=0
> for(itr; itr != ploy3.end(); ++itr)
> {
> pts3(index)=*itr;
> index++;
> }

They are just like stl iterators (in fact they are std::vector iterators in this case.) Just do:
std::vector<point_type> pts;
Pts.insert(pts.end(), poly3.begin(), poly3.end());

However, you need extra code before you get to that point.

Try

        typedef std::vector<boost::polygon::polygon_data<int> > PolySet;
        typedef boost::polygon::polygon_data<int> Poly;
        typedef boost::polygon::polygon_traits<Poly>::point_type Point;
        Poly poly1, poly2;
        gtl::set_points(poly1, pts1, pts1+numcorners1);
      gtl::set_points(poly2, pts2, pts2+numcorners2);
        PolySet polys;
        using namespace boost::polygon::operators;
        boost::polygon::assign(polys, poly1 & poly2);
        for(std::size_t i = 0; i < polys.size(); ++i) {
                std::vector<Point> pts;
                pts.insert(pts.end(), polys[i].begin(), polys[i].end());
                //do whatever you wanted with the points
        }

I wrote the above code off the top of my head, so don't be too alarmed if it doesn't compile for some reason. Use the example code and look at the unit test code as well as the tutorial code to see usage of the library.

Regards,
Luke


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net