Commit 72d6f882 authored by Pierre Kraemer's avatar Pierre Kraemer

Selector in Traversor

parent 307472d9
......@@ -62,30 +62,27 @@ bool exportPLY(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
vertices.reserve(nbDarts/6) ;
CellMarker markV(map, VERTEX) ;
TraversorF<MAP> t(map) ;
TraversorF<MAP> t(map, good) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(good(d))
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
++degree ;
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
if(!markV.isMarked(it))
{
++degree ;
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
if(!markV.isMarked(it))
{
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
fidx.push_back(vIndex[vNum]) ;
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
fidx.push_back(vIndex[vNum]) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
}
out << "ply" << std::endl ;
......@@ -140,30 +137,27 @@ bool exportOFF(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
vertices.reserve(nbDarts/6) ;
CellMarker markV(map, VERTEX) ;
TraversorF<MAP> t(map) ;
TraversorF<MAP> t(map, good) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(good(d))
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
++degree ;
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
if(!markV.isMarked(it))
{
++degree ;
unsigned int vNum = map.getEmbedding(VERTEX, it) ;
if(!markV.isMarked(it))
{
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
fidx.push_back(vIndex[vNum]) ;
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
fidx.push_back(vIndex[vNum]) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
}
out << "OFF" << std::endl ;
......@@ -201,27 +195,24 @@ bool exportCTM(typename PFP::MAP& map, const typename PFP::TVEC3& position, cons
verticesBuffer.reserve(nbDarts/5); // TODO non optimal reservation
indicesBuffer.reserve(nbDarts/3);
CellMarker markV(map,VERTEX);
TraversorF<MAP> t(map) ;
CellMarker markV(map, VERTEX);
TraversorF<MAP> t(map, good) ;
unsigned int lab = 0;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(good(d))
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
if (!markV.isMarked(it))
{
if (!markV.isMarked(it))
{
markV.mark(it);
tableVertLab[it] = lab++;
const VEC3& vert = position[it];
verticesBuffer.push_back(vert[0]);
verticesBuffer.push_back(vert[1]);
verticesBuffer.push_back(vert[2]);
}
indicesBuffer.push_back(tableVertLab[it]);
markV.mark(it);
tableVertLab[it] = lab++;
const VEC3& vert = position[it];
verticesBuffer.push_back(vert[0]);
verticesBuffer.push_back(vert[1]);
verticesBuffer.push_back(vert[2]);
}
indicesBuffer.push_back(tableVertLab[it]);
}
}
......@@ -274,32 +265,29 @@ bool exportPlyPTMgeneric(typename PFP::MAP& map, const char* filename, const typ
faces.reserve(nbDarts/3);
CellMarker markV(map, VERTEX);
TraversorF<MAP> t(map) ;
TraversorF<MAP> t(map, good) ;
unsigned int lab = 0;
unsigned int nbf = 0;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(good(d))
std::vector<unsigned int> face ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
std::vector<unsigned int> face ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
if (!markV.isMarked(it))
{
if (!markV.isMarked(it))
{
markV.mark(it);
tableVertLab[it] = lab++;
vertices.push_back(map.getEmbedding(VERTEX, it));
}
face.push_back(tableVertLab[it]);
markV.mark(it);
tableVertLab[it] = lab++;
vertices.push_back(map.getEmbedding(VERTEX, it));
}
face.push_back(tableVertLab[it]);
}
faces.push_back(face.size()) ;
for (unsigned int i = 0 ; i < face.size() ; ++i)
faces.push_back(face.at(i)) ;
faces.push_back(face.size()) ;
for (unsigned int i = 0 ; i < face.size() ; ++i)
faces.push_back(face.at(i)) ;
++nbf;
}
++nbf;
}
TVEC3 frame[3] ;
......@@ -415,32 +403,29 @@ bool exportPLYPTM(typename PFP::MAP& map, const char* filename, const typename P
faces.reserve(nbDarts/3);
CellMarker markV(map, VERTEX);
TraversorF<MAP> t(map) ;
TraversorF<MAP> t(map, good) ;
unsigned int lab = 0;
unsigned int nbf = 0;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(good(d))
std::vector<unsigned int> face ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
std::vector<unsigned int> face ;
Traversor2FV<typename PFP::MAP> tfv(map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
if (!markV.isMarked(it))
{
if (!markV.isMarked(it))
{
markV.mark(it);
tableVertLab[it] = lab++;
vertices.push_back(map.getEmbedding(VERTEX, it));
}
face.push_back(tableVertLab[it]);
markV.mark(it);
tableVertLab[it] = lab++;
vertices.push_back(map.getEmbedding(VERTEX, it));
}
face.push_back(tableVertLab[it]);
}
faces.push_back(face.size()) ;
for (unsigned int i = 0 ; i < face.size() ; ++i)
faces.push_back(face.at(i)) ;
faces.push_back(face.size()) ;
for (unsigned int i = 0 ; i < face.size() ; ++i)
faces.push_back(face.at(i)) ;
++nbf;
}
++nbf;
}
out << "ply" << std::endl ;
......
......@@ -48,36 +48,33 @@ void filterAverageAttribute_OneRing(
FunctorAverage<T> fa(attIn) ;
Algo::Selection::Collector_OneRing<PFP> col(map) ;
TraversorV<typename PFP::MAP> t(map) ;
TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE)
fa.reset() ;
if (neigh & INSIDE)
{
switch (attIn.getOrbit())
{
switch (attIn.getOrbit())
{
case VERTEX :
col.applyOnInsideVertices(fa) ;
break;
case EDGE :
col.applyOnInsideEdges(fa) ;
break;
case FACE :
col.applyOnInsideFaces(fa) ;
break;
}
case VERTEX :
col.applyOnInsideVertices(fa) ;
break;
case EDGE :
col.applyOnInsideEdges(fa) ;
break;
case FACE :
col.applyOnInsideFaces(fa) ;
break;
}
if (neigh & BORDER)
col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
if (neigh & BORDER)
col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
}
......@@ -95,29 +92,26 @@ void filterAverageVertexAttribute_WithinSphere(
FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorV<typename PFP::MAP> t(map) ;
TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
attOut[d] = T(0);
if (neigh & INSIDE){
faInside.reset() ;
col.applyOnInsideVertices(faInside) ;
attOut[d] += faInside.getSum();
}
if (neigh & BORDER){
faBorder.reset(position[d], radius);
col.applyOnBorder(faBorder) ;
attOut[d] += faBorder.getSum();
}
attOut[d] /= faInside.getCount() + faBorder.getCount() ;
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
attOut[d] = T(0);
if (neigh & INSIDE){
faInside.reset() ;
col.applyOnInsideVertices(faInside) ;
attOut[d] += faInside.getSum();
}
if (neigh & BORDER){
faBorder.reset(position[d], radius);
col.applyOnBorder(faBorder) ;
attOut[d] += faBorder.getSum();
}
attOut[d] /= faInside.getCount() + faBorder.getCount() ;
}
}
......@@ -134,21 +128,18 @@ void filterAverageEdgeAttribute_WithinSphere(
FunctorAverage<T> fa(attIn) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorV<typename PFP::MAP> t(map) ;
TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE) col.applyOnInsideEdges(fa) ;
if (neigh & BORDER) col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE) col.applyOnInsideEdges(fa) ;
if (neigh & BORDER) col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
}
......@@ -165,21 +156,18 @@ void filterAverageFaceAttribute_WithinSphere(
FunctorAverage<T> fa(attIn) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorV<typename PFP::MAP> t(map) ;
TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE) col.applyOnInsideFaces(fa) ;
if (neigh & BORDER) col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE) col.applyOnInsideFaces(fa) ;
if (neigh & BORDER) col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ;
}
}
......
......@@ -52,28 +52,25 @@ void computeNewPositionsFromFaceNormals(
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
TraversorV<typename PFP::MAP> t(map) ;
TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
const VEC3& pos_d = position[d] ;
const VEC3& pos_d = position[d] ;
VEC3 displ(0) ;
REAL sumAreas = 0 ;
VEC3 displ(0) ;
REAL sumAreas = 0 ;
Traversor2VF<typename PFP::MAP> tvf(map, d) ;
for(Dart it = tvf.begin(); it != tvf.end(); it = tvf.next())
{
sumAreas += faceArea[it] ;
VEC3 vT = faceCentroid[it] - pos_d ;
vT = (vT * faceNewNormal[it]) * faceNormal[it] ;
displ += faceArea[it] * vT ;
}
displ /= sumAreas ;
position2[d] = pos_d + displ ;
Traversor2VF<typename PFP::MAP> tvf(map, d) ;
for(Dart it = tvf.begin(); it != tvf.end(); it = tvf.next())
{
sumAreas += faceArea[it] ;
VEC3 vT = faceCentroid[it] - pos_d ;
vT = (vT * faceNewNormal[it]) * faceNormal[it] ;
displ += faceArea[it] * vT ;
}
displ /= sumAreas ;
position2[d] = pos_d + displ ;
}
}
......@@ -94,28 +91,25 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos
AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ;
// Compute new normals
TraversorF<typename PFP::MAP> tf(map) ;
TraversorF<typename PFP::MAP> tf(map, select) ;
for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{
if(select(d))
{
REAL sumArea = 0 ;
VEC3 meanFilter(0) ;
// traversal of adjacent faces (by edges and vertices)
Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
{
sumArea += faceArea[it] ;
meanFilter += faceArea[it] * faceNormal[it] ;
}
REAL sumArea = 0 ;
VEC3 meanFilter(0) ;
// finalize the computation of meanFilter normal
meanFilter /= sumArea ;
meanFilter.normalize() ;
// and store it
faceNewNormal[d] = meanFilter ;
// traversal of adjacent faces (by edges and vertices)
Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
{
sumArea += faceArea[it] ;
meanFilter += faceArea[it] * faceNormal[it] ;
}
// finalize the computation of meanFilter normal
meanFilter /= sumArea ;
meanFilter.normalize() ;
// and store it
faceNewNormal[d] = meanFilter ;
}
// Compute new vertices position
......@@ -141,69 +135,66 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3
AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ;
// Compute new normals
TraversorF<typename PFP::MAP> tf(map) ;
TraversorF<typename PFP::MAP> tf(map, select) ;
for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{
if( select(d))
{
// traversal of neighbour vertices
REAL sumArea = 0 ;
REAL sigmaX2 = 0 ;
REAL sigmaY2 = 0 ;
REAL sigmaZ2 = 0 ;
// traversal of neighbour vertices
REAL sumArea = 0 ;
REAL sigmaX2 = 0 ;
REAL sigmaY2 = 0 ;
REAL sigmaZ2 = 0 ;
VEC3 meanFilter(0) ;
VEC3 meanFilter(0) ;
// traversal of adjacent faces (by edges and vertices)
Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
{
// get info from face embedding and sum
REAL area = faceArea[it] ;
sumArea += area ;
VEC3 normal = faceNormal[it] ;
meanFilter += area * normal ;
sigmaX2 += area * normal[0] * normal[0] ;
sigmaY2 += area * normal[1] * normal[1] ;
sigmaZ2 += area * normal[2] * normal[2] ;
}
// traversal of adjacent faces (by edges and vertices)
Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
{
// get info from face embedding and sum
REAL area = faceArea[it] ;
sumArea += area ;
VEC3 normal = faceNormal[it] ;
meanFilter += area * normal ;
sigmaX2 += area * normal[0] * normal[0] ;
sigmaY2 += area * normal[1] * normal[1] ;
sigmaZ2 += area * normal[2] * normal[2] ;
}
meanFilter /= sumArea ;
sigmaX2 /= sumArea ;
sigmaX2 -= meanFilter[0] * meanFilter[0] ;
sigmaY2 /= sumArea ;
sigmaY2 -= meanFilter[1] * meanFilter[1] ;
sigmaZ2 /= sumArea ;
sigmaZ2 -= meanFilter[2] * meanFilter[2] ;
meanFilter /= sumArea ;
sigmaX2 /= sumArea ;
sigmaX2 -= meanFilter[0] * meanFilter[0] ;
sigmaY2 /= sumArea ;
sigmaY2 -= meanFilter[1] * meanFilter[1] ;
sigmaZ2 /= sumArea ;
sigmaZ2 -= meanFilter[2] * meanFilter[2] ;
VEC3& oldNormal = faceNormal[d] ;
VEC3 newNormal ;
VEC3& oldNormal = faceNormal[d] ;
VEC3 newNormal ;
if(sigmaX2 < sigmaN2)
newNormal[0] = meanFilter[0] ;
else
{
newNormal[0] = (1 - (sigmaN2 / sigmaX2)) * oldNormal[0] ;
newNormal[0] += (sigmaN2 / sigmaX2) * meanFilter[0] ;
}
if(sigmaY2 < sigmaN2)
newNormal[1] = meanFilter[1] ;
else
{
newNormal[1] = (1 - (sigmaN2 / sigmaY2)) * oldNormal[1] ;
newNormal[1] += (sigmaN2 / sigmaY2) * meanFilter[1] ;
}
if(sigmaZ2 < sigmaN2)
newNormal[2] = meanFilter[2] ;
else
{
newNormal[2] = (1 - (sigmaN2 / sigmaZ2)) * oldNormal[2] ;
newNormal[2] += (sigmaN2 / sigmaZ2) * meanFilter[2] ;
}
newNormal.normalize() ;
faceNewNormal[d] = newNormal ;
if(sigmaX2 < sigmaN2)
newNormal[0] = meanFilter[0] ;
else
{
newNormal[0] = (1 - (sigmaN2 / sigmaX2)) * oldNormal[0] ;
newNormal[0] += (sigmaN2 / sigmaX2) * meanFilter[0] ;
}
if(sigmaY2 < sigmaN2)
newNormal[1] = meanFilter[1] ;
else
{
newNormal[1] = (1 - (sigmaN2 / sigmaY2)) * oldNormal[1] ;
newNormal[1] += (sigmaN2 / sigmaY2) * meanFilter[1] ;
}
if(sigmaZ2 < sigmaN2)
newNormal[2] = meanFilter[2] ;
else
{
newNormal[2] = (1 - (sigmaN2 / sigmaZ2)) * oldNormal[2] ;
newNormal[2] += (sigmaN2 / sigmaZ2) * meanFilter[2] ;
}
newNormal.normalize() ;
faceNewNormal[d] = newNormal ;
}
// Compute new vertices position
......@@ -233,95 +224,92 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
long nbAdapt = 0 ;
long nbSusan = 0 ;
TraversorF<typename PFP::MAP> tf(map) ;
TraversorF<typename PFP::MAP> tf(map, select) ;
for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{
if( select(d))
{
const VEC3& normF = faceNormal[d] ;
const VEC3& normF = faceNormal[d] ;