changed representation of One dimensional triangulations

This commit is contained in:
Mariette Yvinec 1998-08-14 15:55:01 +00:00
parent 243f7f40fc
commit b61572171c
7 changed files with 864 additions and 844 deletions

View File

@ -1,3 +1,11 @@
// ============================================================================
//
// $Id$
//
// ============================================================================
#ifndef CGAL_TRIANGULATION_2_H
#define CGAL_TRIANGULATION_2_H
@ -8,7 +16,7 @@
#include <pair.h>
#include <CGAL/Pointer.h>
#include <CGAL/circulator.h>
#include <CGAL/triangulation_asserions.h>
#include <CGAL/triangulation_assertions.h>
#include <CGAL/Triangulation_short_names_2.h>
#include <CGAL/Triangulation_default_data_structure_2.h>
#include <CGAL/Triangulation_face_2.h>
@ -152,11 +160,11 @@ public:
int number_of_faces() const
{
int count = _tds.number_of_faces();
Face circulator fc= infinite_vertex()->incident_faces(),
Face_circulator fc= infinite_vertex()->incident_faces(),
done(fc);
if (fc != NULL) {
do {
count++; fc++;
--count; ++fc;
} while (fc != done);
}
return count;
@ -165,12 +173,14 @@ public:
const Vertex_handle infinite_vertex() const
{
_infinite_vertex();
return _infinite_vertex;
}
const Vertex_handle finite_vertex() const
{
CGAL_triangulation_precondition (number_of_vertices() >= 1);
return (vertices_begin());
}
Face_handle infinite_face() const
{
@ -189,31 +199,41 @@ public:
bool result = _tds.is_valid();
Face_iterator it;
for(it=faces_begin(); it!=faces_end(); it++){
CGAL_Orientation s = geom_traits().orientation(it->vertex(0)->point(),
switch(dimension()) {
case 0 :
break;
case 1:
// to be done
break;
case 2:
for(it=faces_begin(); it!=faces_end(); it++){
CGAL_triangulation_assertion( !is_infinite(it));
CGAL_Orientation s = geom_traits().orientation(it->vertex(0)->point(),
it->vertex(1)->point(),
it->vertex(2)->point());
CGAL_triangulation_assertion( s == CGAL_LEFTTURN );
result = result && ( s == CGAL_LEFTTURN );
}
CGAL_triangulation_assertion( s == CGAL_LEFTTURN );
result = result && ( s == CGAL_LEFTTURN );
}
Vertex_circulator start = infinite_vertex()->incident_vertices(),
pc(start),
qc(start),
rc(start);
++qc;
++rc;
++rc;
do{
CGAL_Orientation s = geom_traits().orientation(pc->point(),
if (number_of_vertices() < 2) { return result;}
Vertex_circulator start = infinite_vertex()->incident_vertices(),
pc(start),
qc(start),
rc(start);
++qc;
++rc;
++rc;
do{
CGAL_Orientation s = geom_traits().orientation(pc->point(),
qc->point(),
rc->point());
CGAL_triangulation_assertion( s != CGAL_LEFTTURN );
result = result && ( s != CGAL_LEFTTURN );
pc = qc;
qc = rc;
++rc;
}while(pc != start);
CGAL_triangulation_assertion( s != CGAL_LEFTTURN );
result = result && ( s != CGAL_LEFTTURN );
pc = qc;
qc = rc;
++rc;
}while(pc != start);
}
return result;
}
@ -318,8 +338,8 @@ public:
{
CGAL_triangulation_precondition(number_of_vertices() == 1 &&
v != infinite_vertex() &&
v != finite_vertex();)
_tds.insert_third( &(*v), &(*infinite_vertex()) );
v != finite_vertex());
_tds.insert_outside_affine_hull( &(*v), &(*infinite_vertex()), true );
return;
}
@ -348,43 +368,47 @@ public:
void
insert_outside_convex_hull(Vertex_handle v, Face_handle f, int i)
insert_outside_convex_hull(Vertex_handle v, Face_handle f)
{
CGAL_triangulation_precondition(f->neighbor(i)->is_infinite());
CGAL_triangulation_precondition(is_infinite(f));
if (dimension() == 1) {
insert_outside_convex_hull_1(Vertex_handle v, Face_handle f, int i);
insert_outside_convex_hull_1(v, f);
}
if (dimension() == 2){
insert_outside_convex_hull_2(Vertex_handle v, Face_handle f, int i);
insert_outside_convex_hull_2(v, f);
}
}
private:
insert_outside_convex_hull_1(Vertex_handle v, Face_handle f, int i)
void insert_outside_convex_hull_1(Vertex_handle v, Face_handle f)
{
int i = f->index(infinite_vertex());
Face_handle n = f->neighbor(i-1);
int in = n->index(f);
CGAL_triangulation_precondition( ! is_infinite(n));
CGAL_triangulation_precondition(
geom_traits().orientation( f->neighbor(i)->vertex(i)->point(),
f->vertex(i)->point(),
geom_traits().orientation( n->vertex(in)->point(),
n->vertex(1-in)->point(),
v->point() ) == CGAL_COLLINEAR &&
collinear_between( f->neighbor(i)->vertex(i)->point(),
f->vertex(i)->point(),
v->point()) );
_tds.insert_in_edge(v, f, i);
collinear_between( n->vertex(in)->point(),
n->vertex(1-in)->point(),
v->point()) );
_tds.insert_in_edge(&(*v), &(*f), 3);
return;
}
insert_outside_convex_hull_2(Vertex_handle v, Face_handle f, int i)
void insert_outside_convex_hull_2(Vertex_handle v, Face_handle f)
{
CGAL_triangulation_precondition(f->neighbor(i)->is_infinite());
f = f->neighbor(i);
CGAL_triangulation_precondition(is_infinite(f));
int li = f->index(infinite_vertex());
list<Face_handle> ccwlist;
list<Face_handle> cwlist;
int li;
Point p = vp->point();
Point p = v->point();
Point q,r;
li = f->index(infinite_vertex());
@ -419,7 +443,7 @@ private:
else {done=true;}
}
_tds.insert_in_face( &(*vp), &(*f));
_tds.insert_in_face( &(*v), &(*f));
Face_handle fh;
while ( ! ccwlist.empty()) {
@ -437,7 +461,7 @@ private:
}
//reset infinite_vertex()->face();
fc = vp->incident_faces();
fc = v->incident_faces();
while( ! is_infinite(&(*fc))) {
fc++;}
infinite_vertex()->set_face(&(*fc));
@ -445,18 +469,17 @@ private:
}
public :
void
insert_outside_affine_hull(Vertex_handle v)
void insert_outside_affine_hull(Vertex_handle v)
{
CGAL_triangulation_precondition(dimension() == 1);
Face_handle f( faces_begin());
CGAL_orientation or = geom_traits().orientation( f->vertex(0)->point(),
Face_handle f = (*edges_begin()).first;
CGAL_Orientation or = geom_traits().orientation( f->vertex(0)->point(),
f->vertex(1)->point(),
v->point());
CGAL_triangulation_precondition(or != CGAL_COLLINEAR);
bool conform = ( or == CGAL_COUNTER_CLOCKWISE);
bool conform = ( or == CGAL_COUNTERCLOCKWISE);
_tds.insert_outside_affine_hull( &(*v), infinite_vertex(), or);
_tds.insert_outside_affine_hull( &(*v), &(*infinite_vertex()), conform);
return;
}
@ -464,14 +487,14 @@ public :
Vertex_handle insert(const Point& p,
Vertex_handle insert(const Point& p,
Locate_type& lt,
Face_handle f = Face_handle() )
{
Vertex_handle v;
if(number_of_vertices() == 0) {
v = new Vertex(p);
lt = OUTSIDE;
lt = OUTSIDE_AFFINE_HULL;
//_tds.insert_first(&(*v));
insert_first(v);
return v;
@ -482,7 +505,7 @@ public :
return finite_vertex();
}
v = new Vertex(p);
lt = OUTSIDE;
lt = OUTSIDE_AFFINE_HULL;
//_tds.insert_second(&(*v));
insert_second(v);
return v;
@ -503,7 +526,7 @@ public :
{
v = new Vertex(p);
//_tds.insert_on_edge( &(*v), &(*loc), li);
insert_on_edge(v,loc,li);
insert_in_edge(v,loc,li);
break;
}
@ -518,7 +541,7 @@ public :
{
v = new Vertex(p);
//_tds.insert_collinear_outside( &(*v), &(*loc),li);
insert_outside_affine_hull(v,loc,li);
insert_outside_affine_hull(v);
break;
}
@ -626,7 +649,7 @@ void remove_first(Vertex_handle v)
void remove_second(Vertex_handle v)
{
_tds.remove_third(&(*v));
_tds.remove_down(&(*v));
return;
}
@ -641,7 +664,7 @@ void remove(Vertex_handle v)
}
if (number_of_vertices() == 2) {
remove_second();
remove_second(v);
}
else{
if ( dimension() == 1) remove_1D(v);
@ -656,7 +679,7 @@ void remove(Vertex_handle v)
protected:
void remove_1D(Vertex_handle v)
{
_tds.remove_1D(&(*v);
_tds.remove_1D(&(*v));
}
void remove_2D(Vertex_handle v)
@ -666,29 +689,32 @@ protected:
// 1) any finite face is incident to v
// 2) all vertices are colinear
bool dim1 = true;
Face iterator fit = faces_begin();
Face_iterator fit = faces_begin();
while (dim1==true && fit != faces_end()) {
dim1 = dim1 && fit->has_vertex(v);
}
Face circulator fic = v->incident_faces(),
done(fic);
Face_handle start(fic);
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) {
dim1 = dim1 &&
geom_traits().orientation(start->vertex(cw(i))->point(),
start->vertex(ccw(i))->point(),
fic->vertex(cw(ii)->point()) )
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_2D_to_1D(v);
_tds.remove_down(&(*v));
}
else {
List<Edge> hole;
make_hole(& hole)
fill_hole(& hole);
Delete v;
list<Edge> hole;
make_hole(v, hole);
fill_hole(v, hole);
v.Delete();
set_number_of_vertices(number_of_vertices()-1);
}
return;
@ -697,10 +723,10 @@ protected:
private :
make_hole ( List<Edge> & hole)
void make_hole ( Vertex_handle v, list<Edge> & hole)
{
List<Edge>::iterator hit;
list<Edge>::iterator hit;
list<Face_handle> to_delete;
Face_handle f, ff, fn;
@ -726,7 +752,7 @@ private :
while(fc != done);
while (! to_delete.empty()){
delete to_delete.front();
(to_delete.front()).Delete();
to_delete.pop_front();
}
return;
@ -734,10 +760,11 @@ private :
private :
fill_hole ( list< Edge > & hole )
void fill_hole ( Vertex_handle v, list< Edge > & hole )
{
typedef list< Edge > Hole;
Point p = v->point();
Face_handle f, ff, fn;
int i =0,ii =0, in =0;
Vertex_handle v0, v1, v2;
@ -761,8 +788,8 @@ private :
// nhole decount the number of hole edges passed
// from the last created edges
while (hole.size()>3 && nhole>0) {
ff = (Face *) ( (hole.front()).first);
//ff = hole.front().first
//ff = (Face *) ( (hole.front()).first);
ff = hole.front().first;
ii = (hole.front()).second;
hole.pop_front();
@ -791,7 +818,7 @@ private :
fn->set_neighbor(in,newf);
hole.pop_front();
//hole.push_front(Hole_neighbor(&(*newf),1));
/hole.push_front(Edge(newf,1));
hole.push_front(Edge(newf,1));
nhole = hole.size();
continue;
}
@ -815,8 +842,8 @@ private :
if(hole.size() != 3) {
nhole = hole.size();
while ( nhole>0) {
ff = (Face *) ((hole.front()).first);
// ff = ((hole.front()).first)
//ff = (Face *) ((hole.front()).first);
ff = ((hole.front()).first);
ii = (hole.front()).second;
hole.push_back(hole.front());
hole.pop_front();
@ -826,8 +853,8 @@ private :
v1 = ff->vertex(ccw(ii));
if(is_infinite(v0) || is_infinite(v1)) continue;
fn = (Face *) ((hole.front()).first);
// fn = ((hole.front()).first)
//fn = (Face *) ((hole.front()).first);
fn = ((hole.front()).first);
in = (hole.front()).second;
v2 = fn->vertex(ccw(in));
if( is_infinite(v2) ) continue;
@ -843,7 +870,7 @@ private :
fn->set_neighbor(in,newf);
hole.pop_back();
hole.pop_front();
hole.push_front(Hole_neighbor(&(*newf),1));
hole.push_front(Edge(newf,1));
break;
}
}
@ -852,16 +879,13 @@ private :
if(hole.size() != 3) {
// look for infinite vertex
ff = (Face *) ((hole.front()).first);
//ff = (hole.front()).first;
//ff = ((hole.front()).first)->handle();
ff = (hole.front()).first;
ii = (hole.front()).second;
while ( ! is_infinite(ff->vertex(cw(ii)))){
hole.push_back(hole.front());
hole.pop_front();
ff = (Face *)((hole.front()).first);
//ff = (hole.front()).first;
//ff = ((hole.front()).first)->handle();
//ff = (Face *)((hole.front()).first);
ff = (hole.front()).first;
ii = (hole.front()).second;
}
//create faces
@ -888,19 +912,20 @@ private :
}
// now hole has three edges
Face_handle newf = new Face();
hit = hole.begin();
for(int j = 0;j<3;j++) {
//ff = (Face *)((*hit).first);
ff = (*hit).first;
//ff = ((*hit).first)->handle();
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)));
}
}
list<Edge>::iterator hit;
Face_handle newf = new Face();
hit = hole.begin();
for(int j = 0;j<3;j++) {
//ff = (Face *)((*hit).first);
ff = (*hit).first;
//ff = ((*hit).first)->handle();
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)));
}
}
@ -922,14 +947,23 @@ public:
vertex_edge,
edge_vertex,
edge_edge};
private:
CGAL_Triangulation_2<Gt, Tds>* _tr;
State s;
int i;
Point p, q;
public:
Line_face_circulator()
: Face::Face_handle(), _tr(NULL), s(undefined), i(-1)
{}
Line_face_circulator(const Line_face_circulator& lfc)
: Face::Face_handle(& (*lfc)), _tr(lfc._tr), s(lfc.s), i(lfc.i),
p(lfc.p), q(lfc.q))
p(lfc.p), q(lfc.q)
{}
~Line_face_circulator()
@ -945,7 +979,7 @@ Line_face_circulator(const Face_handle& face,
: Face::Face_handle(face), _tr(t), s(state), i(index), p(pp), q(qq)
{
CGAL_triangulation_precondition(p != q);
CGAL_triangulation_precondition(t.dimension ==2);
CGAL_triangulation_precondition(t->dimension() ==2);
}
@ -1077,7 +1111,7 @@ Line_face_circulator(const Face_handle& face,
: _tr(t), s(undefined), p(pp), q(qq)
{
CGAL_triangulation_precondition(pp != qq);
CGAL_triangulation_precondition(t.dimension ==2);
CGAL_triangulation_precondition(t->dimension() ==2);
Vertex_handle inf = _tr->infinite_vertex();
Face_circulator fc = inf->incident_faces(),
@ -1158,7 +1192,7 @@ Line_face_circulator(const Face_handle& face,
: Face::Face_handle(ff), _tr(t), s(undefined), p(pp), q(qq)
{
CGAL_triangulation_precondition(p != q);
CGAL_triangulation_precondition(t.dimension ==2);
CGAL_triangulation_precondition(t->dimension() ==2);
//CGAL_triangulation_precondition(_tr->is_infinite(f) ||
// _tr->oriented_side(f,p) != CGAL_ON_NEGATIVE_SIDE);
@ -1375,7 +1409,7 @@ Line_face_circulator(const Face_handle& face,
ptr()->vertex(cw(i))->point(),
ptr()->vertex(ccw(i))->point(),
t) != CGAL_LEFTTURN);
lt = OUTSIDE;
lt = OUTSIDE_CONVEX_HULL;
li = i;
return true;
}
@ -1399,7 +1433,7 @@ Line_face_circulator(const Face_handle& face,
default: // edge_vertex
{
if(_tr->is_infinite(ptr()->vertex(i))){
lt = OUTSIDE;
lt = OUTSIDE_CONVEX_HULL;
li = i;
return true;
}
@ -1504,13 +1538,7 @@ Line_face_circulator(const Face_handle& face,
&& (! _tr->is_infinite(ptr()->vertex(i)));
}
// private:
// o debug
public:
CGAL_Triangulation_2<Gt, Tds>* _tr;
State s;
int i;
Point p, q;
};
@ -1521,9 +1549,9 @@ Line_face_circulator(const Face_handle& face,
int& li) const
{
Face handle ff = infinite_face();
Face_handle ff = infinite_face();
int iv = ff->index(infinite_vertex());
Face_handle f = if->neighbor(iv);
Face_handle f = ff->neighbor(iv);
CGAL_Orientation pqt = geom_traits().orientation(f->vertex(0)->point(),
f->vertex(1)->point(),
t);
@ -1621,7 +1649,7 @@ Line_face_circulator(const Face_handle& face,
return f;
}
if (pqt == CGAL_LEFTTURN){
lt = OUTSIDE;
lt = OUTSIDE_CONVEX_HULL;
return f ;
}
@ -1646,11 +1674,11 @@ Line_face_circulator(const Face_handle& face,
int& li,
Face_handle start = Face_handle()) const
{
if(number_of_vertices() < 2) {
if( dimension() == 0) {
if(number_of_vertices() == 0) {
lt = OUTSIDE;
lt = OUTSIDE_AFFINE_HULL;
} else { // number_of_vertices() == 1
lt = (p == finite_vertex()->point()) ? VERTEX : OUTSIDE;
lt = (p == finite_vertex()->point()) ? VERTEX : OUTSIDE_AFFINE_HULL;
}
return NULL;
}
@ -2002,7 +2030,6 @@ template < class Gt, class Tds >
istream&
operator>>(istream& is, CGAL_Triangulation_2<Gt, Tds> &tr)
{
return operator>>(is, tr._tds);
}

View File

@ -62,12 +62,20 @@ public:
CGAL_Triangulation_face_circulator_2(const Vertex_handle& v)
: _bfc(&(*v))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ||
v->face()->dimension() == 1) { _bfc = Base_face_circulator();}
}
CGAL_Triangulation_face_circulator_2(const Vertex_handle& v,
const Face_handle& f)
: _bfc( &(*v), &(*f))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ||
v->face()->dimension() == 1) { _bfc = Base_face_circulator();}
}
@ -164,7 +172,7 @@ public:
typedef CGAL_Triangulation_face_circulator_2<Gt,Tds> Face_circulator;
typedef CGAL_Triangulation_edge_circulator_2<Gt,Tds> Edge_circulator;
typedef CGAL_Triangulation_vertex_circulator_2<Gt,Tds> Vertex_circulator;
typedef CGAL_Triangulation_vertex_circulator_2<Gt,Tds> Vertex_circulator;
static int ccw(int i)
@ -183,12 +191,18 @@ public:
CGAL_Triangulation_vertex_circulator_2(const Vertex_handle& v)
: _bvc(&(*v))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ) { _bvc = Base_vertex_circulator();}
}
CGAL_Triangulation_vertex_circulator_2(const Vertex_handle& v,
const Face_handle& f)
: _bvc( &(*v), &(*f))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ) { _bvc = Base_vertex_circulator();}
}
CGAL_Triangulation_vertex_circulator_2(const Vertex_circulator &vc)
: _bvc(vc._bvc)
@ -304,12 +318,18 @@ public:
CGAL_Triangulation_edge_circulator_2(const Vertex_handle& v)
: _bec(&(*v))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ) { _bec = Base_face_circulator();}
}
CGAL_Triangulation_edge_circulator_2(const Vertex_handle& v,
const Face_handle& f)
: _bec( &(*v), &(*f))
{}
{
if (v->face()==NULL ||
v->face()->dimension() == 0 ) { _bec = Base_face_circulator();}
}
CGAL_Triangulation_edge_circulator_2(const Vertex_circulator &ec)
: _bec(ec._bec)

