mirror of https://github.com/CGAL/cgal
replaced template parameter NT with a traits type
This commit is contained in:
parent
5ca5b2b6c7
commit
65a38adb8a
|
|
@ -1,5 +1,11 @@
|
|||
#include <fstream>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Segment_2.h>
|
||||
#include <CGAL/Iso_rectangle_2.h>
|
||||
#include "EmptyRect.h"
|
||||
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/IO/leda_window.h>
|
||||
#include <CGAL/leda_real.h>
|
||||
|
||||
typedef double Number_Type;
|
||||
|
||||
|
|
@ -7,39 +13,29 @@ typedef CGAL::Cartesian<Number_Type> Repr;
|
|||
typedef CGAL::Point_2<Repr> Point;
|
||||
typedef CGAL::Vector_2<Repr> Vector;
|
||||
typedef CGAL::Segment_2<Repr> Segment;
|
||||
typedef pair<Number_Type,Number_Type> Nt_pair;
|
||||
typedef pair<Nt_pair,Nt_pair> Bbox;
|
||||
typedef CGAL::Iso_rectangle_2<Repr> Iso_rectangle_2;
|
||||
|
||||
typedef CGAL::Polygon_traits_2<Repr> Traits;
|
||||
typedef std::list<Point> Container;
|
||||
typedef CGAL::Polygon_2<Traits,Container> Polygon;
|
||||
|
||||
typedef CGAL::Largest_empty_iso_rectangle_2<Repr> Largest_empty_rect;
|
||||
Polygon P;
|
||||
|
||||
void display_points(Largest_Empty_Rect<Number_Type> &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<Number_Type>::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<Number_Type> &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<Number_Type> &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<Number_Type> &empty_rectangle,CGAL::Window_stream
|
|||
display_bounding_box(empty_rectangle,W);
|
||||
}
|
||||
|
||||
void redraw(Largest_Empty_Rect<Number_Type> &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<Number_Type> &empty_rectangle,CGAL::Window_stream
|
|||
}
|
||||
|
||||
|
||||
void show_biggest_rec(Largest_Empty_Rect<Number_Type> &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<Number_Type> 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);
|
||||
|
|
|
|||
|
|
@ -1,55 +1,50 @@
|
|||
#include <fstream>
|
||||
|
||||
#ifndef CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H
|
||||
#define CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H
|
||||
|
||||
#include <set.h>
|
||||
#include <list.h>
|
||||
#include <CGAL/Cartesian.h>
|
||||
#include <CGAL/Point_2.h>
|
||||
#include <CGAL/predicates_on_points_2.h>
|
||||
#include <CGAL/Segment_2.h>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/IO/leda_window.h>
|
||||
#include <CGAL/leda_real.h>
|
||||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
enum point_type{reg,bot_right,bot_left,top_left,top_right};
|
||||
|
||||
using namespace CGAL;
|
||||
|
||||
template<class NT>
|
||||
class Largest_Empty_Rect {
|
||||
typedef pair<pair<NT,NT>,pair<NT,NT> > Bbox;
|
||||
typedef CGAL::Cartesian<NT> Repr;
|
||||
typedef CGAL::Point_2<Repr> Point_2;
|
||||
typedef CGAL::Vector_2<Repr> Vector_2;
|
||||
typedef CGAL::Polygon_traits_2<Repr> Traits;
|
||||
typedef std::list<Point_2> Container;
|
||||
typedef CGAL::Polygon_2<Traits,Container> Polygon;
|
||||
template<class T>
|
||||
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<point_data *,y_ptr_bigger> *right_tent;
|
||||
set<point_data *,y_ptr_bigger> *left_tent;
|
||||
set<Point_data *,y_ptr_bigger> *right_tent;
|
||||
set<Point_data *,y_ptr_bigger> *left_tent;
|
||||
point_type type;
|
||||
|
||||
point_data(NT x_inp,NT y_inp);
|
||||
point_data(NT x_inp,NT y_inp,set<point_data *,y_ptr_bigger> *r_tent,set<point_data *,y_ptr_bigger> *l_tent);
|
||||
point_data(NT x_inp,NT y_inp,set<point_data *,y_ptr_bigger> *r_tent,set<point_data *,y_ptr_bigger> *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<Point_data *,y_ptr_bigger> *r_tent,set<Point_data *,y_ptr_bigger> *l_tent);
|
||||
Point_data(NT x_inp,NT y_inp,set<Point_data *,y_ptr_bigger> *r_tent,set<Point_data *,y_ptr_bigger> *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 *,x_ptr_bigger> Point_data_set_of_x;
|
||||
typedef set<point_data *,y_ptr_bigger> Point_data_set_of_y;
|
||||
typedef set<Point_data *,x_ptr_bigger> Point_data_set_of_x;
|
||||
typedef set<Point_data *,y_ptr_bigger> Point_data_set_of_y;
|
||||
|
||||
Point_data_set_of_x x_sorted;
|
||||
Point_data_set_of_y y_sorted;
|
||||
set<Point_2,point_bigger> 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 *> &point_data_list);
|
||||
void copy_x_point_data_to_list(list<point_data *> &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<point_data *>::iterator &iter,list<point_data *>::iterator &beyond);
|
||||
void get_prev_for_top(list<point_data *>::iterator &iter);
|
||||
void get_next_for_bot(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond);
|
||||
void get_prev_for_bot(list<point_data *>::iterator &iter);
|
||||
void copy_y_Point_data_to_list(list<Point_data *> &Point_data_list);
|
||||
void copy_x_Point_data_to_list(list<Point_data *> &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<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond);
|
||||
void get_prev_for_top(list<Point_data *>::iterator &iter);
|
||||
void get_next_for_bot(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond);
|
||||
void get_prev_for_bot(list<Point_data *>::iterator &iter);
|
||||
void get_next_for_bot(Point_data_set_of_y::iterator &iter);
|
||||
void Largest_Empty_Rect<NT>::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last);
|
||||
void Largest_empty_iso_rectangle_2<T>::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<point_data *>::iterator &iter,list<point_data *>::iterator &beyond);
|
||||
void get_prev_for_left(list<point_data *>::iterator &iter);
|
||||
void get_next_for_right(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond);
|
||||
void get_prev_for_right(list<point_data *>::iterator &iter);
|
||||
void get_next_for_left(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond);
|
||||
void get_prev_for_left(list<Point_data *>::iterator &iter);
|
||||
void get_next_for_right(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond);
|
||||
void get_prev_for_right(list<Point_data *>::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<Point_2,point_bigger>::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<pair<NT,NT> > &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<class NT>
|
||||
Largest_Empty_Rect<NT>::~Largest_Empty_Rect()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::~Largest_empty_iso_rectangle_2()
|
||||
{
|
||||
for(Point_data_set_of_x::iterator iter = x_sorted.begin();iter != x_sorted.end();++iter)
|
||||
delete(*iter);
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
Largest_Empty_Rect<NT>::point_data::point_data(NT x_inp,NT y_inp) : x(x_inp),y(y_inp),type(reg)
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::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<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::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<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_list_of_points(list<pair<NT,NT> > &points_list)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_list_of_points(list<pair<NT,NT> > &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<NT>::get_list_of_points(list<pair<NT,NT> > &points_list)
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::add_point(Point_2 p,point_type i_type)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
bool Largest_Empty_Rect<NT>::remove_point(Point_2 p)
|
||||
template<class T>
|
||||
bool
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::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<class NT>
|
||||
void Largest_Empty_Rect<NT>::check_for_bigger(NT x0,NT y0,NT x1,NT y1)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::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<NT>::check_for_bigger(NT x0,NT y0,NT x1,NT y1)
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_1_on_x()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::phase_1_on_x()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_1_on_y()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::phase_1_on_y()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_1()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::phase_1()
|
||||
{
|
||||
phase_1_on_x();
|
||||
phase_1_on_y();
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::copy_x_point_data_to_list(list<point_data *> &point_data_list)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::copy_x_Point_data_to_list(list<Point_data *> &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<class NT>
|
||||
void Largest_Empty_Rect<NT>::copy_y_point_data_to_list(list<point_data *> &point_data_list)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::copy_y_Point_data_to_list(list<Point_data *> &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<class NT>
|
||||
void Largest_Empty_Rect<NT>::tent(point_data *first,point_data *second)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::tent(point_data *first,point_data *second)
|
|||
second->left_tent->insert(first);
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::tent(point_data *first,point_data *second,point_data *third)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::tent(point_data *first,point_data *second,point_dat
|
|||
third->left_tent->insert(first);
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_top(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_next_for_top(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond)
|
||||
{
|
||||
while(iter != beyond && ((*iter)->type == bot_right || (*iter)->type == bot_left))
|
||||
++iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_prev_for_top(list<point_data *>::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_prev_for_top(list<Point_data *>::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == bot_right || (*iter)->type == bot_left)
|
||||
--iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_bot(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_next_for_bot(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond)
|
||||
{
|
||||
while(iter != beyond && ((*iter)->type == top_left || (*iter)->type == top_right))
|
||||
++iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_prev_for_bot(list<point_data *>::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_prev_for_bot(list<Point_data *>::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == top_left || (*iter)->type == top_right)
|
||||
--iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_bot(Point_data_set_of_y::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_next_for_bot(Point_data_set_of_y::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == top_left || (*iter)->type == top_right)
|
||||
++iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_bot(Point_data_set_of_y::iterator &iter,Point_data_set_of_y::iterator &last)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_prev_for_bot(Point_data_set_of_y::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_prev_for_bot(Point_data_set_of_y::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == top_left || (*iter)->type == top_right)
|
||||
--iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_left(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_next_for_left(list<Point_data *>::iterator &iter, list<Point_data *>::iterator &beyond)
|
||||
{
|
||||
while(iter != beyond && ((*iter)->type == bot_right || (*iter)->type == top_right))
|
||||
++iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_prev_for_left(list<point_data *>::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_prev_for_left(list<Point_data *>::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == bot_right || (*iter)->type == top_right)
|
||||
--iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_next_for_right(list<point_data *>::iterator &iter,list<point_data *>::iterator &beyond)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_next_for_right(list<Point_data *>::iterator &iter,list<Point_data *>::iterator &beyond)
|
||||
{
|
||||
while(iter != beyond && ((*iter)->type == bot_left || (*iter)->type == top_left))
|
||||
++iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::get_prev_for_right(list<point_data *>::iterator &iter)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::get_prev_for_right(list<Point_data *>::iterator &iter)
|
||||
{
|
||||
while((*iter)->type == bot_left || (*iter)->type == top_left)
|
||||
--iter;
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_2_on_bot()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::phase_2_on_bot()
|
||||
{
|
||||
list<point_data *> point_data_list;
|
||||
copy_x_point_data_to_list(point_data_list);
|
||||
list<point_data *>::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 *> Point_data_list;
|
||||
copy_x_Point_data_to_list(Point_data_list);
|
||||
list<Point_data *>::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<NT>::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<NT>::phase_2_on_bot()
|
|||
}
|
||||
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_2_on_top()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::phase_2_on_top()
|
||||
{
|
||||
list<point_data *> point_data_list;
|
||||
copy_x_point_data_to_list(point_data_list);
|
||||
list<point_data *>::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 *> Point_data_list;
|
||||
copy_x_Point_data_to_list(Point_data_list);
|
||||
list<Point_data *>::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<NT>::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<NT>::phase_2_on_top()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_2_on_left()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::phase_2_on_left()
|
||||
{
|
||||
list<point_data *> point_data_list;
|
||||
copy_y_point_data_to_list(point_data_list);
|
||||
list<point_data *>::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 *> Point_data_list;
|
||||
copy_y_Point_data_to_list(Point_data_list);
|
||||
list<Point_data *>::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<NT>::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<NT>::phase_2_on_left()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_2_on_right()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::phase_2_on_right()
|
||||
{
|
||||
list<point_data *> point_data_list;
|
||||
copy_y_point_data_to_list(point_data_list);
|
||||
list<point_data *>::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 *> Point_data_list;
|
||||
copy_y_Point_data_to_list(Point_data_list);
|
||||
list<Point_data *>::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<NT>::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<NT>::phase_2_on_right()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_2()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::Bbox Largest_Empty_Rect<NT>::get_biggest_rect()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::Iso_rectangle_2
|
||||
Largest_empty_iso_rectangle_2<T>::get_biggest_rect()
|
||||
{
|
||||
return(Bbox(pair<NT,NT>(biggest_rect_x0,biggest_rect_y0),pair<NT,NT>(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<class NT>
|
||||
template<class T>
|
||||
void
|
||||
Largest_Empty_Rect<NT>::determine_next_iter(Point_data_set_of_y::iterator &iter,
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::determine_next_iter(Point_data_set_of_y::iterator &iter,
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::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<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::phase_3_check_for_bigger(Point_data_set_of_y::itera
|
|||
check_for_bigger((*iter1)->x,(*iter)->y,(*iter2)->x,(*iter3)->y);
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::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<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::calls_for_tents(Point_data_set_of_y::iterator iter1
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::calls_for_tents(Point_data_set_of_y::iterator iter1,Point_data_set_of_y::iterator iter2)
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::calls_for_tents(Point_data_set_of_y::iterator iter1
|
|||
tent(*iter2,*iter1);
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::phase_3()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::phase_3()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::empty_tents()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::empty_tents()
|
|||
}
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
Largest_Empty_Rect<NT>::Bbox Largest_Empty_Rect<NT>::get_largest_empty_rectangle()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::Iso_rectangle_2
|
||||
Largest_empty_iso_rectangle_2<T>::get_largest_empty_rectangle()
|
||||
{
|
||||
if(x_sorted.size() == 4)
|
||||
return(get_bounding_box());
|
||||
|
|
@ -731,25 +757,27 @@ Largest_Empty_Rect<NT>::Bbox Largest_Empty_Rect<NT>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::Bbox Largest_Empty_Rect<NT>::get_bounding_box()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::Iso_rectangle_2
|
||||
Largest_empty_iso_rectangle_2<T>::get_bounding_box()
|
||||
{
|
||||
return(Bbox(pair<NT,NT>(min_x,min_y),pair<NT,NT>(max_x,max_y)));
|
||||
return(Iso_rectangle_2(Point_2(min_x,min_y),
|
||||
Point_2(max_x,max_y)));
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
Largest_Empty_Rect<NT>::Largest_Empty_Rect(Polygon &inp_polygon)
|
||||
/*
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::Largest_empty_iso_rectangle_2(Polygon &inp_polygon)
|
||||
{
|
||||
polygon = new Polygon(inp_polygon);
|
||||
|
||||
|
|
@ -760,10 +788,10 @@ Largest_Empty_Rect<NT>::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<NT>::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<NT>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::Largest_Empty_Rect(Bbox &b)
|
||||
*/
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::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<class NT>
|
||||
Largest_Empty_Rect<NT>::const_iterator Largest_Empty_Rect<NT>::begin()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::const_iterator
|
||||
Largest_empty_iso_rectangle_2<T>::begin()
|
||||
{
|
||||
return(public_set.begin());
|
||||
}
|
||||
|
||||
template<class NT>
|
||||
Largest_Empty_Rect<NT>::const_iterator Largest_Empty_Rect<NT>::end()
|
||||
template<class T>
|
||||
Largest_empty_iso_rectangle_2<T>::const_iterator
|
||||
Largest_empty_iso_rectangle_2<T>::end()
|
||||
{
|
||||
return(public_set.end());
|
||||
}
|
||||
|
||||
|
||||
template<class NT>
|
||||
void Largest_Empty_Rect<NT>::clear()
|
||||
template<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::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<class NT>
|
||||
void Largest_Empty_Rect<NT>::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<class T>
|
||||
void
|
||||
Largest_empty_iso_rectangle_2<T>::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<NT>::determine_first_two_iters(Point_data_set_of_y::iter
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
||||
#endif // CGAL_LARGEST_EMPTY_ISO_RECTANGLE_2_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue