Commit 88f32610 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

filters almost OK with Traversors

parent f3502715
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
#include "viewer.h" #include "viewer.h"
#include "Algo/Filtering/bilateral.h"
#include "Algo/Filtering/average_normals.h"
Viewer::Viewer() : Viewer::Viewer() :
m_renderStyle(FLAT), m_renderStyle(FLAT),
m_drawVertices(false), m_drawVertices(false),
...@@ -198,6 +201,20 @@ void Viewer::importMesh(std::string& filename) ...@@ -198,6 +201,20 @@ void Viewer::importMesh(std::string& filename)
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ; Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
AttributeHandler<PFP::VEC3> position2 = myMap.addAttribute<PFP::VEC3>(VERTEX, "position2") ;
// for(unsigned int i = 0; i < 3; ++i)
// {
Algo::Filtering::filterVNBA<PFP>(myMap, 0.01f, 0.35f, position, position2, normal) ;
myMap.swapAttributes(position, position2) ;
Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;
// }
m_positionVBO->updateData(position) ; m_positionVBO->updateData(position) ;
m_normalVBO->updateData(normal) ; m_normalVBO->updateData(normal) ;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/traversorCell.h"
#include "Algo/Filtering/functors.h" #include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h" #include "Algo/Selection/collector.h"
...@@ -47,13 +48,11 @@ void filterAverageAttribute_OneRing( ...@@ -47,13 +48,11 @@ void filterAverageAttribute_OneRing(
FunctorAverage<T> fa(attIn) ; FunctorAverage<T> fa(attIn) ;
Algo::Selection::Collector_OneRing<PFP> col(map) ; Algo::Selection::Collector_OneRing<PFP> col(map) ;
CellMarker markV(map, VERTEX) ; TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = t.begin(); d != t.end(); d = t.next())
{ {
if(select(d) && !markV.isMarked(d)) if(select(d))
{ {
markV.mark(d) ;
if (neigh & INSIDE) if (neigh & INSIDE)
col.collectAll(d) ; col.collectAll(d) ;
else else
...@@ -75,14 +74,15 @@ void filterAverageAttribute_OneRing( ...@@ -75,14 +74,15 @@ void filterAverageAttribute_OneRing(
break; break;
} }
} }
if (neigh & BORDER) col.applyOnBorder(fa) ; if (neigh & BORDER)
col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ; attOut[d] = fa.getAverage() ;
} }
} }
} }
template <typename PFP, typename T> template <typename PFP, typename T>
void filterAverageEdgesAttribute_WithinSphere( void filterAverageVertexAttribute_WithinSphere(
typename PFP::MAP& map, typename PFP::MAP& map,
const AttributeHandler<T>& attIn, const AttributeHandler<T>& attIn,
AttributeHandler<T>& attOut, AttributeHandler<T>& attOut,
...@@ -91,31 +91,38 @@ void filterAverageEdgesAttribute_WithinSphere( ...@@ -91,31 +91,38 @@ void filterAverageEdgesAttribute_WithinSphere(
typename PFP::REAL radius, typename PFP::REAL radius,
const FunctorSelect& select = SelectorTrue()) const FunctorSelect& select = SelectorTrue())
{ {
FunctorAverage<T> fa(attIn) ; FunctorAverage<T> faInside(attIn) ;
FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ; Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
CellMarker markV(map, VERTEX) ; TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = t.begin(); d != t.end(); d = t.next())
{ {
if(select(d) && !markV.isMarked(d)) if(select(d))
{ {
markV.mark(d) ;
if (neigh & INSIDE) if (neigh & INSIDE)
col.collectAll(d) ; col.collectAll(d) ;
else else
col.collectBorder(d) ; col.collectBorder(d) ;
fa.reset() ; attOut[d] = T(0);
if (neigh & INSIDE) col.applyOnInsideEdges(fa) ; if (neigh & INSIDE){
if (neigh & BORDER) col.applyOnBorder(fa) ; faInside.reset() ;
attOut[d] = fa.getAverage() ; 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() ;
} }
} }
} }
template <typename PFP, typename T> template <typename PFP, typename T>
void filterAverageFacesAttribute_WithinSphere( void filterAverageEdgeAttribute_WithinSphere(
typename PFP::MAP& map, typename PFP::MAP& map,
const AttributeHandler<T>& attIn, const AttributeHandler<T>& attIn,
AttributeHandler<T>& attOut, AttributeHandler<T>& attOut,
...@@ -124,24 +131,21 @@ void filterAverageFacesAttribute_WithinSphere( ...@@ -124,24 +131,21 @@ void filterAverageFacesAttribute_WithinSphere(
typename PFP::REAL radius, typename PFP::REAL radius,
const FunctorSelect& select = SelectorTrue()) const FunctorSelect& select = SelectorTrue())
{ {
FunctorAverage<T> fa(attIn) ; FunctorAverage<T> fa(attIn) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ; Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
CellMarker markV(map, VERTEX) ; TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = t.begin(); d != t.end(); d = t.next())
{ {
if(select(d) && !markV.isMarked(d)) if(select(d))
{ {
markV.mark(d) ;
if (neigh & INSIDE) if (neigh & INSIDE)
col.collectAll(d) ; col.collectAll(d) ;
else else
col.collectBorder(d) ; col.collectBorder(d) ;
fa.reset() ; fa.reset() ;
if (neigh & INSIDE) col.applyOnInsideFaces(fa) ; if (neigh & INSIDE) col.applyOnInsideEdges(fa) ;
if (neigh & BORDER) col.applyOnBorder(fa) ; if (neigh & BORDER) col.applyOnBorder(fa) ;
attOut[d] = fa.getAverage() ; attOut[d] = fa.getAverage() ;
} }
...@@ -149,7 +153,7 @@ void filterAverageFacesAttribute_WithinSphere( ...@@ -149,7 +153,7 @@ void filterAverageFacesAttribute_WithinSphere(
} }
template <typename PFP, typename T> template <typename PFP, typename T>
void filterAverageVertexAttribute_WithinSphere( void filterAverageFaceAttribute_WithinSphere(
typename PFP::MAP& map, typename PFP::MAP& map,
const AttributeHandler<T>& attIn, const AttributeHandler<T>& attIn,
AttributeHandler<T>& attOut, AttributeHandler<T>& attOut,
...@@ -158,34 +162,23 @@ void filterAverageVertexAttribute_WithinSphere( ...@@ -158,34 +162,23 @@ void filterAverageVertexAttribute_WithinSphere(
typename PFP::REAL radius, typename PFP::REAL radius,
const FunctorSelect& select = SelectorTrue()) const FunctorSelect& select = SelectorTrue())
{ {
FunctorAverage<T> faInside(attIn) ; FunctorAverage<T> fa(attIn) ;
FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ; Algo::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
CellMarker markV(map, VERTEX) ; TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = t.begin(); d != t.end(); d = t.next())
{ {
if(select(d) && !markV.isMarked(d)) if(select(d))
{ {
markV.mark(d) ;
if (neigh & INSIDE) if (neigh & INSIDE)
col.collectAll(d) ; col.collectAll(d) ;
else else
col.collectBorder(d) ; col.collectBorder(d) ;
attOut[d] = T(0); fa.reset() ;
if (neigh & INSIDE){ if (neigh & INSIDE) col.applyOnInsideFaces(fa) ;
faInside.reset() ; if (neigh & BORDER) col.applyOnBorder(fa) ;
col.applyOnInsideVertices(faInside) ; attOut[d] = fa.getAverage() ;
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() ;
} }
} }
} }
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -51,35 +52,31 @@ void computeNewPositionsFromFaceNormals( ...@@ -51,35 +52,31 @@ void computeNewPositionsFromFaceNormals(
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
CellMarker markV(map, VERTEX); TraversorV<typename PFP::MAP> t(map) ;
for (Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = t.begin(); d != t.end(); d = t.next())
{ {
if(select(d) && !markV.isMarked(d)) if(select(d))
{ {
markV.mark(d);
// get pos of vertex
const VEC3& pos_d = position[d] ; const VEC3& pos_d = position[d] ;
// traversal of vertices neighbourhood
VEC3 displ(0) ; VEC3 displ(0) ;
REAL sumAreas = 0 ; REAL sumAreas = 0 ;
Dart dd = d ;
do Traversor2VF<typename PFP::MAP> tvf(map, d) ;
for(Dart it = tvf.begin(); it != tvf.end(); it = tvf.next())
{ {
sumAreas += faceArea[dd] ; sumAreas += faceArea[it] ;
VEC3 vT = faceCentroid[dd] - pos_d ; VEC3 vT = faceCentroid[it] - pos_d ;
vT = (vT * faceNewNormal[dd]) * faceNormal[dd] ; vT = (vT * faceNewNormal[it]) * faceNormal[it] ;
displ += faceArea[dd] * vT ; displ += faceArea[it] * vT ;
dd = map.phi1(map.phi2(dd)) ; }
} while(dd != d) ;
displ /= sumAreas ; displ /= sumAreas ;
position2[d] = pos_d + displ ; position2[d] = pos_d + displ ;
} }
} }
} }
template <typename PFP> template <typename PFP>
void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
...@@ -97,37 +94,21 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos ...@@ -97,37 +94,21 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos
AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ; AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ;
// Compute new normals // Compute new normals
CellMarker markF(map, FACE); TraversorF<typename PFP::MAP> tf(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{ {
if(select(d) && !markF.isMarked(d)) if(select(d))
{ {
markF.mark(d);
REAL sumArea = 0 ; REAL sumArea = 0 ;
VEC3 meanFilter(0) ; VEC3 meanFilter(0) ;
// traversal of adjacent faces (by edges and vertices) // traversal of adjacent faces (by edges and vertices)
Dart d_n = map.phi1(d) ; // next dart in the face Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
Dart e = map.phi2(d) ; // current dart for the traversal
Dart d_last = e ;
do
{ {
// get info from face embedding and sum sumArea += faceArea[it] ;
sumArea += faceArea[e] ; meanFilter += faceArea[it] * faceNormal[it] ;
meanFilter += faceArea[e] * faceNormal[e] ; }
e = map.phi_1(e) ;
e = map.phi2(e) ;
if(e == d_f)
{
e = map.phi2(d_n) ;
d_n = map.phi1(d_n) ;
d_f = map.phi1(map.phi2(d_n)) ;
}
} while(e != d_last) ;
// finalize the computation of meanFilter normal // finalize the computation of meanFilter normal
meanFilter /= sumArea ; meanFilter /= sumArea ;
...@@ -160,13 +141,11 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3 ...@@ -160,13 +141,11 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3
AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ; AutoAttributeHandler<VEC3> faceNewNormal(map, FACE, "faceNewNormal") ;
// Compute new normals // Compute new normals
CellMarker markF(map,FACE); TraversorF<typename PFP::MAP> tf(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{ {
if( select(d) && !markF.isMarked(d)) if( select(d))
{ {
markF.mark(d);
// traversal of neighbour vertices // traversal of neighbour vertices
REAL sumArea = 0 ; REAL sumArea = 0 ;
REAL sigmaX2 = 0 ; REAL sigmaX2 = 0 ;
...@@ -176,31 +155,18 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3 ...@@ -176,31 +155,18 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3
VEC3 meanFilter(0) ; VEC3 meanFilter(0) ;
// traversal of adjacent faces (by edges and vertices) // traversal of adjacent faces (by edges and vertices)
Dart d_n = map.phi1(d) ; // next dart in the face Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
Dart e = map.phi2(d) ; // current dart for the traversal
Dart d_last = e ;
do
{ {
// get info from face embedding and sum // get info from face embedding and sum
REAL area = faceArea[e] ; REAL area = faceArea[it] ;
sumArea += area ; sumArea += area ;
VEC3 normal = faceNormal[e] ; VEC3 normal = faceNormal[it] ;
meanFilter += area * normal ; meanFilter += area * normal ;
sigmaX2 += area * normal[0] * normal[0] ; sigmaX2 += area * normal[0] * normal[0] ;
sigmaY2 += area * normal[1] * normal[1] ; sigmaY2 += area * normal[1] * normal[1] ;
sigmaZ2 += area * normal[2] * normal[2] ; sigmaZ2 += area * normal[2] * normal[2] ;
e = map.phi_1(e) ; }
e = map.phi2(e) ;
if(e == d_f)
{
e = map.phi2(d_n) ;
d_n = map.phi1(d_n) ;
d_f = map.phi1(map.phi2(d_n)) ;
}
} while(e != d_last) ;
meanFilter /= sumArea ; meanFilter /= sumArea ;
sigmaX2 /= sumArea ; sigmaX2 /= sumArea ;
...@@ -267,13 +233,11 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -267,13 +233,11 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
long nbAdapt = 0 ; long nbAdapt = 0 ;
long nbSusan = 0 ; long nbSusan = 0 ;
CellMarker markF(map, FACE); TraversorF<typename PFP::MAP> tf(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{ {
if( select(d) && !markF.isMarked(d)) if( select(d))
{ {
markF.mark(d);
const VEC3& normF = faceNormal[d] ; const VEC3& normF = faceNormal[d] ;
// traversal of neighbour vertices // traversal of neighbour vertices
...@@ -286,20 +250,16 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -286,20 +250,16 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
bool SUSANregion = false ; bool SUSANregion = false ;
// traversal of adjacent faces (by edges and vertices) // traversal of adjacent faces (by edges and vertices)
Dart d_n = map.phi1(d) ; // next dart in the face Traversor2FFaV<typename PFP::MAP> taf(map, d) ;
Dart d_f = map.phi1(map.phi2(d_n)) ; // test dart for end of vertex turning for(Dart it = taf.begin(); it != taf.end(); it = taf.next())
Dart e = map.phi2(d) ; // current dart for the traversal
Dart d_last = e ;
do
{ {
// get info from face embedding and sum // get info from face embedding and sum
const VEC3& normal = faceNormal[e] ; const VEC3& normal = faceNormal[it] ;
float angle = Geom::angle(normF, normal) ; float angle = Geom::angle(normF, normal) ;
if(angle <= SUSANthreshold) if(angle <= SUSANthreshold)
{ {
REAL area = faceArea[e] ; REAL area = faceArea[it] ;
sumArea += area ; sumArea += area ;
meanFilter += area * normal ; meanFilter += area * normal ;
sigmaX2 += area * normal[0] * normal[0] ; sigmaX2 += area * normal[0] * normal[0] ;
...@@ -307,18 +267,7 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -307,18 +267,7 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
sigmaZ2 += area * normal[2] * normal[2] ; sigmaZ2 += area * normal[2] * normal[2] ;
} }
else SUSANregion = true ; else SUSANregion = true ;
}
e = map.phi_1(e) ;
e = map.phi2(e) ;
if(e == d_f)
{
e = map.phi2(d_n) ;
d_n = map.phi1(d_n) ;
d_f = map.phi1(map.phi2(d_n)) ;
}
} while(e != d_last) ;
if(SUSANregion) if(SUSANregion)
++nbSusan ; ++nbSusan ;
...@@ -407,13 +356,11 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -407,13 +356,11 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
long nbAdapt = 0 ; long nbAdapt = 0 ;
long nbSusan = 0 ; long nbSusan = 0 ;
CellMarker markV(map, VERTEX); TraversorV<typename PFP::MAP> tv(map) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = tv.begin(); d != tv.end(); d = tv.next())
{ {
if( select(d) && !markV.isMarked(d)) if( select(d))
{ {
markV.mark(d) ;
const VEC3& normV = normal[d] ; const VEC3& normV = normal[d] ;
// traversal of neighbour vertices // traversal of neighbour vertices
...@@ -426,23 +373,15 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -426,23 +373,15 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
bool SUSANregion = false ; bool SUSANregion = false ;
Dart dd = d ; Traversor2VVaE<typename PFP::MAP> tav(map, d) ;
do for(Dart it = tav.begin(); it != tav.end(); it = tav.next())