View File

@ -1,3 +1,10 @@
// ============================================================================
//
// $Id$
//
// ============================================================================
#ifndef CGAL_TRIANGULATION_DEFAULT_DATA_STRUCTURE_2_H
#define CGAL_TRIANGULATION_DEFAULT_DATA_STRUCTURE_2_H
@ -14,7 +21,26 @@
#include <CGAL/Triangulation_ds_iterators_2.h>
#include <CGAL/Triangulation_ds_circulators_2.h>
template <class Tds>
class CGAL_Triangulation_ds_iterator_base_2;
template <class Tds>
class CGAL_Triangulation_ds_face_iterator_2;
template <class Tds>
class CGAL_Triangulation_ds_vertex_iterator_2;
template <class Tds>
class CGAL_Triangulation_ds_edge_iterator_2;
template<class Vertex, class Face>
class CGAL_Triangulation_ds_face_circulator_2;
template<class Vertex, class Face>
class CGAL_Triangulation_ds_vertex_circulator_2;
template<class Vertex, class Face>
class CGAL_Triangulation_ds_edges_circulator_2;
template < class Gt , class Vb, class Fb>
@ -22,12 +48,13 @@ class CGAL_Triangulation_default_data_structure_2
{
friend istream& operator>> CGAL_NULL_TMPL_ARGS
(istream& is, CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb>& tds);
friend CGAL_Triangulation_ds_iterator_base_2<CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> >;
friend CGAL_Triangulation_ds_face_iterator_2<CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> >;
friend CGAL_Triangulation_ds_vertex_iterator_2<CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> >;
friend CGAL_Triangulation_ds_edge_iterator_2<CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> >;
public:
typedef Gt Geom_traits;
//typedef typename Geom_traits::Point Point;
//typedef typename Geom_traits::Segment Segment;
//typedef typename Geom_traits::Triangle Triangle;
typedef CGAL_Triangulation_ds_vertex_2<Vb,Fb> Vertex;
typedef CGAL_Triangulation_ds_face_2<Vb,Fb> Face;
@ -41,30 +68,27 @@ public:
typedef CGAL_Triangulation_ds_face_circulator_2<Vertex,Face> Face_circulator;
typedef CGAL_Triangulation_ds_vertex_circulator_2<Vertex,Face> Vertex_circulator;
typedef CGAL_Triangulation_ds_edge_circulator_2<Vertex,Face> Edge_circulator;
//creators
CGAL_Triangulation_default_data_structure_2()
: _infinite_vertex(NULL),_finite_vertex(NULL), _number_of_vertices(1)
: _infinite_vertex(NULL),_number_of_vertices(0)
{ }
CGAL_Triangulation_default_data_structure_2(const Geom_traits& gt)
: _geom_traits(gt), _infinite_vertex(NULL), _finite_vertex(NULL),
_number_of_vertices(1), _dimension(0)
: _geom_traits(gt), _infinite_vertex(NULL),
_number_of_vertices(0), _dimension(0)
{ }
CGAL_Triangulation_default_data_structure_2(Vertex * v)
: _infinite_vertex(v),_finite_vertex(NULL),
_number_of_vertices(1), _dimension(0)
{
init(v);
CGAL_triangulation_postcondition( is_valid() );
}
CGAL_Triangulation_default_data_structure_2(Vertex * v, const Geom_traits& gt)
: _geom_traits(gt), _infinite_vertex(v), _finite_vertex(NULL),
_number_of_vertices(1), _dimension(0)
: _geom_traits(gt)
{
init(v);
CGAL_triangulation_postcondition( is_valid() );
@ -90,7 +114,6 @@ public:
private:
Geom_traits _geom_traits;
Vertex* _infinite_vertex;
Vertex* _finite_vertex; // to handle number_of_vertices == 1
int _number_of_vertices;
int _dimension;
@ -110,16 +133,13 @@ public:
}
const Geom_traits& geom_traits() const {return _geom_traits;}
private:
Vertex* finite_vertex() const
{
//CGAL_triangulation_precondition( number_of_vertices() > 0);
//this precondition plants the swap function
return _finite_vertex;
}
public:
//this should be private but
// it is used by >> input operator
// and apparently friend declaration does not work
Vertex* infinite_vertex() const {return _infinite_vertex; }
private:
Face* infinite_face() const
{
CGAL_triangulation_precondition( number_of_vertices() >= 2 &&
@ -137,8 +157,8 @@ private:
}
bool is_infinite(const Face* f, int i) const {
return is_infinite(f->vertex(ccw(i))) ||
is_infinite(f->vertex(cw(i)));
return ( is_infinite(f->vertex(ccw(i))) ||
is_infinite(f->vertex(cw(i))) );
}
bool is_infinite(Edge e) const {
@ -161,18 +181,9 @@ public:
void set_dimension (int n) {_dimension = n ;}
private:
void set_finite_vertex(Vertex* v) { _finite_vertex = v;}
// void set_finite_vertex(CGAL_NULL_TYPE v)
// {
// CGAL_triangulation_assertion( v == NULL);
// _finite_vertex=NULL;
// }
//
void set_infinite_vertex(Vertex* v) { _infinite_vertex = v;}
public:
// MODIFY
void flip(Face* f, int i)
{
@ -224,38 +235,21 @@ private:
void insert_second(Vertex* v)
{
CGAL_triangulation_precondition( number_of_vertices() == 1);
set_finite_vertex(v);
v->set_face(NULL);
set_number_of_vertices(2);
return;
}
void insert_third(Vertex* v)
{
CGAL_triangulation_precondition( number_of_vertices() == 2);
set_number_of_vertices(3);
set_dimension(1);
Face* f1 = new Face(infinite_vertex(), finite_vertex(), NULL,
NULL, NULL, NULL);
Face* f2 = new Face(finite_vertex(), v, NULL
NULL, NULL, NULL);
Face* f3 = new Face (v, infinite_vertex(), NULL,
NULL, NULL, NULL);
f1->set_neighbor(0, f2);
f1->set_neighbor(1, f2);
f2->set_neighbor(0, f3);
f2->set_neighbor(1, f1);
f3->set_neighbor(0, f1);
f3->set_neighbor(1, f2);
infinite_vertex()->set_face(f1);
finite_vertex()->set_face(f1);
CGAL_triangulation_precondition( number_of_vertices() == 1 &&
v != infinite_vertex());
Face * f1 = new Face( _infinite_vertex, NULL, NULL);
Face * f2 = new Face( v, NULL, NULL);
f1->set_neighbor(0,f2);
f2->set_neighbor(0,f1);
_infinite_vertex->set_face(f1);
v->set_face(f2);
set_number_of_vertices(2);
set_dimension(0);
return;
}
void insert_in_face(Vertex* v, Face* f)
//insert in face
// vertex v will replace f->vertex(0)
@ -299,7 +293,7 @@ private:
CGAL_triangulation_precondition(v != NULL && f != NULL);
CGAL_triangulation_precondition(dimension() >= 1);
if (dimension() == 1) {CGAL_triangulation_precondition( i=3);}
if (dimension() == 2) {CGAL_triangulation_preconditioni == 0 || i == 1 || i == 2);
if (dimension() == 2) {CGAL_triangulation_precondition(i == 0 || i == 1 || i == 2);}
if (dimension() == 1) {
Face * g = new Face(v,f->vertex(1),NULL, NULL, NULL, NULL);
@ -321,66 +315,85 @@ private:
}
void insert_outside_affine_hull(Vertex *v, Vertex *w, bool)
void insert_outside_affine_hull(Vertex *v, Vertex *w, bool orient)
{
// the following function insert
// a vertex v which is outside the convex hull of a 1 dim triangulation
// a vertex v which is outside the affine hull of a 1 dim or 0 dim triangulation
// w is the infinite vertex of the triangulation
// bool governs the orientation of the resulting triangulation
// orient governs the orientation of the resulting triangulation
list<Faces *> faces_list;
Face_iterator fit = faces.begin();
for ( ; fit != faces.end() ; fit ++){
faces_list.push_back(fit);
list<Face *> faces_list;
Face_iterator fit = faces_begin();
for ( ; fit != faces_end() ; ++fit){
faces_list.push_back( & (*fit));
}
list<Faces *> to_delete;
list<Faces *>::iterator fit = faces_list.begin();
list<Face *> to_delete;
list<Face *>::iterator lfit = faces_list.begin();
int i = dimension()+1; // maximun non NULL index in faces after the insertion
Face *f, *g;
for ( ; fit != faces.end() ; fit ++) {
Faces * f = * fit;
Faces * g = new Face(f);
f->set_vertex(3,v); f->set_neighbor(3,g);
g->set_vertex(3,w); g->set_neighbor(3,f);
for ( ; lfit != faces_list.end() ; ++lfit) {
f = * lfit;
g = new Face( f);
f->set_vertex(i,v); f->set_neighbor(i,g);
g->set_vertex(i,w); g->set_neighbor(i,f);
if (f->has_vertex(w)) to_delete.push_back(g); // flat face to be deleted later
}
fit = faces_list.begin();
for ( ; fit != faces.end() ; fit ++) {
Faces * f = * fit;
Faces * g = f->neighbor(3);
g->set_neighbor(1)= f->neighbor(1)->neighbor(3);
g->set_neighbor(2)= f->neighbor(2)->neighbor(3);
lfit = faces_list.begin();
for ( ; lfit != faces_list.end() ; ++lfit) {
f = * lfit;
g = f->neighbor(i);
for(int j = 0; j < i ; j++) {
g->set_neighbor(j, f->neighbor(j)->neighbor(i));
}
}
fit = faces_list.begin();
for( ;fit != faces.end(); fit ++){
if (bool) {Faces* f = (*fit)->neighbor(3);}
else { f = *fit;}
Vertex* vtemp = f->vertex(1);
f->set_vertex(1, f->vertex(2)) ; f->set_vertex(2,vtemp);
Faces* ftemp = f->neighbor(1); f->set_neighbor(1, f->neighbor(2));
f->set_neighbor(2,ftemp);
// couldn't unify the code for reorientation mater
if (dimension() == 0){
lfit = faces_list.begin() ; ++lfit;
f = *lfit;
Vertex* vtemp = f->vertex(0);
f->set_vertex(0, f->vertex(1)) ; f->set_vertex(1,vtemp);
Face* ftemp = f->neighbor(0); f->set_neighbor(0, f->neighbor(1));
f->set_neighbor(1,ftemp);
}
else { // dimension == 1
lfit = faces_list.begin();
for( ;lfit != faces_list.end(); ++lfit ){
if (orient) {f = (*lfit)->neighbor(2);}
else { f = *lfit;}
Vertex* vtemp = f->vertex(0);
f->set_vertex(0, f->vertex(1)) ; f->set_vertex(1,vtemp);
Face* ftemp = f->neighbor(0); f->set_neighbor(0, f->neighbor(1));
f->set_neighbor(1,ftemp);
}
}
fit = to_delete.begin();
for ( ;fit != to_delete.end(); fit ++){
Face* f = *fit ;
int i ;
if (f->vertex(0) != w) {i=0;}
else if (f->vertex(1) != w) {i=1}
else {i=2};
Faces f1= f->neighbor(cw(i)); int i1= f1->index(f);
Faces f2= f->neighbor(ccw(i)); int i2 = f2->index(f);
lfit = to_delete.begin();
Face *f1, *f2;
int i1, i2;
for ( ;lfit != to_delete.end(); ++lfit){
f = *lfit ;
int j ;
if (f->vertex(0) == w) {j=0;}
else {j=1;}
f1= f->neighbor(i); i1= f1->index(f);
f2= f->neighbor(j); i2 = f2->index(f);
f1->set_neighbor(i1,f2);
f2->set_neighbor(i2,f1);
delete f;
}
set_dimension(2);
set_number_of_vertices(number_of_vertices + 1);
v->set_face( *(faces_list.begin()));
set_dimension(dimension() + 1);
set_number_of_vertices(number_of_vertices() + 1);
}
void remove_degree_3(Vertex* v, Face* f = NULL)
// remove a vertex of degree 3
{
@ -424,108 +437,105 @@ private:
delete right;
delete left;
// // take care of _finite_vertex data member
// if (finite_vertex() == v){
// int i=f->index(v);
// Vertex* vv=is_infinite(f->vertex(cw(i))) ?
// f->vertex(ccw(i)) : f->vertex(cw(i));
// set_finite_vertex( vv);
// }
delete v;
set_number_of_vertices( number_of_vertices() -1);
}
void remove_2D_to_1D(Vertex* v)
void remove_down(Vertex* v)
{
CGAL_triangulation_precondition ( dimension==2 &&
number_of_vertices > 3);
// the faces incident to v are down graded to one dimensional faces
CGAL_triangulation_precondition ( (dimension() == 1 && number_of_vertices() == 3) ||
(dimension() == 2 && number_of_vertices() > 3) );
// the faces incident to v are down graded to one dimension
// the other faces are deleted
List<Face* > to_delete;
List<Face* > to_downgrade;
Face iterator fit = faces_begin();
list<Face* > to_delete;
list<Face* > to_downgrade;
Face_iterator fit = faces_begin();
if ( ! fit->has_vertex(v) ) { to_delete.push_back(&(*fit));}
else { to_downgrade.push_back(&(*fit));}
List<Face*>::iterator lfit = to_downgrade.begin();
int i;
list<Face*>::iterator lfit = to_downgrade.begin();
int j;
Face * f;
for( ; lfit != to_downgrade.end() ; lfit++) {
i = lfit->index(v);
switch(i) {
case 1 :
lfit->set_vertex(1, lfit->vertex(2));
lfit->set_vertex(2, lfit->vertex(3));
lfit->set_neighbor(1, lfit->neighbor(2));
lfit->set_neighbor(3, lfit->neighbor(3));
break;
case 2 :
lfit->set_vertex(2, lfit->vertex(1));
lfit->set_vertex(1, lfit->vertex(3));
lfit->set_neighbor(2, lfit->neighbor(1));
lfit->set_neighbor(1, lfit->neighbor(3));
break;
case 3 :
break;
f = *lfit; j = f->index(v);
if (dimension() == 1){
if (j == 0) {
f->set_vertex(0, f->vertex(1));
f->set_neighbor(0, f->neighbor(1));
}
f->set_vertex(1,NULL);
f->set_neighbor(1,NULL);
}
lfit->vertex(3,NULL);
lfit->neighbor(3,NULL);
else{ //dimension() == 2
switch(j) {
case 0 :
f->set_vertex(0, f->vertex(1));
f->set_vertex(1, f->vertex(2));
f->set_neighbor(0, f->neighbor(1));
f->set_neighbor(2, f->neighbor(2));
break;
case 1 :
f->set_vertex(1, f->vertex(0));
f->set_vertex(0, f->vertex(2));
f->set_neighbor(1, f->neighbor(0));
f->set_neighbor(0, f->neighbor(2));
break;
case 2 :
break;
}
f->set_vertex(2,NULL);
f->set_neighbor(2,NULL);
}
f->vertex(0)->set_face(f);
}
lfit = to_delete.begin();
for( ; lfit != to_delete.end() ; lfit++) {
delete lfit;
delete *lfit;
}
delete v;
set_number_of_vertices(number_of_vertices -1);
set_dimension(1);
set_number_of_vertices(number_of_vertices() -1);
set_dimension(dimension() -1);
return;
}
void remove_1D(Vertex* v)
{
}
void remove_third(Vertex* v)
// remove the before last vertex
{
CGAL_triangulation_precondition(number_of_vertices()== 3);
CGAL_triangulation_precondition(v != infinite_vertex);
// take care of finite_vertex data member
Face* f = v->face();
int i=f->index(v);
Vertex* vv=is_infinite(f->vertex(cw(i))) ?
f->vertex(ccw(i)) : f->vertex(cw(i));
set_finite_vertex( vv);
}
CGAL_triangulation_precondition( dimension() == 1 &&
number_of_vertices() >= 3);
Face* f = v->face();
delete f->neighbor(0);
delete f->neighbor(1);
delete;
int i = f->index(v);
if (i==0) {f = f->neighbor(1);}
CGAL_triangulation_assertion( f->index(v) == 1);
Face* g= f->neighbor(0);
f->set_vertex(1, g->vertex(1));
f->set_neighbor(0,g->neighbor(0));
g->neighbor(0)->set_neighbor(1,f);
g->vertex(1)->set_face(f);
delete g;
delete v;
set_number_of_vertices(2);
set_dimension(0);
set_number_of_vertices(number_of_vertices() -1);
return;
}
void remove_second(Vertex* v)
{
CGAL_triangulation_precondition(number_of_vertices()== 1);
CGAL_triangulation_precondition( finite_vertex()==v);
CGAL_triangulation_precondition(number_of_vertices()== 2);
delete v;
set_finite_vertex(NULL);
set_number_of_vertices(1);
infinite_vertex()->set_face(NULL);
return;
}
// ITERATOR METHODS
Face_iterator faces_begin() const
{
@ -570,9 +580,7 @@ void remove_third(Vertex* v)
// CHECKING
bool is_valid(bool verbose = false, int level = 0) const
{
if(number_of_vertices() <= 1){
return true;
}
if (number_of_vertices() <= 3) return true;
bool result = true;
CGAL_triangulation_assertion( is_infinite(infinite_vertex()->face()));
@ -612,26 +620,24 @@ void remove_third(Vertex* v)
++face_count;
result = result && it->is_valid(verbose, level);
CGAL_triangulation_assertion( it->is_valid(verbose, level) );
result = result && (! is_infinite( &(*it)));
CGAL_triangulation_assertion( ! is_infinite(&(*it)) );
++it;
}
}
Face_circulator fc(infinite_vertex());
Face_circulator fcdone(fc);
do {
result = result && fc->is_valid(verbose, level);
CGAL_triangulation_assertion( fc->is_valid(verbose, level) );
++face_count;
++edge_count;
}
while(++fc != fcdone);
// Face_circulator fc(infinite_vertex());
// Face_circulator fcdone(fc);
// do {
// result = result && fc->is_valid(verbose, level);
// CGAL_triangulation_assertion( fc->is_valid(verbose, level) );
// ++face_count;
// ++edge_count;
// }
// while(++fc != fcdone);
result = result && ( edge_count == 3* (vertex_count -1) );
CGAL_triangulation_assertion( edge_count == 3* (vertex_count -1) );
result = result && ( face_count == 2* (vertex_count -1) );
CGAL_triangulation_assertion( face_count == 2* (vertex_count -1) );
result = result && ( edge_count == 3*vertex_count - 6 );
CGAL_triangulation_assertion( edge_count == 3*vertex_count -6 );
result = result && ( face_count == 2*vertex_count - 4 );
CGAL_triangulation_assertion( face_count == 2*vertex_count - 4 );
return result;
}
@ -641,37 +647,43 @@ public:
void init(Vertex* v)
{
if( v == NULL ){
_infinite_vertex = new Vertex();
set_number_of_vertices(0);
} else if( v->face() == NULL ){
_infinite_vertex = new Vertex();
set_finite_vertex(v);
set_number_of_vertices(1);
} else if( (v->face()->neighbor(0) == v->face()->neighbor(1))
&&(v->face()->neighbor(0) == v->face()->neighbor(2)) ){
set_infinite_vertex(v);
Face* f = v->face();
int i = f->index(v);
set_finite_vertex(f->vertex(cw(i)));
set_number_of_vertices(2);
} else {
set_infinite_vertex(v);
Face* f = v->face();
int i = f->index(v);
set_finite_vertex(f->vertex(cw(i)));
// the following makes that the constructor of the
// vertex iterator class works correctly
set_number_of_vertices(3);
return;
}
set_infinite_vertex(v);
Vertex_iterator it = vertices_begin();
while(it != vertices_end()){
++_number_of_vertices;
++it;
}
set_number_of_vertices(number_of_vertices()-3);
if( v->face() == NULL ){ //only one vertex
set_number_of_vertices(1);
set_dimension(0);
return;
}
if( v->face()->neighbor(1) == NULL ){ //two vertices
set_number_of_vertices(2);
set_dimension(0);
return;
}
if( v->face()->neighbor(2) == NULL ){ //One dimensional triangulation
set_dimension(1);
}
else{
set_dimension(2);
}
//count number of vertices
set_number_of_vertices(2);
Vertex_iterator it = vertices_begin();
while(it != vertices_end()){
++_number_of_vertices;
++it;
}
set_number_of_vertices(number_of_vertices()-2);
return;
}
public:
void copy_tds(const Tds &tds)
{
@ -797,9 +809,9 @@ public:
if(number_of_vertices() == 0) return;
if(number_of_vertices()==1) {
infinite_vertex()->set_face(NULL);
delete _finite_vertex;
set_finite_vertex(NULL);
delete infinite_vertex();
set_infinite_vertex(NULL);
set_dimension(0);
set_number_of_vertices(0);
return;
}
@ -842,14 +854,11 @@ public:
}while(++it!=done);
}
infinite_vertex()->set_face(NULL);
set_finite_vertex(NULL);
set_infinite_vertex(NULL);
set_number_of_vertices(0);
set_dimension(0);
}
};
@ -862,15 +871,18 @@ operator>>(istream& is, CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb>&
typedef Gt Geom_traits;
typedef typename Vb::Point Point;
if(tds.number_of_vertices() != 0){
tds.clear();
if(tds.number_of_vertices() != 0){ //clear but keep infinite_vertex;
Vertex* vtemp = tds.infinite_vertex();
tds.clear();
tds.set_infinite_vertex(vtemp);
tds.infinite_vertex()->set_face(NULL);
}
int i = 0;
int n, m, d;
is >> n >> m >> d;
tds.set_number_of_vertices(n-1);
tds.set_number_of_vertices(n);
vector<Vertex* > V(n);
vector<Face*> F(m);
@ -896,7 +908,6 @@ operator>>(istream& is, CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb>&
V[i] = new Vertex(p);
}
tds.set_finite_vertex(V[i-1]);
if(n == 2){
return is;

View File

@ -1,4 +1,4 @@
#ifndef CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
#ifndef CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
#define CGAL_TRIANGULATION_DS_CIRCULATORS_2_H
@ -14,9 +14,14 @@ class CGAL_Triangulation_ds_face_circulator_2
: public CGAL_Bidirectional_circulator_base<Face,ptrdiff_t,size_t>
{
public:
typedef CGAL_Triangulation_ds_face_circulator_2<Vertex,Face> Face_circulator;
typedef CGAL_Triangulation_ds_face_circulator_2<Vertex,Face> Face_circulator;
private:
Vertex* _v;
Face* pos;
public :
static int ccw(int i)
{
return (i+1) % 3;
@ -35,12 +40,13 @@ public:
CGAL_Triangulation_ds_face_circulator_2(Vertex* v)
: pos(v->face()), _v(v)
{}
{ }
CGAL_Triangulation_ds_face_circulator_2(Vertex* v,
Face* f)
: pos(f),_v(v)
{}
CGAL_Triangulation_ds_face_circulator_2(Vertex* v, Face* f)
: pos(f),_v(v)
{
CGAL_triangulation_precondition( f->has_vertex(v));
}
CGAL_Triangulation_ds_face_circulator_2(const Face_circulator &fc)
@ -51,11 +57,11 @@ public:
Face_circulator& operator++()
{
CGAL_triangulation_precondition( (pos != NULL) && (_v != NULL) );
//then dimension() cannot be 0
int i = pos->index(_v);
pos = pos->neighbor(ccw(i));
if(pos == NULL){
pos = _v->face();
}
if(pos->dimension() == 1) {pos = pos->neighbor(1-i);} //for one dim case
else{pos = pos->neighbor(ccw(i));}
return *this;
}
@ -71,21 +77,8 @@ public:
{
CGAL_triangulation_precondition( (pos != NULL) && (_v != NULL) );
int i = pos->index(_v);
Face* f = pos->neighbor(cw(i));
if(f == NULL) {
Face* n;
do{
i = pos->index(_v);
// n = pos->neighbor(cw(i));
n = pos->neighbor(ccw(i));
if(n != NULL){
pos = n;
}
}while(n != NULL);
}
else{
pos = f;
}
if(pos->dimension() == 1) {pos = pos->neighbor(1-i);} //for one dim case
else {pos = pos->neighbor(cw(i));}
return *this;
}
@ -123,7 +116,7 @@ public:
operator==(CGAL_NULL_TYPE n) const
{
CGAL_triangulation_assertion( n == NULL);
return (_v == NULL) && (pos == NULL);
return (pos == NULL);
}
bool
@ -133,9 +126,6 @@ public:
return ! (*this == NULL);
}
private:
Vertex* _v;
Face* pos;
};
@ -158,30 +148,42 @@ public:
return (i+2) % 3;
}
private:
Vertex* _v;
Face* _f;
int _ri;
int _dim;
public:
CGAL_Triangulation_ds_vertex_circulator_2()
: _v(), _f(NULL)
: _v(NULL), _f(NULL), _dim(0)
{}
CGAL_Triangulation_ds_vertex_circulator_2(Vertex* v,
Face* f)
: _v( v ), _f(f)
{
if( _f != NULL ) {
int i = _f->index( _v );
_ri = ccw(i);
}
}
CGAL_Triangulation_ds_vertex_circulator_2(Vertex* v)
: _v( v ), _f(v->face())
{
if( _f != NULL ) {
int i = _f->index( _v );
_ri = ccw(i);
if (_f->dimension() == 2) {_ri = ccw(i);}
else {_ri = 1-i;}
}
}
CGAL_Triangulation_ds_vertex_circulator_2(Vertex* v,
Face* f)
: _v( v ), _f(f)
{
if( _f != NULL ) {
int i = _f->index( _v );
if (_f->dimension() == 2) {_ri = ccw(i);}
else {_ri = 1-i;}
}
}
CGAL_Triangulation_ds_vertex_circulator_2(const Vertex_circulator &vc)
: _ri(vc._ri), _v(vc._v), _f(vc._f)
{}
@ -207,20 +209,15 @@ public:
Vertex_circulator& operator++()
{
Face* n = _f;
int i = _f->index(_v);
n = _f->neighbor(ccw(i));
if(n == NULL){
if(_ri == ccw(i)){
_ri = cw(i);
} else {
_f = _v->face();
i = _f->index(_v);
_ri = ccw(i);
}
}
else {
_f = n;
CGAL_triangulation_precondition( (_f != NULL) && (_v != NULL) );
int i = _f->index(_v);
if (_f->dimension() == 1) {
_f = _f->neighbor(1-i);
_ri = 1 - _f->index(_v);
}
else{
_f = _f->neighbor(ccw(i));
i = _f->index(_v);
_ri = ccw(i);
}
@ -236,29 +233,17 @@ public:
Vertex_circulator& operator--()
{
Face* n = _f;
int i = _f->index(_v);
n = _f->neighbor(cw(i));
if(n == NULL) {
do{
n = _f->neighbor(ccw(i));
if(n != NULL){
_f = n;
i = _f->index(_v);
}
}while(n != NULL);
CGAL_triangulation_precondition( (_f != NULL) && (_v != NULL) );
int i = _f->index(_v);
if (_f->dimension() == 1) {
_f = _f->neighbor(1-i);
_ri = 1 - _f->index(_v);
}
else{
_f = _f->neighbor(cw(i));
i = _f->index(_v);
_ri = cw(i);
}
else {
if(_ri == cw(i)){
_ri = ccw(i);
}
else {
_f = n;
i = _f->index(_v);
_ri = ccw(i);
}
_ri = ccw(i);
}
return *this;
}
@ -285,7 +270,7 @@ public:
bool operator==(CGAL_NULL_TYPE n) const
{
CGAL_triangulation_assertion( n == NULL);
return (_v == NULL) && (_f == NULL);
return (_f == NULL);
}
@ -295,10 +280,6 @@ public:
return !(*this == NULL);
}
private:
int _ri;
Vertex* _v;
Face* _f;
};
@ -323,6 +304,12 @@ public:
return (i+2) % 3;
}
private:
int _ri;
Vertex* _v;
Face* _f;
public:
CGAL_Triangulation_ds_edge_circulator_2()
: _v(NULL), _f(NULL)
{}
@ -333,7 +320,8 @@ public:
{
if( _f != NULL ){
int i = _f->index(_v);
_ri = ccw(i);
if (_f->dimension() == 2) {_ri = ccw(i);}
else {_ri = 1-i;}
}
}
@ -343,7 +331,8 @@ public:
{
if( _f != NULL ){
int i = _f->index(_v);
_ri = ccw(i);
if (_f->dimension() == 2) {_ri = ccw(i);}
else {_ri = 1-i;}
}
}
@ -359,35 +348,27 @@ public:
return *this;
}
Edge&
Edge
operator*()
{
if( _f == NULL) {
return make_pair(_f, 0);
}
return make_pair(_f, _ri);
return make_pair(_f, _ri);
}
Edge_circulator& operator++()
{
Face* n = _f;
CGAL_triangulation_precondition( (_f != NULL) && (_v != NULL) );
int i = _f->index(_v);
n = _f->neighbor(ccw(i));
if(n == NULL){
if(_ri == ccw(i)){
_ri = cw(i);
}
else {
_f = _v->face();
i = _f->index(_v);
_ri = ccw(i);
}
}
else {
_f = n;
if (_f->dimension() == 1) {
_f = _f->neighbor(1-i);
_ri = 1 - _f->index(_v);
return *this;
}
else{
_f = _f->neighbor(ccw(i));
i = _f->index(_v);
_ri = ccw(i);
}
}
return *this;
}
@ -400,28 +381,19 @@ public:
Edge_circulator& operator--()
{
Face* n = _f;
CGAL_triangulation_precondition( (_f != NULL) && (_v != NULL) );
int i = _f->index(_v);
n = _f->neighbor(cw(i));
if(n == NULL){
do{
n = _f->neighbor(ccw(i));
if(n != NULL){
_f = n;
i = _f->index(_v);
}
}while(n != NULL);
i = _f->index(_v);
_ri = cw(i);
} else {
if(_ri == cw(i)){
_ri = ccw(i);
} else {
_f = n;
i = _f->index(_v);
_ri = ccw(i);
}
if (_f->dimension() == 1) {
_f = _f->neighbor(1-i);
_ri = 1 - _f->index(_v);
return *this;
}
else{
_f = _f->neighbor(cw(i));
i = _f->index(_v);
_ri = ccw(i);
}
return *this;
}
@ -445,7 +417,7 @@ public:
bool operator==(CGAL_NULL_TYPE n) const
{
CGAL_triangulation_assertion( n == NULL);
return (_v == NULL) && (_f == NULL);
return (_f == NULL);
}
bool operator!=(CGAL_NULL_TYPE n) const
@ -454,10 +426,7 @@ public:
return !(*this == NULL);
}
private:
int _ri;
Vertex* _v;
Face* _f;
};

View File

@ -31,6 +31,12 @@ public:
: Fb(v0,v1,v2,n0,n1,n2)
{}
CGAL_Triangulation_ds_face_2( const Face * f)
: Fb()
{
set_vertices(f->vertex(0), f->vertex(1), f->vertex(2));
set_neighbors(f->neighbor(0), f->neighbor(1), f->neighbor(2));
}
//setting
inline
@ -119,16 +125,13 @@ public:
}
//Miscelleanous
// inline int ccw(int i) const
// {
// return (i+1) % 3;
// }
//
// inline int cw(int i) const
// {
// return (i+2) % 3;
// }
//
int dimension()
{
if (vertex(2) != NULL) {return 2;}
else return( vertex(1) != NULL ? 1 : 0);
}
//Additionnal Operations

View File

@ -17,14 +17,6 @@ template <class Tds>
class CGAL_Triangulation_ds_iterator_base_2
{
public:
// typedef Gt Geom_traits;
//
// typedef CGAL_Triangulation_ds_vertex_2<Vb,Fb> Vertex;
// typedef CGAL_Triangulation_ds_face_2<Vb,Fb> Face;
// typedef pair<Face*, int> Edge;
//
// typedef CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
typedef typename Tds::Geom_traits Geom_traits;
typedef typename Tds::Vertex Vertex;
typedef typename Tds::Face Face;
@ -40,7 +32,7 @@ public:
if(_tds->number_of_vertices() < 2) {
return;
}
pos = _tds->infinite_face();
pos = _tds->infinite_vertex()->face();
}
CGAL_Triangulation_ds_iterator_base_2(Tds* tds, int i)
@ -55,7 +47,7 @@ protected:
Tds* _tds;
Face* pos;
public:
static
int
ccw(int i)
@ -75,6 +67,11 @@ protected:
void
increment()
{
if (_tds->dimension() == 1 || _tds->dimension() == 0){
pos = pos->neighbor(0);
return;
}
int max = maximum(pos);
Face* next=pos->neighbor(max); // tentative first child
Face* parent;
@ -106,7 +103,18 @@ protected:
void
decrement()
{
int max = maximum(pos);
if(_tds->dimension() == 0){
pos = pos->neighbor(0);
return;
}
if (_tds->dimension() == 1){
pos = pos->neighbor(1);
return;
}
// dimension() ==2
int max = maximum(pos);
Face* next=pos->neighbor(cw(max)); // parent of pos
int max2 = maximum(next);
if ( next->neighbor(max2) == pos) // pos is the first child of next
@ -174,33 +182,17 @@ protected:
{ return 0; }
}
};
//template < class Gt , class Vb, class Fb>
// the following iterator visit all the Tds faces
// whatever may be the dimensionality of those faces
template<class Tds>
class CGAL_Triangulation_ds_face_iterator_2
// : public CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb>,
// public bidirectional_iterator<CGAL_Triangulation_ds_face_2<Vb,Fb>, ptrdiff_t>
: public CGAL_Triangulation_ds_iterator_base_2<Tds>,
public bidirectional_iterator<typename Tds::Face, ptrdiff_t>
{
public:
// typedef Gt Geom_traits;
//
// typedef CGAL_Triangulation_ds_vertex_2<Vb,Fb> Vertex;
// typedef CGAL_Triangulation_ds_face_2<Vb,Fb> Face;
// typedef pair<Face*, int> Edge;
//
// typedef CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
// typedef CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb> Iterator_base;
//
// typedef CGAL_Triangulation_ds_face_iterator_2<Gt,Vb,Fb> Face_iterator;
// // typedef CGAL_Triangulation_ds_vertex_iterator_2<Gt,Vb,Fb> Vertex_iterator;
// // typedef CGAL_Triangulation_ds_edge_iterator_2<Gt,Vb,Fb> Edge_iterator;
//
typedef typename Tds::Geom_traits Geom_traits;
typedef typename Tds::Vertex Vertex;
typedef typename Tds::Face Face;
@ -214,20 +206,7 @@ public:
{}
CGAL_Triangulation_ds_face_iterator_2(Tds * tds)
: Iterator_base(tds)
{
if (tds->number_of_vertices()<2){
pos = NULL; // there is no faces
return;
}
Face* start = pos;
while (_tds->is_infinite(pos)){
increment();
if(pos == start){
pos = NULL; // there is no finite triangle
return;
}
}
}
{}
CGAL_Triangulation_ds_face_iterator_2(Tds* tds, int i)
: Iterator_base(tds,i)
@ -263,33 +242,30 @@ public:
{
if ( pos == NULL ){
return *this; // past-the-end iterator cannot advance
}
do{
increment();
if ( pos == (_tds->infinite_face()) ){
pos = NULL; // complete tour
return *this;
}
}while (_tds->is_infinite(pos));
} // include the case dimension()==0
increment();
if ( pos == _tds->infinite_face() ){
pos = NULL; // complete tour
}
return *this; // next finite triangle found
}
Face_iterator&
operator--()
{
if ( pos == NULL ) {// past the end iterator can decrease
*this = Face_iterator(_tds); // first finite triangle
} //next loop will go to last finite triangle
do{
decrement();
if ( pos == _tds->infinite_face()){
pos = NULL; // complete tour
return *this;
}
}while (_tds->is_infinite(pos));
return *this; // next finite triangle found
}
if (dimension() == 0) {return this;}
if (pos == _tds->infinite_face()) {
pos == NULL; //first face, can't decrement
return *this;
}
if (pos == NULL) { // past the end iterator, can decrease
*this = Face_iterator(_tds); //first face, decrement will give the last one if any
}
decrement();
return *this;
}
Face_iterator
operator++(int)
@ -322,27 +298,13 @@ public:
};
//template < class Gt , class Vb, class Fb>
template < class Tds>
class CGAL_Triangulation_ds_vertex_iterator_2
// : public CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb>,
// public bidirectional_iterator<CGAL_Triangulation_ds_vertex_2<Vb,Fb>, ptrdiff_t>
: public CGAL_Triangulation_ds_iterator_base_2<Tds>,
public bidirectional_iterator<typename Tds::Vertex, ptrdiff_t>
{
public:
// typedef Gt Geom_traits;
//
// typedef CGAL_Triangulation_ds_vertex_2<Vb,Fb> Vertex;
// typedef CGAL_Triangulation_ds_face_2<Vb,Fb> Face;
// typedef pair<Face*, int> Edge;
//
// typedef CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
// typedef CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb> Iterator_base;
//
// typedef CGAL_Triangulation_ds_face_iterator_2<Gt,Vb,Fb> Face_iterator;
// typedef CGAL_Triangulation_ds_vertex_iterator_2<Gt,Vb,Fb> Vertex_iterator;
//
typedef typename Tds::Geom_traits Geom_traits;
typedef typename Tds::Vertex Vertex;
typedef typename Tds::Face Face;
@ -352,57 +314,86 @@ public:
typedef CGAL_Triangulation_ds_vertex_iterator_2<Tds> Vertex_iterator;
private :
int index;
public:
CGAL_Triangulation_ds_vertex_iterator_2()
: Iterator_base()
: Iterator_base(), index(0)
{}
CGAL_Triangulation_ds_vertex_iterator_2(Tds * tds)
: Iterator_base(tds)
: Iterator_base(tds), index(0)
{
switch( _tds->number_of_vertices() ){
switch( tds->number_of_vertices() ){
case 0: // past-the-end
pos = NULL;
return;
case 1:
pos = (Face*)1 ; // different from any pointer;
return; // "points" to the only vertex of the triangulation
pos = (Face*)1 ; // different from any pointer;
return; // the iterator must "point" to the only vertex of the triangulation
default:
{
pos = _tds->infinite_face();
while ( associated_vertex() ==NULL){
increment();
}
return;
}
}
pos = tds->infinite_face();
index = 0;
while ( ! associated_vertex()){
increment();
}
return;
}
}
CGAL_Triangulation_ds_vertex_iterator_2(Tds* tds, int i)
: Iterator_base(tds,i)
: Iterator_base(tds,i), index(0)
{}
private:
void increment()
{
if ( index==_tds->dimension()) {Iterator_base::increment(); index = 0;}
else { index +=1; }
return;
}
void decrement()
{
if (index == 0) {
Iterator_base::decrement();
index = _tds->dimension();
}
else {index -= 1;}
return;
}
bool associated_vertex()
{
return ( pos->vertex(index)->face() == pos ); // marche en toute dimension
}
public:
Vertex_iterator&
operator++()
{
if (pos==NULL){
return *this; // cannot advance past-the-end iterator
}
if (_tds->number_of_vertices()==1){
pos = NULL; // past-the-end
return *this;
}
} // include the case number_of_vertices() == 0
if (pos==(Face*)1){
pos == NULL; //number_of_vertices() == 1
return *this;
}
do{
increment();
if ( pos == _tds->infinite_face()){
if ( pos == _tds->infinite_face() && index == 0){
pos = NULL; // complete tour
return *this;
}
}while ( associated_vertex() ==NULL);
}while ( ! associated_vertex() );
return *this;
}
public:
Vertex_iterator&
operator--()
{
@ -417,19 +408,22 @@ public:
}
return *this; // can decrease past-the-end iterator
default:
if (pos==NULL){
*this = Vertex_iterator(_tds);
--*this;
return *this; // can decrease past-the-end iterator
}
do{
decrement();
if ( pos == _tds->infinite_face()){
pos = NULL; // complete tour
return *this;
}
}while ( associated_vertex() ==NULL);
return *this;
if (pos == _tds->infinite_face() && index == 0){ //first position, cannot decrease
pos = NULL;
return *this;
}
if (pos==NULL){ // can decrease past-the-end iterator
*this = Vertex_iterator(_tds);
}
do{
decrement();
if ( pos == _tds->infinite_face() && index == 0){
pos = NULL; // complete tour
return *this;
}
}while ( ! associated_vertex());
return *this;
}
}
@ -450,9 +444,19 @@ public:
}
bool operator==(const Vertex_iterator& fi) const
{
return ( (pos == fi.pos ) && (_tds ==fi._tds) );
{
if ((pos==fi.pos)&&(_tds==fi._tds)){
if (pos==NULL) {
return true;
}else{
return (index == fi.index);
}
}
else{
return false;
}
}
bool operator!=(const Vertex_iterator& fi) const
{
@ -461,89 +465,26 @@ public:
inline Vertex& operator*() const
{
return *(associated_vertex());
return *(pos->vertex(index));
}
inline Vertex* operator->() const
{
return associated_vertex();
return pos->vertex(index);
}
Vertex*
associated_vertex() const
{
if(pos == NULL) {
return NULL;
}
switch(_tds->number_of_vertices() ){
case 0:
return NULL;
case 1:
return _tds->finite_vertex();
case 2:
return pos->vertex(cw(maximum(pos)));
default:
{
int i = cw(maximum(pos)); // candidate associate vertex
if(_tds->geom_traits().compare_y(pos->vertex(i)->point(),
pos->vertex(cw(i))->point())
==CGAL_LARGER){
// vcw(i) < vi
return pos->vertex(i);
}
if ( _tds->is_infinite(pos)){
Face* f=pos->neighbor(cw(i));
// next edge on the CH in cw order
int j=f->index(_tds->infinite_vertex() );
CGAL_Comparison_result comp =
_tds->geom_traits().compare_y(pos->vertex(i)->point(),
f->vertex(cw(j))->point());
if (comp == CGAL_SMALLER){ // vi smaller vertex
return pos->vertex(i);
}
if(comp ==CGAL_EQUAL){ // horizontal part of CH
comp = _tds->geom_traits().compare_x(
pos->vertex(i)->point(),
f->vertex(cw(j))->point());
if(comp == CGAL_LARGER){ // lower hull
return pos->vertex(i);
}
if(pos->vertex(cw(i)) == f->vertex(cw(j))){ // 1 dim. horiz.
return pos->vertex(i);
}
}
}
}
}
return NULL;
}
};
//template < class Gt , class Vb, class Fb>
template <class Tds>
class CGAL_Triangulation_ds_edge_iterator_2
// : public CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb>,
// public bidirectional_iterator<pair<CGAL_Triangulation_ds_face_2<Vb,Fb>,int>, ptrdiff_t>
: public CGAL_Triangulation_ds_iterator_base_2<Tds>,
public bidirectional_iterator<typename Tds::Edge, ptrdiff_t>
{
public:
// // typedef Gt Geom_traits;
// //
// // typedef CGAL_Triangulation_ds_vertex_2<Vb,Fb> Vertex;
// // typedef CGAL_Triangulation_ds_face_2<Vb,Fb> Face;
// // typedef pair<Face*, int> Edge;
// //
// // typedef CGAL_Triangulation_default_data_structure_2<Gt,Vb,Fb> Tds;
// typedef CGAL_Triangulation_ds_iterator_base_2<Gt,Vb,Fb> Iterator_base;
//
// // typedef CGAL_Triangulation_ds_face_iterator_2<Gt,Vb,Fb> Face_iterator;
// // typedef CGAL_Triangulation_ds_vertex_iterator_2<Gt,Vb,Fb> Vertex_iterator;
// typedef CGAL_Triangulation_ds_edge_iterator_2<Gt,Vb,Fb> Edge_iterator;
//
typedef typename Tds::Geom_traits Geom_traits;
typedef typename Tds::Vertex Vertex;
typedef typename Tds::Face Face;
@ -552,32 +493,36 @@ public:
typedef CGAL_Triangulation_ds_iterator_base_2<Tds> Iterator_base;
typedef CGAL_Triangulation_ds_edge_iterator_2<Tds> Edge_iterator;
private:
int index;
public:
CGAL_Triangulation_ds_edge_iterator_2()
: Iterator_base(),status(0)
: Iterator_base(),index(0)
{}
CGAL_Triangulation_ds_edge_iterator_2(Tds * tds)
: Iterator_base(tds)
: Iterator_base(tds), index(0)
{
if (tds->number_of_vertices()<2){
pos = NULL; // there is no finite edge
if (_tds->dimension()== 0){
pos = NULL; // there is no edge
return;
}
pos = tds->infinite_face();
Face* start = pos;
while ( ! compute_status(true) ){
pos = _tds->infinite_face();
if (_tds->dimension() == 1) {index = 2;}
else {index = 0;}
while ( !associated_edge() ){
increment();
if(pos == start){
pos=NULL; // there is no finite triangle
return;
}
}
}
}
CGAL_Triangulation_ds_edge_iterator_2(Tds* tds, int i)
: Iterator_base(tds,i),status(0)
{}
: Iterator_base(tds,i),index(0)
{
if (_tds->dimension() == 1) {index = 2;}
}
bool
operator==(const Edge_iterator& fi) const
@ -586,7 +531,7 @@ public:
if (pos==NULL) {
return true;
}else{
return (status==fi.status);
return (index==fi.index);
}
}
else{
@ -600,23 +545,84 @@ public:
{
return ! (*this == fi);
}
private:
void increment()
{
if (_tds->dimension() == 1) {Iterator_base::increment();}
else {
if (index == 2) {
Iterator_base::increment();
index = 0;
}
else{
index +=1;
}
}
return;
}
void decrement()
{
if (_tds->dimension() == 1) {Iterator_base::increment();}
else {
if (index == 0) {
Iterator_base::decrement();
index = 2;
}
else {index -= 1;}
return;
}
}
bool associated_edge()
{
if (_tds->dimension() == 1) {return true;}
int max = maximum(pos);
if (index == cw(max)) {return true; }
if (index == ccw(max)) { return false;}
// index = maximun(pos)
if ( pos->vertex(max) != _tds->infinite_vertex()){
return ( _tds->geom_traits().compare_y(pos->vertex(cw(max))->point(),
pos->vertex(ccw(max))->point())
== CGAL_LARGER);
}
else{ //pos->vertex(max) == infinite_vertex(), convex hull edge
return ( _tds->geom_traits().compare_y(pos->vertex(cw(max))->point(),
pos->vertex(ccw(max))->point())
== CGAL_LARGER ||
(_tds->geom_traits().compare_y(pos->vertex(cw(max))->point(),
pos->vertex(ccw(max))->point())
== CGAL_EQUAL // convex hull horizntal edges
&&
_tds->geom_traits().compare_x(pos->vertex(cw(max))->point(),
pos->vertex(ccw(max))->point())
== CGAL_SMALLER )
);
}
}
public:
Edge_iterator&
operator++()
{
if (pos==NULL){
return *this; // cannot advance past-the-end iterator
}
if ( (status >=3) && (status <=5) ) {
// current status is 3 + ccw(i), next status is 6+i
status = 6 + cw( status -3);
} else do{
if(_tds->dimension()==1){
Iterator_base::increment();
if ( pos == _tds->infinite_face()) { pos = NULL ; return *this;}
}
else{
do{
increment();
if ( pos == _tds->infinite_face()){
pos = NULL; // tour complete
return *this;
if ( pos == _tds->infinite_face() && index == 0){
pos = NULL; // complete tour
return *this;
}
}while (!compute_status(true));
}while ( ! associated_edge() );
}
return *this;
}
@ -626,22 +632,31 @@ Edge_iterator&
Edge_iterator&
operator--()
{
if (pos==NULL){
*this = Edge_iterator(_tds);
--*this;
return *this; // can decrease past-the=end iteartor
}
if ( (status >=3) && (status <=5) ) {
// current status is 6+i, next status is 3 + ccw(i)
status = 3 + ccw( status -6);
} else do{
decrement();
if ( pos == triangulation->infinite_face()){
pos = NULL; // tour complete
return *this;
}
}while (compute_status(false));
return *this;
switch(_tds->dimension()){
case 0:
return *this;
case 1:
if (pos == _tds->infinite_face()) { pos=NULL; return *this;}
if (pos == NULL) { pos= _tds->infinite_face;}
decrement();
return *this;
case 2:
if (pos == _tds->infinite_face() && index == 0){
pos == NULL; //first edge, cannot decrement
return this;
}
if (pos == NULL){ //past the end, can decrement;
*this = Edge_iterator(_tds);
}
do{
decrement();
if ( pos == _tds->infinite_face() && index == 0){
pos = NULL; // complete tour
return *this;
}
}while ( ! associated_edge());
return *this;
}
}
@ -665,58 +680,7 @@ Edge_iterator&
Edge
operator*() const
{
int j = (status<3) ? status : (status<6) ? status-3 : status-6;
return make_pair(pos, j);
}
private:
int status;
bool
compute_status(bool forward)
{
if (pos == NULL){
return false;
}
int i = maximum(pos); // higher point
if ( ! _tds->is_infinite(pos)){
if(_tds->geom_traits().compare_y(pos->vertex(cw(i))->point(),
pos->vertex(ccw(i))->point())
== CGAL_LARGER){
// vccw(i) < vcw(i)
// right edges = i cw(i) cw(i) ccw(i)
status = (forward) ? 3+ccw(i) : 6+i;
} else {
// right edge = i cw(i)
status = ccw(i);
}
return true;
}
CGAL_Comparison_result comp = _tds->geom_traits().compare_y(
pos->vertex(cw(i))->point(),
pos->vertex(ccw(i))->point());
if( comp==CGAL_SMALLER){
return false;
}
if( comp==CGAL_LARGER){
// vccw(i) < vcw(i)
// right edge = cw(i) ccw(i)
status = i;
return true;
}
// comp = CGAL_EQUAL
if ( _tds->geom_traits().compare_x(pos->vertex(cw(i))->point(),
pos->vertex(ccw(i))->point())
== CGAL_SMALLER){
// vccw(i) < vcw(i)
// upper horizontal edge = cw(i) ccw(i)
status = i;
return true;
}
return false;
return make_pair(pos, index);
}
};

View File

@ -34,40 +34,46 @@ public:
typedef typename Tds::Face Fa;
typedef typename Tds::Face_iterator Iterator_base;
typedef CGAL_Triangulation_face_2<Gt,Tds> Face;
typedef CGAL_Triangulation_vertex_2<Gt,Tds> Vertex;
typedef typename Vertex::Vertex_handle Vertex_handle;
typedef typename Face::Face_handle Face_handle;
typedef pair<Face_handle, int> Edge;
typedef CGAL_Triangulation_2<Gt,Tds> Triangulation;
typedef typename Triangulation::Face Face;
typedef typename Triangulation::Vertex Vertex;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Face_handle Face_handle;
typedef typename Triangulation::Edge Edge;
typedef CGAL_Triangulation_face_iterator_2<Gt,Tds> Face_iterator;
typedef CGAL_Triangulation_edge_iterator_2<Gt,Tds> Edge_iterator;
typedef CGAL_Triangulation_vertex_iterator_2<Gt,Tds> Vertex_iterator;
static int ccw(int i)
{
return (i+1) % 3;
}
static int cw(int i)
{
return (i+2) % 3;
}
private:
Iterator_base _ib;
Triangulation* _tr;
public:
CGAL_Triangulation_face_iterator_2()
: _ib()
: _ib(), _tr(NULL)
{}
CGAL_Triangulation_face_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr)
: _ib( &(tr->_tds))
{ }
: _ib( &(tr->_tds)), _tr(tr)
{
if (tr->dimension() == 0 ||tr->dimension() ==1){
_ib = Iterator_base(&(tr->_tds),1);
return;
}
while ( _ib != Iterator_base(&(tr->_tds),1) && _tr->is_infinite((Face *) &(*_ib))){
++_ib;
}
return;
}
CGAL_Triangulation_face_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr, int i)
: _ib( &(tr->_tds), i)
: _ib( &(tr->_tds), i), _tr(tr)
{ }
CGAL_Triangulation_face_iterator_2(const Face_iterator& fi)
: _ib(fi._ib)
: _ib(fi._ib), _tr(fi._tr)
{}
@ -75,13 +81,14 @@ public:
operator=(const Face_iterator& fi)
{
_ib = fi._ib;
_tr = fi._tr;
return *this;
}
bool
operator==(const Face_iterator& fi) const
{
return ( _ib == fi._ib);
return ( _tr == fi._tr && _ib == fi._ib);
}
bool
@ -93,14 +100,20 @@ public:
Face_iterator&
operator++()
{
++_ib;
++_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *)&( *_ib))){
++_ib;
}
return *this;
}
Face_iterator&
operator--()
{
--_ib;
--ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *) &(*_ib))){
--_ib;
}
return *this;
}
@ -131,8 +144,6 @@ public:
return (Face*)( & (*_ib));
}
private:
Iterator_base _ib;
};
@ -145,46 +156,48 @@ public:
typedef typename Tds::Face Fa;
typedef typename Tds::Vertex_iterator Iterator_base;
typedef CGAL_Triangulation_face_2<Gt,Tds> Face;
typedef CGAL_Triangulation_vertex_2<Gt,Tds> Vertex;
typedef typename Vertex::Vertex_handle Vertex_handle;
typedef typename Face::Face_handle Face_handle;
typedef pair<Face_handle, int> Edge;
typedef CGAL_Triangulation_2<Gt,Tds> Triangulation;
typedef typename Triangulation::Face Face;
typedef typename Triangulation::Vertex Vertex;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Face_handle Face_handle;
typedef typename Triangulation::Edge Edge;
typedef CGAL_Triangulation_face_iterator_2<Gt,Tds> Face_iterator;
typedef CGAL_Triangulation_edge_iterator_2<Gt,Tds> Edge_iterator;
typedef CGAL_Triangulation_vertex_iterator_2<Gt,Tds> Vertex_iterator;
static int ccw(int i)
{
return (i+1) % 3;
}
static int cw(int i)
{
return (i+2) % 3;
}
private:
Iterator_base _ib;
Triangulation* _tr;
public:
CGAL_Triangulation_vertex_iterator_2()
: _ib()
: _ib(),_tr(NULL)
{}
CGAL_Triangulation_vertex_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr)
: _ib( &(tr->_tds))
{ }
: _ib( &(tr->_tds)), _tr(tr)
{
if (_tr->number_of_vertices() == 0) { _ib = Iterator_base(&(tr->_tds),1);}
//else if ( _tr->is_infinite( (Vertex &) *_ib) ) { ++_ib;}
else if ( _tr->is_infinite( (Vertex *) &(*_ib)) ){ ++_ib;}
return;
}
CGAL_Triangulation_vertex_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr, int i)
: _ib( &(tr->_tds), i)
{ }
: _ib( &(tr->_tds), i), _tr(tr)
{ }
CGAL_Triangulation_vertex_iterator_2(const Vertex_iterator& vi)
: _ib(vi._ib)
: _ib(vi._ib), _tr(vi._tr)
{}
Vertex_iterator&
operator=(const Vertex_iterator& vi)
{
_tr = vi._tr;
_ib = vi._ib;
return *this;
}
@ -192,7 +205,7 @@ public:
bool
operator==(const Vertex_iterator& vi) const
{
return ( _ib == vi._ib);
return ( _tr == vi._tr && _ib == vi._ib);
}
bool
@ -204,7 +217,10 @@ public:
Vertex_iterator&
operator++()
{
++_ib;
++_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Vertex *) &(*_ib))){
++_ib;
}
return *this;
}
@ -212,6 +228,9 @@ public:
operator--()
{
--_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Vertex *) &(*_ib))){
--_ib;
}
return *this;
}
@ -242,8 +261,6 @@ public:
return (Vertex*)( & (*_ib));
}
private:
Iterator_base _ib;
};
@ -256,46 +273,53 @@ public:
typedef typename Tds::Face Fa;
typedef typename Tds::Edge_iterator Iterator_base;
typedef CGAL_Triangulation_face_2<Gt,Tds> Face;
typedef CGAL_Triangulation_vertex_2<Gt,Tds> Vertex;
typedef typename Vertex::Vertex_handle Vertex_handle;
typedef typename Face::Face_handle Face_handle;
typedef pair<Face_handle, int> Edge;
typedef CGAL_Triangulation_2<Gt,Tds> Triangulation;
typedef typename Triangulation::Face Face;
typedef typename Triangulation::Vertex Vertex;
typedef typename Triangulation::Vertex_handle Vertex_handle;
typedef typename Triangulation::Face_handle Face_handle;
typedef typename Triangulation::Edge Edge;
typedef CGAL_Triangulation_face_iterator_2<Gt,Tds> Face_iterator;
typedef CGAL_Triangulation_edge_iterator_2<Gt,Tds> Edge_iterator;
typedef CGAL_Triangulation_vertex_iterator_2<Gt,Tds> Vertex_iterator;
static int ccw(int i)
{
return (i+1) % 3;
}
static int cw(int i)
{
return (i+2) % 3;
}
private:
Iterator_base _ib;
Triangulation* _tr;
public:
CGAL_Triangulation_edge_iterator_2()
: _ib()
: _ib(), _tr(NULL)
{}
CGAL_Triangulation_edge_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr)
: _ib( &(tr->_tds))
{ }
: _ib( &(tr->_tds)), _tr(tr)
{
if (_tr->dimension() == 0 ) {
_ib = Iterator_base(&(tr->_tds),1);
return;
}
while ( _ib != Iterator_base(&(tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
++_ib;
}
return;
}
CGAL_Triangulation_edge_iterator_2(CGAL_Triangulation_2<Gt,Tds> *tr, int i)
: _ib( &(tr->_tds), i)
: _ib( &(tr->_tds), i), _tr(tr)
{ }
CGAL_Triangulation_edge_iterator_2(const Edge_iterator& ei)
: _ib(ei._ib)
: _ib(ei._ib), _tr(ei._tr)
{}
Edge_iterator&
operator=(const Edge_iterator& ei)
{
_tr = ei._tr;
_ib = ei._ib;
return *this;
}
@ -303,7 +327,7 @@ public:
bool
operator==(const Edge_iterator& ei) const
{
return ( _ib == ei._ib);
return ( _tr == ei._tr && _ib == ei._ib);
}
bool
@ -315,7 +339,10 @@ public:
Edge_iterator&
operator++()
{
++_ib;
++_ib;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), (*_ib).second)){
++_ib;
}
return *this;
}
@ -323,7 +350,10 @@ public:
operator--()
{
--_ib;
return *this;
while ( _ib != Iterator_base(&(_tr->_tds),1) && _tr->is_infinite((Face *)((*_ib).first), *_ib.second)){
--_ib;
}
return *this;
}
Edge_iterator
@ -349,10 +379,6 @@ public:
return make_pair( fh , (*_ib).second );
}
private:
Iterator_base _ib ;
};