Updating the changes due to the usage of the new Polygons_bops_traits.

The new traits provides a function for computing the intersection point
of a vertical ray enamating from a given point, and a given segment.

Now Holes_split does not have to know the types Ray and
does not have to do theis calculation by itself.
This commit is contained in:
Ester Ezra 2002-08-21 15:35:52 +00:00
parent 1454ef27bc
commit 09957314f8
1 changed files with 97 additions and 103 deletions

View File

@ -26,37 +26,25 @@
#ifndef CGAL_HOLES_SPLIT_H
#define CGAL_HOLES_SPLIT_H
//#ifndef LEDA_RAT_RAY_H
//#include <LEDA/rat_ray.h>
//#endif
//#ifndef CGAL_RAY_2_SEGMENT_2_INTERSECTION_H
//#include <CGAL/Ray_2_Segment_2_intersection.h>
//#endif
#ifndef CGAL_ASSERTIONS_H
#include <CGAL/assertions.h>
#endif
CGAL_BEGIN_NAMESPACE
template <class Planar_map_, class Notifier_, class BopsTraits_2_ >
template <class Planar_map_, class Notifier_>
class Holes_split {
//typedef enum { EPSILON=0.01 };
static const int EPSILON=1; //change it to work on VC++.
typedef Planar_map_ Planar_map;
typedef Notifier_ Notifier;
typedef BopsTraits_2_ BopsTraits_2;
typedef typename Planar_map_::Traits Traits;
typedef typename Traits::Point Point;
typedef typename Traits::X_curve X_curve;
typedef typename Traits::Curve Curve;
typedef typename BopsTraits_2::Ray Ray;
typedef typename Planar_map::Vertex Vertex;
typedef typename Planar_map::Face Face;
typedef typename Planar_map::Halfedge Halfedge;
@ -80,15 +68,17 @@ class Holes_split {
typedef typename Planar_map::Locate_type Locate_type;
typedef typename Planar_map::Traits_wrap Traits_wrap;
typedef typename Point::R Kernel;
//typedef typename Point::R Kernel;
//typedef Ray_2<Kernel> Ray;
//typedef leda_rat_ray Ray;
class less_xy_Vertex_handle {
public:
inline bool operator()(Vertex_handle v1, Vertex_handle v2) const {
return CGAL::compare_lexicographically_xy(v1->point(),v2->point()) == CGAL::SMALLER ;
inline bool operator()(Vertex_handle v1,
Vertex_handle v2) const
{
return CGAL::compare_lexicographically_xy(
v1->point(),v2->point()) == CGAL::SMALLER;
}
};
@ -97,10 +87,11 @@ class Holes_split {
{
Halfedge_around_vertex_circulator circ = v->incident_halfedges();
do {
if (circ->decomposing())
return true;
} while(++circ!=v->incident_halfedges());
do
{
if (circ->decomposing())
return true;
} while(++circ!=v->incident_halfedges());
return false;
}
@ -111,54 +102,51 @@ class Holes_split {
bool b=false;
Halfedge_around_vertex_circulator circ = v->incident_halfedges();
do {
if (circ->decomposing()){
b=true;
*halfedges++ = circ;
}
} while(++circ!=v->incident_halfedges());
do
{
if (circ->decomposing()){
b=true;
*halfedges++ = circ;
}
} while(++circ!=v->incident_halfedges());
return b;
}
void add_vertical_curve(Vertex_handle v, Planar_map& pm, Notifier& notf, bool up)
void add_vertical_curve(Vertex_handle v,
Planar_map& pm,
Notifier& notf,
bool up)
{
// debugging.
//cout<< "In add_vertical_curve" <<endl;
//cout<< v->point().xcoordD()<<","<<v->point().ycoordD() << endl;
Locate_type lt;
int eps = up? EPSILON: -EPSILON;
Point pertrubed_p = Point(v->point().x(),
v->point().y() + eps);
//int eps = up? EPSILON: -EPSILON;
//Point pertrubed_p = Point(v->point().x(),
// v->point().y() + eps);
//cout<<"pertrubed_p="<< pertrubed_p.xcoordD()<<","<<pertrubed_p.ycoordD() << endl;
// we have to raise p since the function
// vertical_ray_shoot will return the vertex of of in
// pmwx (that's how it is defined when we shoot a vertical ray
// from a feature that exists in the map.
//Halfedge_handle h = pm.vertical_ray_shoot(pertrubed_p, lt, up);
Halfedge_handle h = pm.vertical_ray_shoot(v->point(), lt, up);
//cout <<"h->curve()="<<h->curve()<<endl;
if (h->face()->is_unbounded())
return; // what we should do here is using the bbox and adding
// a vertical curve upward (downward) will it hits the bbox.
Ray ray(v->point(), pertrubed_p);
Point hitting_point;
//Ray ray(v->point(), pertrubed_p);
//Point hitting_point;
if (!bops_traits_->intersection(h->curve(), ray, hitting_point))
return;
//Object obj=intersection(h->curve(), ray);
//if (!assign(hitting_point, obj))
Point hitting_point = traits_->calc_hitting_point(h->curve(),
v->point());
//if (!bops_traits_->intersection(h->curve(), ray, hitting_point))
// return;
//if (!ray.intersection(h->curve(), hitting_point)) // only for LEDA
// return;
//cout<<"hitting_point="<<hitting_point.xcoordD()<<","<< hitting_point.ycoordD() <<endl;
notf.set_decomposing_edge(true);
//pm.non_intersecting_insert_from_vertex(Curve(v->point(),hitting_point),
// v,up,&notf);
@ -167,7 +155,8 @@ class Holes_split {
X_curve c1,c2;
traits.curve_split(h->curve(), c1, c2, hitting_point);
Halfedge_handle split_h = pm.split_edge(h,c1,c2,&notf);
//Halfedge_handle split_h =
pm.split_edge(h,c1,c2,&notf);
CGAL_assertion(v->point() != hitting_point);
pm.insert(Curve(v->point(),hitting_point),&notf);
@ -193,7 +182,7 @@ public:
Holes_split() {}
Holes_split(BopsTraits_2* bops_traits) : bops_traits_(bops_traits) {}
Holes_split(Traits* traits) : traits_(traits) {}
// This function splits the holes in pm.
// Here, pm has a special structure of one face with possibly many holes.
@ -210,77 +199,82 @@ public:
continue; // splitting only bounded faces.
// keeping all Ccb in a seperate vector, since face is going to be changed.
std::vector<Ccb_halfedge_circulator> holes(face->holes_begin(),face->holes_end());
std::vector<Ccb_halfedge_circulator>
holes(face->holes_begin(),face->holes_end());
//for (Holes_iterator holes_it = face->holes_begin();
// holes_it != face->holes_end(); ++holes_it) {
for (std::vector<Ccb_halfedge_circulator>::iterator holes_it = holes.begin();
holes_it != holes.end(); ++holes_it) {
Ccb_halfedge_circulator face_cc(*holes_it);
// finding the leftmost and the rightmost points of the hole.
std::vector<Vertex_handle> vertices_cc;
do {
vertices_cc.push_back(face_cc->source());
} while (++face_cc != *holes_it);
std::sort(vertices_cc.begin(), vertices_cc.end(), less_xy_Vertex_handle() );
Vertex_handle leftlow_most = vertices_cc[0];
Vertex_handle lefthigh_most = vertices_cc[0];
// updating lefthigh_most to have the highest value of y.
for (unsigned int i=0; i < vertices_cc.size() - 1 &&
vertices_cc[i]->point().x() == vertices_cc[i+1]->point().x(); ++i)
lefthigh_most=vertices_cc[i+1];
Vertex_handle righthigh_most = vertices_cc.back();
Vertex_handle rightlow_most = vertices_cc.back();
// updating rightlow_most to have the lowest value of y.
for (unsigned int i=vertices_cc.size() - 1; i > 1 &&
vertices_cc[i]->point().x() == vertices_cc[i-1]->point().x(); --i)
lefthigh_most=vertices_cc[i-1];
/*Vertex_handle leftlow_most=face_cc->source();
Vertex_handle lefthigh_most=face_cc->source();
Vertex_handle rightlow_most=face_cc->source();
Vertex_handle righthigh_most=face_cc->source();
do {
if (face_cc->source()->point().xcoord() < leftmost->point().xcoord())
lefthigh_most=leftlow_most=face_cc->source();
else if (face_cc->source()->point().xcoord() == leftmost->point().xcoord()){
holes_it != holes.end(); ++holes_it)
{
Ccb_halfedge_circulator face_cc(*holes_it);
}
if (face_cc->source()->point().xcoord() > rightmost->point().xcoord())
rightmost=face_cc->source();
// finding the leftmost and the rightmost points of the hole.
std::vector<Vertex_handle> vertices_cc;
do
{
vertices_cc.push_back(face_cc->source());
} while (++face_cc != *holes_it);
std::sort(vertices_cc.begin(),
vertices_cc.end(),
less_xy_Vertex_handle() );
Vertex_handle leftlow_most = vertices_cc[0];
Vertex_handle lefthigh_most = vertices_cc[0];
// updating lefthigh_most to have the highest value of y.
for (unsigned int i=0; i < vertices_cc.size() - 1 &&
vertices_cc[i]->point().x() == vertices_cc[i+1]->point().x(); ++i)
lefthigh_most=vertices_cc[i+1];
Vertex_handle righthigh_most = vertices_cc.back();
Vertex_handle rightlow_most = vertices_cc.back();
// updating rightlow_most to have the lowest value of y.
for (unsigned int i=vertices_cc.size() - 1; i > 1 &&
vertices_cc[i]->point().x() == vertices_cc[i-1]->point().x(); --i)
lefthigh_most=vertices_cc[i-1];
/*Vertex_handle leftlow_most=face_cc->source();
Vertex_handle lefthigh_most=face_cc->source();
Vertex_handle rightlow_most=face_cc->source();
Vertex_handle righthigh_most=face_cc->source();
do {
if (face_cc->source()->point().xcoord() < leftmost->point().xcoord())
lefthigh_most=leftlow_most=face_cc->source();
else if (face_cc->source()->point().xcoord() == leftmost->point().xcoord()){
}
if (face_cc->source()->point().xcoord() > rightmost->point().xcoord())
rightmost=face_cc->source();
} while (++face_cc != *holes_it);*/
bool b_lefthigh=has_decomposing_edge(lefthigh_most);
bool b_leftlow=has_decomposing_edge(leftlow_most);
bool b_righthigh=has_decomposing_edge(righthigh_most);
bool b_rightlow=has_decomposing_edge(rightlow_most);
bool b_lefthigh=has_decomposing_edge(lefthigh_most);
bool b_leftlow=has_decomposing_edge(leftlow_most);
bool b_righthigh=has_decomposing_edge(righthigh_most);
bool b_rightlow=has_decomposing_edge(rightlow_most);
if (!b_lefthigh)
add_vertical_curve(lefthigh_most, pm, notf, true);
//bool b_leftlow=has_decomposing_edge(leftlow_most);
if (!b_leftlow)
if (!b_lefthigh)
add_vertical_curve(lefthigh_most, pm, notf, true);
//bool b_leftlow=has_decomposing_edge(leftlow_most);
if (!b_leftlow)
add_vertical_curve(leftlow_most, pm, notf, false);
//bool b_righthigh=has_decomposing_edge(righthigh_most);
if (!b_righthigh)
add_vertical_curve(righthigh_most, pm, notf, true);
//bool b_righthigh=has_decomposing_edge(righthigh_most);
if (!b_righthigh)
add_vertical_curve(righthigh_most, pm, notf, true);
//bool b_rightlow=has_decomposing_edge(rightlow_most);
if (!b_rightlow)
add_vertical_curve(rightlow_most, pm, notf, false);
}
if (!b_rightlow)
add_vertical_curve(rightlow_most, pm, notf, false);
}
}
}
private:
BopsTraits_2* bops_traits_;
Traits* traits_;
};
CGAL_END_NAMESPACE