Commit b64fb9aa authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

begin of cleanup decimation

parent 96810274
......@@ -54,7 +54,8 @@ enum ApproximatorType
// note: the following "h" prefix means that half-edges are prioritized instead of edges.
A_hHalfCollapse = 10,
A_hQEM = 11,
A_hLightfieldHalf = 12
A_hLightfieldHalf = 12,
A_MidEdgeLFopt = 13
} ;
template <typename PFP>
......@@ -74,7 +75,6 @@ public:
virtual ~ApproximatorGen()
{}
virtual const std::string& getApproximatedAttributeName(unsigned int index = 0) const = 0 ;
// virtual std::vector<std::string> getApproximatedAttributeNames() const = 0 ;
virtual ApproximatorType getType() const = 0 ;
virtual unsigned int getNbApproximated() const = 0 ;
virtual bool init() = 0 ;
......@@ -188,6 +188,11 @@ public:
return *(m_attrV[index]) ;
}
VertexAttribute<T>& getAttr(unsigned int index = 0)
{
return *(m_attrV[index]) ;
}
std::vector<T> getAllApprox(Dart d) const
{
std::vector<T> res ;
......
......@@ -228,7 +228,7 @@ void Approximator_GeomColOpt<PFP>::approximate(Dart d)
const VEC3& p0 = this->m_attrV[0]->operator[](d) ; // let the new vertex lie
const VEC3& p1 = this->m_attrV[0]->operator[](dd) ; // on either one of the two endpoints
if(!opt)
if(false && !opt)
{
VEC3 p12 = (p0 + p1) / 2.0f ; // or the middle of the edge
REAL e1 = quad(p0) ;
......
......@@ -29,7 +29,6 @@
#include "Algo/Decimation/halfEdgeSelector.h"
#include "Algo/Decimation/geometryApproximator.h"
#include "Algo/Decimation/colorPerVertexApproximator.h"
#include "Algo/Decimation/lightfieldApproximator.h"
namespace CGoGN
{
......@@ -45,20 +44,21 @@ namespace Decimation
/**
* Decimate the mesh through edge contraction
* by using a selector and approximator scheme.
* 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 selected the selector stipulating which darts are eligible for contraction
* \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>
void decimate(
int decimate(
typename PFP::MAP& map,
SelectorType s,
ApproximatorType a,
......@@ -68,9 +68,33 @@ void decimate(
void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL
) ;
/**
* Decimate the mesh through edge contraction
* 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 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,
EdgeSelector<PFP>* s,
std::vector<ApproximatorGen<PFP>*>& a,
unsigned int nbWantedVertices,
EdgeAttribute<typename PFP::REAL> *edgeErrors = NULL,
void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL
) ;
} //namespace Decimation
}
} // Surface
} //namespace Algo
......
......@@ -35,7 +35,7 @@ namespace Decimation
{
template <typename PFP>
void decimate(
int decimate(
typename PFP::MAP& map, SelectorType s, ApproximatorType a,
std::vector<VertexAttribute<typename PFP::VEC3>* >& attribs, unsigned int nbWantedVertices,
EdgeAttribute<typename PFP::REAL> *edgeErrors,
......@@ -106,7 +106,7 @@ void decimate(
// pos
approximators.push_back(new Approximator_QEMhalfEdge<PFP>(map, attribs)) ;
break ;
case A_hLightfieldHalf:
/*case A_hLightfieldHalf:
{
v_approx = new std::vector<VertexAttribute<typename PFP::VEC3>* >[3] ;
......@@ -148,6 +148,27 @@ void decimate(
approximators.push_back(new Approximator_HemiFuncCoefs<PFP>(map, v_approx[2])) ;
}
break ;
case A_MidEdgeLFopt :
{
v_approx = new std::vector<VertexAttribute<typename PFP::VEC3>* >[3] ;
// pos
v_approx[0].push_back(attribs[0]) ;
approximators.push_back(new Approximator_MidEdge<PFP>(map, v_approx[0])) ;
// frame
assert(attribs.size() >= 4 || !"Decimate: A_MidEdgeLFopt --> not enough attribs provided") ;
for (unsigned int i = 0 ; i < 3 ; ++i)
v_approx[1].push_back(attribs[i+1]) ;
approximators.push_back(new Approximator_FrameInterpolation<PFP>(map, v_approx[1])) ;
// hemifunction
assert(attribs.size() >= 5 || !"Decimate: A_MidEdgeLFopt --> not enough attribs provided") ;
for (unsigned int i = 0 ; i < attribs.size() - 4 ; ++i)
v_approx[2].push_back(attribs[i+4]) ;
approximators.push_back(new Approximator_HemiFuncCoefs<PFP>(map, v_approx[2])) ;
}
break ;*/
}
switch(s)
......@@ -191,7 +212,16 @@ void decimate(
case S_hQEMml :
selector = new HalfEdgeSelector_QEMml<PFP>(map, position, approximators) ;
break ;
case S_Lightfield :
case S_hColorExperimental:
selector = new HalfEdgeSelector_ColorExperimental<PFP>(map, position, approximators) ;
break ;
case S_hColorGradient:
selector = new HalfEdgeSelector_ColorGradient<PFP>(map, position, approximators) ;
break ;
case S_GeomColOptGrad:
selector = new EdgeSelector_GeomColOptGradient<PFP>(map, position, approximators) ;
break ;
/*case S_Lightfield :
selector = new EdgeSelector_Lightfield<PFP>(map, position, approximators) ;
break ;
case S_hLightfield :
......@@ -203,12 +233,6 @@ void decimate(
case S_hLightfieldKCL :
selector = new HalfEdgeSelector_LightfieldKCL<PFP>(map, position, approximators) ;
break ;
case S_hColorExperimental:
selector = new HalfEdgeSelector_ColorExperimental<PFP>(map, position, approximators) ;
break ;
case S_hColorGradient:
selector = new HalfEdgeSelector_ColorGradient<PFP>(map, position, approximators) ;
break ;
case S_hLFexperimental:
selector = new HalfEdgeSelector_LFexperimental<PFP>(map, position, approximators) ;
break ;
......@@ -221,24 +245,37 @@ void decimate(
case S_hLFperFace:
selector = new HalfEdgeSelector_LFperFace<PFP>(map, position, approximators) ;
break ;
case S_GeomColOptGrad:
selector = new EdgeSelector_GeomColOptGradient<PFP>(map, position, approximators) ;
case S_LightfieldGradient:
selector = new EdgeSelector_LightfieldGradient<PFP>(map, position, approximators) ;
break ;*/
}
int status = decimate(map, selector, approximators, nbWantedVertices, edgeErrors, callback_wrapper, callback_object) ;
delete selector ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->init() ;
delete (*it) ;
if(!selector->init())
{
delete selector ;
delete[] v_approx ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
delete (*it) ;
return status ;
}
delete[] v_approx ;
template <typename PFP>
int decimate(
typename PFP::MAP& map,
EdgeSelector<PFP>* selector, std::vector<ApproximatorGen<PFP>*>& approximators,
unsigned int nbWantedVertices,
EdgeAttribute<typename PFP::REAL> *edgeErrors = NULL,
void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL
)
{
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
(*it)->init() ;
return ;
}
if(!selector->init())
return -1 ; // init failed
unsigned int nbVertices = map.template getNbOrbits<VERTEX>() ;
bool finished = false ;
......@@ -247,9 +284,7 @@ void decimate(
while(!finished)
{
if(!selector->nextEdge(d))
{
break ;
}
break ; // finished before achieving amount of required vertices
--nbVertices ;
......@@ -272,9 +307,7 @@ void decimate(
selector->updateAfterCollapse(d2, dd2) ;// update selector
if(nbVertices <= nbWantedVertices)
{
finished = true ;
}
// Progress bar support
if (callback_wrapper != NULL && callback_object != NULL)
......@@ -284,18 +317,13 @@ void decimate(
if (edgeErrors != NULL)
selector->getEdgeErrors(edgeErrors) ;
delete selector ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
delete (*it) ;
delete[] v_approx ;
return finished == true ? 0 : 1 ; // finished correctly
}
} //namespace Decimation
} // namespace Decimation
}
} // namespace Surface
} //namespace Algo
} // namespace Algo
} //namespace CGoGN
} // namespace CGoGN
......@@ -26,11 +26,11 @@
#define __EDGESELECTOR_H__
#include "Algo/Decimation/selector.h"
#include "Algo/Decimation/approximator.h"
#include "Algo/Geometry/boundingbox.h"
#include "Container/fakeAttribute.h"
//#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Selection/collector.h"
#include "Algo/Geometry/curvature.h"
......@@ -633,7 +633,7 @@ private:
void updateEdgeInfo(Dart d) ;
void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;
VEC3 computeHalfEdgeGradientColorError(const Dart& v0, const VEC3& p, const VEC3& c) ;
VEC3 computeEdgeGradientColorError(const Dart& v0, const VEC3& p, const VEC3& c) ;
public:
EdgeSelector_GeomColOptGradient(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx) :
......@@ -761,7 +761,7 @@ public:
/*****************************************************************************************************************
* LIGHTFIELD QUADRIC ERROR METRIC *
*****************************************************************************************************************/
*****************************************************************************************************************
template <typename PFP>
class EdgeSelector_Lightfield : public EdgeSelector<PFP>
{
......@@ -769,7 +769,6 @@ public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
typedef typename Geom::Vector<6,REAL> VEC6 ;
private:
typedef struct
......@@ -850,6 +849,121 @@ public:
}
} ;
/*****************************************************************************************************************
* LIGHTFIELD QUADRIC ERROR METRIC *
*****************************************************************************************************************
template <typename PFP>
class EdgeSelector_LightfieldGradient : public EdgeSelector<PFP>
{
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::REAL REAL ;
typedef typename PFP::VEC3 VEC3 ;
private:
typedef struct
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "LightfieldGradientEdgeInfo" ; }
} LightfieldEdgeInfo ;
typedef NoMathIOAttribute<LightfieldEdgeInfo> EdgeInfo ;
EdgeAttribute<EdgeInfo> edgeInfo ;
VertexAttribute<Utils::Quadric<REAL> > m_quadric ;
VertexAttribute<VEC3> m_avgColor ;
int m_approxindex_pos, m_attrindex_pos ;
int m_approxindex_FT, m_attrindex_FT ;
int m_approxindex_FB, m_attrindex_FB ;
int m_approxindex_FN, m_attrindex_FN ;
std::vector<unsigned int> m_approxindex_HF, m_attrindex_HF ;
unsigned int m_K ;
SphericalFunctionIntegratorCartesian m_integrator ;
double *m_n ;
double *m_workspace ;
std::vector<Approximator<PFP, typename PFP::VEC3, EDGE>* > m_approx ;
std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ;
void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d) ;
void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;
VEC3 computeDirDerivativeLFerror(const Dart& v) const ;
VEC3 integrateDlf(const VEC3& d, const unsigned int& K, const VEC3& N, const VEC3& ei, const VEC3& ej,
const VEC3* coefs0, const VEC3& T0, const VEC3& B0, const VEC3& N0, const VEC3& avg0,
const VEC3* coefs1, const VEC3& T1, const VEC3& B1, const VEC3& N1, const VEC3& avg1,
const VEC3* coefsi, const VEC3& Ti, const VEC3& Bi, const VEC3& Ni, const VEC3& avgi,
const VEC3* coefsj, const VEC3& Tj, const VEC3& Bj, const VEC3& Nj, const VEC3& avgj) const ;
static bool isInDomain(double x, double y, double z, void *data) ;
static double dlf (double x, double y, double z, void* data) ;
static double evalF(double* N, double* avg, unsigned int nb, double* T, double* B, double* coefs, double& x, double& y, double& z) ;
public:
EdgeSelector_LightfieldGradient(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx) :
EdgeSelector<PFP>(m, pos, approx),
m_approxindex_pos(-1),
m_attrindex_pos(-1),
m_approxindex_FT(-1),
m_attrindex_FT(-1),
m_approxindex_FB(-1),
m_attrindex_FB(-1),
m_approxindex_FN(-1),
m_attrindex_FN(-1),
m_K(0),
m_n(NULL),
m_workspace(NULL)
{
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
m_quadric = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
m_avgColor = m.template getAttribute<typename PFP::VEC3, VERTEX>("color") ;
m_n = new double[3] ;
assert(m_avgColor.isValid()) ;
}
~EdgeSelector_LightfieldGradient()
{
this->m_map.removeAttribute(edgeInfo) ;
this->m_map.removeAttribute(m_quadric) ;
m_integrator.Release() ;
delete[] m_workspace ;
delete[] m_n ;
}
SelectorType getType() { return S_LightfieldGradient ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
void updateAfterCollapse(Dart d2, Dart dd2) ;
void updateWithoutCollapse() { }
void getEdgeErrors(EdgeAttribute<typename PFP::REAL> *errors) const
{
assert(errors != NULL || !"EdgeSelector::setColorMap requires non null vertexattribute argument") ;
if (!errors->isValid())
std::cerr << "EdgeSelector::setColorMap requires valid edgeattribute argument" << std::endl ;
assert(edgeInfo.isValid()) ;
TraversorE<typename PFP::MAP> travE(this->m_map) ;
for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
{
if (edgeInfo[d].valid)
{
(*errors)[d] = edgeInfo[d].it->first ;
}
else
(*errors)[d] = -1 ;
}
}
} ;
*/
} // namespace Decimation
}
......
This diff is collapsed.
......@@ -26,7 +26,6 @@
#define __HALFEDGESELECTOR_H__
#include "Algo/Decimation/selector.h"
#include "Utils/SphericalFunctionIntegratorCartesian.h"
namespace CGoGN
{
......@@ -668,7 +667,7 @@ public:
/*****************************************************************************************************************
* HALF-EDGE LF EXPERIMENTAL METRIC *
*****************************************************************************************************************/
*****************************************************************************************************************
template <typename PFP>
class HalfEdgeSelector_LFexperimental : public EdgeSelector<PFP>
{
......@@ -773,7 +772,7 @@ public:
/*****************************************************************************************************************
* HALF-EDGE LF GRADIENT METRIC *
*****************************************************************************************************************/
*****************************************************************************************************************
template <typename PFP>
class HalfEdgeSelector_LFgradient : public EdgeSelector<PFP>
{
......@@ -818,14 +817,27 @@ private:
void computeHalfEdgeInfo(Dart d, HalfEdgeInfo& einfo) ;
void recomputeQuadric(const Dart d) ;
VEC3 computeDirDerivativeLFerror(const Dart& v0, const Dart& v1) ;
VEC3 computeGradientLFerror(const Dart& v0, const Dart& v1) const ;
VEC3 computeSquaredLightfieldDifferenceAnalytical(const Dart& d1, const Dart& d2) const ;
VEC3 computeSquaredLightfieldDifferenceNumerical(const Dart& d1, const Dart& d2) const ;
VEC3 computeSquaredLightfieldDifferenceNumerical(const Dart& d1, const Dart& d2, const VEC3& N) const ;
VEC3 integrateDscalGrad(const VEC3& d, const unsigned int& K, const VEC3& N, const VEC3& ei, const VEC3& ej,
const VEC3* coefs1, const VEC3& T1, const VEC3& B1, const VEC3& N1, const VEC3& avg1,
const VEC3* coefsi, const VEC3& Ti, const VEC3& Bi, const VEC3& Ni, const VEC3& avgi,
const VEC3* coefsj, const VEC3& Tj, const VEC3& Bj, const VEC3& Nj, const VEC3& avgj) const ;
VEC3 integrateDlf(const VEC3& d, const unsigned int& K, const VEC3& N, const VEC3& ei, const VEC3& ej,
const std::vector<VEC3*> coefs0, const VEC3& T0, const VEC3& B0, const VEC3& N0, const VEC3& avg0,
const std::vector<VEC3*> coefs1, const VEC3& T1, const VEC3& B1, const VEC3& N1, const VEC3& avg1,
const std::vector<VEC3*> coefsi, const VEC3& Ti, const VEC3& Bi, const VEC3& Ni, const VEC3& avgi,
const std::vector<VEC3*> coefsj, const VEC3& Tj, const VEC3& Bj, const VEC3& Nj, const VEC3& avgj) const ;
VEC3 computeGradient(const VEC3& P0, const VEC3& Pi, const VEC3& Pj, const Dart& v0, const Dart& v1, const Dart& vi, const Dart& vj, unsigned int channel) const ;
REAL computeIntegral(const double *avgi, const VEC3& ti, const VEC3& bi, const VEC3& ni, unsigned int nbCoefs, const std::vector<double>& coefs) const ;
static bool isInDomain(double x, double y, double z, void *data) ;
static double CartesianFunction (double x, double y, double z, void* data) ;
static double dispScalGrad (double x, double y, double z, void* data) ;
static double dlf (double x, double y, double z, void* data) ;
static double evalF(double* N, double* avg, unsigned int nb, double* T, double* B, double* coefs, double& x, double& y, double& z) ;
static double SquaredDifferenceOfCartesianFunctions (double x, double y, double z, void* data) ;
public:
......@@ -894,7 +906,7 @@ public:
/*****************************************************************************************************************
* HALF-EDGE COLOR PER FACE *
*****************************************************************************************************************/
*****************************************************************************************************************
template <typename PFP>
class HalfEdgeSelector_ColorPerFace : public EdgeSelector<PFP>
{
......@@ -983,7 +995,7 @@ public:
/*****************************************************************************************************************
* HALF-EDGE LF PER FACE *
*****************************************************************************************************************/
*****************************************************************************************************************
template <typename PFP>
class HalfEdgeSelector_LFperFace : public EdgeSelector<PFP>
{
......@@ -1083,7 +1095,7 @@ public:
}
}
} ;
*/
} // namespace Decimation
......
......@@ -25,6 +25,8 @@
#ifndef __SELECTOR_H__
#define __SELECTOR_H__
#include "Utils/SphericalFunctionIntegratorCartesian.h"
namespace CGoGN
{
......@@ -52,6 +54,7 @@ enum SelectorType
S_QEMextColor = 10,
S_Lightfield = 11,
S_GeomColOptGrad = 23,
S_LightfieldGradient = 24,
// note: the following "h" prefix means that half-edges are prioritized instead of edges.
S_hQEMextColor = 12,
S_hQEMml = 13,
......
......@@ -110,7 +110,7 @@ void TextureSticker::fullScreenTextureDepth(CGoGNGLuint texId, CGoGNGLuint dtexI
}
// Check if depth test is enabled
GLboolean wasDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
//GLboolean wasDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
// Disable depth test if it was enabled
// if (wasDepthTestEnabled == GL_TRUE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment