Refactored and commented. Now can also cut along non faux edges
This commit is contained in:
parent
a989737e26
commit
298714ccea
|
@ -28,113 +28,99 @@
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
|
|
||||||
/*
|
/** \brief Open a mesh cutting all the edges where the two faces make an angle *larger* than the indicated threshold
|
||||||
Crease Angle
|
*/
|
||||||
Assume che:
|
|
||||||
la mesh abbia la topologia ff
|
|
||||||
la mesh non abbia complex (o se li aveva fossero stati detached)
|
|
||||||
Abbia le normali per faccia normalizzate!!
|
|
||||||
|
|
||||||
|
|
||||||
Prende una mesh e duplica tutti gli edge le cui normali nelle facce incidenti formano un angolo maggiore
|
|
||||||
di <angle> (espresso in rad).
|
|
||||||
foreach face
|
|
||||||
foreach unvisited vert vi
|
|
||||||
scan the star of triangles around vi duplicating vi each time we encounter a crease angle.
|
|
||||||
|
|
||||||
the new (and old) vertexes are put in a std::vector that is swapped with the original one at the end.
|
|
||||||
|
|
||||||
Si tiene un vettore di interi 3 *fn che dice l'indice del vertice puntato da ogni faccia.
|
|
||||||
quando si scandisce la stella intorno ad un vertici, per ogni wedge si scrive l'indice del vertice corrsipondente.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<class MESH_TYPE>
|
template<class MESH_TYPE>
|
||||||
void CreaseCut(MESH_TYPE &m, float angleRad)
|
void CreaseCut(MESH_TYPE &m, float angleRad)
|
||||||
{
|
{
|
||||||
typedef typename MESH_TYPE::CoordType CoordType;
|
tri::UpdateFlags<MESH_TYPE>::FaceFauxSignedCrease(m, -angleRad, angleRad);
|
||||||
typedef typename MESH_TYPE::ScalarType ScalarType;
|
CutMeshAlongNonFauxEdges(m);
|
||||||
typedef typename MESH_TYPE::VertexType VertexType;
|
}
|
||||||
typedef typename MESH_TYPE::VertexPointer VertexPointer;
|
|
||||||
typedef typename MESH_TYPE::VertexIterator VertexIterator;
|
|
||||||
typedef typename MESH_TYPE::FaceIterator FaceIterator;
|
|
||||||
typedef typename MESH_TYPE::FaceType FaceType;
|
|
||||||
typedef typename MESH_TYPE::FacePointer FacePointer;
|
|
||||||
|
|
||||||
tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
|
/**
|
||||||
tri::Allocator<MESH_TYPE>::CompactFaceVector(m);
|
* \brief Open a mesh along non-faux edges
|
||||||
|
*
|
||||||
|
* Duplicate exisiting vertices so that non-faux edges become boundary edges.
|
||||||
|
* It assume FF topology and manifoldness.
|
||||||
|
* The idea is that we scan faces around each vertex duplicating it each time we encounter a marked edge.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template<class MESH_TYPE>
|
||||||
|
void CutMeshAlongNonFauxEdges(MESH_TYPE &m)
|
||||||
|
{
|
||||||
|
typedef typename MESH_TYPE::FaceIterator FaceIterator;
|
||||||
|
typedef typename MESH_TYPE::FaceType FaceType;
|
||||||
|
|
||||||
tri::UpdateNormal<MESH_TYPE>::NormalizePerFace(m);
|
tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
|
||||||
|
tri::Allocator<MESH_TYPE>::CompactFaceVector(m);
|
||||||
|
tri::RequireFFAdjacency(m);
|
||||||
|
|
||||||
assert(tri::HasFFAdjacency(m));
|
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
||||||
typename MESH_TYPE::ScalarType cosangle=math::Cos(angleRad);
|
std::vector<int> indVec(m.fn*3,-1);
|
||||||
|
int newVertexCounter=m.vn;
|
||||||
|
int startVn=m.vn;
|
||||||
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
|
{
|
||||||
|
for(int j=0;j<3;++j)
|
||||||
|
if(!(*fi).V(j)->IsV() ) // foreach unvisited vertex we loop around it searching for creases.
|
||||||
|
{
|
||||||
|
(*fi).V(j)->SetV();
|
||||||
|
|
||||||
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j));
|
||||||
std::vector<int> indVec(m.fn*3,-1);
|
size_t vertInd = Index(m, iPos.V());
|
||||||
int newVertexCounter=m.vn;
|
bool isBorderVertex = iPos.FindBorder(); // for border vertex we start from the border.
|
||||||
int startVn=m.vn;
|
face::JumpingPos<FaceType> startPos=iPos;
|
||||||
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
if(!isBorderVertex) // for internal vertex we search the first crease and start from it
|
||||||
for(int j=0;j<3;++j)
|
{
|
||||||
if(!(*fi).V(j)->IsV() ) // foreach unvisited vertex we loop around it searching for creases.
|
do {
|
||||||
{
|
bool creaseFlag = !iPos.IsFaux();
|
||||||
(*fi).V(j)->SetV();
|
iPos.NextFE();
|
||||||
|
if(creaseFlag) break;
|
||||||
|
} while (startPos!=iPos);
|
||||||
|
startPos=iPos; // the found crease become the new starting pos.
|
||||||
|
}
|
||||||
|
|
||||||
face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j));
|
int locCreaseCounter=0;
|
||||||
size_t vertInd = Index(m,iPos.v); //
|
int curVertexCounter =vertInd;
|
||||||
bool isBorderVertex = iPos.FindBorder(); // for border vertex we start from the border.
|
|
||||||
face::JumpingPos<FaceType> startPos=iPos;
|
|
||||||
if(!isBorderVertex) // for internal vertex we search the first crease and start from it
|
|
||||||
{
|
|
||||||
do {
|
|
||||||
ScalarType dotProd = iPos.FFlip()->cN().dot(iPos.f->N());
|
|
||||||
iPos.NextFE();
|
|
||||||
if(dotProd<cosangle) break;
|
|
||||||
} while (startPos!=iPos);
|
|
||||||
startPos=iPos; // the found crease become the new starting pos.
|
|
||||||
}
|
|
||||||
|
|
||||||
int locCreaseCounter=0;
|
do { // The real Loop
|
||||||
int curVertexCounter =vertInd;
|
size_t faceInd = Index(m,iPos.F());
|
||||||
|
indVec[faceInd*3+ iPos.VInd()] = curVertexCounter;
|
||||||
|
|
||||||
do { // The real Loop
|
if(!iPos.IsFaux())
|
||||||
ScalarType dotProd=iPos.FFlip()->cN().dot(iPos.f->N()); // test normal with the next face (fflip)
|
{ //qDebug(" Crease FOUND");
|
||||||
size_t faceInd = Index(m,iPos.f);
|
++locCreaseCounter;
|
||||||
indVec[faceInd*3+ iPos.VInd()] = curVertexCounter;
|
curVertexCounter=newVertexCounter;
|
||||||
|
newVertexCounter++;
|
||||||
|
}
|
||||||
|
iPos.NextFE();
|
||||||
|
} while (startPos!=iPos);
|
||||||
|
if(locCreaseCounter>0 && (!isBorderVertex) ) newVertexCounter--;
|
||||||
|
//printf("For vertex %i found %i creases\n",vertInd,locCreaseCounter);
|
||||||
|
}
|
||||||
|
} // end foreach face/vert
|
||||||
|
|
||||||
if(dotProd<cosangle)
|
// Now the indVec vector contains for each the new index of each vertex (duplicated as necessary)
|
||||||
{ //qDebug(" Crease FOUND");
|
// We do a second loop to copy split vertexes into new positions
|
||||||
++locCreaseCounter;
|
tri::Allocator<MESH_TYPE>::AddVertices(m,newVertexCounter-m.vn);
|
||||||
curVertexCounter=newVertexCounter;
|
|
||||||
newVertexCounter++;
|
|
||||||
}
|
|
||||||
iPos.NextFE();
|
|
||||||
} while (startPos!=iPos);
|
|
||||||
if(locCreaseCounter>0 && (!isBorderVertex) ) newVertexCounter--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A questo punto ho un vettore che mi direbbe per ogni faccia quale vertice devo mettere. Dopo che ho aggiunto i vertici necessari,
|
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
||||||
// rifaccio il giro delle facce
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
//qDebug("adding %i vert for %i crease edges ",newVertexCounter-m.vn, creaseCounter);
|
for(int j=0;j<3;++j)
|
||||||
tri::Allocator<MESH_TYPE>::AddVertices(m,newVertexCounter-m.vn);
|
{
|
||||||
|
size_t faceInd = Index(m, *fi);
|
||||||
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
size_t vertInd = Index(m, (*fi).V(j));
|
||||||
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
int curVertexInd = indVec[faceInd*3+ j];
|
||||||
for(int j=0;j<3;++j) // foreach unvisited vertex
|
assert(curVertexInd != -1);
|
||||||
{
|
assert(curVertexInd < m.vn);
|
||||||
size_t faceInd = Index(m, *fi);
|
if(curVertexInd < startVn) assert(size_t(curVertexInd) == vertInd);
|
||||||
size_t vertInd = Index(m, (*fi).V(j));
|
if(curVertexInd >= startVn)
|
||||||
int curVertexInd = indVec[faceInd*3+ j];
|
{
|
||||||
assert(curVertexInd != -1);
|
m.vert[curVertexInd].ImportData(*((*fi).V(j)));
|
||||||
assert(curVertexInd < m.vn);
|
(*fi).V(j) = & m.vert[curVertexInd];
|
||||||
if(curVertexInd < startVn) assert(size_t(curVertexInd) == vertInd);
|
}
|
||||||
if(curVertexInd >= startVn)
|
}
|
||||||
{
|
|
||||||
m.vert[curVertexInd].ImportData(*((*fi).V(j)));
|
|
||||||
(*fi).V(j) = & m.vert[curVertexInd];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tri::UpdateNormal<MESH_TYPE>::PerVertexFromCurrentFaceNormal(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace tri
|
} // end namespace tri
|
||||||
|
|
Loading…
Reference in New Issue