Commit a07476af authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~vanhoey/CGoGN

parents 548b6638 8058dafc
......@@ -178,6 +178,11 @@ public:
return m_approx[index][d] ;
}
const VertexAttribute<T>& getAttr(unsigned int index = 0) const
{
return *(m_attrV[index]) ;
}
std::vector<T> getAllApprox(Dart d) const
{
std::vector<T> res ;
......@@ -249,169 +254,6 @@ public:
}
} ;
//template <typename PFP, typename T>
//class ApproximatorEdge : public ApproximatorGen<PFP>
//{
//public:
// typedef typename PFP::MAP MAP ;
// typedef typename PFP::VEC3 VEC3 ;
// typedef typename PFP::REAL REAL ;
//
//protected:
// Predictor<PFP, T>* m_predictor ;
//
// std::vector<VertexAttribute<T>* > m_attrV ; // vertex attributes to be approximated
// std::vector<EdgeAttribute<T> > m_approx ; // attributes to store approximation result
// std::vector<EdgeAttribute<T> > m_detail ; // attributes to store detail information for reconstruction
// std::vector<T> m_app ;
//
//public:
// ApproximatorEdge(MAP& m, std::vector<VertexAttribute<T>* > va, Predictor<PFP, T> * predictor) :
// ApproximatorGen<PFP>(m), m_predictor(predictor), m_attrV(va)
// {
// const unsigned int& size = m_attrV.size() ;
// assert(size > 0 || !"ApproximatorEdge: no attributes provided") ;
//
// m_approx.resize(size) ;
// m_detail.resize(size) ;
// m_app.resize(size) ;
//
// for (unsigned int i = 0 ; i < size ; ++i)
// {
// if (!m_attrV[i]->isValid())
// std::cerr << "ApproximatorEdge Warning: attribute number " << i << " is not valid" << std::endl ;
//
// std::stringstream aname ;
// aname << "approx_" << m_attrV[i]->name() ;
// m_approx[i] = this->m_map.template addAttribute<T, EDGE>(aname.str()) ;
//
// if(m_predictor) // if predictors are associated to the approximator
// { // create attributes to store the details needed for reconstruction
// std::stringstream dname ;
// dname << "detail_" << m_attrV[i]->name() ;
// m_detail[i] = this->m_map.template addAttribute<T, EDGE>(dname.str()) ;
// }
// }
// }
//
// virtual ~ApproximatorEdge()
// {
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// {
// this->m_map.template removeAttribute(m_approx[i]) ;
// if(m_predictor)
// this->m_map.template removeAttribute(m_detail[i]) ;
// }
// }
//
// const std::string& getApproximatedAttributeName(unsigned int index = 0) const
// {
// return m_attrV[index]->name() ;
// }
//
//// std::vector<std::string> getApproximatedAttributeNames() const
//// {
//// std::vector<std::string> names ;
//// names.resize(m_attrV.size()) ;
//// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
//// names[i] = m_attrV[i]->name() ;
////
//// return names ;
//// }
//
// unsigned int getNbApproximated() const
// {
// return m_attrV.size() ;
// }
//
// void saveApprox(Dart d)
// {
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// m_app[i] = m_approx[i][d] ;
// }
//
// void affectApprox(Dart d)
// {
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// m_attrV[i]->operator[](d) = m_app[i] ;
// }
//
// const T& getApprox(Dart d, unsigned int index = 0) const
// {
// return m_approx[index][d] ;
// }
//
// std::vector<T> getAllApprox(Dart d) const
// {
// std::vector<T> res ;
// res.resize(m_attrV.size()) ;
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// res[i] = m_approx[i][d] ;
//
// return res ;
// }
//
// const Predictor<PFP, T>* getPredictor() const
// {
// return m_predictor ;
// }
//
// const T& getDetail(Dart d, unsigned int index = 0) const
// {
// assert(m_predictor || !"Trying to get detail on a non-predictive scheme") ;
// return m_detail[index][d] ;
// }
//
// std::vector<T> getAllDetail(Dart d) const
// {
// assert(m_predictor || !"Trying to get detail on a non-predictive scheme") ;
//
// std::vector<T> res ;
// res.resize(m_attrV.size()) ;
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// res[i] = m_detail[i][d] ;
// return res ;
// }
//
// void setDetail(Dart d, unsigned int index, T& val)
// {
// assert(m_predictor || !"Trying to set detail on a non-predictive scheme") ;
// m_detail[index][d] = val ;
// }
//
// void setDetail(Dart d, std::vector<T>& val)
// {
// assert(m_predictor || !"Trying to set detail on a non-predictive scheme") ;
//
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// m_detail[index][d] = val[i] ;
// }
//
//
//// // TODO works only for vector types !!
//// REAL detailMagnitude(Dart d)
//// {
//// assert(m_predictor || !"Trying to get detail magnitude on a non-predictive scheme") ;
//// return m_detail[d].norm2() ;
//// }
//
// void addDetail(Dart d, double amount, bool sign, typename PFP::MATRIX33* detailTransform)
// {
// assert(m_predictor || !"Trying to add detail on a non-predictive scheme") ;
//
// for (unsigned int i = 0 ; i < m_attrV.size() ; ++i)
// {
// T det = m_detail[i][d] ;
// if(detailTransform)
// det = (*detailTransform) * det ;
// det *= amount ;
// if(!sign)
// det *= REAL(-1) ;
// m_attrV[i]->operator[](d) += det ;
// }
// }
//} ;
} //namespace Decimation
} // surface
......
......@@ -105,7 +105,7 @@ void decimate(
// pos
v_approx[0].push_back(attribs[0]) ;
approximators.push_back(new Approximator_QEMhalfEdge<PFP>(map, v_approx[0])) ;
approximators.push_back(new Approximator_HalfCollapse<PFP>(map, v_approx[0])) ;
// frame
assert(attribs.size() >= 4 || !"Decimate: A_hLightfieldHalf --> not enough attribs provided") ;
......@@ -193,6 +193,9 @@ void decimate(
case S_hLightfieldExp :
selector = new HalfEdgeSelector_LightfieldExp<PFP>(map, position, approximators, selected) ;
break ;
case S_hLightfieldKCL :
selector = new HalfEdgeSelector_LightfieldKCL<PFP>(map, position, approximators, selected) ;
break ;
}
for(typename std::vector<ApproximatorGen<PFP>*>::iterator it = approximators.begin(); it != approximators.end(); ++it)
......
......@@ -166,12 +166,16 @@ public:
TraversorE<typename PFP::MAP> travE(this->m_map) ;
for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
{
(*errors)[d] = -1 ;
if (halfEdgeInfo[d].valid)
{
(*errors)[d] = halfEdgeInfo[d].it->first ;
}
else
(*errors)[d] = -1 ;
Dart dd = this->m_map.phi2(d) ;
if (halfEdgeInfo[dd].valid && halfEdgeInfo[dd].it->first < (*errors)[d])
{
(*errors)[d] = halfEdgeInfo[dd].it->first ;
}
}
}
} ;
......@@ -193,9 +197,9 @@ private:
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "QEMextColorHalfEdgeInfo" ; }
} QEMextColorHalfEdgeInfo ;
typedef NoMathIOAttribute<QEMextColorHalfEdgeInfo> HalfEdgeInfo ;
static std::string CGoGNnameOfType() { return "LightfieldHalfEdgeInfo" ; }
} LightfieldHalfEdgeInfo ;
typedef NoMathIOAttribute<LightfieldHalfEdgeInfo> HalfEdgeInfo ;
DartAttribute<HalfEdgeInfo> halfEdgeInfo ;
......@@ -261,7 +265,7 @@ public:
(*errors)[d] = halfEdgeInfo[d].it->first ;
}
Dart dd = this->m_map.phi2(d) ;
if (halfEdgeInfo[dd].valid && halfEdgeInfo[d].it->first < (*errors)[d])
if (halfEdgeInfo[dd].valid && halfEdgeInfo[dd].it->first < (*errors)[d])
{
(*errors)[d] = halfEdgeInfo[dd].it->first ;
}
......@@ -286,9 +290,9 @@ private:
{
typename std::multimap<float,Dart>::iterator it ;
bool valid ;
static std::string CGoGNnameOfType() { return "QEMextColorHalfEdgeInfo" ; }
} QEMextColorHalfEdgeInfo ;
typedef NoMathIOAttribute<QEMextColorHalfEdgeInfo> HalfEdgeInfo ;
static std::string CGoGNnameOfType() { return "LightfieldHalfEdgeInfo" ; }
} LightfieldHalfEdgeInfo ;
typedef NoMathIOAttribute<LightfieldHalfEdgeInfo> HalfEdgeInfo ;
DartAttribute<HalfEdgeInfo> halfEdgeInfo ;
......@@ -301,7 +305,6 @@ private:
int m_approxindex_FN, m_attrindex_FN ;
std::vector<unsigned int> m_approxindex_HF, m_attrindex_HF ;
unsigned int m_K ;
int m_approxindex_color, m_attrindex_color ;
std::vector<Approximator<PFP, typename PFP::VEC3, DART>* > m_approx ;
......@@ -320,9 +323,7 @@ public:
m_attrindex_pos(-1),
m_approxindex_FN(-1),
m_attrindex_FN(-1),
m_K(0),
m_approxindex_color(-1),
m_attrindex_color(-1)
m_K(0)
{
halfEdgeInfo = m.template addAttribute<HalfEdgeInfo, DART>("halfEdgeInfo") ;
m_quadricGeom = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
......@@ -335,7 +336,113 @@ public:
this->m_map.removeAttribute(m_quadricGeom) ;
this->m_map.removeAttribute(halfEdgeInfo) ;
}
SelectorType getType() { return S_hLightfield ; }
SelectorType getType() { return S_hLightfieldExp ; }
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)
{
assert(errors != NULL || !"EdgeSelector::setColorMap requires non null vertexattribute argument") ;
if (!errors->isValid())
std::cerr << "EdgeSelector::setColorMap requires valid edgeattribute argument" << std::endl ;
assert(halfEdgeInfo.isValid()) ;
TraversorE<typename PFP::MAP> travE(this->m_map) ;
for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
{
(*errors)[d] = -1 ;
if (halfEdgeInfo[d].valid)
{
(*errors)[d] = halfEdgeInfo[d].it->first ;
}
Dart dd = this->m_map.phi2(d) ;
if (halfEdgeInfo[dd].valid && halfEdgeInfo[dd].it->first < (*errors)[d])
{
(*errors)[d] = halfEdgeInfo[dd].it->first ;
}
}
}
} ;
/*****************************************************************************************************************
* HALF-EDGE LIGHTFIELD METRIC KCL08-like *
*****************************************************************************************************************/
template <typename PFP>
class HalfEdgeSelector_LightfieldKCL : 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 "LightfieldHalfEdgeInfo" ; }
} LightfieldHalfEdgeInfo ;
typedef NoMathIOAttribute<LightfieldHalfEdgeInfo> HalfEdgeInfo ;
DartAttribute<HalfEdgeInfo> halfEdgeInfo ;
VertexAttribute<Utils::Quadric<REAL> > m_quadricGeom ;
VertexAttribute<REAL> m_visualImportance ;
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 ;
REAL tmpVisualImportance ;
std::vector<Approximator<PFP, typename PFP::VEC3,DART>* > m_approx ;
std::multimap<float,Dart> halfEdges ;
typename std::multimap<float,Dart>::iterator cur ;
void initHalfEdgeInfo(Dart d) ;
void updateHalfEdgeInfo(Dart d, bool recompute) ;
void computeHalfEdgeInfo(Dart d, HalfEdgeInfo& einfo) ;
void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;
REAL computeLightfieldError(Dart v0) ;
REAL computeSquaredLightfieldDifference(Dart d1, Dart d2) ;
public:
HalfEdgeSelector_LightfieldKCL(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
EdgeSelector<PFP>(m, pos, approx, select),
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)
{
halfEdgeInfo = m.template addAttribute<HalfEdgeInfo, DART>("halfEdgeInfo") ;
m_quadricGeom = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
m_visualImportance = m.template addAttribute<typename PFP::REAL, VERTEX>("VisualImportance") ;
m_avgColor = m.template getAttribute<typename PFP::VEC3, VERTEX>("color") ;
assert(m_avgColor.isValid()) ;
}
~HalfEdgeSelector_LightfieldKCL()
{
this->m_map.removeAttribute(m_quadricGeom) ;
this->m_map.removeAttribute(halfEdgeInfo) ;
this->m_map.removeAttribute(m_visualImportance) ;
}
SelectorType getType() { return S_hLightfieldKCL ; }
bool init() ;
bool nextEdge(Dart& d) ;
void updateBeforeCollapse(Dart d) ;
......@@ -359,10 +466,11 @@ public:
(*errors)[d] = halfEdgeInfo[d].it->first ;
}
Dart dd = this->m_map.phi2(d) ;
if (halfEdgeInfo[dd].valid && halfEdgeInfo[d].it->first < (*errors)[d])
if (halfEdgeInfo[dd].valid && halfEdgeInfo[dd].it->first < (*errors)[d])
{
(*errors)[d] = halfEdgeInfo[dd].it->first ;
}
//m_avgColor[d] = VEC3(m_visualImportance[d]/6.,m_visualImportance[d]/6.,m_visualImportance[d]/6.) ;
}
}
} ;
......
......@@ -239,16 +239,16 @@ void Approximator_FrameInterpolationHalfEdge<PFP>::approximate(Dart d)
// }
// else
{
// Create two segments : v0-v1 and v0-v
VEC3 v0v1 = this->m_position[dd] ;
v0v1 -= this->m_position[d] ;
VEC3 v0v = this->m_approxposition[d] ;
v0v -= this->m_position[d] ;
// Orthogonal projection of v0-v onto v0-v1 : get coefficient t
REAL t = this->m_position[d] == this->m_position[dd] ? 1. : (v0v1 * v0v) / v0v1.norm() ;
t = std::max (std::min (t , REAL(1)) , REAL(0) ) ; // clamp it to [0,1]
// // Create two segments : v0-v1 and v0-v
// VEC3 v0v1 = this->m_position[dd] ;
// v0v1 -= this->m_position[d] ;
//
// VEC3 v0v = this->m_approxposition[d] ;
// v0v -= this->m_position[d] ;
//
// // Orthogonal projection of v0-v onto v0-v1 : get coefficient t
// REAL t = this->m_position[d] == this->m_position[dd] ? 1. : (v0v1 * v0v) / v0v1.norm() ;
// t = std::max (std::min (t , REAL(1)) , REAL(0) ) ; // clamp it to [0,1]
VEC3& normal1 = this->m_attrV[2]->operator[](d) ;
VEC3& normal2 = this->m_attrV[2]->operator[](dd) ;
......
......@@ -55,7 +55,8 @@ enum SelectorType
S_hQEMextColor,
S_hQEMml,
S_hLightfield,
S_hLightfieldExp
S_hLightfieldExp,
S_hLightfieldKCL
} ;
template <typename PFP> class ApproximatorGen ;
......
......@@ -95,7 +95,7 @@ public:
* \param p2 second point
* \param p3 third point
*/
Quadric(VEC3& p1, VEC3& p2, VEC3& p3) ;
Quadric(const VEC3& p1, const VEC3& p2, const VEC3& p3) ;
/*!
......
......@@ -39,7 +39,7 @@ Quadric<REAL>::Quadric(int i)
}
template <typename REAL>
Quadric<REAL>::Quadric(VEC3& p1, VEC3& p2, VEC3& p3)
Quadric<REAL>::Quadric(const VEC3& p1, const VEC3& p2, const VEC3& p3)
{
// compute the equation of the plane of the 3 points
Geom::Plane3D<REAL> plane(p1, p2, p3) ;
......
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