diff --git a/Packages/Largest_empty_rect_2/EmptyRect.C b/Packages/Largest_empty_rect_2/EmptyRect.C index 2725b982a55..331b933d00e 100644 --- a/Packages/Largest_empty_rect_2/EmptyRect.C +++ b/Packages/Largest_empty_rect_2/EmptyRect.C @@ -1,5 +1,11 @@ +#include +#include +#include +#include #include "EmptyRect.h" - +#include +#include +#include typedef double Number_Type; @@ -7,39 +13,29 @@ typedef CGAL::Cartesian Repr; typedef CGAL::Point_2 Point; typedef CGAL::Vector_2 Vector; typedef CGAL::Segment_2 Segment; -typedef pair Nt_pair; -typedef pair Bbox; +typedef CGAL::Iso_rectangle_2 Iso_rectangle_2; typedef CGAL::Polygon_traits_2 Traits; typedef std::list Container; typedef CGAL::Polygon_2 Polygon; - +typedef CGAL::Largest_empty_iso_rectangle_2 Largest_empty_rect; Polygon P; -void display_points(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream &W) +void display_points(Largest_empty_rect &empty_rectangle,CGAL::Window_stream &W) { W << CGAL::BLACK; - for(Largest_Empty_Rect::const_iterator it = empty_rectangle.begin();it != empty_rectangle.end();++it) + for(Largest_empty_rect::const_iterator it = empty_rectangle.begin();it != empty_rectangle.end();++it) W << *it; } -void display_bounding_box(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream &W) +void display_bounding_box(Largest_empty_rect &empty_rectangle,CGAL::Window_stream &W) { - Bbox b = empty_rectangle.get_bounding_box(); - double x1 = CGAL::to_double(b.first.first), - y1 = CGAL::to_double(b.first.second), - x2 = CGAL::to_double(b.second.first), - y2 = CGAL::to_double(b.second.second); - W << CGAL::GREEN; - W << Segment(Point(x1,y1),Point(x2,y1)); - W << Segment(Point(x1,y1),Point(x1,y2)); - W << Segment(Point(x1,y2),Point(x2,y2)); - W << Segment(Point(x2,y2),Point(x2,y1)); + W << empty_rectangle.get_bounding_box(); } -void clear(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream &W) +void clear(Largest_empty_rect &empty_rectangle,CGAL::Window_stream &W) { empty_rectangle.clear(); @@ -49,7 +45,7 @@ void clear(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream display_bounding_box(empty_rectangle,W); } -void redraw(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream &W) +void redraw(Largest_empty_rect &empty_rectangle,CGAL::Window_stream &W) { W.clear(); W << CGAL::BLUE; @@ -66,24 +62,15 @@ void redraw(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream } -void show_biggest_rec(Largest_Empty_Rect &empty_rectangle,CGAL::Window_stream &W) +void show_biggest_rec(Largest_empty_rect &empty_rectangle,CGAL::Window_stream &W) { - Bbox b = empty_rectangle.get_largest_empty_rectangle(); + Iso_rectangle_2 b = empty_rectangle.get_largest_empty_rectangle(); - W << CGAL::RED; + W << CGAL::RED << b; - double x1 = CGAL::to_double(b.first.first), - y1 = CGAL::to_double(b.first.second), - x2 = CGAL::to_double(b.second.first), - y2 = CGAL::to_double(b.second.second); - W << Segment(Point(x1,y1),Point(x2,y1)); - W << Segment(Point(x1,y1),Point(x1,y2)); - W << Segment(Point(x1,y2),Point(x2,y2)); - W << Segment(Point(x2,y2),Point(x2,y1)); - - cout << "\nThe biggest rectangle is :\n buttom-left point - (" << x1 << ":" << y1 << ")\n top-right point - (" << x2 << ":" << y2 << ")\n"; - cout << "Its size is " << abs((x2 - x1) * (y2 - y1)) << endl; + cout << "\nThe biggest rectangle is :\n buttom-left point - (" << b.min().x() << ":" << b.min().y() << ")\n top-right point - (" << b.max().x() << ":" << b.max().y() << ")\n"; + //cout << "Its size is " << abs((x2 - x1) * (y2 - y1)) << endl; } int main(int argc,char *argv[]) @@ -135,8 +122,14 @@ int main(int argc,char *argv[]) W.set_node_width(3); W << P; + Iso_rectangle_2 b(Point(x1, y1), Point(x2, y2)); + Largest_empty_rect empty_rectangle(b); - Largest_Empty_Rect empty_rectangle(P); + for(Polygon::Vertex_const_iterator it = P.vertices_begin(); + it != P.vertices_end(); + ++it){ + empty_rectangle.insert(*it); + } display_bounding_box(empty_rectangle,W); display_points(empty_rectangle,W); diff --git a/Packages/Largest_empty_rect_2/EmptyRect.h b/Packages/Largest_empty_rect_2/EmptyRect.h index 8bc8e600a07..e1c0fed74a8 100644 --- a/Packages/Largest_empty_rect_2/EmptyRect.h +++ b/Packages/Largest_empty_rect_2/EmptyRect.h @@ -1,55 +1,50 @@ -#include + +#ifndef CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H +#define CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H + #include #include -#include -#include -#include -#include -#include -#include -#include +CGAL_BEGIN_NAMESPACE enum point_type{reg,bot_right,bot_left,top_left,top_right}; -using namespace CGAL; -template -class Largest_Empty_Rect { - typedef pair,pair > Bbox; - typedef CGAL::Cartesian Repr; - typedef CGAL::Point_2 Point_2; - typedef CGAL::Vector_2 Vector_2; - typedef CGAL::Polygon_traits_2 Traits; - typedef std::list Container; - typedef CGAL::Polygon_2 Polygon; +template +class Largest_empty_iso_rectangle_2 { + + typedef typename T::FT NT; + typedef T::Point_2 Point_2; + typedef T::Vector_2 Vector_2; + typedef T::Iso_rectangle_2 Iso_rectangle_2; private: struct y_ptr_bigger; struct x_ptr_bigger; - class point_data { + class Point_data { public: + NT x; NT y; - set *right_tent; - set *left_tent; + set *right_tent; + set *left_tent; point_type type; - point_data(NT x_inp,NT y_inp); - point_data(NT x_inp,NT y_inp,set *r_tent,set *l_tent); - point_data(NT x_inp,NT y_inp,set *r_tent,set *l_tent,point_type i_type); - point_data(const point_data &other) : x(other.x),y(other.y),right_tent(other.right_tent),left_tent(other.left_tent) {} - ~point_data() {delete right_tent;delete left_tent;} - bool x_smaller(point_data *second) {return(x < second->x || x == second->x && y < second->y);} - bool y_smaller(point_data *second) {return(y < second->y || y == second->y && x < second->x);} - bool x_bigger(point_data *second) {return(x > second->x || x == second->x && y > second->y);} - bool y_bigger(point_data *second) {return(y > second->y || y == second->y && x > second->x);} + Point_data(NT x_inp,NT y_inp); + Point_data(NT x_inp,NT y_inp,set *r_tent,set *l_tent); + Point_data(NT x_inp,NT y_inp,set *r_tent,set *l_tent,point_type i_type); + Point_data(const Point_data &other) : x(other.x),y(other.y),right_tent(other.right_tent),left_tent(other.left_tent) {} + ~Point_data() {delete right_tent;delete left_tent;} + bool x_smaller(Point_data *second) {return(x < second->x || x == second->x && y < second->y);} + bool y_smaller(Point_data *second) {return(y < second->y || y == second->y && x < second->x);} + bool x_bigger(Point_data *second) {return(x > second->x || x == second->x && y > second->y);} + bool y_bigger(Point_data *second) {return(y > second->y || y == second->y && x > second->x);} }; struct y_ptr_bigger { - bool operator()(const point_data *a,const point_data *b) const + bool operator()(const Point_data *a,const Point_data *b) const { return(a->y < b->y || a->y == b->y && a->x < b->x); } @@ -57,7 +52,7 @@ private: struct x_ptr_bigger { - bool operator()(const point_data *a,const point_data *b) const + bool operator()(const Point_data *a,const Point_data *b) const { return(a->x < b->x || a->x == b->x && a->y < b->y); } @@ -71,17 +66,17 @@ private: } }; - typedef set Point_data_set_of_x; - typedef set Point_data_set_of_y; + typedef set Point_data_set_of_x; + typedef set Point_data_set_of_y; Point_data_set_of_x x_sorted; Point_data_set_of_y y_sorted; set public_set; NT min_x,min_y,max_x,max_y,min_x2,min_y2,max_x2,max_y2; NT biggest_rect_x0,biggest_rect_y0,biggest_rect_x1,biggest_rect_y1,biggest_rect_size; - Polygon *polygon; + // Polygon *polygon; - Bbox get_biggest_rect(); + Iso_rectangle_2 get_biggest_rect(); void phase_1(); void phase_1_on_x(); void phase_1_on_y(); @@ -92,21 +87,21 @@ private: void phase_2(); void phase_3(); void check_for_bigger(NT x0,NT y0,NT x1,NT y1); - void copy_y_point_data_to_list(list &point_data_list); - void copy_x_point_data_to_list(list &point_data_list); - void tent(point_data *first,point_data *second); - void tent(point_data *first,point_data *second,point_data *third); - void get_next_for_top(list::iterator &iter,list::iterator &beyond); - void get_prev_for_top(list::iterator &iter); - void get_next_for_bot(list::iterator &iter,list::iterator &beyond); - void get_prev_for_bot(list::iterator &iter); + void copy_y_Point_data_to_list(list &Point_data_list); + void copy_x_Point_data_to_list(list &Point_data_list); + void tent(Point_data *first,Point_data *second); + void tent(Point_data *first,Point_data *second,Point_data *third); + void get_next_for_top(list::iterator &iter,list::iterator &beyond); + void get_prev_for_top(list::iterator &iter); + void get_next_for_bot(list::iterator &iter,list::iterator &beyond); + void get_prev_for_bot(list::iterator &iter); void get_next_for_bot(Point_data_set_of_y::iterator &iter); - void Largest_Empty_Rect::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last); + void Largest_empty_iso_rectangle_2::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last); void get_prev_for_bot(Point_data_set_of_y::iterator &iter); - void get_next_for_left(list::iterator &iter,list::iterator &beyond); - void get_prev_for_left(list::iterator &iter); - void get_next_for_right(list::iterator &iter,list::iterator &beyond); - void get_prev_for_right(list::iterator &iter); + void get_next_for_left(list::iterator &iter,list::iterator &beyond); + void get_prev_for_left(list::iterator &iter); + void get_next_for_right(list::iterator &iter,list::iterator &beyond); + void get_prev_for_right(list::iterator &iter); void determine_first_two_iters(Point_data_set_of_y::iterator &iter1,Point_data_set_of_y::iterator &iter2,Point_data_set_of_y::iterator &iter3,bool &first_iter_is_right,bool &second_iter_is_right,bool &third_iter_is_right); void determine_next_iter(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &right_iter,Point_data_set_of_y::iterator &left_iter,Point_data_set_of_y::const_iterator right_iter_end,Point_data_set_of_y::const_iterator left_iter_end,bool &iter_is_right,bool &exist); void calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2); @@ -118,15 +113,15 @@ private: public: typedef set::const_iterator const_iterator; // ctor - Largest_Empty_Rect(Bbox &b); + Largest_empty_iso_rectangle_2(const Iso_rectangle_2 &b); // ctor - Largest_Empty_Rect(Polygon &inp_polygon); + // Largest_empty_iso_rectangle_2(Polygon &inp_polygon); // add a point to data - void add_point(Point_2 p,point_type i_type = reg); + void insert(const Point_2& p, point_type i_type = reg); // remove a point from data - bool remove_point(Point_2 p); + bool remove_point(const Point_2& p); // retrieve biggest rectangle - Bbox get_largest_empty_rectangle(); + Iso_rectangle_2 get_largest_empty_rectangle(); // clear data(remove points) void clear(); // get a begin iterator to points @@ -137,33 +132,34 @@ public: // get a list of the current points void get_list_of_points(list > &points_list); // get bounding box - Bbox get_bounding_box(); + Iso_rectangle_2 get_bounding_box(); // dtor - ~Largest_Empty_Rect(); + ~Largest_empty_iso_rectangle_2(); }; -template -Largest_Empty_Rect::~Largest_Empty_Rect() +template +Largest_empty_iso_rectangle_2::~Largest_empty_iso_rectangle_2() { for(Point_data_set_of_x::iterator iter = x_sorted.begin();iter != x_sorted.end();++iter) delete(*iter); } -template -Largest_Empty_Rect::point_data::point_data(NT x_inp,NT y_inp) : x(x_inp),y(y_inp),type(reg) +template +Largest_empty_iso_rectangle_2::Point_data::Point_data(NT x_inp,NT y_inp) : x(x_inp),y(y_inp),type(reg) { right_tent = 0; left_tent = 0; } -template -Largest_Empty_Rect::point_data::point_data(NT x_inp,NT y_inp,Point_data_set_of_y *r_tent,Point_data_set_of_y *l_tent) : x(x_inp),y(y_inp),right_tent(r_tent),left_tent(l_tent),type(reg) {} +template +Largest_empty_iso_rectangle_2::Point_data::Point_data(NT x_inp,NT y_inp,Point_data_set_of_y *r_tent,Point_data_set_of_y *l_tent) : x(x_inp),y(y_inp),right_tent(r_tent),left_tent(l_tent),type(reg) {} -template -Largest_Empty_Rect::point_data::point_data(NT x_inp,NT y_inp,Point_data_set_of_y *r_tent,Point_data_set_of_y *l_tent,point_type i_type) : x(x_inp),y(y_inp),right_tent(r_tent),left_tent(l_tent),type(i_type) {} +template +Largest_empty_iso_rectangle_2::Point_data::Point_data(NT x_inp,NT y_inp,Point_data_set_of_y *r_tent,Point_data_set_of_y *l_tent,point_type i_type) : x(x_inp),y(y_inp),right_tent(r_tent),left_tent(l_tent),type(i_type) {} -template -void Largest_Empty_Rect::get_list_of_points(list > &points_list) +template +void +Largest_empty_iso_rectangle_2::get_list_of_points(list > &points_list) { Point_data_set_of_x::const_iterator last_point = x_sorted.end(),iter = x_sorted.begin(); --last_point; @@ -177,27 +173,27 @@ void Largest_Empty_Rect::get_list_of_points(list > &points_list) } } -template -void Largest_Empty_Rect::add_point(Point_2 p,point_type i_type) +template +void +Largest_empty_iso_rectangle_2::insert(const Point_2& p,point_type i_type) { NT x = p.x(),y = p.y(); Point_data_set_of_y *right_tent = new Point_data_set_of_y; Point_data_set_of_y *left_tent = new Point_data_set_of_y; - point_data *po = new point_data(x,y,right_tent,left_tent,i_type); + Point_data *po = new Point_data(x,y,right_tent,left_tent,i_type); x_sorted.insert(po); y_sorted.insert(po); - // insert to public point set - Point_2 public_p(x,y); - public_set.insert(public_p); + public_set.insert(p); } -template -bool Largest_Empty_Rect::remove_point(Point_2 p) +template +bool +Largest_empty_iso_rectangle_2::remove_point(const Point_2& p) { NT x = p.x(),y = p.y(); - point_data *po = new point_data(x,y); + Point_data *po = new Point_data(x,y); Point_data_set_of_x::iterator iter1 = x_sorted.find(po),iter2 = y_sorted.find(po); // point does not exist or a corner point @@ -210,18 +206,17 @@ bool Largest_Empty_Rect::remove_point(Point_2 p) x_sorted.erase(iter1); y_sorted.erase(iter2); - // remove from public point set - Point_2 public_p(x,y); - public_set.erase(public_p); + public_set.erase(p); return(true); } -template -void Largest_Empty_Rect::check_for_bigger(NT x0,NT y0,NT x1,NT y1) +template +void +Largest_empty_iso_rectangle_2::check_for_bigger(NT x0,NT y0,NT x1,NT y1) { bool do_check = true; - + /* if(polygon) { NT bw = x1 - x0; NT bh = y1 - y0; @@ -231,7 +226,7 @@ void Largest_Empty_Rect::check_for_bigger(NT x0,NT y0,NT x1,NT y1) Point_2 center(bx,by); do_check = polygon->has_on_bounded_side(center); } - + */ // check if the rectangle represented by the parameters is bigger than the current one if(do_check && abs(x1 - x0) * abs(y1 - y0) > biggest_rect_size) { biggest_rect_size = abs(x1 - x0) * abs(y1 - y0); @@ -242,8 +237,9 @@ void Largest_Empty_Rect::check_for_bigger(NT x0,NT y0,NT x1,NT y1) } } -template -void Largest_Empty_Rect::phase_1_on_x() +template +void +Largest_empty_iso_rectangle_2::phase_1_on_x() { Point_data_set_of_x::const_iterator iter = x_sorted.begin(),last_iter = x_sorted.end(),prev_iter = iter; ++iter; @@ -265,8 +261,9 @@ void Largest_Empty_Rect::phase_1_on_x() } } -template -void Largest_Empty_Rect::phase_1_on_y() +template +void +Largest_empty_iso_rectangle_2::phase_1_on_y() { Point_data_set_of_y::const_iterator iter = y_sorted.begin(),last_iter = y_sorted.end(),prev_iter = iter; ++iter; @@ -288,31 +285,35 @@ void Largest_Empty_Rect::phase_1_on_y() } } -template -void Largest_Empty_Rect::phase_1() +template +void +Largest_empty_iso_rectangle_2::phase_1() { phase_1_on_x(); phase_1_on_y(); } -template -void Largest_Empty_Rect::copy_x_point_data_to_list(list &point_data_list) +template +void +Largest_empty_iso_rectangle_2::copy_x_Point_data_to_list(list &Point_data_list) { for(Point_data_set_of_x::const_iterator iter = x_sorted.begin();iter != x_sorted.end();++iter) - point_data_list.push_back(*iter); + Point_data_list.push_back(*iter); } -template -void Largest_Empty_Rect::copy_y_point_data_to_list(list &point_data_list) +template +void +Largest_empty_iso_rectangle_2::copy_y_Point_data_to_list(list &Point_data_list) { for(Point_data_set_of_y::const_iterator iter = y_sorted.begin(); iter != (Point_data_set_of_y::const_iterator)y_sorted.end(); ++iter) - point_data_list.push_back(*iter); + Point_data_list.push_back(*iter); } -template -void Largest_Empty_Rect::tent(point_data *first,point_data *second) +template +void +Largest_empty_iso_rectangle_2::tent(Point_data *first,Point_data *second) { if(first->y_smaller(second)) /* if(first->y < second->y)*/ @@ -321,8 +322,9 @@ void Largest_Empty_Rect::tent(point_data *first,point_data *second) second->left_tent->insert(first); } -template -void Largest_Empty_Rect::tent(point_data *first,point_data *second,point_data *third) +template +void +Largest_empty_iso_rectangle_2::tent(Point_data *first,Point_data *second,Point_data *third) { first->right_tent->insert(second); third->left_tent->insert(second); @@ -333,90 +335,102 @@ void Largest_Empty_Rect::tent(point_data *first,point_data *second,point_dat third->left_tent->insert(first); } -template -void Largest_Empty_Rect::get_next_for_top(list::iterator &iter,list::iterator &beyond) +template +void +Largest_empty_iso_rectangle_2::get_next_for_top(list::iterator &iter,list::iterator &beyond) { while(iter != beyond && ((*iter)->type == bot_right || (*iter)->type == bot_left)) ++iter; } -template -void Largest_Empty_Rect::get_prev_for_top(list::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_prev_for_top(list::iterator &iter) { while((*iter)->type == bot_right || (*iter)->type == bot_left) --iter; } -template -void Largest_Empty_Rect::get_next_for_bot(list::iterator &iter,list::iterator &beyond) +template +void +Largest_empty_iso_rectangle_2::get_next_for_bot(list::iterator &iter,list::iterator &beyond) { while(iter != beyond && ((*iter)->type == top_left || (*iter)->type == top_right)) ++iter; } -template -void Largest_Empty_Rect::get_prev_for_bot(list::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_prev_for_bot(list::iterator &iter) { while((*iter)->type == top_left || (*iter)->type == top_right) --iter; } -template -void Largest_Empty_Rect::get_next_for_bot(Point_data_set_of_y::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_next_for_bot(Point_data_set_of_y::iterator &iter) { while((*iter)->type == top_left || (*iter)->type == top_right) ++iter; } -template -void Largest_Empty_Rect::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last) +template +void +Largest_empty_iso_rectangle_2::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last) { while(iter != last && ((*iter)->type == top_left || (*iter)->type == top_right)) ++iter; } -template -void Largest_Empty_Rect::get_prev_for_bot(Point_data_set_of_y::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_prev_for_bot(Point_data_set_of_y::iterator &iter) { while((*iter)->type == top_left || (*iter)->type == top_right) --iter; } -template -void Largest_Empty_Rect::get_next_for_left(list::iterator &iter,list::iterator &beyond) +template +void +Largest_empty_iso_rectangle_2::get_next_for_left(list::iterator &iter, list::iterator &beyond) { while(iter != beyond && ((*iter)->type == bot_right || (*iter)->type == top_right)) ++iter; } -template -void Largest_Empty_Rect::get_prev_for_left(list::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_prev_for_left(list::iterator &iter) { while((*iter)->type == bot_right || (*iter)->type == top_right) --iter; } -template -void Largest_Empty_Rect::get_next_for_right(list::iterator &iter,list::iterator &beyond) +template +void +Largest_empty_iso_rectangle_2::get_next_for_right(list::iterator &iter,list::iterator &beyond) { while(iter != beyond && ((*iter)->type == bot_left || (*iter)->type == top_left)) ++iter; } -template -void Largest_Empty_Rect::get_prev_for_right(list::iterator &iter) +template +void +Largest_empty_iso_rectangle_2::get_prev_for_right(list::iterator &iter) { while((*iter)->type == bot_left || (*iter)->type == top_left) --iter; } -template -void Largest_Empty_Rect::phase_2_on_bot() +template +void +Largest_empty_iso_rectangle_2::phase_2_on_bot() { - list point_data_list; - copy_x_point_data_to_list(point_data_list); - list::iterator iter1 = point_data_list.begin(),iter2,iter3,first_iter,beyond = point_data_list.end(); - int points_removed = 0,size = point_data_list.size(); + list Point_data_list; + copy_x_Point_data_to_list(Point_data_list); + list::iterator iter1 = Point_data_list.begin(),iter2,iter3,first_iter,beyond = Point_data_list.end(); + int points_removed = 0,size = Point_data_list.size(); get_next_for_bot(iter1,beyond); first_iter = iter1; @@ -427,14 +441,14 @@ void Largest_Empty_Rect::phase_2_on_bot() ++iter3; get_next_for_bot(iter3,beyond); - while(size - 4 > points_removed && iter3 != point_data_list.end()) { + while(size - 4 > points_removed && iter3 != Point_data_list.end()) { if((*iter1)->y_smaller(*iter2) && (*iter2)->y_bigger(*iter3)) { // Rectangles in phase 2 should be ignored for polygon - if(!polygon) + //if(!polygon) check_for_bigger((*iter1)->x,min_y,(*iter3)->x,(*iter2)->y); tent(*iter1,*iter2,*iter3); ++points_removed; - point_data_list.erase(iter2); + Point_data_list.erase(iter2); if(iter1 != first_iter) { // move back iter2 = iter1; --iter1; @@ -454,13 +468,14 @@ void Largest_Empty_Rect::phase_2_on_bot() } -template -void Largest_Empty_Rect::phase_2_on_top() +template +void +Largest_empty_iso_rectangle_2::phase_2_on_top() { - list point_data_list; - copy_x_point_data_to_list(point_data_list); - list::iterator iter1 = point_data_list.begin(),iter2,iter3,first_iter,beyond = point_data_list.end(); - int points_removed = 0,size = point_data_list.size(); + list Point_data_list; + copy_x_Point_data_to_list(Point_data_list); + list::iterator iter1 = Point_data_list.begin(),iter2,iter3,first_iter,beyond = Point_data_list.end(); + int points_removed = 0,size = Point_data_list.size(); get_next_for_top(iter1,beyond); iter2 = iter1; @@ -471,11 +486,11 @@ void Largest_Empty_Rect::phase_2_on_top() ++iter3; get_next_for_top(iter3,beyond); - while(size - 4 > points_removed && iter3 != point_data_list.end()) { + while(size - 4 > points_removed && iter3 != Point_data_list.end()) { if((*iter1)->y_bigger(*iter2) && (*iter2)->y_smaller(*iter3)) { check_for_bigger((*iter1)->x,max_y,(*iter3)->x,(*iter2)->y); ++points_removed; - point_data_list.erase(iter2); + Point_data_list.erase(iter2); if(iter1 != first_iter) { // move back iter2 = iter1; --iter1; @@ -494,13 +509,14 @@ void Largest_Empty_Rect::phase_2_on_top() } } -template -void Largest_Empty_Rect::phase_2_on_left() +template +void +Largest_empty_iso_rectangle_2::phase_2_on_left() { - list point_data_list; - copy_y_point_data_to_list(point_data_list); - list::iterator iter1 = point_data_list.begin(),iter2,iter3,first_iter,beyond = point_data_list.end(); - int points_removed = 0,size = point_data_list.size(); + list Point_data_list; + copy_y_Point_data_to_list(Point_data_list); + list::iterator iter1 = Point_data_list.begin(),iter2,iter3,first_iter,beyond = Point_data_list.end(); + int points_removed = 0,size = Point_data_list.size(); get_next_for_left(iter1,beyond); first_iter = iter1; @@ -511,11 +527,11 @@ void Largest_Empty_Rect::phase_2_on_left() ++iter3; get_next_for_left(iter3,beyond); - while(size - 4 > points_removed && iter3 != point_data_list.end()) { + while(size - 4 > points_removed && iter3 != Point_data_list.end()) { if((*iter1)->x_smaller(*iter2) && (*iter2)->x_bigger(*iter3)) { check_for_bigger(min_x,(*iter1)->y,(*iter2)->x,(*iter3)->y); ++points_removed; - point_data_list.erase(iter2); + Point_data_list.erase(iter2); if(iter1 != first_iter) { // move back iter2 = iter1; --iter1; @@ -534,13 +550,14 @@ void Largest_Empty_Rect::phase_2_on_left() } } -template -void Largest_Empty_Rect::phase_2_on_right() +template +void +Largest_empty_iso_rectangle_2::phase_2_on_right() { - list point_data_list; - copy_y_point_data_to_list(point_data_list); - list::iterator iter1 = point_data_list.begin(),iter2,iter3,first_iter,beyond = point_data_list.end(); - int points_removed = 0,size = point_data_list.size(); + list Point_data_list; + copy_y_Point_data_to_list(Point_data_list); + list::iterator iter1 = Point_data_list.begin(),iter2,iter3,first_iter,beyond = Point_data_list.end(); + int points_removed = 0,size = Point_data_list.size(); get_next_for_right(iter1,beyond); first_iter = iter1; @@ -551,11 +568,11 @@ void Largest_Empty_Rect::phase_2_on_right() ++iter3; get_next_for_right(iter3,beyond); - while(size - 4 > points_removed && iter3 != point_data_list.end()) { + while(size - 4 > points_removed && iter3 != Point_data_list.end()) { if((*iter1)->x_bigger(*iter2) && (*iter2)->x_smaller(*iter3)) { check_for_bigger((*iter2)->x,(*iter1)->y,max_x,(*iter3)->y); ++points_removed; - point_data_list.erase(iter2); + Point_data_list.erase(iter2); if(iter1 != first_iter) { // move back iter2 = iter1; --iter1; @@ -574,29 +591,32 @@ void Largest_Empty_Rect::phase_2_on_right() } } -template -void Largest_Empty_Rect::phase_2() +template +void +Largest_empty_iso_rectangle_2::phase_2() { // Rectangles in phase 2 should be ignored for polygon - if(!polygon) { + //if(!polygon) { phase_2_on_top(); phase_2_on_left(); phase_2_on_right(); - } + //} // Done only for building tents for phase 3 phase_2_on_bot(); } -template -Largest_Empty_Rect::Bbox Largest_Empty_Rect::get_biggest_rect() +template +Largest_empty_iso_rectangle_2::Iso_rectangle_2 +Largest_empty_iso_rectangle_2::get_biggest_rect() { - return(Bbox(pair(biggest_rect_x0,biggest_rect_y0),pair(biggest_rect_x1,biggest_rect_y1))); + return(Iso_rectangle_2(Point_2(biggest_rect_x0, biggest_rect_y0), + Point_2(biggest_rect_x1,biggest_rect_y1))); } -template +template void -Largest_Empty_Rect::determine_next_iter(Point_data_set_of_y::iterator &iter, +Largest_empty_iso_rectangle_2::determine_next_iter(Point_data_set_of_y::iterator &iter, Point_data_set_of_y::iterator &right_iter, Point_data_set_of_y::iterator &left_iter, Point_data_set_of_y::const_iterator right_iter_end, @@ -631,8 +651,9 @@ Largest_Empty_Rect::determine_next_iter(Point_data_set_of_y::iterator &iter, } } -template -void Largest_Empty_Rect::phase_3_check_for_bigger(Point_data_set_of_y::iterator iter,Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2,Point_data_set_of_y::iterator iter3,bool first_iter_is_right,bool second_iter_is_right,bool third_iter_is_right) +template +void +Largest_empty_iso_rectangle_2::phase_3_check_for_bigger(Point_data_set_of_y::iterator iter,Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2,Point_data_set_of_y::iterator iter3,bool first_iter_is_right,bool second_iter_is_right,bool third_iter_is_right) { if(first_iter_is_right) { if(!second_iter_is_right) @@ -642,8 +663,9 @@ void Largest_Empty_Rect::phase_3_check_for_bigger(Point_data_set_of_y::itera check_for_bigger((*iter1)->x,(*iter)->y,(*iter2)->x,(*iter3)->y); } -template -void Largest_Empty_Rect::calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2,Point_data_set_of_y::iterator iter3) +template +void +Largest_empty_iso_rectangle_2::calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2,Point_data_set_of_y::iterator iter3) { bool first_is_right_to_second = (*iter1)->x_smaller(*iter2); bool second_is_right_to_third = (*iter2)->x_smaller(*iter3); @@ -666,8 +688,9 @@ void Largest_Empty_Rect::calls_for_tents(Point_data_set_of_y::iterator iter1 } } -template -void Largest_Empty_Rect::calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2) +template +void +Largest_empty_iso_rectangle_2::calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2) { if((*iter1)->x_smaller(*iter2)) /* if((*iter1)->x < (*iter2)->x) */ @@ -676,8 +699,9 @@ void Largest_Empty_Rect::calls_for_tents(Point_data_set_of_y::iterator iter1 tent(*iter2,*iter1); } -template -void Largest_Empty_Rect::phase_3() +template +void +Largest_empty_iso_rectangle_2::phase_3() { bool first_iter_is_right,second_iter_is_right,third_iter_is_right,first_exist,second_exist,third_exist; Point_data_set_of_y::iterator iter,last_iter = y_sorted.end(); @@ -713,8 +737,9 @@ void Largest_Empty_Rect::phase_3() } } -template -void Largest_Empty_Rect::empty_tents() +template +void +Largest_empty_iso_rectangle_2::empty_tents() { for(Point_data_set_of_x::const_iterator iter = x_sorted.begin();iter != x_sorted.end();++iter) { (*iter)->right_tent->clear(); @@ -722,8 +747,9 @@ void Largest_Empty_Rect::empty_tents() } } -template -Largest_Empty_Rect::Bbox Largest_Empty_Rect::get_largest_empty_rectangle() +template +Largest_empty_iso_rectangle_2::Iso_rectangle_2 +Largest_empty_iso_rectangle_2::get_largest_empty_rectangle() { if(x_sorted.size() == 4) return(get_bounding_box()); @@ -731,25 +757,27 @@ Largest_Empty_Rect::Bbox Largest_Empty_Rect::get_largest_empty_rectangle biggest_rect_size = 0; // Rectangles in phase 1 should be ignored for polygon - if(!polygon) + //if(!polygon) phase_1(); phase_2(); phase_3(); - Bbox b = get_biggest_rect(); + Iso_rectangle_2 b = get_biggest_rect(); empty_tents(); return(b); } -template -Largest_Empty_Rect::Bbox Largest_Empty_Rect::get_bounding_box() +template +Largest_empty_iso_rectangle_2::Iso_rectangle_2 +Largest_empty_iso_rectangle_2::get_bounding_box() { - return(Bbox(pair(min_x,min_y),pair(max_x,max_y))); + return(Iso_rectangle_2(Point_2(min_x,min_y), + Point_2(max_x,max_y))); } - -template -Largest_Empty_Rect::Largest_Empty_Rect(Polygon &inp_polygon) +/* +template +Largest_empty_iso_rectangle_2::Largest_empty_iso_rectangle_2(Polygon &inp_polygon) { polygon = new Polygon(inp_polygon); @@ -760,10 +788,10 @@ Largest_Empty_Rect::Largest_Empty_Rect(Polygon &inp_polygon) max_y2 = max_y = polygon->top_vertex()->y(); // add extreme points - add_point(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); - add_point(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); - add_point(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); - add_point(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); + insert(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); + insert(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); + insert(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); + insert(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); // insert the polygon Polygon::Vertex_iterator it = polygon->vertices_begin(); @@ -773,7 +801,7 @@ Largest_Empty_Rect::Largest_Empty_Rect(Polygon &inp_polygon) Point_2 p0 = *it; while(it != polygon->vertices_end()) { - add_point(*it); + insert(*it); ++next; if(next == polygon->vertices_end()) q = p0; @@ -784,19 +812,21 @@ Largest_Empty_Rect::Largest_Empty_Rect(Polygon &inp_polygon) // add some points on the segment Vector_2 v = (q - p)/6; for(int j = 1; j < 6; j++) { - add_point(p + j * v); + insert(p + j * v); } ++it; } } - -template -Largest_Empty_Rect::Largest_Empty_Rect(Bbox &b) +*/ +template +Largest_empty_iso_rectangle_2::Largest_empty_iso_rectangle_2(const Iso_rectangle_2 &b) { - polygon = NULL; + // polygon = NULL; - NT x0 = b.first.first,y0 = b.first.second,x1 = b.second.first, y1 = b.second.second; + + NT x0 = b.min().x(),y0 = b.min().y(); + NT x1 = b.max().x(), y1 = b.max().y(); // determine extreme values of bounding box min_x2 = min_x = ((x0 < x1) ? x0 : x1); min_y2 = min_y = ((y0 < y1) ? y0 : y1); @@ -804,28 +834,31 @@ Largest_Empty_Rect::Largest_Empty_Rect(Bbox &b) max_y2 = max_y = ((y0 > y1) ? y0 : y1); // add extreme points - add_point(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); - add_point(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); - add_point(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); - add_point(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); + insert(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); + insert(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); + insert(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); + insert(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); } -template -Largest_Empty_Rect::const_iterator Largest_Empty_Rect::begin() +template +Largest_empty_iso_rectangle_2::const_iterator +Largest_empty_iso_rectangle_2::begin() { return(public_set.begin()); } -template -Largest_Empty_Rect::const_iterator Largest_Empty_Rect::end() +template +Largest_empty_iso_rectangle_2::const_iterator +Largest_empty_iso_rectangle_2::end() { return(public_set.end()); } -template -void Largest_Empty_Rect::clear() +template +void +Largest_empty_iso_rectangle_2::clear() { for(Point_data_set_of_x::iterator iter = x_sorted.begin();iter != x_sorted.end();++iter) delete(*iter); @@ -833,15 +866,16 @@ void Largest_Empty_Rect::clear() x_sorted.clear(); y_sorted.clear(); - add_point(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); - add_point(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); - add_point(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); - add_point(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); + insert(Point_2(min_x - 0.000001,min_y - 0.000001),bot_left); + insert(Point_2(max_x + 0.000001,min_y2 - 0.000001),bot_right); + insert(Point_2(min_x2 - 0.000001,max_y + 0.000001),top_left); + insert(Point_2(max_x2 + 0.000001,max_y2 + 0.000001),top_right); } -template -void Largest_Empty_Rect::determine_first_two_iters(Point_data_set_of_y::iterator &iter1,Point_data_set_of_y::iterator &iter2,Point_data_set_of_y::iterator &iter3,bool &first_iter_is_right,bool &second_iter_is_right,bool &third_iter_is_right) +template +void +Largest_empty_iso_rectangle_2::determine_first_two_iters(Point_data_set_of_y::iterator &iter1,Point_data_set_of_y::iterator &iter2,Point_data_set_of_y::iterator &iter3,bool &first_iter_is_right,bool &second_iter_is_right,bool &third_iter_is_right) { if(first_iter_is_right) { if(second_iter_is_right) { @@ -880,3 +914,8 @@ void Largest_Empty_Rect::determine_first_two_iters(Point_data_set_of_y::iter } } + +CGAL_END_NAMESPACE + + +#endif // CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H