Commit b009736c authored by Sylvain Thery's avatar Sylvain Thery
Browse files

more compil testing

parent b4155a6f
...@@ -5,14 +5,14 @@ project(testing_algo) ...@@ -5,14 +5,14 @@ project(testing_algo)
#add_subdirectory(BooleanOperator) #add_subdirectory(BooleanOperator)
add_subdirectory(Decimation) add_subdirectory(Decimation)
#add_subdirectory(Export) #add_subdirectory(Export)
#add_subdirectory(Filtering) add_subdirectory(Filtering)
add_subdirectory(Geometry) add_subdirectory(Geometry)
#add_subdirectory(Histogram) #add_subdirectory(Histogram)
#add_subdirectory(ImplicitHierarchicalMesh) #add_subdirectory(ImplicitHierarchicalMesh)
#add_subdirectory(Import) #add_subdirectory(Import)
#add_subdirectory(LinearSolving) #add_subdirectory(LinearSolving)
#add_subdirectory(MC) #add_subdirectory(MC)
#add_subdirectory(Modelisation) add_subdirectory(Modelisation)
#add_subdirectory(MovingObjects) #add_subdirectory(MovingObjects)
#add_subdirectory(Multiresolution) #add_subdirectory(Multiresolution)
add_subdirectory(ProgressiveMesh) add_subdirectory(ProgressiveMesh)
......
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
#include "Topology/gmap/embeddedGMap2.h" #include "Topology/gmap/embeddedGMap2.h"
using namespace CGoGN;
#include "Algo/Decimation/halfEdgeSelector.h" #include "Algo/Decimation/halfEdgeSelector.h"
using namespace CGoGN;
struct PFP1 : public PFP_STANDARD struct PFP1 : public PFP_STANDARD
{ {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#include "Topology/map/embeddedMap2.h" #include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h" #include "Topology/gmap/embeddedGMap2.h"
#include "Algo/Decimation/predictor.h"
using namespace CGoGN; using namespace CGoGN;
#include "Algo/Decimation/predictor.h"
struct PFP1 : public PFP_STANDARD struct PFP1 : public PFP_STANDARD
......
cmake_minimum_required(VERSION 2.6)
project(testing_algo_filtering)
add_executable( test_algo_filtering
algo_filtering.cpp
average.cpp
average_normals.cpp
bilateral.cpp
taubin.cpp
tools.cpp
)
target_link_libraries( test_algo_filtering
${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
#include <iostream>
extern int test_average();
extern int test_average_normals();
extern int test_bilateral();
extern int test_taubin();
extern int test_tools();
int main()
{
test_average();
test_average_normals();
test_bilateral();
test_taubin();
test_tools();
return 0;
}
/******************************************************************************* #include "Topology/generic/parameters.h"
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * #include "Topology/map/embeddedMap2.h"
* version 0.1 * #include "Topology/map/embeddedMap3.h"
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * #include "Topology/gmap/embeddedGMap2.h"
* *
* 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 * #include "Algo/Filtering/average.h"
* 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.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/traversor/traversorCell.h"
#include "Algo/Filtering/functors.h"
#include "Algo/Selection/collector.h"
namespace CGoGN
{
namespace Algo using namespace CGoGN;
struct PFP1 : public PFP_STANDARD
{ {
typedef EmbeddedMap2 MAP;
};
namespace Surface struct PFP2 : public PFP_DOUBLE
{ {
typedef EmbeddedMap2 MAP;
};
namespace Filtering struct PFP3 : public PFP_DOUBLE
{ {
typedef EmbeddedGMap2 MAP;
};
enum neighborhood { INSIDE = 1, BORDER = 2 };
template <typename PFP, typename T> template void Algo::Surface::Filtering::filterAverageAttribute_OneRing<PFP1, Geom::Vec3d>(PFP1::MAP& map,
void filterAverageAttribute_OneRing( const VertexAttribute<Geom::Vec3d, PFP1::MAP>& attIn, VertexAttribute<Geom::Vec3d, PFP1::MAP>& attOut, int neigh);
typename PFP::MAP& map,
const VertexAttribute<T, typename PFP::MAP>& attIn, template void Algo::Surface::Filtering::filterAverageVertexAttribute_WithinSphere<PFP1, Geom::Vec3d>(PFP1::MAP& map,
VertexAttribute<T, typename PFP::MAP>& attOut, const VertexAttribute<Geom::Vec3d, PFP1::MAP>& attIn, VertexAttribute<Geom::Vec3d, PFP1::MAP>& attOut, int neigh,
int neigh) VertexAttribute<PFP1::VEC3, PFP1::MAP>& position, PFP1::REAL radius);
{
FunctorAverage<VertexAttribute<T, typename PFP::MAP> > fa(attIn) ; template void Algo::Surface::Filtering::filterAverageEdgeAttribute_WithinSphere<PFP1, Geom::Vec3d>(PFP1::MAP& map,
Algo::Surface::Selection::Collector_OneRing<PFP> col(map) ; const EdgeAttribute<Geom::Vec3d, PFP1::MAP>& attIn, EdgeAttribute<Geom::Vec3d, PFP1::MAP>& attOut, int neigh,
VertexAttribute<PFP1::VEC3, PFP1::MAP>& position, PFP1::REAL radius);
TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(!map.isBoundaryVertex(d))
{
if (neigh & INSIDE)
col.collectAll(d) ;
else
col.collectBorder(d) ;
fa.reset() ;
if (neigh & INSIDE)
{
switch (attIn.getOrbit())
{
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() ;
}
else
attOut[d] = attIn[d] ;
}
}
template <typename PFP, typename T>
void filterAverageVertexAttribute_WithinSphere(
typename PFP::MAP& map,
const VertexAttribute<T, typename PFP::MAP>& attIn,
VertexAttribute<T, typename PFP::MAP>& attOut,
int neigh,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
typename PFP::REAL radius)
{
FunctorAverage<VertexAttribute<T, typename PFP::MAP> > faInside(attIn) ;
FunctorAverageOnSphereBorder<PFP, T> faBorder(map, attIn, position) ;
Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
if(!map.isBoundaryVertex(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() ;
}
else
attOut[d] = attIn[d] ;
}
}
template <typename PFP, typename T>
void filterAverageEdgeAttribute_WithinSphere(
typename PFP::MAP& map,
const EdgeAttribute<T, typename PFP::MAP>& attIn,
EdgeAttribute<T, typename PFP::MAP>& attOut,
int neigh,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
typename PFP::REAL radius)
{
FunctorAverage<EdgeAttribute<T, typename PFP::MAP> > fa(attIn) ;
Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorE<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
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() ;
}
}
template <typename PFP, typename T>
void filterAverageFaceAttribute_WithinSphere(
typename PFP::MAP& map,
const FaceAttribute<T, typename PFP::MAP>& attIn,
FaceAttribute<T, typename PFP::MAP>& attOut,
int neigh,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
typename PFP::REAL radius)
{
FunctorAverage<FaceAttribute<T, typename PFP::MAP> > fa(attIn) ;
Algo::Surface::Selection::Collector_WithinSphere<PFP> col(map, position, radius) ;
TraversorF<typename PFP::MAP> t(map) ; template void Algo::Surface::Filtering::filterAverageFaceAttribute_WithinSphere<PFP1, Geom::Vec3d>(PFP1::MAP& map,
for(Dart d = t.begin(); d != t.end(); d = t.next()) const FaceAttribute<Geom::Vec3d, PFP1::MAP>& attIn, FaceAttribute<Geom::Vec3d, PFP1::MAP>& attOut, int neigh,
{ VertexAttribute<PFP1::VEC3, PFP1::MAP>& position, PFP1::REAL radius);
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() ;
}
}
} // namespace Filtering
} // namespace Surface template void Algo::Surface::Filtering::filterAverageAttribute_OneRing<PFP2, Geom::Vec3f>(PFP2::MAP& map,
const VertexAttribute<Geom::Vec3f, PFP2::MAP>& attIn, VertexAttribute<Geom::Vec3f, PFP2::MAP>& attOut, int neigh);
} // namespace Algo template void Algo::Surface::Filtering::filterAverageVertexAttribute_WithinSphere<PFP2, Geom::Vec3f>(PFP2::MAP& map,
const VertexAttribute<Geom::Vec3f, PFP2::MAP>& attIn, VertexAttribute<Geom::Vec3f, PFP2::MAP>& attOut, int neigh,
VertexAttribute<PFP2::VEC3, PFP2::MAP>& position, PFP2::REAL radius);
template void Algo::Surface::Filtering::filterAverageEdgeAttribute_WithinSphere<PFP2, Geom::Vec3f>(PFP2::MAP& map,
const EdgeAttribute<Geom::Vec3f, PFP2::MAP>& attIn, EdgeAttribute<Geom::Vec3f, PFP2::MAP>& attOut, int neigh,
VertexAttribute<PFP2::VEC3, PFP2::MAP>& position, PFP2::REAL radius);
template void Algo::Surface::Filtering::filterAverageFaceAttribute_WithinSphere<PFP2, Geom::Vec3f>(PFP2::MAP& map,
const FaceAttribute<Geom::Vec3f, PFP2::MAP>& attIn, FaceAttribute<Geom::Vec3f, PFP2::MAP>& attOut, int neigh,
VertexAttribute<PFP2::VEC3, PFP2::MAP>& position, PFP2::REAL radius);
template void Algo::Surface::Filtering::filterAverageAttribute_OneRing<PFP3, Geom::Vec3f>(PFP3::MAP& map,
const VertexAttribute<Geom::Vec3f, PFP3::MAP>& attIn, VertexAttribute<Geom::Vec3f, PFP3::MAP>& attOut, int neigh);
template void Algo::Surface::Filtering::filterAverageVertexAttribute_WithinSphere<PFP3, Geom::Vec3f>(PFP3::MAP& map,
const VertexAttribute<Geom::Vec3f, PFP3::MAP>& attIn, VertexAttribute<Geom::Vec3f, PFP3::MAP>& attOut, int neigh,
VertexAttribute<PFP3::VEC3, PFP3::MAP>& position, PFP3::REAL radius);
template void Algo::Surface::Filtering::filterAverageEdgeAttribute_WithinSphere<PFP3, Geom::Vec3f>(PFP3::MAP& map,
const EdgeAttribute<Geom::Vec3f, PFP3::MAP>& attIn, EdgeAttribute<Geom::Vec3f, PFP3::MAP>& attOut, int neigh,
VertexAttribute<PFP3::VEC3, PFP3::MAP>& position, PFP3::REAL radius);
template void Algo::Surface::Filtering::filterAverageFaceAttribute_WithinSphere<PFP3, Geom::Vec3f>(PFP3::MAP& map,
const FaceAttribute<Geom::Vec3f, PFP3::MAP>& attIn, FaceAttribute<Geom::Vec3f, PFP3::MAP>& attOut, int neigh,
VertexAttribute<PFP3::VEC3, PFP3::MAP>& position, PFP3::REAL radius);
int test_average()
{
} // namespace CGoGN return 0;
}
\ No newline at end of file
/******************************************************************************* #include "Topology/generic/parameters.h"
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * #include "Topology/map/embeddedMap2.h"
* version 0.1 * #include "Topology/gmap/embeddedGMap2.h"
* Copyright (C) 2009-2012, 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.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor2.h"
namespace CGoGN #include "Algo/Filtering/average_normals.h"
{
namespace Algo
{
namespace Surface using namespace CGoGN;
{
namespace Filtering struct PFP1 : public PFP_STANDARD
{ {
typedef EmbeddedMap2 MAP;
};
/** struct PFP2 : public PFP_DOUBLE
* compute new position of vertices from normals (normalAverage & MMSE filters)
* @param map the map
*/
template <typename PFP>
void computeNewPositionsFromFaceNormals(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position,
VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position2,
const FaceAttribute<typename PFP::REAL, typename PFP::MAP>& faceArea,
const FaceAttribute<typename PFP::VEC3, typename PFP::MAP>& faceCentroid,
const FaceAttribute<typename PFP::VEC3, typename PFP::MAP>& faceNormal,
const FaceAttribute<typename PFP::VEC3, typename PFP::MAP>& faceNewNormal)
{ {
typedef typename PFP::VEC3 VEC3 ; typedef EmbeddedMap2 MAP;
typedef typename PFP::REAL REAL ; };
TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
const VEC3& pos_d = position[d] ;
VEC3 displ(0) ;
REAL sumAreas = 0 ;
Traversor2VF<typename PFP::MAP> tvf(map, d) ; struct PFP3 : public PFP_DOUBLE
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 ;
}
}
template <typename PFP>
void filterAverageNormals(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position2)
{ {
typedef typename PFP::MAP MAP ; typedef EmbeddedGMap2 MAP;
typedef typename PFP::VEC3 VEC3 ; };
typedef typename PFP::REAL REAL ;
FaceAutoAttribute<REAL, MAP> faceArea(map, "faceArea") ;
FaceAutoAttribute<VEC3, MAP> faceNormal(map, "faceNormal") ;
FaceAutoAttribute<VEC3, MAP> faceCentroid(map, "faceCentroid") ;
Algo::Surface::Geometry::computeAreaFaces<PFP>(map, position, faceArea) ;
Algo::Surface::Geometry::computeNormalFaces<PFP>(map, position, faceNormal) ;
Algo::Surface::Geometry::computeCentroidFaces<PFP>(map, position, faceCentroid) ;
FaceAutoAttribute<VEC3, MAP> faceNewNormal(map, "faceNewNormal") ;
// Compute new normals
TraversorF<MAP> tf(map) ;
for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{
REAL sumArea = 0 ;
VEC3 meanFilter(0) ;
// traversal of adjacent faces (by edges and vertices)
Traversor2FFaV<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
computeNewPositionsFromFaceNormals<PFP>(
map, position, position2, faceArea, faceCentroid, faceNormal, faceNewNormal) ;
}
template <typename PFP>
void filterMMSE(typename PFP::MAP& map, float sigmaN2, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position2)
{
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
FaceAutoAttribute<REAL, MAP> faceArea(map, "faceArea") ;
FaceAutoAttribute<VEC3, MAP> faceNormal(map, "faceNormal") ;
FaceAutoAttribute<VEC3, MAP> faceCentroid(map, "faceCentroid") ;
Algo::Surface::Geometry::computeAreaFaces<PFP>(map, position, faceArea) ;
Algo::Surface::Geometry::computeNormalFaces<PFP>(map, position, faceNormal) ;
Algo::Surface::Geometry::computeCentroidFaces<PFP>(map, position, faceCentroid) ;
FaceAutoAttribute<VEC3, MAP> faceNewNormal(map, "faceNewNormal") ;
// Compute new normals
TraversorF<typename PFP::MAP> tf(map) ;
for(Dart d = tf.begin(); d != tf.end(); d = tf.next())
{
// traversal of neighbour vertices
REAL sumArea = 0 ;
REAL sigmaX2 = 0 ;
REAL sigmaY2 = 0 ;
REAL sigmaZ2 = 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] ;
}
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 ;
if(sigmaX2 < sigmaN2) template void Algo::Surface::Filtering::computeNewPositionsFromFaceNormals<PFP1>(PFP1::MAP& map,
newNormal[0] = meanFilter[0] ; const VertexAttribute<PFP1::VEC3, PFP1::MAP>& position, VertexAttribute<PFP1::VEC3, PFP1::MAP>& position2,
else const FaceAttribute<PFP1::REAL, PFP1::MAP>& faceArea,
{ const FaceAttribute<PFP1::VEC3, PFP1::MAP>& faceCentroid,
newNormal[0] = (1 - (sigmaN2 / sigmaX2)) * oldNormal[0] ; const FaceAttribute<PFP1::VEC3, PFP1::MAP>& faceNormal,
newNormal[0] += (sigmaN2 / sigmaX2) * meanFilter[0] ; const FaceAttribute<PFP1::VEC3, PFP1::MAP>& faceNewNormal);
}
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] ;
}