Fixed a few bugs, added a few tricks.
This commit is contained in:
parent
36db742b83
commit
e4a4dd72bb
|
@ -40,6 +40,7 @@ class Pivot {
|
||||||
Coord center; //center of the sphere touching the face
|
Coord center; //center of the sphere touching the face
|
||||||
int count; //test delay touch edges.
|
int count; //test delay touch edges.
|
||||||
|
|
||||||
|
bool active; //keep tracks of wether it is in front or in deads
|
||||||
float angle;
|
float angle;
|
||||||
int candidate;
|
int candidate;
|
||||||
Coord newcenter;
|
Coord newcenter;
|
||||||
|
@ -299,13 +300,17 @@ int addFace() {
|
||||||
if(!front.size()) {
|
if(!front.size()) {
|
||||||
//maybe there are unconnected parts of the mesh:
|
//maybe there are unconnected parts of the mesh:
|
||||||
//find a non D, V, B point and try to seed if failed D it.
|
//find a non D, V, B point and try to seed if failed D it.
|
||||||
for(; last_seed < mesh.vert.size(); ++last_seed) {
|
while(last_seed < mesh.vert.size() {
|
||||||
CVertex &v = mesh.vert[last_seed];
|
++last_seed;
|
||||||
|
CVertex &v = mesh.vert[last_seed-1];
|
||||||
if(v.IsD() || v.IsV() || v.IsB()) continue;
|
if(v.IsD() || v.IsV() || v.IsB()) continue;
|
||||||
printf("seeding new: %i\n", last_seed);
|
|
||||||
if(seed(true, last_seed)) return 1;
|
printf("seeding new: %i\n", last_seed-1);
|
||||||
|
if(seed(true, last_seed-1)) return 1;
|
||||||
|
|
||||||
v.SetD();
|
v.SetD();
|
||||||
--mesh.vn;
|
--mesh.vn;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -316,21 +321,6 @@ int addFace() {
|
||||||
Edgex &previous = *e.previous;
|
Edgex &previous = *e.previous;
|
||||||
Edgex &next = *e.next;
|
Edgex &next = *e.next;
|
||||||
|
|
||||||
/* if(e.count == -1) {
|
|
||||||
printf("angle %f\n", e.angle);
|
|
||||||
if(e.angle < 1) e.count = 0;
|
|
||||||
else if(e.angle < 1.5) e.count = 2;
|
|
||||||
else if(e.angle < 2) e.count = 4;
|
|
||||||
else e.count = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(e.count > 0) {
|
|
||||||
printf("delay\n");
|
|
||||||
e.count--;
|
|
||||||
moveBack(ei);
|
|
||||||
return 0;
|
|
||||||
} */
|
|
||||||
|
|
||||||
int v0 = e.v0, v1 = e.v1;
|
int v0 = e.v0, v1 = e.v1;
|
||||||
|
|
||||||
assert(nb[v0] < 10 && nb[v1] < 10);
|
assert(nb[v0] < 10 && nb[v1] < 10);
|
||||||
|
@ -374,19 +364,14 @@ int addFace() {
|
||||||
|
|
||||||
detach(v0);
|
detach(v0);
|
||||||
|
|
||||||
previous.v1 = v1;
|
typename std::list<Edgex>::iterator up = newEdge(Edgex(v2, v1, v0, fn, center));
|
||||||
previous.v2 = v0;
|
(*up).previous = previous.previous;
|
||||||
previous.face = fn;
|
(*up).next = e.next;
|
||||||
previous.center = center;
|
(*previous.previous).next = up;
|
||||||
|
next.previous = up;
|
||||||
previous.next = e.next;
|
erase(e.previous);
|
||||||
next.previous = e.previous;
|
erase(ei);
|
||||||
pivot(previous);
|
trovamiunnome(up);
|
||||||
moveBack(e.previous);
|
|
||||||
|
|
||||||
//this checks if we can glue something to e.previous
|
|
||||||
trovamiunnome(e.previous);
|
|
||||||
front.erase(ei);
|
|
||||||
|
|
||||||
|
|
||||||
} else if(v2 == next.v1) {
|
} else if(v2 == next.v1) {
|
||||||
|
@ -403,33 +388,18 @@ int addFace() {
|
||||||
|
|
||||||
detach(v1);
|
detach(v1);
|
||||||
|
|
||||||
next.v0 = v0;
|
typename std::list<Edgex>::iterator up = newEdge(Edgex(v0, v2, v1, fn, center));
|
||||||
next.v2 = v1;
|
(*up).previous = e.previous;
|
||||||
next.face = fn;
|
(*up).next = (*e.next).next;
|
||||||
next.center = center;
|
previous.next = up;
|
||||||
next.previous = e.previous;
|
(*next.next).previous = up;
|
||||||
previous.next = e.next;
|
erase(e.next);
|
||||||
pivot(next);
|
erase(ei);
|
||||||
// moveBack(e.next);
|
trovamiunnome(up);
|
||||||
|
|
||||||
//this checks if we can glue something to e.previous
|
|
||||||
trovamiunnome(e.next);
|
|
||||||
front.erase(ei);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* if(e.count == -1) {
|
|
||||||
e.count = 4;
|
|
||||||
moveBack(ei);
|
|
||||||
return 0;
|
|
||||||
}*/
|
|
||||||
/* this code would delay the joining edge to avoid bad situations not used but..
|
|
||||||
if(e.count < 2) {
|
|
||||||
e.count++;
|
|
||||||
moveBack(ei);
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//touching some loop: split (or merge it is local does not matter.
|
//touching some loop: split (or merge it is local does not matter.
|
||||||
//like this
|
//like this
|
||||||
/*
|
/*
|
||||||
|
@ -469,8 +439,6 @@ int addFace() {
|
||||||
(*up).v1 = v2;
|
(*up).v1 = v2;
|
||||||
(*up).face = fn;
|
(*up).face = fn;
|
||||||
(*up).center = center;
|
(*up).center = center;
|
||||||
pivot(*up);
|
|
||||||
pivot(*down);
|
|
||||||
moveBack(ei);
|
moveBack(ei);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,8 +472,6 @@ int addFace() {
|
||||||
e.face = fn;
|
e.face = fn;
|
||||||
e.center = center;
|
e.center = center;
|
||||||
e.next = down;
|
e.next = down;
|
||||||
pivot(*ei);
|
|
||||||
pivot(*down);
|
|
||||||
moveBack(ei);
|
moveBack(ei);
|
||||||
}
|
}
|
||||||
addFace(v0, v2, v1);
|
addFace(v0, v2, v1);
|
||||||
|
@ -557,15 +523,6 @@ int addFace() {
|
||||||
|
|
||||||
Point3x p = mesh.vert[id].P();
|
Point3x p = mesh.vert[id].P();
|
||||||
|
|
||||||
if(normals && normal * mesh.vert[id].N() < 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Prevent 360 edges, also often reject ~ 50% points */
|
|
||||||
Point3x n = ((p - v0)^(v1 - v0)).Normalize();
|
|
||||||
if(n * normal < crease) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Find the sphere through v0, p, v1 (store center on end_pivot */
|
/* Find the sphere through v0, p, v1 (store center on end_pivot */
|
||||||
if(!findSphere(v0, p, v1, center)) {
|
if(!findSphere(v0, p, v1, center)) {
|
||||||
|
@ -591,19 +548,20 @@ int addFace() {
|
||||||
|
|
||||||
if(alpha > beta) alpha -= 2*M_PI;
|
if(alpha > beta) alpha -= 2*M_PI;
|
||||||
}
|
}
|
||||||
//if alphs < 0.1
|
//scale alpha by distance:
|
||||||
|
if(edge.candidate == -1 || alpha < edge.angle) {
|
||||||
//scale alpha by distance:
|
|
||||||
if(edge.candidate == -1 ||
|
|
||||||
(alpha < 0.1 && id < edge.candidate) ||
|
|
||||||
(alpha >= 0.1 && alpha < edge.angle)) {
|
|
||||||
edge.candidate = id;
|
edge.candidate = id;
|
||||||
edge.angle = alpha;
|
edge.angle = alpha;
|
||||||
edge.newcenter = center;
|
edge.newcenter = center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(edge.candidate == -1) return false;
|
||||||
|
Point3x n = ((mesh.vert[edge.candidate].P() - v0)^(v1 - v0)).Normalize();
|
||||||
//found no point suitable.
|
//found no point suitable.
|
||||||
if(edge.candidate == -1 || normal * mesh.vert[edge.candidate].N() < 0) {
|
if(normal * mesh.vert[edge.candidate].N() < 0 ||
|
||||||
|
n * normal < crease ||
|
||||||
|
nb[edge.candidate] >= 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,13 +573,19 @@ int addFace() {
|
||||||
//front management:
|
//front management:
|
||||||
//Add a new edge to the back of the queue
|
//Add a new edge to the back of the queue
|
||||||
typename std::list<Edgex>::iterator newEdge(Edgex e) {
|
typename std::list<Edgex>::iterator newEdge(Edgex e) {
|
||||||
|
e.active = true;
|
||||||
return front.insert(front.end(), e);
|
return front.insert(front.end(), e);
|
||||||
}
|
}
|
||||||
//move an Edge among the dead ones
|
//move an Edge among the dead ones
|
||||||
void killEdge(typename std::list<Edgex>::iterator e) {
|
void killEdge(typename std::list<Edgex>::iterator e) {
|
||||||
|
(*e).active = false;
|
||||||
deads.splice(deads.end(), front, e);
|
deads.splice(deads.end(), front, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void erase(typename std::list<Edgex>::iterator e) {
|
||||||
|
if((*e).active) front.erase(e);
|
||||||
|
else deads.erase(e);
|
||||||
|
}
|
||||||
//move an Edge to the back of the queue
|
//move an Edge to the back of the queue
|
||||||
void moveBack(typename std::list<Edgex>::iterator e) {
|
void moveBack(typename std::list<Edgex>::iterator e) {
|
||||||
front.splice(front.end(), front, e);
|
front.splice(front.end(), front, e);
|
||||||
|
@ -671,9 +635,8 @@ int addFace() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void trovamiunnome(typename std::list<Edgex>::iterator e) {
|
bool trovamiunnome(typename std::list<Edgex>::iterator e) {
|
||||||
if(glue((*e).previous, e)) return;
|
return glue((*e).previous, e) || glue(e, (*e).next);
|
||||||
glue(e, (*e).next);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//glue toghether a and b (where a.next = b
|
//glue toghether a and b (where a.next = b
|
||||||
|
|
Loading…
Reference in New Issue