mirror of https://github.com/CGAL/cgal
switch names
This commit is contained in:
parent
08aa9c27f8
commit
d35ac74685
|
|
@ -83,25 +83,25 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<Point_2> Pvec;
|
typedef std::vector<Point_2> Pvec;
|
||||||
typedef std::pair<Point_2, Point_2> Pair;
|
typedef std::pair<Point_2, Point_2> Edge;
|
||||||
|
|
||||||
const Geometry_traits_2 *geom_traits;
|
const Geometry_traits_2 *geom_traits;
|
||||||
const Input_arrangement_2 *p_arr;
|
const Input_arrangement_2 *p_arr;
|
||||||
Point_2 q;
|
Point_2 q;
|
||||||
Point_2 dp;
|
Point_2 dp;
|
||||||
Pvec polygon; //visibility polygon
|
Pvec polygon; //visibility polygon
|
||||||
std::map<Point_2, Pvec> neighbors; //vertex and two edges incident to it that might block vision
|
std::map<Point_2, Pvec> neighbors; //vertex and its neighbours that are relevant to visibility polygon
|
||||||
std::map<Pair, int> edx; //index of edge in the heap
|
std::map<Edge, int> edx; //index of edge in the heap
|
||||||
std::vector<Pair> heap;
|
std::vector<Edge> active_edges; //a heap of edges that interset the current vision ray.
|
||||||
|
|
||||||
Pvec vs; //angular sorted vertices
|
Pvec vs; //angular sorted vertices
|
||||||
bool is_vertex_query;
|
bool is_vertex_query;
|
||||||
bool is_edge_query;
|
bool is_edge_query;
|
||||||
bool is_big_cone; //whether the angle of visibility_cone is greater than pi.
|
bool is_big_cone; //whether the angle of visibility_cone is greater than pi.
|
||||||
std::vector<Halfedge_const_handle> bad_edge_handles;
|
std::vector<Halfedge_const_handle> bad_edge;
|
||||||
Vertex_const_handle query_vertex;
|
Vertex_const_handle query_vertex;
|
||||||
Point_2 source;
|
Point_2 source; //one end of visibility cone
|
||||||
Point_2 target;
|
Point_2 target; //another end of visibility cone
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -112,10 +112,10 @@ public:
|
||||||
|
|
||||||
Face_handle compute_visibility(const Point_2& q, const Halfedge_const_handle e, Arrangement_2& arr_out) {
|
Face_handle compute_visibility(const Point_2& q, const Halfedge_const_handle e, Arrangement_2& arr_out) {
|
||||||
arr_out.clear();
|
arr_out.clear();
|
||||||
bad_edge_handles.clear();
|
bad_edge.clear();
|
||||||
this->q = q;
|
this->q = q;
|
||||||
|
|
||||||
if (q == e->target()->point()) {
|
if (Visibility_2::compare_xy_2(geom_traits, q, e->target()->point())==EQUAL) {
|
||||||
query_vertex = e->target();
|
query_vertex = e->target();
|
||||||
is_vertex_query = true;
|
is_vertex_query = true;
|
||||||
is_edge_query = false;
|
is_edge_query = false;
|
||||||
|
|
@ -127,9 +127,9 @@ public:
|
||||||
first = curr = e->target()->incident_halfedges();
|
first = curr = e->target()->incident_halfedges();
|
||||||
do {
|
do {
|
||||||
if (curr->face() == e->face())
|
if (curr->face() == e->face())
|
||||||
bad_edge_handles.push_back(curr);
|
bad_edge.push_back(curr);
|
||||||
else if (curr->twin()->face() == e->face())
|
else if (curr->twin()->face() == e->face())
|
||||||
bad_edge_handles.push_back(curr->twin());
|
bad_edge.push_back(curr->twin());
|
||||||
} while (++curr != first);
|
} while (++curr != first);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -137,7 +137,7 @@ public:
|
||||||
is_edge_query = true;
|
is_edge_query = true;
|
||||||
source = e->source()->point();
|
source = e->source()->point();
|
||||||
target = e->target()->point();
|
target = e->target()->point();
|
||||||
bad_edge_handles.push_back(e);
|
bad_edge.push_back(e);
|
||||||
is_big_cone = false;
|
is_big_cone = false;
|
||||||
}
|
}
|
||||||
visibility_region_impl(e->face(), q);
|
visibility_region_impl(e->face(), q);
|
||||||
|
|
@ -248,7 +248,6 @@ const Input_arrangement_2& arr() {
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool do_intersect_ray(const Point_2& q,
|
bool do_intersect_ray(const Point_2& q,
|
||||||
const Point_2& dp,
|
const Point_2& dp,
|
||||||
const Point_2& p1,
|
const Point_2& p1,
|
||||||
|
|
@ -299,7 +298,7 @@ private:
|
||||||
vs[i+l+right.size()] = left[left.size()-1-l];
|
vs[i+l+right.size()] = left[left.size()-1-l];
|
||||||
}
|
}
|
||||||
|
|
||||||
void compare_heap(std::vector<Pair>& heap1, std::vector<Pair>& heap2) {
|
void compare_heap(std::vector<Edge>& heap1, std::vector<Edge>& heap2) {
|
||||||
if (heap1.size() != heap2.size()) {
|
if (heap1.size() != heap2.size()) {
|
||||||
print_heap(heap1);
|
print_heap(heap1);
|
||||||
print_heap(heap2);
|
print_heap(heap2);
|
||||||
|
|
@ -311,10 +310,10 @@ private:
|
||||||
print_heap(heap2);
|
print_heap(heap2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout<<"right heap has edges: "<<heap.size()<<std::endl;
|
std::cout<<"right heap has edges: "<<active_edges.size()<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_heap(std::vector<Pair> heap) {
|
void print_heap(std::vector<Edge> heap) {
|
||||||
for (int i=0; i<heap.size(); i++) {
|
for (int i=0; i<heap.size(); i++) {
|
||||||
std::cout<<i<<':'<< heap[i].first<<','<<heap[i].second<<std::endl;
|
std::cout<<i<<':'<< heap[i].first<<','<<heap[i].second<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
@ -323,11 +322,11 @@ private:
|
||||||
void visibility_region_impl(const Face_const_handle f, const Point_2& q) {
|
void visibility_region_impl(const Face_const_handle f, const Point_2& q) {
|
||||||
vs.clear();
|
vs.clear();
|
||||||
polygon.clear();
|
polygon.clear();
|
||||||
heap.clear();
|
active_edges.clear();
|
||||||
neighbors.clear();
|
neighbors.clear();
|
||||||
edx.clear();
|
edx.clear();
|
||||||
|
|
||||||
std::vector<Pair> good_edges;
|
std::vector<Edge> good_edges;
|
||||||
if (is_vertex_query || is_edge_query)
|
if (is_vertex_query || is_edge_query)
|
||||||
input_face(f, good_edges);
|
input_face(f, good_edges);
|
||||||
else
|
else
|
||||||
|
|
@ -344,7 +343,7 @@ private:
|
||||||
|
|
||||||
dp = q + dir;
|
dp = q + dir;
|
||||||
|
|
||||||
std::vector<Pair> heapc;
|
std::vector<Edge> heapc;
|
||||||
heapc.clear();
|
heapc.clear();
|
||||||
//initiation of active_edges
|
//initiation of active_edges
|
||||||
if (is_vertex_query || is_edge_query) {
|
if (is_vertex_query || is_edge_query) {
|
||||||
|
|
@ -385,13 +384,13 @@ private:
|
||||||
//angular sweep begins
|
//angular sweep begins
|
||||||
for (int i=0; i!=vs.size(); i++) {
|
for (int i=0; i!=vs.size(); i++) {
|
||||||
dp = vs[i];
|
dp = vs[i];
|
||||||
Pair closest_e = heap.front(); //save the closest edge;
|
Edge closest_e = active_edges.front(); //save the closest edge;
|
||||||
int insert_cnt(0), remove_cnt(0);
|
int insert_cnt(0), remove_cnt(0);
|
||||||
std::vector<Point_2>& neis=neighbors[dp];
|
std::vector<Point_2>& neis=neighbors[dp];
|
||||||
std::vector<Pair> insert_e, remove_e;
|
std::vector<Edge> insert_e, remove_e;
|
||||||
|
|
||||||
for (int j=0; j!=neis.size(); j++) {
|
for (int j=0; j!=neis.size(); j++) {
|
||||||
Pair e = create_pair(dp, neis[j]);
|
Edge e = create_pair(dp, neis[j]);
|
||||||
// Orientation o=Visibility_2::orientation_2(geom_traits, q, dp, nei);
|
// Orientation o=Visibility_2::orientation_2(geom_traits, q, dp, nei);
|
||||||
/* if (o==RIGHT_TURN ||
|
/* if (o==RIGHT_TURN ||
|
||||||
(o==COLLINEAR && i>0 && Visibility_2::compare_xy_2(geom_traits, nei, vs[i-1])==EQUAL))*/
|
(o==COLLINEAR && i>0 && Visibility_2::compare_xy_2(geom_traits, nei, vs[i-1])==EQUAL))*/
|
||||||
|
|
@ -408,7 +407,7 @@ private:
|
||||||
remove_cnt = remove_e.size();
|
remove_cnt = remove_e.size();
|
||||||
if (remove_e.size()==1 && insert_e.size()==1) {
|
if (remove_e.size()==1 && insert_e.size()==1) {
|
||||||
int remove_idx = edx[remove_e.front()];
|
int remove_idx = edx[remove_e.front()];
|
||||||
heap[remove_idx] = insert_e.front();
|
active_edges[remove_idx] = insert_e.front();
|
||||||
edx[insert_e.front()] = remove_idx;
|
edx[insert_e.front()] = remove_idx;
|
||||||
edx.erase(remove_e.front());
|
edx.erase(remove_e.front());
|
||||||
}
|
}
|
||||||
|
|
@ -421,7 +420,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closest_e != heap.front()) {
|
if (closest_e != active_edges.front()) {
|
||||||
//when the closest edge changed
|
//when the closest edge changed
|
||||||
if (remove_cnt > 0 && insert_cnt > 0) {
|
if (remove_cnt > 0 && insert_cnt > 0) {
|
||||||
//some edges are added and some are deleted, which means the vertice sweeped is a vertice of visibility polygon.
|
//some edges are added and some are deleted, which means the vertice sweeped is a vertice of visibility polygon.
|
||||||
|
|
@ -436,28 +435,28 @@ private:
|
||||||
if (remove_cnt > 0 && insert_cnt == 0) {
|
if (remove_cnt > 0 && insert_cnt == 0) {
|
||||||
//only delete some edges, means some block is moved and the view ray can reach the segments after the block.
|
//only delete some edges, means some block is moved and the view ray can reach the segments after the block.
|
||||||
update_visibility(dp);
|
update_visibility(dp);
|
||||||
update_visibility(ray_seg_intersection(q, dp, heap.front().first, heap.front().second));
|
update_visibility(ray_seg_intersection(q, dp, active_edges.front().first, active_edges.front().second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair create_pair(const Point_2& p1, const Point_2& p2) const{
|
Edge create_pair(const Point_2& p1, const Point_2& p2) const{
|
||||||
assert(p1 != p2);
|
assert(p1 != p2);
|
||||||
if (Visibility_2::compare_xy_2(geom_traits, p1, p2)==SMALLER)
|
if (Visibility_2::compare_xy_2(geom_traits, p1, p2)==SMALLER)
|
||||||
return Pair(p1, p2);
|
return Edge(p1, p2);
|
||||||
else
|
else
|
||||||
return Pair(p2, p1);
|
return Edge(p2, p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void heap_insert(const Pair& e) {
|
void heap_insert(const Edge& e) {
|
||||||
// timer.reset();
|
// timer.reset();
|
||||||
// timer.start();
|
// timer.start();
|
||||||
heap.push_back(e);
|
active_edges.push_back(e);
|
||||||
int i = heap.size()-1;
|
int i = active_edges.size()-1;
|
||||||
edx[e] = i;
|
edx[e] = i;
|
||||||
int parent = (i-1)/2;
|
int parent = (i-1)/2;
|
||||||
while (i!=0 && is_closer(q, heap[i], heap[parent])){
|
while (i!=0 && is_closer(q, active_edges[i], active_edges[parent])){
|
||||||
heap_swap(i, parent);
|
heap_swap(i, parent);
|
||||||
i = parent;
|
i = parent;
|
||||||
parent = (i-1)/2;
|
parent = (i-1)/2;
|
||||||
|
|
@ -470,19 +469,19 @@ private:
|
||||||
// timer.reset();
|
// timer.reset();
|
||||||
// timer.start();
|
// timer.start();
|
||||||
|
|
||||||
edx.erase(heap[i]);
|
edx.erase(active_edges[i]);
|
||||||
if (i== heap.size()-1)
|
if (i== active_edges.size()-1)
|
||||||
{
|
{
|
||||||
heap.pop_back();
|
active_edges.pop_back();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
heap[i] = heap.back();
|
active_edges[i] = active_edges.back();
|
||||||
edx[heap[i]] = i;
|
edx[active_edges[i]] = i;
|
||||||
heap.pop_back();
|
active_edges.pop_back();
|
||||||
int i_before_swap = i;
|
int i_before_swap = i;
|
||||||
|
|
||||||
int parent = (i-1)/2;
|
int parent = (i-1)/2;
|
||||||
while (i!=0 && is_closer(q, heap[i], heap[parent])){
|
while (i!=0 && is_closer(q, active_edges[i], active_edges[parent])){
|
||||||
heap_swap(i, parent);
|
heap_swap(i, parent);
|
||||||
i = parent;
|
i = parent;
|
||||||
parent = (i-1)/2;
|
parent = (i-1)/2;
|
||||||
|
|
@ -493,10 +492,10 @@ private:
|
||||||
int left_son = i*2+1;
|
int left_son = i*2+1;
|
||||||
int right_son = i*2+2;
|
int right_son = i*2+2;
|
||||||
int closest_idx = i;
|
int closest_idx = i;
|
||||||
if (left_son < heap.size() && is_closer(q, heap[left_son], heap[i])) {
|
if (left_son < active_edges.size() && is_closer(q, active_edges[left_son], active_edges[i])) {
|
||||||
closest_idx = left_son;
|
closest_idx = left_son;
|
||||||
}
|
}
|
||||||
if (right_son < heap.size() && is_closer(q, heap[right_son], heap[closest_idx])) {
|
if (right_son < active_edges.size() && is_closer(q, active_edges[right_son], active_edges[closest_idx])) {
|
||||||
closest_idx = right_son;
|
closest_idx = right_son;
|
||||||
}
|
}
|
||||||
swapped = false;
|
swapped = false;
|
||||||
|
|
@ -517,11 +516,11 @@ private:
|
||||||
// timer.reset();
|
// timer.reset();
|
||||||
// timer.start();
|
// timer.start();
|
||||||
|
|
||||||
edx[heap[i]] = j;
|
edx[active_edges[i]] = j;
|
||||||
edx[heap[j]] = i;
|
edx[active_edges[j]] = i;
|
||||||
Pair temp = heap[i];
|
Edge temp = active_edges[i];
|
||||||
heap[i] = heap[j];
|
active_edges[i] = active_edges[j];
|
||||||
heap[j] = temp;
|
active_edges[j] = temp;
|
||||||
|
|
||||||
// timer.stop();
|
// timer.stop();
|
||||||
// heap_swap_t += timer.time();
|
// heap_swap_t += timer.time();
|
||||||
|
|
@ -597,8 +596,8 @@ private:
|
||||||
// };
|
// };
|
||||||
|
|
||||||
bool is_closer(const Point_2& q,
|
bool is_closer(const Point_2& q,
|
||||||
const Pair& e1,
|
const Edge& e1,
|
||||||
const Pair& e2) {
|
const Edge& e2) {
|
||||||
const Point_2& s1=e1.first, t1=e1.second, s2=e2.first, t2=e2.second;
|
const Point_2& s1=e1.first, t1=e1.second, s2=e2.first, t2=e2.second;
|
||||||
Orientation e1q = Visibility_2::orientation_2(geom_traits, s1, t1, q);
|
Orientation e1q = Visibility_2::orientation_2(geom_traits, s1, t1, q);
|
||||||
switch (e1q)
|
switch (e1q)
|
||||||
|
|
@ -672,23 +671,24 @@ private:
|
||||||
Ray_2 ray(q,dp);
|
Ray_2 ray(q,dp);
|
||||||
Segment_2 seg(s,t);
|
Segment_2 seg(s,t);
|
||||||
CGAL::Object result = CGAL::intersection(ray, seg);
|
CGAL::Object result = CGAL::intersection(ray, seg);
|
||||||
if (const Point_2 *ipoint = CGAL::object_cast<Point_2>(&result)) {
|
return *(CGAL::object_cast<Point_2>(&result));
|
||||||
return *ipoint;
|
// if (const Point_2 *ipoint = CGAL::object_cast<Point_2>(&result)) {
|
||||||
}
|
// return *ipoint;
|
||||||
else {
|
// }
|
||||||
if (const Segment_2 *iseg = CGAL::object_cast<Segment_2 >(&result)) {
|
// else {
|
||||||
switch (CGAL::compare_distance_to_point(ray.source(), iseg->source(), iseg->target())) {
|
// if (const Segment_2 *iseg = CGAL::object_cast<Segment_2 >(&result)) {
|
||||||
case (CGAL::SMALLER):
|
// switch (CGAL::compare_distance_to_point(ray.source(), iseg->source(), iseg->target())) {
|
||||||
return iseg->source();
|
// case (CGAL::SMALLER):
|
||||||
break;
|
// return iseg->source();
|
||||||
case (CGAL::LARGER) :
|
// break;
|
||||||
return iseg->target();
|
// case (CGAL::LARGER) :
|
||||||
break;
|
// return iseg->target();
|
||||||
}
|
// break;
|
||||||
} else {
|
// }
|
||||||
assert(false);
|
// } else {
|
||||||
}
|
// assert(false);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_visibility(const Point_2& p){
|
void update_visibility(const Point_2& p){
|
||||||
|
|
@ -696,7 +696,6 @@ private:
|
||||||
polygon.push_back(p);
|
polygon.push_back(p);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if (polygon.back() != p){
|
|
||||||
if (Visibility_2::compare_xy_2(geom_traits, polygon.back(), p) != EQUAL) {
|
if (Visibility_2::compare_xy_2(geom_traits, polygon.back(), p) != EQUAL) {
|
||||||
polygon.push_back(p);
|
polygon.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
@ -775,9 +774,9 @@ private:
|
||||||
|
|
||||||
//for vertex and edge query: the visibility is limited in a cone.
|
//for vertex and edge query: the visibility is limited in a cone.
|
||||||
void input_edge(const Halfedge_const_handle e,
|
void input_edge(const Halfedge_const_handle e,
|
||||||
std::vector<Pair>& good_edges) {
|
std::vector<Edge>& good_edges) {
|
||||||
for (int i=0; i<bad_edge_handles.size(); i++)
|
for (int i=0; i<bad_edge.size(); i++)
|
||||||
if (e == bad_edge_handles[i])
|
if (e == bad_edge[i])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Point_2 v1 = e->target()->point();
|
Point_2 v1 = e->target()->point();
|
||||||
|
|
@ -829,7 +828,7 @@ private:
|
||||||
}
|
}
|
||||||
//for vertex or edge query: traverse the face to get all edges and sort vertices in counter-clockwise order.
|
//for vertex or edge query: traverse the face to get all edges and sort vertices in counter-clockwise order.
|
||||||
void input_face (Face_const_handle fh,
|
void input_face (Face_const_handle fh,
|
||||||
std::vector<Pair>& good_edges)
|
std::vector<Edge>& good_edges)
|
||||||
{
|
{
|
||||||
// timer.reset();
|
// timer.reset();
|
||||||
// timer.start();
|
// timer.start();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue