Commit 97585ab7 authored by Sylvain Thery's avatar Sylvain Thery

compil testing ...

parent e00e38d9
......@@ -99,13 +99,13 @@ void Viewer::cb_initGL()
m_phongShader->setDiffuse(colDif) ;
m_phongShader->setSpecular(colSpec) ;
m_phongShader->setShininess(shininess) ;
m_phongShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_phongShader->setBackColor(Geom::Vec4f(0,0,0.2f,0)) ;
m_flatShader = new Utils::ShaderSimpleFlat(true,false) ;
m_flatShader->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ;
m_flatShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_flatShader->setBackColor(Geom::Vec4f(0,0,0.2f,0)) ;
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
......
......@@ -135,7 +135,7 @@ void MyQT::squareTiling(int code)
{
std::cout << "square grid helicoid tiling" << std::endl;
Algo::Surface::Tilings::Square::Grid<PFP> g(myMap,20,20,true);
g.embedIntoHelicoid(position, 0.2, 0.3, 0.8, 2.0);
g.embedIntoHelicoid(position, 0.2f, 0.3f, 0.8f, 2.0f);
// Geom::Matrix44f trf;
// trf.identity();
......
......@@ -31,7 +31,7 @@ void MyQT::cb_initGL()
{
position = myMap.addAttribute<PFP::VEC3, VERTEX, MAP>("position");
Algo::Surface::Tilings::Square::Cylinder<PFP> c(myMap,50,50);
c.embedIntoCylinder(position,0.5,0.7,1.0);
c.embedIntoCylinder(position,0.5f,0.7f,1.0f);
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
......
......@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.6)
project(testing_algo)
#add_subdirectory(BooleanOperator)
#add_subdirectory(Decimation)
add_subdirectory(Decimation)
#add_subdirectory(Export)
#add_subdirectory(Filtering)
add_subdirectory(Geometry)
......@@ -15,10 +15,10 @@ add_subdirectory(Geometry)
#add_subdirectory(Modelisation)
#add_subdirectory(MovingObjects)
#add_subdirectory(Multiresolution)
#add_subdirectory(ProgressiveMesh)
#add_subdirectory(Remeshing)
add_subdirectory(ProgressiveMesh)
add_subdirectory(Remeshing)
#add_subdirectory(Render)
#add_subdirectory(Selection)
#add_subdirectory(Simulation)
add_subdirectory(Selection)
add_subdirectory(Simulation)
add_subdirectory(Tiling)
add_subdirectory(Topo)
cmake_minimum_required(VERSION 2.6)
project(testing_algo_decimation)
add_executable( test_algo_decimation
algo_decimation.cpp
colorPerVertexApproximator.cpp
decimation.cpp
edgeSelector.cpp
geometryApproximator.cpp
geometryPredictor.cpp
halfEdgeSelector.cpp
predictor.cpp
)
target_link_libraries( test_algo_decimation
${CGoGN_LIBS} ${CGoGN_EXT_LIBS})
#include <iostream>
extern int test_geometryApproximator();
extern int test_colorPerVertexApproximator();
extern int test_predictor();
extern int test_geometryPredictor();
extern int test_edgeSelector();
extern int test_halfEdgeSelector();
extern int test_decimation();
int main()
{
test_geometryApproximator();
test_colorPerVertexApproximator();
test_predictor();
test_geometryPredictor();
test_edgeSelector();
test_halfEdgeSelector();
test_decimation();
return 0;
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2013, IGG Team, ICube, 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 "Algo/Decimation/predictor.h"
#ifndef __APPROXIMATOR_H__
#define __APPROXIMATOR_H__
namespace CGoGN
{
namespace Algo
{
namespace Surface
{
namespace Decimation
{
enum ApproximatorType
{
// One approx per edge
// Geometry approximators
A_QEM = 0, /**< Approximates the geometry of an edge collapse by quadric error metric minimization [GH97]. */
A_MidEdge = 1, /**< Approximates the geometry of an edge collapse by placing the resulting vertex in its middle. */
A_CornerCutting = 2,
A_TangentPredict1 = 3,
A_TangentPredict2 = 4,
A_NormalArea = 5, /**< EXPERIMENTAL Approximates the geometry of an edge collapse by minimization of its normal times area measure [Sauvage] */
// Geometry + color approximators
A_ColorNaive = 6, /**< Approximates the color of the resulting vertex by linear interpolation (based on the approximated position) of its two predecessors. */
A_ColorQEMext = 7, /**< Approximates both geometry and color of the resulting vertex by minimization of the extended (R^6) quadric error metric [GH98]. */
A_GeomColorOpt = 8, /**< EXPERIMENTAL. */
// One approx per half-edge
// Generic (considers all provided attributes) approximator
A_hHalfCollapse = 9, /**< Approximates all provided attributes of a half-edge collapse by keeping the attributes of the first of two vertices. */
// Geometry approximator
A_hQEM = 10, /**< Approximates the geometry of a full-edge collapse by quadric error metric minimization [GH97]. Compatible version for half-edge selectors. */
A_OTHER /**< Can be used for extensions. */
} ;
/*!
* \class ApproximatorGen
* \brief Generic class holder for approximators
*/
template <typename PFP>
class ApproximatorGen
{
protected:
typename PFP::MAP& m_map ;
public:
ApproximatorGen(typename PFP::MAP& m) : m_map(m)
{}
virtual ~ApproximatorGen()
{}
virtual const std::string& getApproximatedAttributeName() const = 0 ;
virtual ApproximatorType getType() const = 0 ;
virtual bool init() = 0 ;
virtual void approximate(Dart d) = 0 ;
virtual void saveApprox(Dart d) = 0 ;
virtual void affectApprox(Dart d) = 0 ;
virtual const PredictorGen<PFP>* getPredictor() const = 0 ;
// virtual REAL detailMagnitude(Dart d) = 0 ;
// virtual void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) = 0 ;
} ;
/*!
* \class Approximator
* \brief Generic class for approximators
*/
template <typename PFP, typename T, unsigned int ORBIT>
class Approximator : public ApproximatorGen<PFP>
{
typedef typename PFP::MAP MAP ;
protected:
VertexAttribute<T, MAP>& m_attr ; // vertex attribute to be approximated
AttributeHandler<T, ORBIT, MAP> m_approx ; // attribute to store approximation result
AttributeHandler<T, ORBIT, MAP> m_detail ; // attribute to store detail information for reconstruction
T m_app ;
Predictor<PFP, T>* m_predictor ;
public:
Approximator(MAP& m, VertexAttribute<T, MAP>& attr, Predictor<PFP, T>* predictor) ;
virtual ~Approximator() ;
const VertexAttribute<T, MAP>& getApproximatedAttribute() const ;
VertexAttribute<T, MAP>& getApproximatedAttribute() ;
const std::string& getApproximatedAttributeName() const ;
const AttributeHandler<T, ORBIT, MAP>& getApproximationResultAttribute() const;
void saveApprox(Dart d) ;
void affectApprox(Dart d) ;
const T& getApprox(Dart d) const ;
const Predictor<PFP, T>* getPredictor() const ;
const T& getDetail(Dart d) const ;
void setDetail(Dart d, const T& val) ;
// REAL detailMagnitude(Dart d) ; // TODO works only for vector types !!
// void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform) ; // TODO works only for vector types !!
} ;
} // namespace Decimation
} // namespace surface
} // namespace Algo
} // namespace CGoGN
#include "Algo/Decimation/approximator.hpp"
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2013, IGG Team, ICube, 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/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h"
#ifndef __COLOR_APPROXIMATOR_H__
#define __COLOR_APPROXIMATOR_H__
#include "Algo/Decimation/colorPerVertexApproximator.h"
#include "Algo/Decimation/approximator.h"
using namespace CGoGN;
namespace CGoGN
{
namespace Algo
{
namespace Surface
struct PFP1 : public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
namespace Decimation
struct PFP2 : public PFP_DOUBLE
{
typedef EmbeddedMap2 MAP;
};
template <typename PFP>
class Approximator_ColorNaive : public Approximator<PFP, typename PFP::VEC3, EDGE>
struct PFP3 : public PFP_DOUBLE
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
typedef EmbeddedGMap2 MAP;
};
protected:
const VertexAttribute<VEC3, MAP>& m_position ;
const EdgeAttribute<VEC3, MAP>& m_approximatedPosition ;
public:
Approximator_ColorNaive(MAP& m, VertexAttribute<VEC3, MAP>& color, const VertexAttribute<VEC3, MAP>& position, const EdgeAttribute<VEC3, MAP>& approximatedPosition, Predictor<PFP, VEC3>* pred = NULL) :
Approximator<PFP, VEC3, EDGE>(m, color, pred),
m_position(position),
m_approximatedPosition(approximatedPosition)
{}
~Approximator_ColorNaive()
{}
ApproximatorType getType() const { return A_ColorNaive ; }
bool init();
void approximate(Dart d) ;
} ;
/*
template <typename PFP>
class Approximator_ColorQEMext : public Approximator<PFP, typename PFP::VEC3, EDGE>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
typedef Geom::Vector<6, REAL> VEC6 ;
protected:
VertexAttribute<Utils::QuadricNd<REAL,6>, MAP> m_quadric ;
VertexAttribute<VEC3, MAP>* m_position ;
VertexAttribute<VEC3, MAP>* m_color ;
template class Algo::Surface::Decimation::Approximator_ColorNaive<PFP1>;
public:
Approximator_ColorQEMext(MAP& m, VertexAttribute<VEC3, MAP>& position, VertexAttribute<VEC3, MAP>& color, Predictor<PFP, VEC3>* pred = NULL) :
Approximator<PFP, VEC3, EDGE>(m, position, pred),
m_position(position),
m_color(color)
{}
~Approximator_ColorQEMext()
{}
ApproximatorType getType() const { return A_ColorQEMext ; }
bool init() ;
void approximate(Dart d) ;
} ;
template <typename PFP>
class Approximator_GeomColOpt : public Approximator<PFP, typename PFP::VEC3, EDGE>
int test_colorPerVertexApproximator()
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
protected:
VertexAttribute<Utils::Quadric<REAL>, MAP> m_quadric ;
VertexAttribute<VEC3, MAP>* m_position ;
VertexAttribute<VEC3, MAP>* m_color ;
public:
Approximator_GeomColOpt(MAP& m, std::vector<VertexAttribute<VEC3, MAP>*>& attr, Predictor<PFP, VEC3>* pred = NULL) :
Approximator<PFP, VEC3, EDGE>(m, attr, pred)
{
assert(attr.size() > 1 || !"Approximator_GeomColOpt: there are not sufficient attributes provided") ;
m_position = this->m_attrV[0] ;
m_color = this->m_attrV[1] ;
}
~Approximator_GeomColOpt()
{}
ApproximatorType getType() const
{
return A_GeomColorOpt ;
}
bool init() ;
void approximate(Dart d) ;
} ;
*/
} // namespace Decimation
} // namespace Surface
} // namespace Algo
} // namespace CGoGN
#include "Algo/Decimation/colorPerVertexApproximator.hpp"
return 0;
}
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2013, IGG Team, ICube, 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 *
* *
*******************************************************************************/
#ifndef __DECIMATION_H__
#define __DECIMATION_H__
#include "Algo/Decimation/edgeSelector.h"
#include "Algo/Decimation/halfEdgeSelector.h"
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/colorPerVertexApproximator.h"
namespace CGoGN
{
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h"
#include "Algo/Decimation/decimation.h"
namespace Algo
using namespace CGoGN;
struct PFP1 : public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
namespace Surface
struct PFP2 : public PFP_DOUBLE
{
typedef EmbeddedMap2 MAP;
};
namespace Decimation
struct PFP3 : public PFP_DOUBLE
{
typedef EmbeddedGMap2 MAP;
};
/**
* \fn decimate
* Function that decimates the provided mesh through successive edge collapses
* by using a declared selector and approximator type (see \file approximator.h and \file selector.h).
*
* \param map the map to decimate
* \param s the SelectorType
* \param a the ApproximatorType
* \param position the vertex position embeddings
* \param nbWantedVertices the aimed amount of vertices after decimation
* \param edgeErrors will (if not null) contain the edge errors computed by the approximator/selector (default NULL)
* \param callback_wrapper a callback function for progress monitoring (default NULL)
* \param callback_object the object to call the callback on (default NULL)
*
* \return >= 0 if finished correctly : 1 if no more edges are collapsible, 0 is nbWantedVertices achieved, -1 if the initialisation of the selector failed
*/
template <typename PFP, typename T>
int decimate(
typename PFP::MAP& map,
template int Algo::Surface::Decimation::decimate<PFP1, Geom::Vec3f>(
PFP1::MAP& map,
SelectorType s,
ApproximatorType a,
std::vector<VertexAttribute<T, typename PFP::MAP> >& attribs,
std::vector<VertexAttribute<Geom::Vec3f, PFP1::MAP> >& attribs,
unsigned int nbWantedVertices,
EdgeAttribute<typename PFP::REAL, typename PFP::MAP>* edgeErrors = NULL,
void (*callback_wrapper)(void*, const void*) = NULL,
void* callback_object = NULL
) ;
/**
*\fn decimate
* Function that decimates the provided mesh through successive edge collapses
* by providing the selector and the approximators
*
* \param map the map to decimate
* \param s the selector
* \param a a vector containing the approximators
* \param nbWantedVertices the aimed amount of vertices after decimation
* \param recomputePriorityList if false and a priority list exists, it is not recomputed
* \param edgeErrors will (if not null) contain the edge errors computed by the approximator/selector (default NULL)
* \param callback_wrapper a callback function for progress monitoring (default NULL)
* \param callback_object the object to call the callback on (default NULL)
*
* \return >= 0 if finished correctly : 1 if no more edges are collapsible, 0 is nbWantedVertices achieved, -1 if the initialisation of the selector failed
*/
template <typename PFP>
int decimate(
typename PFP::MAP& map,
Selector<PFP>* s,
std::vector<ApproximatorGen<PFP>*>& a,
EdgeAttribute<PFP1::REAL, PFP1::MAP>* edgeErrors,
void(*callback_wrapper)(void*, const void*) ,
void* callback_object
);
template int Algo::Surface::Decimation::decimate<PFP1>(
PFP1::MAP& map,
Selector<PFP1>* s,
std::vector<ApproximatorGen<PFP1>*>& a,
unsigned int nbWantedVertices,
bool recomputePriorityList = true,
EdgeAttribute<typename PFP::REAL,
typename PFP::MAP>* edgeErrors = NULL,
void (*callback_wrapper)(void*, const void*) = NULL,
void* callback_object = NULL
) ;
bool recomputePriorityList,
EdgeAttribute<PFP1::REAL, PFP1::MAP>* edgeErrors,
void(*callback_wrapper)(void*, const void*),
void* callback_object
);
} // namespace Decimation
} // namespace Surface
template int Algo::Surface::Decimation::decimate<PFP2, Geom::Vec3d>(
PFP2::MAP& map,
SelectorType s,
ApproximatorType a,
std::vector<VertexAttribute<Geom::Vec3d, PFP2::MAP> >& attribs,
unsigned int nbWantedVertices,
EdgeAttribute<PFP2::REAL, PFP2::MAP>* edgeErrors,
void(*callback_wrapper)(void*, const void*),
void* callback_object
);
//
//
//template int Algo::Surface::Decimation::decimate<PFP2>(
// PFP2::MAP& map,
// Selector<PFP2>* s,
// std::vector<ApproximatorGen<PFP2>*>& a,
// unsigned int nbWantedVertices,
// bool recomputePriorityList,
// EdgeAttribute<PFP2::REAL, PFP2::MAP>* edgeErrors,
// void(*callback_wrapper)(void*, const void*),
// void* callback_object
// );
} // namespace Algo
} // namespace CGoGN
#include "Algo/Decimation/decimation.hpp"
int test_decimation()
{
#endif
return 0;
}
\ No newline at end of file
This diff is collapsed.
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2013, IGG Team, ICube, 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/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Topology/gmap/embeddedGMap2.h"
#ifndef __GEOMETRY_APPROXIMATOR_H__
#define __GEOMETRY_APPROXIMATOR_H__
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/approximator.h"
#include "Utils/convertType.h"
#include <Eigen/Dense>
using namespace CGoGN;
namespace CGoGN
{
namespace Algo
{
namespace Surface
struct PFP1 : public PFP_STANDARD
{
typedef EmbeddedMap2 MAP;
};
namespace Decimation
struct PFP2 : public PFP_DOUBLE
{
typedef EmbeddedMap2 MAP;
};
template <typename PFP>
class Approximator_QEM : public Approximator<PFP, typename PFP::VEC3, EDGE>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
VertexAttribute<Utils::Quadric<REAL>, MAP> m_quadric ;
public:
Approximator_QEM(MAP& m, VertexAttribute<VEC3, MAP>& attr, Predictor<PFP, VEC3>* pred = NULL) :
Approximator<PFP, VEC3, EDGE>(m, attr, pred)
{}
~Approximator_QEM()
{}
ApproximatorType getType() const { return A_QEM ; }
bool init() ;
void approximate(Dart d) ;
} ;
template <typename PFP>
class Approximator_QEMhalfEdge : public Approximator<PFP, typename PFP::VEC3, DART>
struct PFP3 : public PFP_DOUBLE
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ;
protected:
VertexAttribute<Utils::Quadric<REAL>, MAP> m_quadric ;
public:
Approximator_QEMhalfEdge(MAP& m, VertexAttribute<VEC3, MAP>& attr, Predictor<PFP, VEC3>* pred = NULL) :
Approximator<PFP, VEC3, DART>(m, attr, pred)
{}
~Approximator_QEMhalfEdge()
{}
ApproximatorType getType() const { return A_hQEM ; }
bool init() ;
void approximate(Dart d) ;
} ;
typedef EmbeddedGMap2 MAP;
};
template <typename PFP, typename T>
class Approximator_MidEdge : public Approximator<PFP, T, EDGE>
{
public: