changed :

Delaunay_triangulation_2.h remove
Triangulation_2.h  copy, os ,is
Triangulation_default_data_structure_2.h  copy os is
etc...
This commit is contained in:
Mariette Yvinec 1998-11-17 15:05:50 +00:00
parent f14c1dd175
commit 17f766209b
6 changed files with 178 additions and 227 deletions

View File

@ -149,16 +149,15 @@ public:
}
Vertex_handle
nearest_vertex(const Point& p, const Face_handle& f) const
nearest_vertex_2D(const Point& p) const
{
CGAL_triangulation_precondition(dimension() == 2);
Vertex_handle nn;
Face_handle f = locate(p);
Distance closer(p,&geom_traits());
int min;
int i;
if (number_of_vertices() == 0) return NULL;
if (number_of_vertices() == 1) return finite_vertex();
i = ( ! is_infinite(f->vertex(0)) ) ? 0 : 1;
closer.set_point(1,f->vertex(i)->point());
@ -185,12 +184,45 @@ public:
look_nearest_neighbor(p,f,2,min,nn,closer);
return nn;
}
Vertex_handle
nearest_vertex_1D(const Point& p) const
{
Vertex_handle nn;
Distance closer(p,&geom_traits());
int min;
Vertex_iterator vit=vertices_begin();
closer.set_point(1,vit->point());
min = 1;
nn = vit->handle();
do {
closer.set_point( 3-min, (++vit)->point());
if ( ( (min==1)? CGAL_LARGER : CGAL_SMALLER )
== closer.compare() ) {
min = 3-min;
nn=vit->handle();
}
}while( vit != vertices_end());
return nn;
}
inline Vertex_handle
nearest_vertex(const Point &p) const
{
Face_handle f = locate(p);
return nearest_vertex(p, f);
switch (dimension()) {
case 0:
if (number_of_vertices() == 0) return NULL;
if (number_of_vertices() == 1) return finite_vertex();
break;
case 1:
return nearest_vertex_1D(p);
break;
case 2:
return nearest_vertex_2D(p);
break;
}
return NULL;
}
Vertex_handle
@ -242,34 +274,11 @@ private:
//CGAL_triangulation_precondition(v != (CGAL_NULL_TYPE) NULL);
CGAL_triangulation_precondition(! v.is_null());
CGAL_triangulation_precondition( !is_infinite(v));
if (number_of_vertices() == 1) {
CGAL_Triangulation_2<Gt,Tds>::remove(v);
return;
}
// take care of finite_vertex data member
if (finite_vertex() == v){
Face_handle f = v->face();
int i=f->index(v);
Vertex_handle vv= is_infinite(f->vertex(cw(i))) ?
f->vertex(ccw(i)) : f->vertex(cw(i));
set_finite_vertex( vv);
}
if (number_of_vertices() == 2) {
Face_handle f = v->face();
Face_handle ff = f->neighbor(0);
ff.Delete();
f.Delete();
}
else{
if ( dimension() == 1) remove_1D(v);
else remove_2D(v);
}
v.Delete();
set_number_of_vertices(number_of_vertices()-1);
return;
if ( dimension() <= 1) CGAL_Triangulation_2<Gt,Tds>::remove(v);
else remove_2D(v);
return;
}
bool is_valid(bool verbose = false, int level = 0) const
@ -348,51 +357,59 @@ private:
}
void remove_2D(Vertex_handle v )
void remove_2D(Vertex_handle v)
{
//test the dimensionality of the resulting triangulation
//it goes down to 1 iff
// 1) any finite face is incident to v
// 2) all vertices are colinear
bool dim1 = true;
Face_iterator fit = faces_begin();
while (dim1==true && fit != faces_end()) {
dim1 = dim1 && fit->has_vertex(v);
fit++;
}
Face_circulator fic = v->incident_faces();
while (is_infinite(fic)) {++fic;}
Face_circulator done(fic);
Face_handle start(fic); int iv = start->index(v);
Point p = start->vertex(cw(iv))->point(), q = start->vertex(ccw(iv))->point();
while ( dim1 && ++fic != done) {
iv = fic->index(v);
if (fic->vertex(ccw(iv)) != infinite_vertex()) {
dim1 = dim1 &&
geom_traits().orientation(p, q, fic->vertex(ccw(iv))->point())
== CGAL_COLLINEAR;
}
}
if (dim1) {
_tds.remove_down(&(*v));
}
else {
list<Edge> hole;
make_hole(v, hole);
fill_hole(v, hole);
v.Delete();
set_number_of_vertices(number_of_vertices()-1);
}
return;
}
void fill_hole ( Vertex_handle v, list< Edge > & first_hole )
{
// General case
// remove incident faces
// set up list of faces neighboring the hole
// in ccw order around the hole
// problem with gcc link
typedef pair<void *, int> Hole_neighbor;
//typedef pair<Face_handle , int> Hole_neighbor;
typedef list<Hole_neighbor> Hole;
typedef Edge Hole_neighbor;
typedef list<Edge> Hole;
typedef list<Hole> Hole_list;
Hole hole;
Hole_list hole_list;
list<Face_handle> to_delete;
Face_handle f, ff, fn;
int i =0,ii =0, in =0;
Vertex_handle vv;
Face_circulator fc = v->incident_faces();
Face_circulator done(fc);
do {
f = (*fc).handle(); fc++;
i = f->index(v);
fn = f->neighbor(i);
vv = f->vertex(f->cw(i));
if( vv->face()== f) vv->set_face(fn);
vv = f->vertex(f->ccw(i));
if( vv->face()== f) vv->set_face(fn);
in = fn->index( f );
fn->set_neighbor(in, NULL);
hole.push_back(Hole_neighbor(&(*fn),in));
to_delete.push_back(f);
}
while(fc != done);
while (! to_delete.empty()){
to_delete.front().Delete();
to_delete.pop_front();
}
hole_list.push_front(hole);
Hole_list hole_list;
Hole hole;
hole_list.push_front(first_hole);
while( ! hole_list.empty())
{
@ -402,19 +419,17 @@ private:
// if the hole has only three edges, create the triangle
if (hole.size() == 3) {
Face_handle newf = new Face();
hit = hole.begin();
for(int j = 0;j<3;j++){
ff = (Face *) ((*hit).first);
ii = (*hit).second;
hit++;
ff->set_neighbor(ii,newf);
newf->set_neighbor(j,ff);
newf->set_vertex(newf->ccw(j),ff->vertex(ff->cw(ii)));
}
continue;
}
Face_handle newf = new Face();
hit = hole.begin();
for(int j = 0;j<3;j++) {
ff = (*hit).first;
ii = (*hit).second;
hit++;
ff->set_neighbor(ii,newf);
newf->set_neighbor(j,ff);
newf->set_vertex(newf->ccw(j),ff->vertex(ff->cw(ii)));
}
}
// else find an edge with two finite vertices
// on the hole boundary
@ -426,7 +441,7 @@ private:
// is the first of the hole
bool finite= false;
while (!finite){
ff = (Face *) ((hole.front()).first);
ff = (hole.front()).first;
ii = (hole.front()).second;
if ( is_infinite(ff->vertex(cw(ii))) ||
is_infinite(ff->vertex(ccw(ii)))) {
@ -437,7 +452,7 @@ private:
}
// take the first neighboring face and pop it;
ff = (Face *) ((hole.front()).first);
ff = (hole.front()).first;
ii =(hole.front()).second;
hole.pop_front();
@ -456,7 +471,7 @@ private:
// stop at the before last face;
hdone--;
while( hit != hdone) {
fn = (Face *) ((*hit).first);
fn = (*hit).first;
in = (*hit).second;
vv = fn->vertex(ccw(in));
if (is_infinite(vv)) {
@ -488,7 +503,7 @@ private:
// the hole remain a single hole
// otherwise it is split in two holes
fn = (Face *) ((hole.front()).first);
fn = (hole.front()).first;
in = (hole.front()).second;
if (fn->has_vertex(v2, i) && i == fn->ccw(in)) {
newf->set_neighbor(0,fn);
@ -498,7 +513,7 @@ private:
hole_list.push_front(hole);
}
else{
fn = (Face *) ((hole.back()).first);
fn = (hole.back()).first;
in = (hole.back()).second;
if (fn->has_vertex(v2, i) && i== fn->cw(in)) {
newf->set_neighbor(1,fn);

View File

@ -111,27 +111,17 @@ public:
_gt(geom_traits)
{}
CGAL_Triangulation_2(const Vertex_handle& v,
const Geom_traits& geom_traits=Geom_traits())
: _tds(&(*v)), _gt(geom_traits)
{ }
// copy constructor duplicates vertices and faces
CGAL_Triangulation_2(const CGAL_Triangulation_2<Gt,Tds> &tr)
: _tds(tr._tds), _gt(tr._gt)
{}
: _infinite_vertex(tr._infinite_vertex),_tds(tr._tds), _gt(tr._gt)
{}
//Assignement
CGAL_Triangulation_2 &operator=(const CGAL_Triangulation_2 &tr)
{
copy(tr);
copy_triangulation(tr);
return *this;
}
@ -201,7 +191,7 @@ public:
Face_handle infinite_face() const
{
CGAL_triangulation_precondition( ! infinite_vertex()->face().is_null());
//CGAL_triangulation_precondition( ! infinite_vertex()->face().is_null());
return infinite_vertex()->face();
}
@ -797,8 +787,6 @@ protected:
}
private :
void make_hole ( Vertex_handle v, list<Edge> & hole)
{
@ -834,7 +822,6 @@ void make_hole ( Vertex_handle v, list<Edge> & hole)
}
private :
void fill_hole ( Vertex_handle v, list< Edge > & hole )
{
typedef list< Edge > Hole;

View File

@ -94,13 +94,13 @@ public:
//creators
CGAL_Triangulation_default_data_structure_2()
: _infinite_vertex(NULL),_number_of_vertices(0)
: _geom_traits(),_infinite_vertex(NULL),
_dimension(0),_number_of_vertices(0)
{ }
CGAL_Triangulation_default_data_structure_2(const Geom_traits& gt)
: _geom_traits(gt), _infinite_vertex(NULL),
_number_of_vertices(0), _dimension(0)
_dimension(0), _number_of_vertices(0)
{ }
CGAL_Triangulation_default_data_structure_2(Vertex * v)
@ -154,8 +154,15 @@ public:
int dimension() const { return _dimension; }
int number_of_vertices() const {return _number_of_vertices;}
int number_of_faces() const {
return (number_of_vertices() <= 1) ? 0 : 2 * number_of_vertices() - 4;
}
if (number_of_vertices() < 2) return 0;
switch(dimension()){
case 0 : return 2;
case 1: return number_of_vertices();
case 2: return 2 * number_of_vertices() - 4;
}
CGAL_triangulation_assertion(false);
return -1;
}
const Geom_traits& geom_traits() const {return _geom_traits;}
public:
@ -167,8 +174,8 @@ public:
private:
Face* infinite_face() const
{
CGAL_triangulation_precondition( number_of_vertices() >= 2 &&
_infinite_vertex->face() != NULL );
//CGAL_triangulation_precondition( number_of_vertices() >= 2 &&
// _infinite_vertex->face() != NULL );
return _infinite_vertex->face();
}
@ -723,35 +730,30 @@ public:
Face* f2;
int n = tds.number_of_vertices();
//non used?? int m = tds.number_of_faces();
set_number_of_vertices(n);
_number_of_vertices = tds.number_of_vertices();
_geom_traits = tds.geom_traits();
//the class Geom_traits is required to have a pertinent operator=
// create the vertex at infinity
v2 = new Vertex();
V[tds.infinite_vertex()]=v2;
set_infinite_vertex(v2);
_dimension = tds.dimension();
if(n == 0){ return ; }
if(n == 1) {
v2 = new Vertex(tds.finite_vertex()->point());
V[tds.finite_vertex()]=v2;
set_finite_vertex(v2);
return;
}
// create the finite vertices
{
Vertex_iterator it=tds.vertices_begin();
while (it != tds.vertices_end()) {
V[&(*it)] = new Vertex( it->point() );
//if ( & (*it) != infinite_vertex())
{
V[&(*it)] = new Vertex( it->point() );}
++it;
}
}
//set infinite_vertex
v2 = (Vertex*)V[tds.infinite_vertex()];
set_infinite_vertex(v2);
// create the finite faces
// create the faces
{
Face_iterator it = tds.faces_begin();
while(it != tds.faces_end()){
@ -761,22 +763,9 @@ public:
++(it);
}
}
//create the infinite faces
{
Face_circulator fc = tds.infinite_vertex()->incident_faces();
Face_circulator done(fc);
do{
F[&(*fc)]= new Face( (Vertex*) V[fc->vertex(0)],
(Vertex*) V[fc->vertex(1)],
(Vertex*) V[fc->vertex(2)] );
}while(++fc != done);
}
// link the infinite vertex to a triangle
infinite_vertex()->set_face( (Face*) F[tds.infinite_face()] );
// link the finite vertices to a triangle
// link each vertex to a face
{
Vertex_iterator it = tds.vertices_begin();
while(it != tds.vertices_end()) {
@ -786,7 +775,7 @@ public:
}
}
// hook neighbor pointers of the finite faces
// hook neighbor of the faces
{
Face_iterator it = tds.faces_begin();
while(it != tds.faces_end()){
@ -798,17 +787,6 @@ public:
}
}
// hook neighbor pointers of the infinite faces
{
Face_circulator fc = tds.infinite_vertex()->incident_faces(),
done(fc);
do{
f2 = ((Face*) F[&(*fc)]);
for(int j = 0; j < 3; j++){
f2->set_neighbor(j, (Face*) F[fc->neighbor(j)] );
}
}while(++fc != done);
}
CGAL_triangulation_postcondition( is_valid() );
return;
@ -861,11 +839,6 @@ public:
Faces.push_front(&(*it));
++it;
}
// Face_circulator fc = infinite_vertex()->incident_faces(),
// fcdone(fc);
// do{
// Faces.push_front(&(*fc));
// }while(++fc != fcdone);
}
CGAL_triangulation_assertion( number_of_faces() == (int) Faces.size());
@ -989,7 +962,7 @@ operator<<(ostream& os,
Vertex* v;
int n = tds.number_of_vertices() + 1;
int n = tds.number_of_vertices();
int m = tds.number_of_faces();
if(CGAL_is_ascii(os)){
os << n << ' ' << m << ' ' << tds.dimension() << endl;
@ -1009,39 +982,42 @@ operator<<(ostream& os,
return os;
}
// write the finite vertices
// write the other vertices
{
Vertex_iterator
it = tds.vertices_begin();
while(it != tds.vertices_end()){
if ( &(*it) != infinite_vertex()) {
V[&(*it)] = ++i;
os << it->point();
if(CGAL_is_ascii(os)){
os << ' ';
}
++it;
}
++it;
}
}
CGAL_triangulation_assertion( (i+1) == n );
if(CGAL_is_ascii(os)){ os << "\n";}
if(n == 2){
if(n == 1){
return os;
}
i = 0;
// vertices of the finite faces
// vertices of the faces
{
Face_iterator
it = tds.faces_begin();
while(it != tds.faces_end()){
F[&(*it)] = i++;
for(int j = 0; j < 3; j++){
for(int j = 0; j < dimension()+1; j++){
os << V[it->vertex(j)];
if(CGAL_is_ascii(os)){
if(j==2) {
if(j==dimension()) {
os << "\n";
} else {
os << ' ';
@ -1052,37 +1028,18 @@ operator<<(ostream& os,
}
}
// vertices of the infinite faces
{
Face_circulator
fc = tds.infinite_vertex()->incident_faces(),
done(fc);
do{
F[&(*fc)] = i++;
for(int j = 0; j < 3; j++){
os << V[fc->vertex(j)];
if(CGAL_is_ascii(os)){
if(j==2) {
os << "\n";
} else {
os << ' ';
}
}
}
}while(++fc != done);
}
CGAL_triangulation_assertion( i == m );
// neighbor pointers of the finite faces
// neighbor pointers of the faces
{
Face_iterator
it = tds.faces_begin();
while(it != tds.faces_end()){
for(int j = 0; j < 3; j++){
for(int j = 0; j < dimension()+1; j++){
os << F[&(* it->neighbor(j))];
if(CGAL_is_ascii(os)){
if(j==2) {
if(j== dimension()) {
os << "\n";
} else {
os << ' ';
@ -1093,27 +1050,6 @@ operator<<(ostream& os,
}
}
// neighbor pointers of the infinite faces
{
Face_circulator
fc = tds.infinite_vertex()->incident_faces(),
done(fc);
do{
for(int j = 0; j < 3; j++){
os << F[fc->neighbor(j)];
if(CGAL_is_ascii(os)){
if(j==2) {
os << "\n";
} else {
os << ' ';
}
}
}
}while(++fc != done);
}
return os;
}

View File

@ -402,7 +402,7 @@ public:
return *this; // cannot advance past-the-end iterator
} // include the case number_of_vertices() == 0
if (pos==(Face*)1){
pos == NULL; //number_of_vertices() == 1
pos = NULL; index=0; //number_of_vertices() == 1
return *this;
}
@ -488,12 +488,20 @@ public:
inline Vertex& operator*() const
{
return *(pos->vertex(index));
CGAL_triangulation_assertion( pos != NULL);
if (pos == (Face*)1) {// only one vertex;
return *(_tds->infinite_vertex());
}
return *(pos->vertex(index));
}
inline Vertex* operator->() const
{
return pos->vertex(index);
CGAL_triangulation_assertion( pos != NULL);
if (pos == (Face*)1) {// only one vertex;
return _tds->infinite_vertex();
}
return pos->vertex(index);
}

View File

@ -241,7 +241,8 @@ public:
operator++()
{
++_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Vertex *) &(*_ib))){
while ( _ib != Iterator_base(&(_tr->_tds),1) &&
_tr->is_infinite((Vertex *) &(*_ib))){
++_ib;
}
return *this;
@ -251,7 +252,8 @@ public:
operator--()
{
--_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Vertex *) &(*_ib))){
while ( _ib != Iterator_base(&(_tr->_tds),1) &&
_tr->is_infinite((Vertex *) &(*_ib))){
--_ib;
}
return *this;
@ -324,7 +326,8 @@ public:
_ib = Iterator_base(&(tr->_tds),1);
return;
}
while ( _ib != Iterator_base(&(tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
while ( _ib != Iterator_base(&(tr->_tds),1) &&
_tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
++_ib;
}
return;
@ -363,7 +366,8 @@ public:
operator++()
{
++_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
while ( _ib != Iterator_base(&(_tr->_tds),1) &&
_tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
++_ib;
}
return *this;
@ -373,7 +377,8 @@ public:
operator--()
{
--_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), *_ib.second)){
while ( _ib != Iterator_base(&(_tr->_tds),1) &&
_tr->is_infinite((Face *)((*_ib).first), *_ib.second)){
--_ib;
}
return *this;

View File

@ -35,7 +35,7 @@ public:
CGAL_Triangulation_vertex_base_2 ()
: _f(NULL)
: _p(),_f(NULL)
{}
CGAL_Triangulation_vertex_base_2(const Point & p)