corrected some errors and optimized...

This commit is contained in:
Nico Pietroni 2004-08-26 13:10:40 +00:00
parent 01a6912bb6
commit fbdd47a6f5
1 changed files with 114 additions and 56 deletions

View File

@ -144,6 +144,9 @@ struct TetraSets
v0_U_v1.clear(); v0_U_v1.clear();
no_E.clear(); no_E.clear();
E.clear(); E.clear();
indexE.clear();
indexv0.clear();
indexv1.clear();
} }
}; };
@ -197,7 +200,8 @@ static FacePair _FindNoEdgeFace(TetraType *t,int edge)
#ifdef _DEBUG #ifdef _DEBUG
static void _AssertingVolume(TetraType *t) static void _AssertingVolume(TetraType *t)
{ {
assert(t->ComputeVolume() >0); //assert(t->ComputeVolume() >0);
assert(vcg::ComputeVolume<TetraType>(*t)>0);
} }
#endif #endif
@ -257,10 +261,10 @@ static int _Collapse(PosType p,CoordType NewP)
//i remove the tetrahedrons that have the edge //i remove the tetrahedrons that have the edge
// to collapse // to collapse
Topology::DetachVTTopology(pos.T()); Topology::DetachVTTopology(pos.T());
//end setting the V-T topology //end setting the V-T topology
To_Del.push_back(pos.T()); To_Del.push_back(pos.T());
pos.NextT(); pos.NextT();
n_deleted++; n_deleted++;
// tm.tn--; // tm.tn--;
} }
@ -292,6 +296,7 @@ static int _Collapse(PosType p,CoordType NewP)
#endif #endif
} }
if (Vdel->IsB()) if (Vdel->IsB())
Vrem->SetB(); Vrem->SetB();
//set as deleted the vertex //set as deleted the vertex
@ -338,7 +343,6 @@ static bool isMarkedF(Face F,char M)
else return ((*FI).second & M); else return ((*FI).second & M);
} }
///this structure is used to find the sets that are used in link conditions and more
///verify the link conditions on faces ///verify the link conditions on faces
static bool _LinkConditionsF(PosType pos) static bool _LinkConditionsF(PosType pos)
@ -351,8 +355,10 @@ static bool _LinkConditionsF(PosType pos)
// Mark edges of ve0 // Mark edges of ve0
vector< TetraType *>::iterator ti=_Sets().v0.begin(); vector< TetraType *>::iterator ti=_Sets().v0.begin();
vector< char >::iterator en=_Sets().indexv0.begin(); vector< char >::iterator en=_Sets().indexv0.begin();
VertexType *v0=(*ti)->V(*en);
while (ti!=_Sets().v0.end()) while (ti!=_Sets().v0.end())
{ {
assert(v0==(*ti)->V(*en));
//put dummy face //put dummy face
for (int f=0;f<3;f++) for (int f=0;f<3;f++)
{ {
@ -398,9 +404,10 @@ static bool _LinkConditionsF(PosType pos)
//and at the end I verify if the intersection is equal to the star of the edge //and at the end I verify if the intersection is equal to the star of the edge
ti=_Sets().v1.begin(); ti=_Sets().v1.begin();
en=_Sets().indexv1.begin(); en=_Sets().indexv1.begin();
VertexType *v1=(*ti)->V(*en);
while (ti!=_Sets().v1.end()) while (ti!=_Sets().v1.end())
{ {
assert(v1==(*ti)->V(*en));
//dummy edges control //dummy edges control
for (int f=0;f<3;f++) for (int f=0;f<3;f++)
{ {
@ -415,7 +422,7 @@ static bool _LinkConditionsF(PosType pos)
((isMarkedF(f_test1,LINK_V0))&&(!isMarkedF(f_test1,LINK_EE)))|| ((isMarkedF(f_test1,LINK_V0))&&(!isMarkedF(f_test1,LINK_EE)))||
((isMarkedF(f_test2,LINK_V0))&&(!isMarkedF(f_test2,LINK_EE)))) ((isMarkedF(f_test2,LINK_V0))&&(!isMarkedF(f_test2,LINK_EE))))
{ {
FAIL::LKF(); // FAIL::LKF();
return false; return false;
} }
} }
@ -426,6 +433,7 @@ static bool _LinkConditionsF(PosType pos)
return true; return true;
} }
///verify the link conditions on edges ///verify the link conditions on edges
static bool _LinkConditionsE(PosType pos) static bool _LinkConditionsE(PosType pos)
{ {
@ -501,7 +509,7 @@ static bool _LinkConditionsE(PosType pos)
((isMarkedE(e_test1,LINK_V0))&&(!isMarkedE(e_test1,LINK_EE)))|| ((isMarkedE(e_test1,LINK_V0))&&(!isMarkedE(e_test1,LINK_EE)))||
((isMarkedE(e_test2,LINK_V0))&&(!isMarkedE(e_test2,LINK_EE)))) ((isMarkedE(e_test2,LINK_V0))&&(!isMarkedE(e_test2,LINK_EE))))
{ {
FAIL::LKE(); // FAIL::LKE();
return false; return false;
} }
} }
@ -512,13 +520,61 @@ static bool _LinkConditionsE(PosType pos)
return true; return true;
} }
static bool _QuickConditions(PosType pos)
{
VertexType *v0=pos.T()->V(Tetra::VofE(pos.E(),0));
VertexType *v1=pos.T()->V(Tetra::VofE(pos.E(),1));
//if the two vertices are of border and the edge is not a border edge
//we can do it.
bool border0=v0->IsB();
bool border1=v1->IsB();
bool bordere=Topology::IsExternEdge(pos.T(),pos.E());
//first case vertex external and edge internal
if ((border0 && border1)&&(!bordere))
{
return false;
}
else /// look if the 2 other faces that don't share the vertex are external on not
{
vector< TetraType *>::iterator ti=_Sets().E.begin();
vector< char >::iterator en=_Sets().indexE.begin();
//mark them as intersection
while (ti!=_Sets().E.end())
{
//get the two faces that doesn't share the edge
FacePair fp=_FindNoEdgeFace(pos.T(),pos.E());
int fa0=fp.first;
int fa1=fp.second;
//now set the T-T topology on that faces
TetraType *tleft=pos.T()->TTp(fa0);
TetraType *tright=pos.T()->TTp(fa1);
int ileft=pos.T()->TTi(fa0);
int iright=pos.T()->TTi(fa1);
//in this case I cannot do the collapse
if (((pos.T()==tleft)&&(pos.T()==tright)))
{
return false;
}
ti++;
en++;
}
}
return true;
}
///verify the link conditions on vertices ///verify the link conditions on vertices
static bool _LinkConditionsV() static bool _LinkConditionsV()
{ {
const int LINK_V0 = VertexType::NewUserBit(); const int LINK_V0 = VertexType::NewBitFlag();
const int LINK_V1 = VertexType::NewUserBit(); const int LINK_V1 = VertexType::NewBitFlag();
const int LINK_EE = VertexType::NewUserBit(); const int LINK_EE = VertexType::NewBitFlag();
const int NOT_LINKED = ~(LINK_V0 | LINK_V1 | LINK_EE); const int NOT_LINKED = ~(LINK_V0 | LINK_V1 | LINK_EE);
_DummyV().Flags() &= NOT_LINKED; _DummyV().Flags() &= NOT_LINKED;
@ -624,18 +680,18 @@ static bool _LinkConditionsV()
if (!correct) if (!correct)
{ {
VertexType::DeleteUserBit(LINK_EE); VertexType::DeleteBitFlag(LINK_EE);
VertexType::DeleteUserBit(LINK_V1); VertexType::DeleteBitFlag(LINK_V1);
VertexType::DeleteUserBit(LINK_V0); VertexType::DeleteBitFlag(LINK_V0);
FAIL::LKV(); // FAIL::LKV();
return (false); return (false);
} }
en++; en++;
ti++; ti++;
} }
VertexType::DeleteUserBit(LINK_EE); VertexType::DeleteBitFlag(LINK_EE);
VertexType::DeleteUserBit(LINK_V1); VertexType::DeleteBitFlag(LINK_V1);
VertexType::DeleteUserBit(LINK_V0); VertexType::DeleteBitFlag(LINK_V0);
return true; return true;
} }
@ -647,11 +703,10 @@ static bool _FlipCondition(PosType pos,CoordType NewP)
VertexType *ve1=pos.T()->V(Tetra::VofE(edge,1)); VertexType *ve1=pos.T()->V(Tetra::VofE(edge,1));
CoordType oldpos0; CoordType oldpos0;
CoordType oldpos1; CoordType oldpos1;
//CoordType newpos=((ve0->P()*alfa)+(ve1->P()*(1.f-alfa)));
vector< TetraType *>::iterator ti=_Sets().no_E.begin(); vector< TetraType *>::iterator ti=_Sets().no_E.begin();
//verification //saving old position
oldpos0 = ve0->P(); oldpos0 = ve0->P();
oldpos1 = ve1->P(); oldpos1 = ve1->P();
@ -664,10 +719,9 @@ static bool _FlipCondition(PosType pos,CoordType NewP)
assert(!(*ti)->IsD()); assert(!(*ti)->IsD());
assert((((*ti)->V(0)==ve0)||((*ti)->V(1)==ve0)||((*ti)->V(2)==ve0)||((*ti)->V(3)==ve0))^ assert((((*ti)->V(0)==ve0)||((*ti)->V(1)==ve0)||((*ti)->V(2)==ve0)||((*ti)->V(3)==ve0))^
(((*ti)->V(0)==ve1)||((*ti)->V(1)==ve1)||((*ti)->V(2)==ve1)||((*ti)->V(3)==ve1))); (((*ti)->V(0)==ve1)||((*ti)->V(1)==ve1)||((*ti)->V(2)==ve1)||((*ti)->V(3)==ve1)));
if (vcg::ComputeVolume<TetraType>(**ti)<=0) if (vcg::ComputeVolume<TetraType>(**ti)<=0)
{ {
FAIL::VOL(); // FAIL::VOL();
ve0->P()=oldpos0; ve0->P()=oldpos0;
ve1->P()=oldpos1; ve1->P()=oldpos1;
return false; return false;
@ -758,13 +812,17 @@ static bool CheckPreconditions(PosType pos,CoordType NewP)
bool border0=v0->IsB(); bool border0=v0->IsB();
bool border1=v1->IsB(); bool border1=v1->IsB();
bool bordere=Topology::IsExternEdge(pos.T(),pos.E()); bool bordere=Topology::IsExternEdge(pos.T(),pos.E());
if (!_QuickConditions(pos))
//first case vertex external and edge internal
if ((border0 && border1)&&(!bordere))
{ {
FAIL::BOR(); //FAIL::BOR();
return false; return false;
} }
// //first case vertex external and edge internal
//if ((border0 && border1)&&(!bordere))
//{
// //FAIL::BOR();
// return false;
//}
else else
//if both vertex are internal so is enougth to verify flip conditions //if both vertex are internal so is enougth to verify flip conditions
if ((!border0) && (!border1)) if ((!border0) && (!border1))