Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_p2r.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <vector>
9 #include <list>
10 #include <set>
12 using std::cout;
13 using std::endl;
14 using std::vector;
15 using std::list;
16 using std::set;
17 using namespace limbo::geometry;
18 
22 struct Point
23 {
25  typedef int value_type;
27  value_type m_x;
29  value_type m_y;
34  value_type const& x() const {return m_x;}
39  value_type const& y() const {return m_y;}
43  void x(value_type v) {m_x = v;}
47  void y(value_type v) {m_y = v;}
48 
49  //bool operator==(Point const& rhs) {return x() == rhs.x() && y() == rhs.y();}
50 };
51 
52 namespace limbo { namespace geometry {
53 
59 template <>
61 {
63  typedef Point point_type;
65  typedef int coordinate_type;
66 
73  static coordinate_type get(const point_type& point, orientation_2d orient)
74  {
75  if (orient == HORIZONTAL) return point.x();
76  else if (orient == VERTICAL) return point.y();
77  else assert(0);
78  }
85  static void set(point_type& point, orientation_2d orient, coordinate_type value)
86  {
87  if (orient == HORIZONTAL) return point.x(value);
88  else if (orient == VERTICAL) return point.y(value);
89  else assert(0);
90  }
97  static point_type construct(coordinate_type x, coordinate_type y)
98  {
99  point_type p;
100  p.x(x); p.y(y);
101  return p;
102  }
103 };
104 
105 }}
106 
110 struct Rectangle
111 {
113  typedef int value_type;
114 
116  value_type m_xl;
118  value_type m_yl;
120  value_type m_xh;
122  value_type m_yh;
123 
128  value_type const& xl() const {return m_xl;}
133  value_type const& yl() const {return m_yl;}
138  value_type const& xh() const {return m_xh;}
143  value_type const& yh() const {return m_yh;}
148  void xl(value_type v) {m_xl = v;}
153  void yl(value_type v) {m_yl = v;}
158  void xh(value_type v) {m_xh = v;}
163  void yh(value_type v) {m_yh = v;}
164 };
165 
166 namespace limbo { namespace geometry {
167 
171 template <>
173 {
177  typedef int coordinate_type;
178 
185  static coordinate_type get(const rectangle_type& rect, direction_2d dir)
186  {
187  switch (dir)
188  {
189  case LEFT: return rect.xl();
190  case BOTTOM: return rect.yl();
191  case RIGHT: return rect.xh();
192  case TOP: return rect.yh();
193  default: assert(0);
194  }
195  }
202  static void set(rectangle_type& rect, direction_2d dir, coordinate_type value)
203  {
204  switch (dir)
205  {
206  case LEFT: rect.xl(value); break;
207  case BOTTOM: rect.yl(value); break;
208  case RIGHT: rect.xh(value); break;
209  case TOP: rect.yh(value); break;
210  default: assert(0);
211  }
212  }
218  static rectangle_type construct(coordinate_type xl, coordinate_type yl, coordinate_type xh, coordinate_type yh)
219  {
220  rectangle_type rect;
221  rect.xl(xl); rect.yl(yl);
222  rect.xh(xh); rect.yh(yh);
223  return rect;
224  }
225 };
226 
227 }}
228 
233 void test1(string const& filename)
234 {
235  vector<Rectangle> vRect;
236  Polygon2Rectangle<vector<Point>, vector<Rectangle> > p2r (vRect, HOR_VER_SLICING);
237  assert(p2r.read(filename));
238  assert(p2r());
239  p2r.print("p2r1.gp");
240 }
241 
246 void test2(string const& filename)
247 {
248  vector<Rectangle> vRect;
249  Polygon2Rectangle<list<Point>, vector<Rectangle> > p2r (vRect, HOR_VER_SLICING);
250  assert(p2r.read(filename));
251  assert(p2r());
252  p2r.print("p2r2.gp");
253 }
254 
259 void test3(string const& filename)
260 {
261  vector<Rectangle> vRect;
262  Polygon2Rectangle<set<Point, point_compare_type>, vector<Rectangle> > p2r (vRect, HOR_VER_SLICING);
263  assert(p2r.read(filename));
264  assert(p2r());
265  p2r.print("p2r3.gp");
266 }
267 
274 int main(int argc, char** argv)
275 {
276  if (argc > 1)
277  {
278  test1(argv[1]);
279  test2(argv[1]);
280  test3(argv[1]);
281  }
282  else cout << "at least 1 argument is required" << endl;
283 
284  return 0;
285 }
static void set(point_type &point, orientation_2d orient, coordinate_type value)
set coordinates
Definition: test_p2r.cpp:85
int value_type
coordinate type
Definition: test_p2r.cpp:113
direction_2d
direction type for rectangles
Definition: Geometry.h:72
value_type m_x
x coordinate
Definition: test_p2r.cpp:27
void test1(string const &filename)
test polygon-to-rectangle for std::vector
Definition: test_p2r.cpp:233
value_type m_yl
bottom
Definition: test_p2r.cpp:118
a custom point class
Definition: test_p2r.cpp:22
value_type m_y
y coordinate
Definition: test_p2r.cpp:29
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
value_type const & xl() const
access left coordinate
Definition: test_p2r.cpp:128
static point_type construct(coordinate_type x, coordinate_type y)
construct a point object
Definition: test_p2r.cpp:97
value_type const & x() const
access x coordinate
Definition: test_p2r.cpp:34
void x(value_type v)
set x coordinate
Definition: test_p2r.cpp:43
value_type m_xh
right
Definition: test_p2r.cpp:120
void yl(value_type v)
set bottom coordinate
Definition: test_p2r.cpp:153
type traits for rectangle
Definition: Geometry.h:199
value_type const & yl() const
access bottom coordinate
Definition: test_p2r.cpp:133
void test2(string const &filename)
test polygon-to-rectangle for std::list
Definition: test_p2r.cpp:246
namespace for Limbo
Definition: GraphUtility.h:22
value_type const & yh() const
access top coordinate
Definition: test_p2r.cpp:143
void test3(string const &filename)
test polygon-to-rectangle for std::set
Definition: test_p2r.cpp:259
value_type m_yh
top
Definition: test_p2r.cpp:122
void print(string const &filename) const
print polygon to file in gnuplot format
static void set(rectangle_type &rect, direction_2d dir, coordinate_type value)
set coordinates
Definition: test_p2r.cpp:202
void xl(value_type v)
set left coordinate
Definition: test_p2r.cpp:148
int main(int argc, char **argv)
main function requires an input benchmark in gnuplot format
Definition: test_p2r.cpp:274
a custom rectangle class
Definition: test_p2r.cpp:110
value_type const & xh() const
access right coordinate
Definition: test_p2r.cpp:138
void y(value_type v)
set y coordinate
Definition: test_p2r.cpp:47
a generic implementation of polygon-to-rectangle conversion
namespace for Limbo.Geometry
Definition: Geometry.h:20
horizontal/vertical slicing and choose rectangle with larger area every time
Definition: Geometry.h:43
value_type m_xl
left
Definition: test_p2r.cpp:116
type traits for point
Definition: Geometry.h:168
int coordinate_type
coordinate type
Definition: test_p2r.cpp:65
int value_type
coordinate type
Definition: test_p2r.cpp:25
static rectangle_type construct(coordinate_type xl, coordinate_type yl, coordinate_type xh, coordinate_type yh)
construct rectangle
Definition: test_p2r.cpp:218
value_type const & y() const
access y coordinate
Definition: test_p2r.cpp:39
a class denoting orientation of lines
Definition: Geometry.h:92
void xh(value_type v)
set right coordinate
Definition: test_p2r.cpp:158
void yh(value_type v)
set top coordinate
Definition: test_p2r.cpp:163