Boost logo

Boost :

Subject: Re: [boost] Simple boost polygon boolean OR doesn't work: help needed
From: Praveen Vs (vs.praveen78_at_[hidden])
Date: 2012-02-08 22:58:53


Changing to int doesn't work either. MSVC2010 throws a bunch of
compilation errors. Do you use any special compiler flags? or Boost
macros?

#include <boost/polygon/gtl.hpp>
#include <cassert>

using namespace std;

static void test_boost_polygons()
{
    namespace gtl = boost::polygon;
    using namespace gtl;
    using namespace boost::polygon::operators;

    typedef gtl::polygon_set_data<int> CPolygonSet;
    typedef gtl::polygon_data<int> CPolygon;

    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, 0));
    poly1Points.push_back(gtl::construct<CPoint>(50, 50));
    poly1Points.push_back(gtl::construct<CPoint>(100, -50));
    poly1Points.push_back(gtl::construct<CPoint>(50, -50));

    poly2Points.push_back(gtl::construct<CPoint>(50, 0));
    poly2Points.push_back(gtl::construct<CPoint>(100, 50));
    poly2Points.push_back(gtl::construct<CPoint>(150, -50));

    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());

    //rset = polyset1 + polyset2; // this too causes compilation errors!

    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;
        }
    }
}

On Wed, Feb 8, 2012 at 10:24 PM, Simonson, Lucanus J
<lucanus.j.simonson_at_[hidden]> wrote:
> Praveen Vs wrote:
>
>> typedef gtl::polygon_set_data<double> CPolygonSet; typedef gtl::polygon_data<double> CPolygon;
>
> While the coordinate data type is templates, floating point coordinate types are not supported for polygon clipping operations because of the difficulty making the calculations numerically robust.  Of the open source polygon clipping libraries I know of only CGAL is numerically robust with floating point coordinates, and it uses multi-precision arithmetic extensively.  You need to use integer coordinates.  If you don't like the rounding error scale the data to make the rounding error smaller.
>
> Your compiler error should hopefully go away with integer coordinate types.  I believe my tests are passing on MSVC2010.
>
> Regards,
> Luke
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

-- 
-praveen

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk