| 1 | #include <boost/polygon/polygon.hpp>
|
|---|
| 2 |
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 |
|
|---|
| 5 | namespace bp = boost::polygon;
|
|---|
| 6 |
|
|---|
| 7 | typedef bp::polygon_set_data<int> PolygonSet;
|
|---|
| 8 | typedef bp::polygon_data<PolygonSet::coordinate_type> Polygon;
|
|---|
| 9 | typedef bp::polygon_with_holes_data<PolygonSet::coordinate_type> PolygonWithHoles;
|
|---|
| 10 | typedef bp::polygon_traits<Polygon>::point_type Point;
|
|---|
| 11 |
|
|---|
| 12 | std::ostream &
|
|---|
| 13 | operator<<(std::ostream &os, const Point &pt)
|
|---|
| 14 | {
|
|---|
| 15 | return os << "(" << bp::x(pt) << " " << bp::y(pt) << ")";
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | std::ostream &
|
|---|
| 19 | operator<<(std::ostream &os, const Polygon &poly)
|
|---|
| 20 | {
|
|---|
| 21 | os << "polygon ";
|
|---|
| 22 | for (Polygon::iterator_type p = poly.begin() ; p != poly.end() ; ++p)
|
|---|
| 23 | os << " " << *p;
|
|---|
| 24 | return os;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | std::ostream &
|
|---|
| 28 | operator<<(std::ostream &os, const PolygonSet &ps)
|
|---|
| 29 | {
|
|---|
| 30 | std::vector<Polygon> temp;
|
|---|
| 31 | ps.get(temp);
|
|---|
| 32 | os << "polygonset ";
|
|---|
| 33 | for (std::vector<Polygon>::const_iterator p = temp.begin()
|
|---|
| 34 | ; p != temp.end() ; ++p)
|
|---|
| 35 | os << " " << *p;
|
|---|
| 36 | return os;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | int
|
|---|
| 40 | main(int argc, char *argv[])
|
|---|
| 41 | {
|
|---|
| 42 | using namespace bp::operators;
|
|---|
| 43 |
|
|---|
| 44 | const Point points[] = {
|
|---|
| 45 | Point(2,0),
|
|---|
| 46 | Point(4,0),
|
|---|
| 47 | Point(4,3),
|
|---|
| 48 | Point(0,3),
|
|---|
| 49 | Point(0,0),
|
|---|
| 50 | Point(2,0),
|
|---|
| 51 | Point(2,1),
|
|---|
| 52 | Point(1,1),
|
|---|
| 53 | Point(1,2),
|
|---|
| 54 | Point(3,2),
|
|---|
| 55 | Point(3,1),
|
|---|
| 56 | Point(2,1),
|
|---|
| 57 | Point(2,0)
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | Polygon poly1;
|
|---|
| 61 | bp::set_points(poly1, &points[0],
|
|---|
| 62 | &points[sizeof(points)/sizeof(points[0])]);
|
|---|
| 63 | std::cout << "poly1 = " << poly1 << "\n";
|
|---|
| 64 |
|
|---|
| 65 | PolygonSet ps;
|
|---|
| 66 | ps.insert(poly1);
|
|---|
| 67 | std::cout << "ps = " << ps << "\n";
|
|---|
| 68 |
|
|---|
| 69 | std::vector<Polygon> traps;
|
|---|
| 70 |
|
|---|
| 71 | // Note: bp::VERTICAL works fine
|
|---|
| 72 | get_trapezoids(traps, ps, bp::HORIZONTAL);
|
|---|
| 73 | std::cout << "Output: (" << traps.size() << ")\n";
|
|---|
| 74 | for (std::vector<Polygon>::const_iterator p = traps.begin()
|
|---|
| 75 | ; p != traps.end() ; ++p)
|
|---|
| 76 | std::cout << *p << "\n";
|
|---|
| 77 | }
|
|---|