Limbo 3.5.4
Loading...
Searching...
No Matches
test_boostpolygonapi.cpp
Go to the documentation of this file.
1
6
7#include <iostream>
8#include <string>
9#include <vector>
10#include <list>
11#include <set>
12#include <boost/polygon/polygon.hpp>
16using std::cout;
17using std::endl;
18using std::string;
19using std::vector;
20using std::list;
21using std::set;
22
23namespace gtl = boost::polygon;
24namespace lg = limbo::geometry;
25
31
36void test1(string const& filename)
37{
38 std::vector<gtl::rectangle_data<int> > vRect;
39 lg::Polygon2Rectangle<vector<gtl::point_data<int> >, vector<gtl::rectangle_data<int> > > p2r (vRect, lg::HOR_VER_SLICING);
40 assert(p2r.read(filename));
41 assert(p2r());
42 p2r.print("p2r1.gp");
43}
44
49void test2(string const& filename)
50{
51 std::vector<gtl::rectangle_data<int> > vRect;
52 lg::Polygon2Rectangle<list<gtl::point_data<int> >, vector<gtl::rectangle_data<int> > > p2r (vRect, lg::HOR_VER_SLICING);
53 assert(p2r.read(filename));
54 assert(p2r());
55 p2r.print("p2r2.gp");
56}
57
62void test3(string const& filename)
63{
64 std::vector<gtl::rectangle_data<int> > vRect;
65 lg::Polygon2Rectangle<set<gtl::point_data<int> , lg::point_compare_type>, vector<gtl::rectangle_data<int> > > p2r (vRect, lg::HOR_VER_SLICING);
66 assert(p2r.read(filename));
67 assert(p2r());
68 p2r.print("p2r3.gp");
69}
70
74void test4()
75{
76 vector<gtl::point_data<int> > vPoint (8);
77 vPoint[0] = gtl::construct<gtl::point_data<int> >(0, 0);
78 vPoint[1] = gtl::construct<gtl::point_data<int> >(0, 10);
79 vPoint[2] = gtl::construct<gtl::point_data<int> >(10, 10);
80 vPoint[3] = gtl::construct<gtl::point_data<int> >(10, 20);
81 vPoint[4] = gtl::construct<gtl::point_data<int> >(20, 20);
82 vPoint[5] = gtl::construct<gtl::point_data<int> >(20, 10);
83 vPoint[6] = gtl::construct<gtl::point_data<int> >(30, 10);
84 vPoint[7] = gtl::construct<gtl::point_data<int> >(30, 0);
85 //vPoint.push_back(gtl::construct<gtl::point_data<int> >(0, 0));
86 vector<gtl::rectangle_data<int> > vRectangle;
87 assert(lg::polygon2RectangleBoost(vPoint, vRectangle));
88 for (std::size_t i = 0; i != vRectangle.size(); ++i)
89 {
90 gtl::rectangle_data<int> const& rect = vRectangle[i];
91 cout << "(" << gtl::xl(rect) << ", " << gtl::yl(rect) << ", " << gtl::xh(rect) << ", " << gtl::yh(rect) << ")\n";
92 }
93 cout << "test 4 passed\n";
94}
95
102int main(int argc, char** argv)
103{
104 test4();
105 if (argc > 1)
106 {
107 test1(argv[1]);
108 test2(argv[1]);
109 test3(argv[1]);
110 }
111 else cout << "at least 1 argument is required" << endl;
112
113 return 0;
114}
Geometry traits for Boost.Polygon, include this file when you use Boost.Polygon geometric types.
this file extracts polygon-to-rectangle conversion for Boost.Polygon API.
a generic implementation of polygon-to-rectangle conversion
a class implement conversion from manhattan polygon to rectangle
bool read(string const &filename)
read polygon from file try to be compatible to gnuplot format
void print(string const &filename) const
print polygon to file in gnuplot format
namespace for Limbo.Geometry
Definition Geometry.h:21
bool polygon2RectangleBoost(std::vector< gtl::point_data< int > > const &vPoint, std::vector< gtl::rectangle_data< int > > &vRectangle)
this function takes a set of points describing a rectilinear polygon and decomposes it into rectangle...
@ HOR_VER_SLICING
horizontal/vertical slicing and choose rectangle with larger area every time
Definition Geometry.h:43
sort helper if orient == HORIZONTAL, sort by left lower if orient == VERTICAL, sort by lower left
int main()
void test4()
test polygon-to-rectangle for array of points
void test2(string const &filename)
test polygon-to-rectangle for std::list
void test3(string const &filename)
test polygon-to-rectangle for std::set
void test1()
test function API