|
Boost : |
Subject: [boost] Simple boost polygon boolean OR doesn't work: help needed
From: Praveen Vs (vs.praveen78_at_[hidden])
Date: 2012-02-08 05:55:02
Hi,
Below is code for doing a boolean OR operation. I'm not sure of the
mistake I'm doing here. The output generated is wrong. I'm not using
the operator+() becaue of the compile issue on MSVC2010.
#include <boost/polygon/polygon.hpp>
namespace gtl = boost::polygon;
using namespace gtl;
using namespace boost::polygon::operators;
using namespace std;
typedef gtl::polygon_set_data<double> CPolygonSet;
typedef gtl::polygon_data<double> CPolygon;
static void test_boost_polygons()
{
CPolygonSet polyset1, polyset2, rset;
CPolygon polygon1, polygon2;
typedef gtl::polygon_traits<CPolygon>::point_type CPoint;
vector<CPoint> poly1Points, poly2Points;
poly1Points.push_back(gtl::construct<CPoint>(0.0000, 0.0000));
poly1Points.push_back(gtl::construct<CPoint>(50.0000, 50.0000));
poly1Points.push_back(gtl::construct<CPoint>(100.0000, -50.0000));
poly1Points.push_back(gtl::construct<CPoint>(50.0000, -50.0000));
poly2Points.push_back(gtl::construct<CPoint>(50.0000, 0.0000));
poly2Points.push_back(gtl::construct<CPoint>(100.0000, 50.0000));
poly2Points.push_back(gtl::construct<CPoint>(150.0000, -50.0000));
polygon1.set(poly1Points.begin(), poly1Points.end());
polygon2.set(poly2Points.begin(), poly2Points.end());
vector<CPolygon> polygonArray1, polygonArray2;
polygonArray1.push_back(polygon1);
polygonArray2.push_back(polygon2);
polyset1.insert(polygonArray1.begin(), polygonArray1.end());
polyset2.insert(polygonArray2.begin(), polygonArray2.end());
gtl::arbitrary_boolean_op<CPolygonSet::coordinate_type> bop;
bop.execute(rset, polyset1.begin(), polyset1.end(),
polyset2.begin(), polyset2.end(), 0);
vector<CPolygon> polys;
rset.get(polys);
for(unsigned int i = 0; i < polys.size(); ++i)
{
CPolygon::iterator_type it = polys[i].begin();
for(; it != polys[i].end(); ++it)
{
cout<<"("<<(*it).x()<<", "<<(*it).y()<<")"<<endl;
}
}
}
void main()
{
test_boost_polygons();
}
-- -praveen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk