Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_boostpolygonapi.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <string>
9 #include <vector>
10 #include <list>
11 #include <set>
12 #include <boost/polygon/polygon.hpp>
16 using std::cout;
17 using std::endl;
18 using std::string;
19 using std::vector;
20 using std::list;
21 using std::set;
22 
23 namespace gtl = boost::polygon;
24 namespace lg = limbo::geometry;
25 
36 void 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 
49 void 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 
62 void 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 
74 void 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 
102 int 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 }
void test2(string const &filename)
test polygon-to-rectangle for std::list
sort helper if orient == HORIZONTAL, sort by left lower if orient == VERTICAL, sort by lower left ...
bool read(string const &filename)
read polygon from file try to be compatible to gnuplot format
a class implement conversion from manhattan polygon to rectangle
void test4()
test polygon-to-rectangle for array of points
int main(int argc, char **argv)
main function requires an input benchmark in gnuplot format
void test3(string const &filename)
test polygon-to-rectangle for std::set
void test1(string const &filename)
test Boost.Polygon API
void print(string const &filename) const
print polygon to file in gnuplot format
Geometry traits for Boost.Polygon, include this file when you use Boost.Polygon geometric types...
a generic implementation of polygon-to-rectangle conversion
this file extracts polygon-to-rectangle conversion for Boost.Polygon API.
namespace for Limbo.Geometry
Definition: Geometry.h:20
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...
horizontal/vertical slicing and choose rectangle with larger area every time
Definition: Geometry.h:43