Commit 0d36fdf8 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Cleanup and reorganisation of decimation

parent 60bae45d
...@@ -48,9 +48,9 @@ enum ApproximatorType ...@@ -48,9 +48,9 @@ enum ApproximatorType
// note: the following "h" prefix means that half-edges are prioritized instead of edges. // note: the following "h" prefix means that half-edges are prioritized instead of edges.
A_hHalfCollapse, A_hHalfCollapse,
A_hQEM, A_hQEM,
A_hLightfieldHalf/*, A_hLightfieldHalf,
A_LightfieldHalf_deprecated, A_hLightfield
A_LightfieldFull_deprecated*/
} ; } ;
template <typename PFP> template <typename PFP>
...@@ -131,7 +131,6 @@ public: ...@@ -131,7 +131,6 @@ public:
{ {
for (unsigned int i = 0 ; i < m_attrV.size() ; ++i) for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
{ {
std::cout << "delete " << m_approx[i].name() << std::endl ;
this->m_map.template removeAttribute(m_approx[i]) ; this->m_map.template removeAttribute(m_approx[i]) ;
if(m_predictor) if(m_predictor)
this->m_map.template removeAttribute(m_detail[i]) ; this->m_map.template removeAttribute(m_detail[i]) ;
......
...@@ -45,7 +45,7 @@ void decimate( ...@@ -45,7 +45,7 @@ void decimate(
typename PFP::MAP& map, typename PFP::MAP& map,
SelectorType s, SelectorType s,
ApproximatorType a, ApproximatorType a,
VertexAttribute<typename PFP::VEC3>& position, std::vector<VertexAttribute<typename PFP::VEC3> *>& position,
unsigned int nbWantedVertices, unsigned int nbWantedVertices,
const FunctorSelect& selected = allDarts, const FunctorSelect& selected = allDarts,
void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL void (*callback_wrapper)(void*, const void*) = NULL, void *callback_object = NULL
......
This diff is collapsed.
...@@ -82,7 +82,9 @@ private: ...@@ -82,7 +82,9 @@ private:
public: public:
EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) : EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
EdgeSelector<PFP>(m, pos, approx, select) EdgeSelector<PFP>(m, pos, approx, select),
cur(0),
allSkipped(false)
{} {}
~EdgeSelector_Random() ~EdgeSelector_Random()
{} {}
...@@ -400,15 +402,17 @@ private: ...@@ -400,15 +402,17 @@ private:
typedef NoMathIOAttribute<ColorNaiveedgeInfo> EdgeInfo ; typedef NoMathIOAttribute<ColorNaiveedgeInfo> EdgeInfo ;
EdgeAttribute<EdgeInfo> edgeInfo ; EdgeAttribute<EdgeInfo> edgeInfo ;
VertexAttribute<VEC3> m_color ;
VertexAttribute<Quadric<REAL> > m_quadric ; VertexAttribute<Quadric<REAL> > m_quadric ;
VertexAttribute<VEC3> m_pos, m_color ;
int m_approxindex_pos, m_attrindex_pos ;
int m_approxindex_color, m_attrindex_color ;
std::vector<Approximator<PFP, typename PFP::VEC3>* > m_approx ;
std::multimap<float,Dart> edges ; std::multimap<float,Dart> edges ;
typename std::multimap<float,Dart>::iterator cur ; typename std::multimap<float,Dart>::iterator cur ;
Approximator<PFP, typename PFP::VEC3>* m_positionApproximator ;
Approximator<PFP, typename PFP::VEC3>* m_colorApproximator ;
void initEdgeInfo(Dart d) ; void initEdgeInfo(Dart d) ;
void updateEdgeInfo(Dart d, bool recompute) ; void updateEdgeInfo(Dart d, bool recompute) ;
void computeEdgeInfo(Dart d,EdgeInfo& einfo) ; void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
...@@ -417,14 +421,13 @@ private: ...@@ -417,14 +421,13 @@ private:
public: public:
EdgeSelector_ColorNaive(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) : EdgeSelector_ColorNaive(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
EdgeSelector<PFP>(m, pos, approx, select), EdgeSelector<PFP>(m, pos, approx, select),
m_positionApproximator(NULL), m_approxindex_pos(-1),
m_colorApproximator(NULL) m_attrindex_pos(-1),
m_approxindex_color(-1),
m_attrindex_color(-1)
{ {
edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ; edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
m_quadric = m.template addAttribute<Quadric<REAL>, VERTEX>("QEMquadric") ; m_quadric = m.template addAttribute<Quadric<REAL>, VERTEX>("QEMquadric") ;
m_color = m.template getAttribute<VEC3, VERTEX>("color") ;
assert(m_color.isValid() || !"EdgeSelector_ColorNaive: Color atrribute to select is not valid") ;
} }
~EdgeSelector_ColorNaive() ~EdgeSelector_ColorNaive()
{ {
...@@ -463,11 +466,9 @@ private: ...@@ -463,11 +466,9 @@ private:
VertexAttribute<QuadricNd<REAL,6> > m_quadric ; VertexAttribute<QuadricNd<REAL,6> > m_quadric ;
VertexAttribute<VEC3> m_pos, m_color ; VertexAttribute<VEC3> m_pos, m_color ;
//VertexAttribute<VEC3> *m_HF ;
int m_approxindex_pos, m_attrindex_pos ; int m_approxindex_pos, m_attrindex_pos ;
int m_approxindex_color, m_attrindex_color ; int m_approxindex_color, m_attrindex_color ;
// Approximator<PFP, typename PFP::VEC3>* m_poscolApproximator ;
std::vector<Approximator<PFP, typename PFP::VEC3>* > m_approx ; std::vector<Approximator<PFP, typename PFP::VEC3>* > m_approx ;
std::multimap<float,Dart> edges ; std::multimap<float,Dart> edges ;
...@@ -481,7 +482,6 @@ private: ...@@ -481,7 +482,6 @@ private:
public: public:
EdgeSelector_QEMextColor(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) : EdgeSelector_QEMextColor(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
EdgeSelector<PFP>(m, pos, approx, select), EdgeSelector<PFP>(m, pos, approx, select),
// m_poscolApproximator(NULL),
m_approxindex_pos(-1), m_approxindex_pos(-1),
m_attrindex_pos(-1), m_attrindex_pos(-1),
m_approxindex_color(-1), m_approxindex_color(-1),
......
...@@ -1104,27 +1104,43 @@ bool EdgeSelector_ColorNaive<PFP>::init() ...@@ -1104,27 +1104,43 @@ bool EdgeSelector_ColorNaive<PFP>::init()
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
assert(this->m_approximators[0]->getType() != A_hQEM || !"Approximator(hQEM) and selector (ColorNaive) are not compatible") ;
assert(this->m_approximators[0]->getType() != A_hHalfCollapse || !"Approximator(hHalfCollapse) and selector (ColorNaive) are not compatible") ;
assert(this->m_approximators[0]->getType() != A_hLightfieldHalf || !"Approximator(hLightfieldHalf) and selector (ColorNaive) are not compatible") ;
// Verify availability of required approximators // Verify availability of required approximators
char ok = 0 ; unsigned int ok = 0 ;
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = this->m_approximators.begin(); for (unsigned int approxindex = 0 ; approxindex < this->m_approximators.size() ; ++approxindex)
it != this->m_approximators.end();
++it)
{ {
// constraint : 2 approximators in specific order bool saved = false ;
if(ok == 0 && (*it)->getApproximatedAttributeName(0) == "position") for (unsigned int attrindex = 0 ; attrindex < this->m_approximators[approxindex]->getNbApproximated() ; ++ attrindex)
{
m_positionApproximator = reinterpret_cast<Approximator<PFP, VEC3>* >(*it) ; // 1) position
// check incompatibilities
assert(m_positionApproximator->getType() != A_hQEM || !"Approximator(hQEM) and selector (ColorNaive) are not compatible") ;
assert(m_positionApproximator->getType() != A_hHalfCollapse || !"Approximator(hHalfCollapse) and selector (ColorNaive) are not compatible") ;
assert(m_positionApproximator->getType() != A_hLightfieldHalf || !"Approximator(hLightfieldHalf) and selector (ColorNaive) are not compatible") ;
++ok ;
}
else if( ok == 1 && (*it)->getApproximatedAttributeName(0) == "color")
{ {
m_colorApproximator = reinterpret_cast<Approximator<PFP, VEC3>* >(*it) ; // 2) color (needs position) // constraint : 2 approximators in specific order
++ok ; if(ok == 0 && this->m_approximators[approxindex]->getApproximatedAttributeName(attrindex) == "position")
{
++ok ;
m_approxindex_pos = approxindex ;
m_attrindex_pos = attrindex ;
m_pos = this->m_position ;
if (!saved)
{
m_approx.push_back(reinterpret_cast<Approximator<PFP, VEC3>* >(this->m_approximators[approxindex])) ;
saved = true ;
}
}
else if(ok == 1 && this->m_approximators[approxindex]->getApproximatedAttributeName(attrindex) == "color")
{
++ok ;
m_approxindex_color = approxindex ;
m_attrindex_color = attrindex ;
m_color = m.template getAttribute<typename PFP::VEC3, VERTEX>("color") ;
assert(m_color.isValid() || !"EdgeSelector_ColorNaive: color attribute is not valid") ;
if (!saved)
{
m_approx.push_back(reinterpret_cast<Approximator<PFP, VEC3>* >(this->m_approximators[approxindex])) ;
saved = true ;
}
}
} }
} }
...@@ -1320,23 +1336,28 @@ void EdgeSelector_ColorNaive<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -1320,23 +1336,28 @@ void EdgeSelector_ColorNaive<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
quad += m_quadric[d] ; // compute the sum of the quad += m_quadric[d] ; // compute the sum of the
quad += m_quadric[dd] ; // two vertices quadrics quad += m_quadric[dd] ; // two vertices quadrics
this->m_positionApproximator->approximate(d) ; // sets newPos // compute all approximated attributes
VEC3 newPos = this->m_positionApproximator->getApprox(d) ; // get newPos for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = this->m_approximators.begin() ;
it != this->m_approximators.end() ;
++it)
{
(*it)->approximate(d) ;
}
// New color // get pos
this->m_colorApproximator->approximate(d) ; // sets new color const VEC3& newPos = this->m_approx[m_approxindex_pos]->getApprox(d,m_attrindex_pos) ; // get newPos
const VEC3& newColor = this->m_colorApproximator->getApprox(d) ; // get new color // get col
const VEC3& newCol = this->m_approx[m_approxindex_color]->getApprox(d,m_attrindex_color) ; // get newPos
// Compute error // compute error
VEC3 colDiff1 = newColor ; VEC3 colDiff1 = newCol ;
VEC3 colDiff2 = newColor ; VEC3 colDiff2 = newCol ;
const VEC3& oldCol1 = m_color[d] ; colDiff1 -= m_color[d] ;
const VEC3& oldCol2 = m_color[dd] ; colDiff2 -= m_color[dd] ;
colDiff1 -= oldCol1 ; const VEC3& colDiff = colDiff1 + colDiff2 ;
colDiff2 -= oldCol2 ;
// sum of QEM metric and squared difference between new color and old colors // sum of QEM metric and squared difference between new color and old colors
REAL err = quad(newPos) + colDiff1.norm() + colDiff2.norm() ; REAL err = quad(newPos) + colDiff.norm() ;
einfo.it = edges.insert(std::make_pair(err, d)) ; einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ; einfo.valid = true ;
...@@ -1350,6 +1371,10 @@ bool EdgeSelector_QEMextColor<PFP>::init() ...@@ -1350,6 +1371,10 @@ bool EdgeSelector_QEMextColor<PFP>::init()
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
assert(this->m_approximators[0]->getType() != A_hQEM || !"Approximator(hQEM) and selector (ColorNaive) are not compatible") ;
assert(this->m_approximators[0]->getType() != A_hHalfCollapse || !"Approximator(hHalfCollapse) and selector (ColorNaive) are not compatible") ;
assert(this->m_approximators[0]->getType() != A_hLightfieldHalf || !"Approximator(hLightfieldHalf) and selector (ColorNaive) are not compatible") ;
// Verify availability of required approximators // Verify availability of required approximators
unsigned int ok = 0 ; unsigned int ok = 0 ;
for (unsigned int approxindex = 0 ; approxindex < this->m_approximators.size() ; ++approxindex) for (unsigned int approxindex = 0 ; approxindex < this->m_approximators.size() ; ++approxindex)
......
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