mirror of https://github.com/CGAL/cgal
moved the following functions to the Tds class
insert_in_face, insert_on_edge, remove_degree_3
This commit is contained in:
parent
54f673c71d
commit
f7b39a717e
|
|
@ -259,9 +259,38 @@ public:
|
|||
|
||||
void insert_in_face(Vertex* v, Face* f)
|
||||
//insert in face
|
||||
// vertex v will replace f->vertex(0)
|
||||
{
|
||||
CGAL_triangulation_precondition( v != NULL & f != NULL);
|
||||
f->insert_in_face(v);
|
||||
|
||||
Vertex* v0 = f->vertex(0);
|
||||
Vertex* v2 = f->vertex(2);
|
||||
Vertex* v1 = f->vertex(1);
|
||||
|
||||
Face* n1 = f->neighbor(1);
|
||||
Face* n2 = f->neighbor(2);
|
||||
int i1,i2 ;
|
||||
if (n1 != NULL) {i1= cw(n1->index(f->vertex(cw(1))));}
|
||||
if (n2 != NULL) {i2 = cw(n2->index(f->vertex(cw(2))));}
|
||||
|
||||
Face* f1 = new Face(v0, v, v2,
|
||||
f, n1, NULL);
|
||||
|
||||
Face* f2 = new Face(v0, v1, v,
|
||||
f, NULL, n2);
|
||||
|
||||
f1->set_neighbor(2, f2);
|
||||
f2->set_neighbor(1, f1);
|
||||
if (n1 != NULL) {n1->set_neighbor(i1,f1);}
|
||||
if (n2 != NULL) {n2->set_neighbor(i2,f2);}
|
||||
|
||||
f->set_vertex(0, v);
|
||||
f->set_neighbor(1, f1);
|
||||
f->set_neighbor(2, f2);
|
||||
|
||||
if( v0->face() == f ) { v0->set_face(f2); }
|
||||
v->set_face(f);
|
||||
|
||||
set_number_of_vertices(number_of_vertices() +1);
|
||||
}
|
||||
|
||||
|
|
@ -281,9 +310,9 @@ public:
|
|||
int in;
|
||||
CGAL_triangulation_assertion( n->has_vertex(f->vertex(cw(i)), in));
|
||||
in = cw(in);
|
||||
f->insert_in_face(v);
|
||||
insert_in_face(v,f);
|
||||
flip(n,in);
|
||||
set_number_of_vertices(number_of_vertices() +1);
|
||||
return;
|
||||
}
|
||||
|
||||
// the following function insert in 1_dim triangulation
|
||||
|
|
@ -310,20 +339,46 @@ public:
|
|||
void remove_degree_3(Vertex* v, Face* f = NULL)
|
||||
// remove a vertex of degree 3
|
||||
{
|
||||
CGAL_triangulation_assertion(v != NULL);
|
||||
CGAL_triangulation_assertion(v != _infinite_vertex);
|
||||
CGAL_triangulation_assertion(v->degree() == 3);
|
||||
|
||||
// this cannot happens because of third assertion;
|
||||
// if (number_of_vertices()==1){
|
||||
// set_number_of_vertices(0);
|
||||
// set_finite_vertex(NULL);
|
||||
// delete v;
|
||||
// return;
|
||||
// }
|
||||
CGAL_triangulation_precondition(v != NULL);
|
||||
CGAL_triangulation_precondition(v != _infinite_vertex);
|
||||
CGAL_triangulation_precondition(v->degree() == 3);
|
||||
|
||||
if (f == NULL) {f= v->face();}
|
||||
else { CGAL_triangulation_assertion( f->has_vertex(v));}
|
||||
|
||||
int i = f->index(v);
|
||||
Face* left = f->neighbor(cw(i));
|
||||
Face* right = f->neighbor(ccw(i));
|
||||
Face *ll, *rr;
|
||||
|
||||
int li = left->index(this);
|
||||
int ri = right->index(this);
|
||||
Vertex* q = left->vertex(li);
|
||||
CGAL_triangulation_assertion( left->vertex(li) == right->vertex(ri));
|
||||
|
||||
ll = left->neighbor(cw(li));
|
||||
if(ll != NULL) {
|
||||
int lli = ll->index(left);
|
||||
ll->set_neighbor(lli, f);
|
||||
}
|
||||
f->set_neighbor(cw(i), ll);
|
||||
if (f->vertex(ccw(i))->face() == left) f->vertex(ccw(i))->set_face(f);
|
||||
|
||||
rr = right->neighbor(ccw(ri));
|
||||
if(rr != NULL) {
|
||||
int rri = rr->index(right);
|
||||
rr->set_neighbor(rri, f);
|
||||
}
|
||||
f->set_neighbor(ccw(i), rr);
|
||||
if (f->vertex(cw(i))->face() == right) f->vertex(cw(i))->set_face(f);
|
||||
|
||||
f->set_vertex(i, q);
|
||||
if (q->face() == right || q->face() == left) {
|
||||
q->set_face(f);
|
||||
}
|
||||
delete right;
|
||||
delete left;
|
||||
|
||||
// take care of _finite_vertex data member
|
||||
if (finite_vertex() == v){
|
||||
int i=f->index(v);
|
||||
|
|
@ -332,23 +387,8 @@ public:
|
|||
set_finite_vertex( vv);
|
||||
}
|
||||
|
||||
// this cannot happens because of third assertion;
|
||||
// if (number_of_vertices() == 2){
|
||||
// Face* ff = f->neighbor(f->index(infinite_vertex()));
|
||||
// delete f;
|
||||
// delete ff;
|
||||
// delete v;
|
||||
// set_number_of_vertices(1);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
f->remove(v); //f->remove returns true because degree 3 has been asserted
|
||||
delete v;
|
||||
//update number of vertices
|
||||
// Vertex* vv= finite_vertex();
|
||||
//Face* f = vv->face();
|
||||
set_number_of_vertices( number_of_vertices() -1);
|
||||
}
|
||||
delete v;
|
||||
set_number_of_vertices( number_of_vertices() -1);
|
||||
}
|
||||
|
||||
void remove_second(Vertex* v)
|
||||
|
|
|
|||
|
|
@ -131,65 +131,61 @@ public:
|
|||
//
|
||||
|
||||
//Additionnal Operations
|
||||
void insert_in_face(Vertex*& v)
|
||||
{
|
||||
CGAL_triangulation_precondition(v != NULL);
|
||||
Vertex* v0 = vertex(0);
|
||||
Vertex* v2 = vertex(2);
|
||||
Vertex* v1 =vertex(1);
|
||||
|
||||
Face* f1 = neighbor(1);
|
||||
Face* f2 = neighbor(2);
|
||||
int i1 = cw(f1->index(vertex(cw(1))));
|
||||
int i2 = cw(f2->index(vertex(cw(2))));
|
||||
|
||||
int ccwi, cwi;
|
||||
if(ccwptr != NULL) {
|
||||
ccwi = cw(ccwptr->index(v0));
|
||||
}
|
||||
if(cwptr != NULL) {
|
||||
cwi = ccw(cwptr->index(v0));
|
||||
}
|
||||
|
||||
Face* n1ptr = new Face(v0, v, v2,
|
||||
this, f1, NULL);
|
||||
|
||||
Face* n2ptr = new Face(v0, v1, v,
|
||||
this, NULL, f2);
|
||||
|
||||
n1ptr->set_neighbor(2, n2ptr);
|
||||
n2ptr->set_neighbor(1, n1ptr);
|
||||
f1->set_neighbor(i1,n1ptr);
|
||||
f2->set_neighbor(i2,n1ptr);
|
||||
|
||||
set_vertex(0, v);
|
||||
set_neighbor(1, n1ptr);
|
||||
set_neighbor(2, n2ptr);
|
||||
|
||||
if( v0->face ==this ) {
|
||||
v0->set_face(n2ptr);
|
||||
}
|
||||
v->set_face(this);
|
||||
}
|
||||
//the following function has been moved to the tds class
|
||||
// void insert_in_face(Vertex*& v)
|
||||
// {
|
||||
// CGAL_triangulation_precondition(v != NULL);
|
||||
// Vertex* v0 = vertex(0);
|
||||
// Vertex* v2 = vertex(2);
|
||||
// Vertex* v1 = vertex(1);
|
||||
//
|
||||
// Face* f1 = neighbor(1);
|
||||
// Face* f2 = neighbor(2);
|
||||
// int i1,i2 ;
|
||||
// if (f1 != NULL) {i1= cw(f1->index(vertex(cw(1))));}
|
||||
// if (f2 != NULL) {i2 = cw(f2->index(vertex(cw(2))));}
|
||||
//
|
||||
// Face* n1ptr = new Face(v0, v, v2,
|
||||
// this, f1, NULL);
|
||||
//
|
||||
// Face* n2ptr = new Face(v0, v1, v,
|
||||
// this, NULL, f2);
|
||||
//
|
||||
// n1ptr->set_neighbor(2, n2ptr);
|
||||
// n2ptr->set_neighbor(1, n1ptr);
|
||||
// if (f1 != NULL) {f1->set_neighbor(i1,n1ptr);}
|
||||
// if (f2 != NULL) {f2->set_neighbor(i2,n2ptr);}
|
||||
//
|
||||
// set_vertex(0, v);
|
||||
// set_neighbor(1, n1ptr);
|
||||
// set_neighbor(2, n2ptr);
|
||||
//
|
||||
// if( v0->face() == this ) { v0->set_face(n2ptr); }
|
||||
// v->set_face(this);
|
||||
// }
|
||||
|
||||
void insert_on_edge(const Vertex* v, int i)
|
||||
{
|
||||
|
||||
CGAL_triangulation_precondition(v != NULL);
|
||||
Face* n = neighbor(i);
|
||||
|
||||
// The following seems natural, but it may fail if the faces
|
||||
// this and n are neighbors on two edges (1-dim triangulation,
|
||||
// with infinite faces
|
||||
// int in = n->index(this);
|
||||
|
||||
int in;
|
||||
CGAL_triangulation_assertion( n->has_vertex(vertex(cw(i),in)));
|
||||
in = cw(in);
|
||||
insert_in_face(v);
|
||||
n->flip(in);
|
||||
}
|
||||
//the following function has been moved to the tds class
|
||||
// void insert_on_edge(const Vertex* v, int i)
|
||||
// {
|
||||
//
|
||||
// CGAL_triangulation_precondition(v != NULL);
|
||||
// Face* n = neighbor(i);
|
||||
//
|
||||
// // The following seems natural, but it may fail if the faces
|
||||
// // this and n are neighbors on two edges (1-dim triangulation,
|
||||
// // with infinite faces
|
||||
// // int in = n->index(this);
|
||||
//
|
||||
// int in;
|
||||
// CGAL_triangulation_assertion( n->has_vertex(vertex(cw(i),in)));
|
||||
// in = cw(in);
|
||||
// insert_in_face(v);
|
||||
// n->flip(in);
|
||||
// }
|
||||
//
|
||||
|
||||
//no longer necessary
|
||||
// bool insert_outside(const Vertex* v, int i)
|
||||
// {
|
||||
// CGAL_triangulation_precondition(v != NULL);
|
||||
|
|
@ -210,140 +206,142 @@ public:
|
|||
// }
|
||||
|
||||
|
||||
bool remove(Vertex* v)
|
||||
{
|
||||
CGAL_triangulation_precondition(v != NULL);
|
||||
CGAL_triangulation_precondition( has_vertex(v));
|
||||
int i = index(v);
|
||||
|
||||
Face* left, *right, *ll, *rr;
|
||||
|
||||
left = neighbor(cw(i));
|
||||
right = neighbor(ccw(i));
|
||||
|
||||
// if(left == NULL || right == NULL) {
|
||||
// if(left == NULL && right == NULL) {
|
||||
// Face* n = neighbor(i);
|
||||
// if(n != NULL) {
|
||||
// int ni = n->index(this);
|
||||
// n->set_neighbor(ni, NULL);
|
||||
// Vertex* q = vertex(cw(i));
|
||||
// if(q != NULL){
|
||||
// q->set_face(n);
|
||||
// }
|
||||
// } else {
|
||||
// cerr << "removal of boundary vertex failed as face has"
|
||||
// << "no neighbors" << endl;
|
||||
// }
|
||||
// handle().Delete();
|
||||
// v.Delete();
|
||||
// return true;
|
||||
// } else {
|
||||
// cerr << "removal of boundary vertex with degree != 2 failed";
|
||||
// cerr << endl;
|
||||
// return false;
|
||||
// }
|
||||
// this function has been moved to the Tds class
|
||||
// bool remove(Vertex* v)
|
||||
// {
|
||||
// CGAL_triangulation_precondition(v != NULL);
|
||||
// CGAL_triangulation_precondition( has_vertex(v));
|
||||
// int i = index(v);
|
||||
//
|
||||
// Face* left, *right, *ll, *rr;
|
||||
//
|
||||
// left = neighbor(cw(i));
|
||||
// right = neighbor(ccw(i));
|
||||
//
|
||||
// // if(left == NULL || right == NULL) {
|
||||
// // if(left == NULL && right == NULL) {
|
||||
// // Face* n = neighbor(i);
|
||||
// // if(n != NULL) {
|
||||
// // int ni = n->index(this);
|
||||
// // n->set_neighbor(ni, NULL);
|
||||
// // Vertex* q = vertex(cw(i));
|
||||
// // if(q != NULL){
|
||||
// // q->set_face(n);
|
||||
// // }
|
||||
// // } else {
|
||||
// // cerr << "removal of boundary vertex failed as face has"
|
||||
// // << "no neighbors" << endl;
|
||||
// // }
|
||||
// // handle().Delete();
|
||||
// // v.Delete();
|
||||
// // return true;
|
||||
// // } else {
|
||||
// // cerr << "removal of boundary vertex with degree != 2 failed";
|
||||
// // cerr << endl;
|
||||
// // return false;
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// if(v->degree() != 3){
|
||||
// cerr << "removal of internal vertex with degree != 3 failed";
|
||||
// cerr << endl;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
if(v->degree() != 3){
|
||||
cerr << "removal of internal vertex with degree != 3 failed";
|
||||
cerr << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int li = left->index(this);
|
||||
int ri = right->index(this);
|
||||
Vertex* q = left->vertex(li);
|
||||
CGAL_triangulation_assertion( left->vertex(li) == right->vertex(ri));
|
||||
|
||||
ll = left->neighbor(cw(li));
|
||||
if(ll != NULL) {
|
||||
int lli = ll->index(left);
|
||||
ll->set_neighbor(lli, this);
|
||||
}
|
||||
set_neighbor(cw(i), ll);
|
||||
if (vertex(ccw(i))->face() == left) vertex(ccw(i))->set_face(this);
|
||||
|
||||
|
||||
|
||||
rr = right->neighbor(ccw(ri));
|
||||
if(rr != NULL) {
|
||||
int rri = rr->index(right);
|
||||
rr->set_neighbor(rri, this);
|
||||
}
|
||||
set_neighbor(ccw(i), rr);
|
||||
if (vertex(cw(i))->face() == right) vertex(cw(i))->set_face(this);
|
||||
|
||||
set_vertex(i, q);
|
||||
if (q->face() == right || q->face() == left) {
|
||||
q->set_face(this);
|
||||
}
|
||||
// int li = left->index(this);
|
||||
// int ri = right->index(this);
|
||||
// Vertex* q = left->vertex(li);
|
||||
// CGAL_triangulation_assertion( left->vertex(li) == right->vertex(ri));
|
||||
//
|
||||
// ll = left->neighbor(cw(li));
|
||||
// if(ll != NULL) {
|
||||
// int lli = ll->index(left);
|
||||
// ll->set_neighbor(lli, this);
|
||||
// }
|
||||
// set_neighbor(cw(i), ll);
|
||||
// if (vertex(ccw(i))->face() == left) vertex(ccw(i))->set_face(this);
|
||||
//
|
||||
//
|
||||
//
|
||||
// rr = right->neighbor(ccw(ri));
|
||||
// if(rr != NULL) {
|
||||
// int rri = rr->index(right);
|
||||
// rr->set_neighbor(rri, this);
|
||||
// }
|
||||
// set_neighbor(ccw(i), rr);
|
||||
// if (vertex(cw(i))->face() == right) vertex(cw(i))->set_face(this);
|
||||
//
|
||||
// set_vertex(i, q);
|
||||
// if (q->face() == right || q->face() == left) {
|
||||
// q->set_face(this);
|
||||
// }
|
||||
//
|
||||
// delete right;
|
||||
// delete left;
|
||||
//
|
||||
// delete v;
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
|
||||
delete right;
|
||||
delete left;
|
||||
|
||||
delete v;
|
||||
return true;
|
||||
}
|
||||
|
||||
void flip(int i)
|
||||
{
|
||||
Face* n = neighbor(i);
|
||||
|
||||
Vertex* v_cw = vertex(cw(i));
|
||||
Vertex* v_ccw = vertex(ccw(i));
|
||||
|
||||
// we should not attempt to flip two faces which are adjacent on two edges
|
||||
// This configuration happens in 1-dim triangulation
|
||||
|
||||
int ni;
|
||||
CGAL_triangulation_assertion( n->has_vertex(v_cw,ni));
|
||||
ni = cw(ni);
|
||||
CGAL_triangulation_assertion( vertex(i) != n->vertex(ni));
|
||||
CGAL_triangulation_assertion( this == n->neighbor(ni) );
|
||||
|
||||
// Old stuff
|
||||
// The following seems natural, but it may fail if the faces
|
||||
// this and n are neighbors on two edges (1-dim triangulation,
|
||||
// with infinite faces
|
||||
// int ni = n->index(this);
|
||||
//
|
||||
// int ni = cw(n->index(v_cw));
|
||||
// CGAL_triangulation_assertion( this == n->neighbor(ni) );
|
||||
|
||||
// bl == bottom left, tr == top right
|
||||
Face* tr = neighbor(ccw(i));
|
||||
Face* bl = n->neighbor(ccw(ni));
|
||||
int bli, tri;
|
||||
|
||||
// Old stuff which seems natural
|
||||
// but makes problem if f and tr or n and bl are incident through two edges
|
||||
// bli = bl->index(n);
|
||||
// tri = tr->index(f);
|
||||
bli = 3 - ( bl->index(n->vertex(ni)) + bl->index(n->vertex(cw(ni))) );
|
||||
tri = 3 - (tr->index(vertex(i)) + tr->index(vertex(cw(i))));
|
||||
|
||||
set_vertex(cw(i), n->vertex(ni));
|
||||
n->set_vertex(cw(ni), vertex(i));
|
||||
|
||||
// update the neighborhood relations
|
||||
set_neighbor(i, bl);
|
||||
bl->set_neighbor(bli, this);
|
||||
|
||||
set_neighbor(ccw(i), n);
|
||||
n->set_neighbor(ccw(ni), this);
|
||||
|
||||
n->set_neighbor(ni, tr);
|
||||
tr->set_neighbor(tri,n);
|
||||
|
||||
if(v_cw->face() == this) {
|
||||
v_cw->set_face(n);
|
||||
}
|
||||
|
||||
if(v_ccw->face() == n) {
|
||||
v_ccw->set_face(this);
|
||||
}
|
||||
}
|
||||
// void flip(int i)
|
||||
// {
|
||||
// Face* n = neighbor(i);
|
||||
//
|
||||
// Vertex* v_cw = vertex(cw(i));
|
||||
// Vertex* v_ccw = vertex(ccw(i));
|
||||
//
|
||||
// // we should not attempt to flip two faces which are adjacent on two edges
|
||||
// // This configuration happens in 1-dim triangulation
|
||||
//
|
||||
// int ni;
|
||||
// CGAL_triangulation_assertion( n->has_vertex(v_cw,ni));
|
||||
// ni = cw(ni);
|
||||
// CGAL_triangulation_assertion( vertex(i) != n->vertex(ni));
|
||||
// CGAL_triangulation_assertion( this == n->neighbor(ni) );
|
||||
//
|
||||
// // Old stuff
|
||||
// // The following seems natural, but it may fail if the faces
|
||||
// // this and n are neighbors on two edges (1-dim triangulation,
|
||||
// // with infinite faces
|
||||
// // int ni = n->index(this);
|
||||
// //
|
||||
// // int ni = cw(n->index(v_cw));
|
||||
// // CGAL_triangulation_assertion( this == n->neighbor(ni) );
|
||||
//
|
||||
// // bl == bottom left, tr == top right
|
||||
// Face* tr = neighbor(ccw(i));
|
||||
// Face* bl = n->neighbor(ccw(ni));
|
||||
// int bli, tri;
|
||||
//
|
||||
// // Old stuff which seems natural
|
||||
// // but makes problem if f and tr or n and bl are incident through two edges
|
||||
// // bli = bl->index(n);
|
||||
// // tri = tr->index(f);
|
||||
// bli = 3 - ( bl->index(n->vertex(ni)) + bl->index(n->vertex(cw(ni))) );
|
||||
// tri = 3 - (tr->index(vertex(i)) + tr->index(vertex(cw(i))));
|
||||
//
|
||||
// set_vertex(cw(i), n->vertex(ni));
|
||||
// n->set_vertex(cw(ni), vertex(i));
|
||||
//
|
||||
// // update the neighborhood relations
|
||||
// set_neighbor(i, bl);
|
||||
// bl->set_neighbor(bli, this);
|
||||
//
|
||||
// set_neighbor(ccw(i), n);
|
||||
// n->set_neighbor(ccw(ni), this);
|
||||
//
|
||||
// n->set_neighbor(ni, tr);
|
||||
// tr->set_neighbor(tri,n);
|
||||
//
|
||||
// if(v_cw->face() == this) {
|
||||
// v_cw->set_face(n);
|
||||
// }
|
||||
//
|
||||
// if(v_ccw->face() == n) {
|
||||
// v_ccw->set_face(this);
|
||||
// }
|
||||
// }
|
||||
|
||||
bool is_valid(bool verbose = false, int level = 0) const
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue