Get rid of construct_segment/construct_ray/intersect/assign in Vertex_visibility_graph

This commit is contained in:
Andreas Fabri 2019-04-09 17:38:40 +02:00
parent ff305562ff
commit c7d55b72cf
5 changed files with 73 additions and 48 deletions

View File

@ -43,7 +43,7 @@ int main( )
Polygon_list partition_polys; Polygon_list partition_polys;
CGAL::y_monotone_partition_2(polygon.vertices_begin(), CGAL::optimal_convex_partition_2(polygon.vertices_begin(),
polygon.vertices_end(), polygon.vertices_end(),
std::back_inserter(partition_polys), std::back_inserter(partition_polys),
traits); traits);

View File

@ -45,8 +45,9 @@ namespace CGAL {
template <class Traits> class Rotation_tree_2; template <class Traits> class Rotation_tree_2;
template <class Traits> template <class Traits>
class Rotation_tree_node_2 : public Traits::Point_2 class Rotation_tree_node_2
{ {
typename Traits::Point_2 point;
public: public:
typedef typename Traits::Point_2 Base_point; typedef typename Traits::Point_2 Base_point;
@ -56,7 +57,7 @@ public:
typedef std::pair<Tree_iterator, bool> Node_ref; typedef std::pair<Tree_iterator, bool> Node_ref;
Rotation_tree_node_2(Base_point p) : Base_point(p) Rotation_tree_node_2(Base_point p) : point(p)
{ {
_parent.second = false; _parent.second = false;
_left_sibling.second = false; _left_sibling.second = false;
@ -64,6 +65,9 @@ public:
_rightmost_child.second = false; _rightmost_child.second = false;
} }
operator Base_point() const
{ return point;}
bool has_left_sibling() const bool has_left_sibling() const
{ return _left_sibling.second; } { return _left_sibling.second; }

View File

@ -96,11 +96,11 @@ private:
Collinear_are_ordered_along_line_2; Collinear_are_ordered_along_line_2;
typedef typename Traits::Are_strictly_ordered_along_line_2 typedef typename Traits::Are_strictly_ordered_along_line_2
Are_strictly_ordered_along_line_2; Are_strictly_ordered_along_line_2;
typedef typename Traits::Construct_segment_2 // typedef typename Traits::Construct_segment_2
Construct_segment_2; // Construct_segment_2;
typedef typename Traits::Construct_ray_2 Construct_ray_2; // typedef typename Traits::Construct_ray_2 Construct_ray_2;
typedef typename Traits::Intersect_2 Intersect_2; // typedef typename Traits::Intersect_2 Intersect_2;
typedef typename Traits::Assign_2 Assign_2; // typedef typename Traits::Assign_2 Assign_2;
typedef CGAL::Segment_less_yx_2<Traits> Segment_less_yx_2; typedef CGAL::Segment_less_yx_2<Traits> Segment_less_yx_2;
typedef Rotation_tree_2<Traits> Tree; typedef Rotation_tree_2<Traits> Tree;
@ -140,10 +140,10 @@ public:
are_strictly_ordered_along_line_2( are_strictly_ordered_along_line_2(
traits.are_strictly_ordered_along_line_2_object()), traits.are_strictly_ordered_along_line_2_object()),
less_xy_2(traits.less_xy_2_object()), less_xy_2(traits.less_xy_2_object()),
construct_segment_2(traits.construct_segment_2_object()), // construct_segment_2(traits.construct_segment_2_object()),
construct_ray_2(traits.construct_ray_2_object()), //construct_ray_2(traits.construct_ray_2_object()),
intersect_2(traits.intersect_2_object()), //intersect_2(traits.intersect_2_object()),
assign_2(traits.assign_2_object()), //assign_2(traits.assign_2_object()),
edges(Point_pair_compare(traits)) edges(Point_pair_compare(traits))
{ {
build(first, beyond, traits); build(first, beyond, traits);
@ -156,8 +156,8 @@ public:
Polygon polygon(first,beyond); Polygon polygon(first,beyond);
Tree tree(polygon.begin(), polygon.end(),traits); Tree tree(polygon.begin(), polygon.end(),traits);
Vertex_map vertex_map; Vertex_map vertex_map(less_xy_2);
initialize_vertex_map(polygon, vertex_map,traits); initialize_vertex_map(polygon, vertex_map, traits);
// NOTE: use the std::list as the basis here because otherwise the basis // NOTE: use the std::list as the basis here because otherwise the basis
// is a deque, which is buggy under MSVC++ // is a deque, which is buggy under MSVC++
@ -421,10 +421,10 @@ private:
Collinear_are_ordered_along_line_2 collinear_ordered_2; Collinear_are_ordered_along_line_2 collinear_ordered_2;
Are_strictly_ordered_along_line_2 are_strictly_ordered_along_line_2; Are_strictly_ordered_along_line_2 are_strictly_ordered_along_line_2;
Less_xy_2 less_xy_2; Less_xy_2 less_xy_2;
Construct_segment_2 construct_segment_2; // Construct_segment_2 construct_segment_2;
Construct_ray_2 construct_ray_2; // Construct_ray_2 construct_ray_2;
Intersect_2 intersect_2; //Intersect_2 intersect_2;
Assign_2 assign_2; // Assign_2 assign_2;
Edge_set edges; Edge_set edges;
}; };

View File

@ -522,6 +522,8 @@ void Vertex_visibility_graph_2<Traits>::update_visibility(
// don't need to do this for the previous visibility point since // don't need to do this for the previous visibility point since
// if it were closer to p than q when looking from p to q, q would // if it were closer to p than q when looking from p to q, q would
// not be visible. // not be visible.
#if 0
Segment_2 next_seg = construct_segment_2(*(*p_it).second.second, Segment_2 next_seg = construct_segment_2(*(*p_it).second.second,
*next_v_p); *next_v_p);
Ray_2 ray = construct_ray_2((*p_it).first, (*q_it).first); Ray_2 ray = construct_ray_2((*p_it).first, (*q_it).first);
@ -535,18 +537,7 @@ void Vertex_visibility_graph_2<Traits>::update_visibility(
if (collinear_ordered_2((*p_it).first, (*q_it).first, i_point)) if (collinear_ordered_2((*p_it).first, (*q_it).first, i_point))
{ {
(*p_it).second.second = (*q_it).second.first; (*p_it).second.second = (*q_it).second.first;
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
std::cout << "p sees something in direction of q, but q is closer;"
<< " p sees q" << std::endl;
#endif
} }
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
else
{
std::cout << "p sees something in direction of q that's closer "
<< "than q; p doesn't see q" << std::endl;
}
#endif
} }
else if (assign_2(i_seg, next_result)) else if (assign_2(i_seg, next_result))
{ {
@ -554,27 +545,57 @@ void Vertex_visibility_graph_2<Traits>::update_visibility(
collinear_ordered_2((*p_it).first,(*q_it).first,i_seg.target())) collinear_ordered_2((*p_it).first,(*q_it).first,i_seg.target()))
{ {
(*p_it).second.second = (*q_it).second.first; (*p_it).second.second = (*q_it).second.first;
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
std::cout << "p sees something in direction of q, but q is closer;"
<< " p sees q" << std::endl;
#endif
} }
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
else
{
std::cout << "p sees something in direction of q that's closer "
<< " than q; p doesn't see q" << std::endl;
}
#endif
} }
else else
{ {
(*p_it).second.second = (*q_it).second.first; (*p_it).second.second = (*q_it).second.first;
#ifdef CGAL_VISIBILITY_GRAPH_DEBUG
std::cout << "p doesn't see something in direction of q; p sees q"
<< std::endl;
#endif
} }
#else
// Segment ab and Ray pq
Point_2 a = *(*p_it).second.second;
Point_2 b = *next_v_p;
Point_2 p = (*p_it).first;
Point_2 q = (*q_it).first;
Orientation pqa = orientation_2(p,q,a);
Orientation pqb = orientation_2(p,q,b);
Orientation abp = orientation_2(a,b,p);
Orientation abq = orientation_2(a,b,q);
bool change = false;
if((pqa == COLLINEAR)&& (pqb == COLLINEAR)){
// the segment lies on the supporting line of the ray
if(collinear_ordered_2(p,q,a) && collinear_ordered_2(p,q,b)){
change = true;
}
} else if (pqa == COLLINEAR){
if (collinear_ordered_2(p,q,a)){ // forget about b as it is not collinear
change = true;
}
} else if (pqb == COLLINEAR){
if (collinear_ordered_2(p,q,b)){ // forget about a
change = true;
}
}else if(pqa == pqb){
// no intersection as the segment is completely to the left or to the right of the ray
}else if((abp == COLLINEAR) || (abq == COLLINEAR) ){
// do nothing because when a ray point lies on the segment collinear_ordered_2 will be false
} else if (abp != abq){
// do nothing as i between p and q
} else if(pqb == RIGHT_TURN){
if(abp == RIGHT_TURN){
change = true;
}
} else {
CGAL_assertion(pqa == RIGHT_TURN);
if(abp == LEFT_TURN){
change = true;
}
}
if(change){
(*p_it).second.second = (*q_it).second.first;
}
#endif
} }
else // p sees what q sees else // p sees what q sees
{ {

View File

@ -117,7 +117,7 @@ public:
typename K::Collinear_are_ordered_along_line_2::result_type typename K::Collinear_are_ordered_along_line_2::result_type
operator()(Arg_type p, Arg_type q, Arg_type r) const operator()(Arg_type p, Arg_type q, Arg_type r) const
{ {
return fct(get(ppmap,p), get(ppmap,q), r.first); return fct(get(ppmap,p), get(ppmap,q), get(ppmap,r));
} }
}; };
@ -204,11 +204,11 @@ public:
Collinear_are_ordered_along_line_2 Collinear_are_ordered_along_line_2
collinear_are_ordered_along_line_2_object() const collinear_are_ordered_along_line_2_object() const
{ return Collinear_are_ordered_along_line_2(); } { return Collinear_are_ordered_along_line_2(ppmap,static_cast<const Base_traits*>(this)->collinear_are_ordered_along_line_2_object()); }
Are_strictly_ordered_along_line_2 Are_strictly_ordered_along_line_2
are_strictly_ordered_along_line_2_object() const are_strictly_ordered_along_line_2_object() const
{ return Are_strictly_ordered_along_line_2(); } { return Are_strictly_ordered_along_line_2(ppmap,static_cast<const Base_traits*>(this)->are_strictly_ordered_along_line_2_object()); }
Is_horizontal_2 Is_horizontal_2