Commit 695d8500 authored by Pierre Kraemer's avatar Pierre Kraemer

update collector + filtering

parent fee3b1fc
...@@ -30,7 +30,7 @@ namespace CGoGN ...@@ -30,7 +30,7 @@ namespace CGoGN
namespace Algo namespace Algo
{ {
namespace Filters2D namespace Filtering
{ {
/** /**
...@@ -48,7 +48,6 @@ void computeNewPositionsFromFaceNormals( ...@@ -48,7 +48,6 @@ void computeNewPositionsFromFaceNormals(
const typename PFP::TVEC3& faceNewNormal, const typename PFP::TVEC3& faceNewNormal,
const FunctorSelect& select) const FunctorSelect& select)
{ {
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
...@@ -70,9 +69,7 @@ void computeNewPositionsFromFaceNormals( ...@@ -70,9 +69,7 @@ void computeNewPositionsFromFaceNormals(
{ {
sumAreas += faceArea[dd] ; sumAreas += faceArea[dd] ;
VEC3 vT = faceCentroid[dd] - pos_d ; VEC3 vT = faceCentroid[dd] - pos_d ;
const VEC3& normal = faceNewNormal[dd] ; vT = (vT * faceNewNormal[dd]) * faceNormal[dd] ;
REAL scal = vT * normal ;
vT = scal * faceNormal[dd] ;
displ += faceArea[dd] * vT ; displ += faceArea[dd] * vT ;
dd = map.phi1(map.phi2(dd)) ; dd = map.phi1(map.phi2(dd)) ;
} while(dd != d) ; } while(dd != d) ;
...@@ -84,9 +81,8 @@ void computeNewPositionsFromFaceNormals( ...@@ -84,9 +81,8 @@ void computeNewPositionsFromFaceNormals(
template <typename PFP> template <typename PFP>
void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select) void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
...@@ -148,9 +144,8 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos ...@@ -148,9 +144,8 @@ void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& pos
} }
template <typename PFP> template <typename PFP>
void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select) void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
...@@ -252,9 +247,8 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3 ...@@ -252,9 +247,8 @@ void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3
} }
template <typename PFP> template <typename PFP>
void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select) void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
...@@ -392,9 +386,8 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -392,9 +386,8 @@ void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
} }
template <typename PFP> template <typename PFP>
void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select) void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
...@@ -550,7 +543,7 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con ...@@ -550,7 +543,7 @@ void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, con
// CGoGNout <<" adaptive rate = "<< float(nbAdapt)/float(nbTot)<<CGoGNendl; // CGoGNout <<" adaptive rate = "<< float(nbAdapt)/float(nbTot)<<CGoGNendl;
} }
} //namespace Filters2D } //namespace Filtering
} //namespace Algo } //namespace Algo
......
...@@ -22,20 +22,26 @@ ...@@ -22,20 +22,26 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"
namespace CGoGN namespace CGoGN
{ {
namespace Algo namespace Algo
{ {
namespace Filters2D namespace Filtering
{ {
template <typename PFP> template <typename PFP>
void filterAverage(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select) void filterAveragePositions(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
FunctorAverage<typename PFP::MAP, typename PFP::VEC3> fa(map, position) ;
Algo::Selection::Collector_OneRing<PFP> c(map) ;
CellMarker markV(map, VERTEX); CellMarker markV(map, VERTEX);
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = map.begin(); d != map.end(); map.next(d))
{ {
...@@ -43,30 +49,16 @@ void filterAverage(typename PFP::MAP& map, const typename PFP::TVEC3& position, ...@@ -43,30 +49,16 @@ void filterAverage(typename PFP::MAP& map, const typename PFP::TVEC3& position,
{ {
markV.mark(d); markV.mark(d);
// get position of vertex c.collectBorder(d) ;
const VEC3& pos_d = position[d] ; fa.reset() ;
c.applyOnBorder(fa) ;
// traversal of neighbour vertices position2[d] = fa.getAverage() ;
VEC3 l(0) ;
int nbE = 0 ;
Dart dd = d ;
do
{
Dart e = map.phi2(dd) ;
l += position[e] - pos_d ;
nbE++ ;
dd = map.phi1(e) ;
} while(dd != d) ;
l /= float(nbE) ;
position2[d] = pos_d + l ;
} }
} }
} }
} //namespace Filters2D } // namespace Filtering
} //namespace Algo } // namespace Algo
} //namespace CGoGN } // namespace CGoGN
...@@ -30,7 +30,7 @@ namespace CGoGN ...@@ -30,7 +30,7 @@ namespace CGoGN
namespace Algo namespace Algo
{ {
namespace Filters2D namespace Filtering
{ {
...@@ -57,8 +57,7 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, ...@@ -57,8 +57,7 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position,
Dart e = map.phi2(dd) ; Dart e = map.phi2(dd) ;
if(!mv.isMarked(e)) if(!mv.isMarked(e))
{ {
VEC3 vec = Algo::Geometry::vectorOutOfDart<PFP>(map, dd, position) ; sumLengths += Algo::Geometry::edgeLength<PFP>(map, dd, position) ;
sumLengths += vec.norm() ;
sumAngles += Geom::angle(normal[d], normal[e]) ; sumAngles += Geom::angle(normal[d], normal[e]) ;
++nbEdges ; ++nbEdges ;
} }
...@@ -74,7 +73,7 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, ...@@ -74,7 +73,7 @@ void sigmaBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position,
} }
template <typename PFP> template <typename PFP>
void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select) void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
...@@ -112,7 +111,7 @@ void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position ...@@ -112,7 +111,7 @@ void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position
} }
template <typename PFP> template <typename PFP>
void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select) void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
...@@ -171,7 +170,7 @@ void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PF ...@@ -171,7 +170,7 @@ void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PF
// CGoGNout <<" susan rate = "<< float(nbSusan)/float(nbTot)<<CGoGNendl; // CGoGNout <<" susan rate = "<< float(nbSusan)/float(nbTot)<<CGoGNendl;
} }
} //namespace Filters2D } //namespace Filtering
} //namespace Algo } //namespace Algo
......
...@@ -22,50 +22,92 @@ ...@@ -22,50 +22,92 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"
namespace CGoGN namespace CGoGN
{ {
namespace Algo namespace Algo
{ {
namespace Filters2D namespace Filtering
{
template <typename PFP>
void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ;
FunctorAverage<typename PFP::MAP, typename PFP::VEC3> fa(map, position) ;
Algo::Selection::Collector_OneRing<PFP> c(map) ;
const float lambda = 0.6307 ;
const float mu = -0.6732 ;
CellMarkerNoUnmark mv(map, VERTEX) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(select(d) && !mv.isMarked(d))
{
mv.mark(d);
c.collectBorder(d) ;
fa.reset() ;
c.applyOnBorder(fa) ;
VEC3 p = position[d] ;
VEC3 displ = fa.getAverage() - p ;
displ *= lambda ;
position2[d] = p + displ ;
}
}
// unshrinking step
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
if(select(d) && mv.isMarked(d))
{
mv.unmark(d);
c.collectBorder(d) ;
fa.reset() ;
c.applyOnBorder(fa) ;
VEC3 p = position2[d] ;
VEC3 displ = fa.getAverage() - p ;
displ *= mu ;
position[d] = p + displ ;
}
}
}
/**
* Taubin filter modified as proposed by [Lav09]
*/
template <typename PFP> template <typename PFP>
void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select) void filterTaubin_modified(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
FunctorAverage<typename PFP::MAP, typename PFP::VEC3> fa(map, position) ;
Algo::Selection::Collector_OneRing<PFP> c(map) ;
const float lambda = 0.6307 ; const float lambda = 0.6307 ;
const float mu = -0.6732 ; const float mu = -0.6732 ;
CellMarkerNoUnmark mv(map, VERTEX); CellMarkerNoUnmark mv(map, VERTEX) ;
for(Dart d = map.begin(); d != map.end(); map.next(d)) for(Dart d = map.begin(); d != map.end(); map.next(d))
{ {
if(select(d) && !mv.isMarked(d)) if(select(d) && !mv.isMarked(d))
{ {
mv.mark(d); mv.mark(d);
// get pos of vertex c.collectBorder(d) ;
const VEC3& pos_d = position[d] ; fa.reset() ;
c.applyOnBorder(fa) ;
// traversal of vertices neighborhood VEC3 p = position[d] ;
VEC3 l(0) ; VEC3 displ = fa.getAverage() - p ;
int nbE = 0 ; displ *= lambda ;
Dart dd = d ; position2[d] = p + displ ;
do
{
Dart e = map.phi2(dd) ;
l += position[e] - pos_d ;
nbE++ ;
dd = map.phi1(e) ;
} while(dd != d) ;
l /= float(nbE) ;
l *= lambda ;
position2[d] = pos_d + l ;
} }
} }
...@@ -76,31 +118,19 @@ void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typenam ...@@ -76,31 +118,19 @@ void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typenam
{ {
mv.unmark(d); mv.unmark(d);
// get pos of vertex c.collectBorder(d) ;
const VEC3& pos_d = position2[d] ; fa.reset() ;
c.applyOnBorder(fa) ;
// traversal of vertices neighborhood VEC3 p = position2[d] ;
VEC3 l(0) ; VEC3 displ = fa.getAverage() - p ;
int nbE = 0 ; displ *= mu ;
Dart dd = d ; position[d] = p + displ ;
do
{
Dart e = map.phi2(dd) ;
l += position2[e] - pos_d ;
nbE++ ;
dd = map.phi1(e) ;
} while(dd != d) ;
l /= float(nbE) ;
l *= mu ;
position[d] = pos_d + l ;
} }
} }
} }
} //namespace Filters2D } // namespace Filtering
} //namespace Algo } // namespace Algo
} //namespace CGoGN } // namespace CGoGN
...@@ -34,11 +34,11 @@ namespace CGoGN ...@@ -34,11 +34,11 @@ namespace CGoGN
namespace Algo namespace Algo
{ {
namespace Filters2D namespace Filtering
{ {
template <typename PFP> template <typename PFP>
float computeHaussdorf(typename PFP::MAP& map, const typename PFP::TVEC3& originalPosition, const typename PFP::TVEC3& position2, const FunctorSelect& select) float computeHaussdorf(typename PFP::MAP& map, const typename PFP::TVEC3& originalPosition, const typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
...@@ -92,7 +92,7 @@ float computeHaussdorf(typename PFP::MAP& map, const typename PFP::TVEC3& origin ...@@ -92,7 +92,7 @@ float computeHaussdorf(typename PFP::MAP& map, const typename PFP::TVEC3& origin
} }
template <typename PFP> template <typename PFP>
void computeNoise(typename PFP::MAP& map, long amount, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select) void computeNoise(typename PFP::MAP& map, long amount, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue())
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
...@@ -143,7 +143,7 @@ void computeNoise(typename PFP::MAP& map, long amount, const typename PFP::TVEC3 ...@@ -143,7 +143,7 @@ void computeNoise(typename PFP::MAP& map, long amount, const typename PFP::TVEC3
} }
} }
} //namespace Filters2D } //namespace Filtering
} //namespace Algo } //namespace Algo
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.u-strasbg.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __FILTERS_2D__
#define __FILTERS_2D__
namespace CGoGN
{
namespace Algo
{
namespace Filters2D
{
enum Filters { AVERAGE, TAUBIN, BILATERAL, AVERAGE_NORMAL, MMSE, SUSAN, TNBA, VNBA } ;
/**
* Average filter need:
* vertex embedding with position & position2
*/
template <typename PFP>
void filterAverage(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
/**
* Taubin filter need:
* vertex embedding with position & position2
*/
template <typename PFP>
void filterTaubin(typename PFP::MAP& map, typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
/**
* bilateral filter need
* vertex embedding with: position & position2
*/
template <typename PFP>
void filterBilateral(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void filterSUSAN(typename PFP::MAP& map, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue()) ;
/**
* Average normal filter need:
* vertex embedding with position & position2
* face embedding with normal, centroid & area
*/
template <typename PFP>
void filterAverageNormals(typename PFP::MAP& map, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
/**
* MMSE filter need:
* vertex embedding with position & position2
* face embedding with normal, centroid & area
*/
template <typename PFP>
void filterMMSE(typename PFP::MAP& map, float sigmaN2, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void filterTNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void filterVNBA(typename PFP::MAP& map, float sigmaN2, float SUSANthreshold, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue()) ;
/**
* some useful tools
*/
template <typename PFP>
float computeHaussdorf(typename PFP::MAP& map, const typename PFP::TVEC3& originalPosition, const typename PFP::TVEC3& position2, const FunctorSelect& select = SelectorTrue()) ;
template <typename PFP>
void computeNoise(typename PFP::MAP& map, long amount, const typename PFP::TVEC3& position, typename PFP::TVEC3& position2, const typename PFP::TVEC3& normal, const FunctorSelect& select = SelectorTrue()) ;
} //namespace Filters2D
} //namespace Algo
} //namespace CGoGN
#include "Algo/Filters2D/average.hpp"
#include "Algo/Filters2D/taubin.hpp"
#include "Algo/Filters2D/bilateral.hpp"
#include "Algo/Filters2D/average_normals.hpp"
#include "Algo/Filters2D/tools.hpp"
#endif
...@@ -340,12 +340,11 @@ void computeCurvatureVertex_NormalCycles( ...@@ -340,12 +340,11 @@ void computeCurvatureVertex_NormalCycles(
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
Algo::Selection::Collector_WithinSphere<PFP> neigh(map, position) ; Algo::Selection::Collector_WithinSphere<PFP> neigh(map, position, radius) ;
neigh.init(dart, radius) ; neigh.collectAll(dart) ;
neigh.collect() ;
neigh.computeArea() ; neigh.computeArea() ;
VEC3 center = position[neigh.getCenter()] ;