harmless small refactoring
This commit is contained in:
parent
f62e07ee66
commit
5aaa6f4720
|
@ -8,7 +8,7 @@
|
||||||
* \ *
|
* \ *
|
||||||
* All rights reserved. *
|
* All rights reserved. *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
#include<vcg/complex/algorithms/update/normal.h>
|
#include<vcg/complex/algorithms/update/normal.h>
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Crease Angle
|
Crease Angle
|
||||||
Assume che:
|
Assume che:
|
||||||
|
@ -36,18 +36,18 @@ la mesh non abbia complex (o se li aveva fossero stati detached)
|
||||||
Abbia le normali per faccia normalizzate!!
|
Abbia le normali per faccia normalizzate!!
|
||||||
|
|
||||||
|
|
||||||
Prende una mesh e duplica tutti gli edge le cui normali nelle facce incidenti formano un angolo maggiore
|
Prende una mesh e duplica tutti gli edge le cui normali nelle facce incidenti formano un angolo maggiore
|
||||||
di <angle> (espresso in rad).
|
di <angle> (espresso in rad).
|
||||||
foreach face
|
foreach face
|
||||||
foreach unvisited vert vi
|
foreach unvisited vert vi
|
||||||
scan the star of triangles around vi duplicating vi each time we encounter a crease angle.
|
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.
|
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.
|
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.
|
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>
|
||||||
|
@ -61,12 +61,12 @@ void CreaseCut(MESH_TYPE &m, float angleRad)
|
||||||
typedef typename MESH_TYPE::FaceIterator FaceIterator;
|
typedef typename MESH_TYPE::FaceIterator FaceIterator;
|
||||||
typedef typename MESH_TYPE::FaceType FaceType;
|
typedef typename MESH_TYPE::FaceType FaceType;
|
||||||
typedef typename MESH_TYPE::FacePointer FacePointer;
|
typedef typename MESH_TYPE::FacePointer FacePointer;
|
||||||
|
|
||||||
tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
|
tri::Allocator<MESH_TYPE>::CompactVertexVector(m);
|
||||||
tri::Allocator<MESH_TYPE>::CompactFaceVector(m);
|
tri::Allocator<MESH_TYPE>::CompactFaceVector(m);
|
||||||
|
|
||||||
tri::UpdateNormal<MESH_TYPE>::NormalizePerFace(m);
|
tri::UpdateNormal<MESH_TYPE>::NormalizePerFace(m);
|
||||||
|
|
||||||
assert(tri::HasFFAdjacency(m));
|
assert(tri::HasFFAdjacency(m));
|
||||||
typename MESH_TYPE::ScalarType cosangle=math::Cos(angleRad);
|
typename MESH_TYPE::ScalarType cosangle=math::Cos(angleRad);
|
||||||
|
|
||||||
|
@ -74,68 +74,66 @@ void CreaseCut(MESH_TYPE &m, float angleRad)
|
||||||
std::vector<int> indVec(m.fn*3,-1);
|
std::vector<int> indVec(m.fn*3,-1);
|
||||||
int newVertexCounter=m.vn;
|
int newVertexCounter=m.vn;
|
||||||
int startVn=m.vn;
|
int startVn=m.vn;
|
||||||
FaceIterator fi;
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
//const FaceType * nextf;
|
for(int j=0;j<3;++j)
|
||||||
for(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.
|
if(!(*fi).V(j)->IsV() ) // foreach unvisited vertex we loop around it searching for creases.
|
||||||
{
|
{
|
||||||
(*fi).V(j)->SetV();
|
(*fi).V(j)->SetV();
|
||||||
|
|
||||||
face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j));
|
face::JumpingPos<FaceType> iPos(&*fi,j,(*fi).V(j));
|
||||||
size_t vertInd = Index(m,iPos.v); //
|
size_t vertInd = Index(m,iPos.v); //
|
||||||
bool isBorderVertex = iPos.FindBorder(); // for border vertex we start from the border.
|
bool isBorderVertex = iPos.FindBorder(); // for border vertex we start from the border.
|
||||||
face::JumpingPos<FaceType> startPos=iPos;
|
face::JumpingPos<FaceType> startPos=iPos;
|
||||||
if(!isBorderVertex) // for internal vertex we search the first crease and start from it
|
if(!isBorderVertex) // for internal vertex we search the first crease and start from it
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
ScalarType dotProd = iPos.FFlip()->cN().dot(iPos.f->N());
|
ScalarType dotProd = iPos.FFlip()->cN().dot(iPos.f->N());
|
||||||
iPos.NextFE();
|
iPos.NextFE();
|
||||||
if(dotProd<cosangle) break;
|
if(dotProd<cosangle) break;
|
||||||
} while (startPos!=iPos);
|
} while (startPos!=iPos);
|
||||||
startPos=iPos; // the found crease become the new starting pos.
|
startPos=iPos; // the found crease become the new starting pos.
|
||||||
}
|
}
|
||||||
|
|
||||||
int locCreaseCounter=0;
|
int locCreaseCounter=0;
|
||||||
int curVertexCounter =vertInd;
|
int curVertexCounter =vertInd;
|
||||||
|
|
||||||
do { // The real Loop
|
do { // The real Loop
|
||||||
ScalarType dotProd=iPos.FFlip()->cN().dot(iPos.f->N()); // test normal with the next face (fflip)
|
ScalarType dotProd=iPos.FFlip()->cN().dot(iPos.f->N()); // test normal with the next face (fflip)
|
||||||
size_t faceInd = Index(m,iPos.f);
|
size_t faceInd = Index(m,iPos.f);
|
||||||
indVec[faceInd*3+ iPos.VInd()] = curVertexCounter;
|
indVec[faceInd*3+ iPos.VInd()] = curVertexCounter;
|
||||||
|
|
||||||
if(dotProd<cosangle)
|
if(dotProd<cosangle)
|
||||||
{ //qDebug(" Crease FOUND");
|
{ //qDebug(" Crease FOUND");
|
||||||
++locCreaseCounter;
|
++locCreaseCounter;
|
||||||
curVertexCounter=newVertexCounter;
|
curVertexCounter=newVertexCounter;
|
||||||
newVertexCounter++;
|
newVertexCounter++;
|
||||||
}
|
}
|
||||||
iPos.NextFE();
|
iPos.NextFE();
|
||||||
} while (startPos!=iPos);
|
} while (startPos!=iPos);
|
||||||
if(locCreaseCounter>0 && (!isBorderVertex) ) newVertexCounter--;
|
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,
|
// A questo punto ho un vettore che mi direbbe per ogni faccia quale vertice devo mettere. Dopo che ho aggiunto i vertici necessari,
|
||||||
// rifaccio il giro delle facce
|
// rifaccio il giro delle facce
|
||||||
//qDebug("adding %i vert for %i crease edges ",newVertexCounter-m.vn, creaseCounter);
|
//qDebug("adding %i vert for %i crease edges ",newVertexCounter-m.vn, creaseCounter);
|
||||||
tri::Allocator<MESH_TYPE>::AddVertices(m,newVertexCounter-m.vn);
|
tri::Allocator<MESH_TYPE>::AddVertices(m,newVertexCounter-m.vn);
|
||||||
|
|
||||||
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
tri::UpdateFlags<MESH_TYPE>::VertexClearV(m);
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
for(int j=0;j<3;++j) // foreach unvisited vertex
|
for(int j=0;j<3;++j) // foreach unvisited vertex
|
||||||
{
|
{
|
||||||
size_t faceInd = Index(m, *fi);
|
size_t faceInd = Index(m, *fi);
|
||||||
size_t vertInd = Index(m, (*fi).V(j));
|
size_t vertInd = Index(m, (*fi).V(j));
|
||||||
int curVertexInd = indVec[faceInd*3+ j];
|
int curVertexInd = indVec[faceInd*3+ j];
|
||||||
assert(curVertexInd != -1);
|
assert(curVertexInd != -1);
|
||||||
assert(curVertexInd < m.vn);
|
assert(curVertexInd < m.vn);
|
||||||
if(curVertexInd < startVn) assert(size_t(curVertexInd) == vertInd);
|
if(curVertexInd < startVn) assert(size_t(curVertexInd) == vertInd);
|
||||||
if(curVertexInd >= startVn)
|
if(curVertexInd >= startVn)
|
||||||
{
|
{
|
||||||
m.vert[curVertexInd].ImportData(*((*fi).V(j)));
|
m.vert[curVertexInd].ImportData(*((*fi).V(j)));
|
||||||
(*fi).V(j) = & m.vert[curVertexInd];
|
(*fi).V(j) = & m.vert[curVertexInd];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tri::UpdateNormal<MESH_TYPE>::PerVertexFromCurrentFaceNormal(m);
|
tri::UpdateNormal<MESH_TYPE>::PerVertexFromCurrentFaceNormal(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue