Boost logo

Geometry :

Subject: Re: [geometry] Boost.Geometry boolean operation usage on many polygons.
From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2012-11-24 06:56:39

Hi Josh,

I was talking about the vector::swap function, which swaps 2 vectors
by swapping their respective internal pointer. It's a costless

My point was : tmpPolySet is only a temporary multipolygon in which
you store the result of union(polyset1, polygon). Then you assign it
back to polyset1 so that the result iteratively accumulates into
polyset1. Since tmpPolyset is a temporary intermediate result, you
clear it at the end of the loop. So rather than assigning it to
polyset1, which involves a per-point copy, you might as well swap
them. polyset1 would then have the contents of tmpPolySet (which is
what you want) and tmpPolySet would have the contents of polyset1
(which is something you don't need but you get rid of it just after
anyway). This way you achieve the same result without a per_point

So, replace this:

boostG::assign(polyset1, tmpPolySet);



and see if performances improve.

To advise further I'd also need to have the declarations of all the
variables you're using and what they're supposed to contain, it's hard
to read the code without having the preconditions.


On Mon, Nov 19, 2012 at 12:26 AM, josh kim <josh.kim0323_at_[hidden]> wrote:
> I apologize for not being specific enough. I am using polygon type provided
> by Boost Geometry.
> typedef boostG::model::d2::point_xy<int> BGPoint;
> typedef boostG::model::polygon< BGPoint, false, true > BGPolygon;
> typedef boostG::model::multi_polygon< BGPolygon > multi_polygon;
> typedef boostG::model::ring<BGPoint, false, true> BGRing;
> typedef vector<BGPolygon> BGPolygonSet;
> these are the types I use that are provided by boost geometry.
> I first used BGPolygonSet to pass two sets of polygons to booleanizing
> operation, however, I figured that I should use multi_polygon type for doing
> that.
> and no. everything is in the for loop.
> Here's my code :
> for (i = 0; i < pnum1; i++) {
> for (j = 0; j < vnumList1[i] - 1; j++) {
> poly_x = polygonList1[i][j*2];
> poly_y = polygonList1[i][j*2+1];
> polyPoints.push_back(make<BGPoint>(poly_x, poly_y));
> }
> boostG::assign_points(polygon, polyPoints);
> boostG::correct(polygon);
> boostG::union_(polyset1, polygon, tmpPolySet);
> boostG::correct(tmpPolySet);
> boostG::assign(polyset1, tmpPolySet);
> boostG::correct(polyset1);
> boostG::clear(tmpPolySet);
> polyPoints.clear();
> }
> I'm using correct polygon just to make sure I can avoid having overlay
> problem issue.
> and using assign(polyset1, tmpPolySet) to recursively add one polygon to the
> list (multipolygon) at a time.
> and what does swap function actually do? it doesn't seem to add a polygon to
> the multipolygon data type.
> and what about the overlay polygon issues I'm having? and the unionizing
> problem that I explained with pictures? The last picture is what I expect.
> And thank you very much for answering my question!
> --
> View this message in context:
> Sent from the Boost Geometry mailing list archive at
> _______________________________________________
> Geometry mailing list
> Geometry_at_[hidden]

Geometry list run by mateusz at