2009年11月8日日曜日

boost::polygon

 キターッ!!!という気がするのだけども、とりあえず演算してみることに…。やっつけスクラッチです。


//#pragma warning (disable: 4351)
//#pragma warning (disable: 4805)

/*
Copyright 2008 Intel Corporation

Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
*/

#include <boost/polygon/polygon.hpp>
#include <boost/foreach.hpp>
#include <cassert>
#include <iostream>
namespace gtl = boost::polygon;
using namespace boost::polygon::operators;

typedef gtl::polygon_data<int> Polygon;
typedef gtl::polygon_traits<Polygon>::point_type Point;
typedef std::vector<Polygon> PolygonSet;

std::ostream& operator << (std::ostream& os, const Point& p ) {
os << "(" << x(p) << "," << y(p) << ")";
return os;
}

std::ostream& operator << (std::ostream& os, const Polygon& p) {
Polygon::iterator_type s = p.begin();
Polygon::iterator_type e = p.end();
while( s != e ) {
os << *s << ",";
++s;
}
return os;
}
std::ostream& operator << (std::ostream& os, const PolygonSet& s) {
BOOST_FOREACH( const Polygon& p, s ) {
os << p << " : ";
}
return os;
}


int main() {

Point pts1[] = {
gtl::construct<Point>( 0, 5000),
gtl::construct<Point>( -4330, -2500),
gtl::construct<Point>( 4330, -2500)
};
Point pts2[] = {
gtl::construct<Point>( 0, -5000),
gtl::construct<Point>( 4330, 2500),
gtl::construct<Point>( -4330, 2500)
};


Polygon poly1, poly2, poly3, poly4;
gtl::set_points(poly1, pts1, pts1+3);
gtl::set_points(poly2, pts2, pts2+3);

PolygonSet ps1, ps2, ps3, ps4, ps5;
ps1 += poly1;
ps2 += poly2;

ps3 += ps1 & ps2;
ps4 += ps1 | ps2;
ps5 += (ps4 - ps3);

std::cout << ps3 << std::endl;
std::cout << ps4 << std::endl;
std::cout << ps5 << std::endl;


return 0;
}


0 件のコメント: