Commit 03f8878d authored by untereiner's avatar untereiner

MR filtering is ok

Adding some noise : Additive Uniform-distributed and Additive Gaussian-distributed
parent f1fbd43f
......@@ -132,10 +132,205 @@ void computeNoise(typename PFP::MAP& map, long amount, const VertexAttribute<typ
}
}
//Uniform-distributed additive noise
//TODO do not touch to boundary vertices
template <typename PFP>
void computeUnfirmAdditiveNoise(typename PFP::MAP& map, float noiseIntensity, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& position2)
{
typedef typename PFP::VEC3 VEC3 ;
// Compute mesh center
unsigned int count = 0;
VEC3 centroid(0.0);
TraversorV<typename PFP::MAP> tv(map) ;
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
centroid += position[dit];
++count;
}
centroid /= count;
double distanceCentroid = 0.0;
// Compute the average distance from vertices to mesh center
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
VEC3 dist = position[dit];
dist -= centroid;
distanceCentroid += float(dist.norm());
}
distanceCentroid /= count;
// add random uniform-distributed (between [-noiseLevel, +noiseLevel])
srand((unsigned)time(NULL));
float noisex, noisey, noisez;
float noiseLevel = distanceCentroid * noiseIntensity;
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
noisex = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2;
noisey = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2;
noisez = noiseLevel * (1.0*rand()/RAND_MAX-0.5)*2;
position2[dit] = position[dit] + VEC3(noisex,noisey,noisez);
}
}
//Gaussian-distributed additive noise
//TODO do not touch to boundary vertices
template <typename PFP>
void computeGaussianAdditiveNoise(typename PFP::MAP& map, float noiseIntensity, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& position2)
{
typedef typename PFP::VEC3 VEC3 ;
// Compute mesh center
unsigned int count = 0;
VEC3 centroid(0.0);
TraversorV<typename PFP::MAP> tv(map) ;
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
centroid += position[dit];
++count;
}
centroid /= count;
double distanceCentroid = 0.0;
// Compute the average distance from vertices to mesh center
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
VEC3 dist = position[dit];
dist -= centroid;
distanceCentroid += float(dist.norm());
}
distanceCentroid /= count;
// add random gaussian-distributed
srand((unsigned)time(NULL));
float noisex, noisey, noisez;
float gaussNumbers[3];
float noiseLevel = distanceCentroid * noiseIntensity;
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
// pseudo-random Gaussian-distributed numbers generation from uniformly-distributed pseudo-random numbers
float x, y, r2;
for (int i=0; i<3; i++)
{
do
{
x = -1.0 + 2.0 * 1.0*rand()/RAND_MAX;
y = -1.0 + 2.0 * 1.0*rand()/RAND_MAX;
r2 = x * x + y * y;
} while ((r2>1.0)||(r2==0.0));
gaussNumbers[i] = y * sqrt(-2.0 * log(r2) / r2);
}
noisex = noiseLevel * gaussNumbers[0];
noisey = noiseLevel * gaussNumbers[1];
noisez = noiseLevel * gaussNumbers[2];
position2[dit] = position[dit] + VEC3(noisex,noisey,noisez);
}
}
} //namespace Filtering
} //namespace Surface
namespace Volume
{
namespace Filtering
{
template <typename PFP>
void computeNoise(typename PFP::MAP& map, long amount, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& position2)
{
typedef typename PFP::VEC3 VEC3 ;
// add random gaussian-distributed
srand((unsigned)time(NULL));
float noisex, noisey, noisez;
float gaussNumbers[3];
float noiseLevel = 0.1f;
TraversorV<typename PFP::MAP> tv(map) ;
for(Dart dit = tv.begin(); dit != tv.end(); dit = tv.next())
{
// pseudo-random Gaussian-distributed numbers generation from uniformly-distributed pseudo-random numbers
float x, y, r2;
for (int i=0; i<3; i++)
{
do
{
x = -1.0 + 2.0 * 1.0*rand()/RAND_MAX;
y = -1.0 + 2.0 * 1.0*rand()/RAND_MAX;
r2 = x * x + y * y;
} while ((r2>1.0)||(r2==0.0));
gaussNumbers[i] = y * sqrt(-2.0 * log(r2) / r2);
}
noisex = noiseLevel * gaussNumbers[0];
noisey = noiseLevel * gaussNumbers[1];
noisez = noiseLevel * gaussNumbers[2];
position2[dit] = position[dit] + VEC3(noisex,noisey,noisez);
}
// // init the seed for random
// srand(time(NULL)) ;
//
// // apply noise on each vertex
// TraversorV<typename PFP::MAP> t(map) ;
// for(Dart d = t.begin(); d != t.end(); d = t.next())
// {
// const VEC3& pos = position[d] ;
// VEC3 norm = position[d] ;
//
// float r1 = float(rand() % amount) / 100.0f ;
// float r2 = 0 ;
// if (amount >= 5)
// r2 = float(rand() % (amount/5)) / 100.0f ;
//
// long sign = rand() % 2 ;
// if (sign == 1) norm *= -1.0f ;
// float avEL = 0.0f ;
// VEC3 td(0) ;
//
// long nbE = 0 ;
// Traversor3VVaE<typename PFP::MAP> tav(map, d) ;
// for(Dart it = tav.begin(); it != tav.end(); it = tav.next())
// {
// const VEC3& p = position[it] ;
// VEC3 vec = p - pos ;
// float el = vec.norm() ;
// vec *= r2 ;
// td += vec ;
// avEL += el ;
// nbE++ ;
// }
//
// avEL /= float(nbE) ;
// norm *= avEL * r1 ;
// norm += td ;
// position2[d] = pos + norm ;
// }
}
} //namespace Filtering
} //namespace Volume
} //namespace Algo
} //namespace CGoGN
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __3MR_BERTRAM_FILTER__
#define __3MR_BERTRAM_FILTER__
#ifndef __2MR_BERTRAM_FILTER__
#define __2MR_BERTRAM_FILTER__
#include <cmath>
#include "Algo/Geometry/centroid.h"
......@@ -66,11 +66,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
......@@ -128,11 +123,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorE<typename PFP::MAP> travE(m_map);
for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
......@@ -171,9 +161,11 @@ public:
{
Dart db = m_map.findBoundaryEdgeOfVertex(d);
m_map.incCurrentLevel() ;
ev = (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]);
ev += (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]) * typename PFP::REAL(0.5);
//ev = (m_position[m_map.phi1(db)] + m_position[m_map.phi_1(db)]);
m_map.decCurrentLevel() ;
ev *= m_a;
ev *= 2 * m_a;
//ev *= m_a;
m_position[d] -= ev;
}
......@@ -220,20 +212,6 @@ public:
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorV<typename PFP::MAP> travV(m_map) ;
for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
{
if(m_map.isBoundaryVertex(d))
m_position[d] /= m_a;
else
m_position[d] /= m_a * m_a;
}
TraversorE<typename PFP::MAP> travE(m_map) ;
for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
{
......@@ -243,6 +221,15 @@ public:
m_position[midE] /= m_a ;
m_map.decCurrentLevel() ;
}
TraversorV<typename PFP::MAP> travV(m_map) ;
for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
{
if(m_map.isBoundaryVertex(d))
m_position[d] /= m_a;
else
m_position[d] /= m_a * m_a;
}
}
};
......@@ -267,11 +254,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorF<typename PFP::MAP> travF(m_map) ;
for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
......@@ -297,14 +279,7 @@ public:
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(m_map.phi1(d));
if(filtering)
{
m_position[midF] = vf + ef ;
}
else
{
m_position[midF] += vf + ef ;
}
m_position[midF] += vf + ef ;
m_map.decCurrentLevel() ;
}
......@@ -316,15 +291,8 @@ public:
ve *= 2.0 * m_a;
m_map.incCurrentLevel() ;
Dart midV = m_map.phi1(d) ;
if(filtering)
{
m_position[midV] = ve;
}
else
{
m_position[midV] += ve;
}
Dart midE = m_map.phi1(d) ;
m_position[midE] += ve;
m_map.decCurrentLevel() ;
}
}
......@@ -344,11 +312,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorV<typename PFP::MAP> travV(m_map);
for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
......@@ -363,14 +326,7 @@ public:
m_map.decCurrentLevel() ;
ev *= 2 * m_a;
if(filtering)
{
m_position[db] = ev;
}
else
{
m_position[db] += ev;
}
m_position[db] += ev;
}
else
{
......@@ -392,14 +348,7 @@ public:
ev /= count;
ev *= 4 * m_a;
if(filtering)
{
m_position[d] = fv + ev;
}
else
{
m_position[d] += fv + ev;
}
m_position[d] += fv + ev;
}
}
......@@ -426,17 +375,11 @@ public:
m_map.incCurrentLevel() ;
Dart midF = m_map.phi1(d);
if(filtering)
{
m_position[midF] = fe;
}
else
{
m_position[midF] += fe;
}
m_position[midF] += fe;
m_map.decCurrentLevel() ;
}
}
}
} ;
......@@ -454,11 +397,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorV<typename PFP::MAP> travV(m_map) ;
for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
......@@ -496,4 +434,4 @@ public:
} // namespace CGoGN
#endif /* __3MR_FILTERS_PRIMAL__ */
#endif /* __2MR_FILTERS_PRIMAL__ */
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __MR_CC_FILTER__
#define __MR_CC_FILTER__
#ifndef __2MR_CC_FILTER__
#define __2MR_CC_FILTER__
#include <cmath>
#include "Algo/Multiresolution/filter.h"
......@@ -93,11 +93,6 @@ public:
first = false;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -126,11 +121,6 @@ public:
first = false;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -157,11 +147,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -210,11 +195,6 @@ public:
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -267,11 +247,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -305,11 +280,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -343,11 +313,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -402,11 +367,6 @@ public:
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -455,11 +415,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -486,11 +441,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
} // namespace Filters
......
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __MR_LERP_FILTER__
#define __MR_LERP_FILTER__
#ifndef __2MR_LERP_FILTER__
#define __2MR_LERP_FILTER__
#include <cmath>
#include "Algo/Multiresolution/filter.h"
......
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __MR_LOOP_FILTER__
#define __MR_LOOP_FILTER__
#ifndef __2MR_LOOP_FILTER__
#define __2MR_LOOP_FILTER__
#include <cmath>
#include "Algo/Multiresolution/filter.h"
......@@ -124,11 +124,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -151,11 +146,6 @@ public:
m_position[d] -= p ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -181,11 +171,6 @@ public:
m_position[d] /= n ;
}
}
void operator() (bool filtering)
{
}
} ;
/*********************************************************************************
......@@ -218,11 +203,6 @@ public:
m_map.decCurrentLevel() ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -245,11 +225,6 @@ public:
m_position[d] += p ;
}
}
void operator() (bool filtering)
{
}
} ;
template <typename PFP>
......@@ -275,11 +250,6 @@ public:
m_position[d] *= n ;
}
}
void operator() (bool filtering)
{
}
} ;
} // namespace Filters
......
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __MR_SQRT2_FILTER__
#define __MR_SQRT2_FILTER__
#ifndef __2MR_SQRT2_FILTER__
#define __2MR_SQRT2_FILTER__
#include <cmath>
#include "Algo/Multiresolution/filter.h"
......@@ -83,11 +83,6 @@ public:
}
}
void operator() (bool filtering)
{
}
} ;
......
......@@ -22,8 +22,8 @@
* *
*******************************************************************************/
#ifndef __MR_SQRT3_FILTER__
#define __MR_SQRT3_FILTER__
#ifndef __2MR_SQRT3_FILTER__
#define __2MR_SQRT3_FILTER__
#include <cmath>
#include "Algo/Multiresolution/filter.h"
......@@ -114,11 +114,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorF<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
......@@ -149,7 +144,6 @@ public:
m_map.decCurrentLevel() ;
}
}
} ;
template <typename PFP>
......@@ -164,11 +158,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorV<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
......@@ -239,7 +228,6 @@ public:
}
}
}
} ;
template <typename PFP>
......@@ -254,11 +242,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorV<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
......@@ -295,7 +278,6 @@ public:
}
}
} ;
template <typename PFP>
......@@ -310,11 +292,6 @@ public:
{}
void operator() ()
{
}
void operator() (bool filtering)
{
TraversorF<typename PFP::MAP> trav(m_map) ;
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
......@@ -338,7 +315,6 @@ public: