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() ;
}
}
......
This diff is collapsed.
......@@ -43,15 +43,12 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position,
float sumAngles = 0.0f ;
long nbEdges = 0 ;
TraversorE<typename PFP::MAP> t(map) ;
TraversorE<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
{
sumLengths += Algo::Geometry::edgeLength<PFP>(map, d, position) ;
sumAngles += Geom::angle(normal[d], normal[map.phi1(d)]) ;
++nbEdges ;
}
sumLengths += Algo::Geometry::edgeLength<PFP>(map, d, position) ;
sumAngles += Geom::angle(normal[d], normal[map.phi1(d)]) ;
++nbEdges ;
}
// update of returned values
......@@ -67,30 +64,27 @@ void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position
float sigmaC, sigmaS ;
sigmaBilateral<PFP>(map, position, normal, sigmaC, sigmaS, select) ;
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))
// get position & normal of vertex
const VEC3& pos_d = position[d] ;
const VEC3& normal_d = normal[d] ;
// traversal of incident edges
float sum = 0.0f, normalizer = 0.0f ;
Traversor2VE<typename PFP::MAP> te(map, d) ;
for(Dart it = te.begin(); it != te.end(); it = te.next())
{
// get position & normal of vertex
const VEC3& pos_d = position[d] ;
const VEC3& normal_d = normal[d] ;
// traversal of incident edges
float sum = 0.0f, normalizer = 0.0f ;
Traversor2VE<typename PFP::MAP> te(map, d) ;
for(Dart it = te.begin(); it != te.end(); it = te.next())
{
VEC3 vec = Algo::Geometry::vectorOutOfDart<PFP>(map, it, position) ;
float h = normal_d * vec ;
float t = vec.norm() ;
float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) ) ;
sum += wcs * h ;
normalizer += wcs ;
}
position2[d] = pos_d + ((sum / normalizer) * normal_d) ;
VEC3 vec = Algo::Geometry::vectorOutOfDart<PFP>(map, it, position) ;
float h = normal_d * vec ;
float t = vec.norm() ;
float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) ) ;
sum += wcs * h ;
normalizer += wcs ;
}
position2[d] = pos_d + ((sum / normalizer) * normal_d) ;
}
}
......@@ -105,45 +99,42 @@ void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PF
long nbTot = 0 ;
long nbSusan = 0 ;
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))
// get position & normal of vertex
const VEC3& pos_d = position[d] ;
const VEC3& normal_d = normal[d] ;
// traversal of incident edges
float sum = 0.0f, normalizer = 0.0f ;
bool SUSANregion = false ;
Traversor2VE<typename PFP::MAP> te(map, d) ;
for(Dart it = te.begin(); it != te.end(); it = te.next())
{
// get position & normal of vertex
const VEC3& pos_d = position[d] ;
const VEC3& normal_d = normal[d] ;
// traversal of incident edges
float sum = 0.0f, normalizer = 0.0f ;
bool SUSANregion = false ;
Traversor2VE<typename PFP::MAP> te(map, d) ;
for(Dart it = te.begin(); it != te.end(); it = te.next())
const VEC3& neighborNormal = normal[map.phi1(it)] ;
float angle = Geom::angle(normal_d, neighborNormal) ;
if( angle <= SUSANthreshold )
{
const VEC3& neighborNormal = normal[map.phi1(it)] ;
float angle = Geom::angle(normal_d, neighborNormal) ;
if( angle <= SUSANthreshold )
{
VEC3 vec = Algo::Geometry::vectorOutOfDart<PFP>(map, it, position) ;
float h = normal_d * vec ;
float t = vec.norm() ;
float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) );
sum += wcs * h ;
normalizer += wcs ;
}
else
SUSANregion = true ;
VEC3 vec = Algo::Geometry::vectorOutOfDart<PFP>(map, it, position) ;
float h = normal_d * vec ;
float t = vec.norm() ;
float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) );
sum += wcs * h ;
normalizer += wcs ;
}
if(SUSANregion)
nbSusan++ ;
nbTot++ ;
if (normalizer != 0.0f)
position2[d] = pos_d + ((sum / normalizer) * normal_d) ;
else
position2[d] = pos_d ;
SUSANregion = true ;
}
if(SUSANregion)
nbSusan++ ;
nbTot++ ;
if (normalizer != 0.0f)
position2[d] = pos_d + ((sum / normalizer) * normal_d) ;
else
position2[d] = pos_d ;
}
// CGoGNout <<" susan rate = "<< float(nbSusan)/float(nbTot)<<CGoGNendl;
......
......@@ -72,12 +72,9 @@ template <typename PFP>
typename PFP::REAL totalArea(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select, unsigned int thread)
{
typename PFP::REAL area(0) ;
TraversorF<typename PFP::MAP> t(map) ;
TraversorF<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
area += convexFaceArea<PFP>(map, d, position) ;
}
area += convexFaceArea<PFP>(map, d, position) ;
return area ;
}
......@@ -132,45 +129,33 @@ typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const typen
template <typename PFP>
void computeAreaFaces(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& face_area, const FunctorSelect& select)
{
TraversorF<typename PFP::MAP> t(map) ;
TraversorF<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(select(d))
face_area[d] = convexFaceArea<PFP>(map, d, position) ;
}
face_area[d] = convexFaceArea<PFP>(map, d, position) ;
}
template <typename PFP>
void computeOneRingAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select)
{
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))
vertex_area[d] = vertexOneRingArea<PFP>(map, d, position) ;
}
vertex_area[d] = vertexOneRingArea<PFP>(map, d, position) ;
}
template <typename PFP>
void computeBarycentricAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select)
{
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))
vertex_area[d] = vertexBarycentricArea<PFP>(map, d, position) ;
}
vertex_area[d] = vertexBarycentricArea<PFP>(map, d, position) ;
}
template <typename PFP>
void computeVoronoiAreaVertices(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TREAL& vertex_area, const FunctorSelect& select)
{
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))
vertex_area[d] = vertexVoronoiArea<PFP>(map, d, position) ;
}
vertex_area[d] = vertexVoronoiArea<PFP>(map, d, position) ;
}
} // namespace Geometry
......
......@@ -42,12 +42,9 @@ template <typename PFP>
Geom::BoundingBox<typename PFP::VEC3> computeBoundingBox(typename PFP::MAP& map, const typename PFP::TVEC3& position, const FunctorSelect& select = SelectorTrue())