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

Cleanup and reorganisation of decimation

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