Commit ddefd869 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey
Browse files

lf decimation

parent f61a4b22
...@@ -76,12 +76,12 @@ public: ...@@ -76,12 +76,12 @@ public:
protected: protected:
AttributeHandler<MATRIX33> m_frame ; AttributeHandler<MATRIX33> m_frame ;
AttributeHandler<MATRIX33> m_approxFrame ; AttributeHandler<MATRIX33> m_approxFrame ;
AutoAttributeHandler<QuadricRGBfunctions<REAL> > *m_quadricRGBfunctions ; AttributeHandler<QuadricRGBfunctions<REAL> > m_quadricRGBfunctions ;
public: public:
Approximator_RGBfunctions(MAP& m, AttributeHandler<MATRIX36>& rgbfunctions, Predictor<PFP, MATRIX36>* pred = NULL) : Approximator_RGBfunctions(MAP& m, AttributeHandler<MATRIX36>& rgbfunctions, Predictor<PFP, MATRIX36>* pred = NULL) :
Approximator<PFP, MATRIX36>(m, rgbfunctions, EDGE_ORBIT, pred) Approximator<PFP, MATRIX36>(m, rgbfunctions, EDGE_ORBIT, pred)
{} { }
~Approximator_RGBfunctions() ~Approximator_RGBfunctions()
{} {}
ApproximatorType getType() const { return A_LightfieldFull ; } ApproximatorType getType() const { return A_LightfieldFull ; }
......
...@@ -104,14 +104,14 @@ bool Approximator_RGBfunctions<PFP>::init() ...@@ -104,14 +104,14 @@ bool Approximator_RGBfunctions<PFP>::init()
// get actual frames and hypothetical approximated frames // get actual frames and hypothetical approximated frames
m_frame = this->m_map.template getAttribute<MATRIX33>(VERTEX_ORBIT, "frame") ; m_frame = this->m_map.template getAttribute<MATRIX33>(VERTEX_ORBIT, "frame") ;
m_approxFrame = this->m_map.template getAttribute<MATRIX33>(EDGE_ORBIT, "approx_frame") ; m_approxFrame = this->m_map.template getAttribute<MATRIX33>(EDGE_ORBIT, "approx_frame") ;
m_quadricRGBfunctions = this->m_map.template getAttribute<QuadricRGBfunctions<REAL> >(EDGE_ORBIT, "quadricRGBfunctions") ;
// create quadric embedding for computing and set them to 0 // create quadric embedding for computing and set them to 0
m_quadricRGBfunctions = new AutoAttributeHandler<QuadricRGBfunctions<REAL> >(this->m_map, EDGE_ORBIT) ;
for (Dart d = this->m_map.begin() ; d != this->m_map.end() ; this->m_map.next(d)) for (Dart d = this->m_map.begin() ; d != this->m_map.end() ; this->m_map.next(d))
(*m_quadricRGBfunctions)[d].zero() ; m_quadricRGBfunctions[d].zero() ;
// Check on embeddings // Check on embeddings
if (!m_frame.isValid() || !m_approxFrame.isValid() || !m_quadricRGBfunctions->isValid()) if (!m_frame.isValid() || !m_approxFrame.isValid() || !m_quadricRGBfunctions.isValid())
{ {
std::cerr << "Approximator_RGBfunctions::init() --> No approxPosition or no quadricRGBfunctions specified" << std::endl ; std::cerr << "Approximator_RGBfunctions::init() --> No approxPosition or no quadricRGBfunctions specified" << std::endl ;
return false ; return false ;
...@@ -162,12 +162,16 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d) ...@@ -162,12 +162,16 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
assert (-3.15 < alpha2 && alpha2 <= 3.15) ; assert (-3.15 < alpha2 && alpha2 <= 3.15) ;
// Create and sum quadrics // Create and sum quadrics
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d], gamma1, alpha1) ; m_quadricRGBfunctions[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d], gamma1, alpha1) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd], gamma2, alpha2) ; m_quadricRGBfunctions[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd], gamma2, alpha2) ;
std::cout << "plop" << std::endl ;
std::cout << m_quadricRGBfunctions[d] << std::endl ;
// Compute new function // Compute new function
if (! (*m_quadricRGBfunctions)[d].findOptimizedRGBfunctions(this->m_approx[d])) if (! m_quadricRGBfunctions[d].findOptimizedRGBfunctions(this->m_approx[d])) {
this->m_approx[d] = this->m_attrV[d]; // if fail take first one this->m_approx[d] = this->m_attrV[d]; // if fail take first one
}
// std::cout << "Approx of : " <<std::endl ; // std::cout << "Approx of : " <<std::endl ;
// std::cout << "Frame1 : " << m_frame[d] << std::endl ; // std::cout << "Frame1 : " << m_frame[d] << std::endl ;
......
...@@ -711,10 +711,11 @@ void EdgeSelector_Lightfield<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo) ...@@ -711,10 +711,11 @@ void EdgeSelector_Lightfield<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
MATRIX36 newRGBf = this->m_RGBfunctionsApproximator->getApprox(d) ; // get newRGBf MATRIX36 newRGBf = this->m_RGBfunctionsApproximator->getApprox(d) ; // get newRGBf
QuadricRGBfunctions<typename PFP::REAL> quadRGBf = quadricRGBfunctions[d]; // get quadricRGBf QuadricRGBfunctions<typename PFP::REAL> quadRGBf = quadricRGBfunctions[d]; // get quadricRGBf
// ?? test if quadRGBf is valid
// Compute error // Compute error
REAL err = quad(newPos) + (2 * acos (n1 * n2)) + quadRGBf(newRGBf) ; REAL err = quad(newPos) + (2 * acos (n1 * n2)) + quadRGBf(newRGBf) ;
// std::cout << err << " -- " << quad(newPos) << " -- " << (2 * acos (n1 * n2)) << " -- " << quadRGBf(newRGBf) << std::endl ;
std::cout << quadRGBf << std::endl ;
einfo.it = edges.insert(std::make_pair(err, d)) ; einfo.it = edges.insert(std::make_pair(err, d)) ;
einfo.valid = true ; einfo.valid = true ;
} }
......
...@@ -30,7 +30,7 @@ public: ...@@ -30,7 +30,7 @@ public:
typedef Geom::Matrix<3,6,REAL> RGBFUNCTIONS; typedef Geom::Matrix<3,6,REAL> RGBFUNCTIONS;
private: private:
MATRIX66 A[COLCHANNELS]; MATRIX66 A;
VEC6 b[COLCHANNELS]; VEC6 b[COLCHANNELS];
REAL c[COLCHANNELS]; REAL c[COLCHANNELS];
...@@ -56,7 +56,15 @@ public: ...@@ -56,7 +56,15 @@ public:
void zero () ; void zero () ;
friend std::ostream& operator<< (std::ostream &out, const QuadricRGBfunctions&) {return out;}; friend std::ostream& operator<< (std::ostream &out, const QuadricRGBfunctions& q) {
out << "quadricRGBf : " << std::endl ;
out << "q.A" << "= " << q.A << std::endl ;
for (unsigned int i = 0 ; i < 3 ; ++i) {
out << "q.b["<<i<<"] = " << q.b[i] << std::endl ;
out << "q.c["<<i<<"] = " << q.c[i] << std::endl ;
}
return out ;
} ;
friend std::istream& operator>> (std::istream &in, const QuadricRGBfunctions&) {return in;}; friend std::istream& operator>> (std::istream &in, const QuadricRGBfunctions&) {return in;};
private : private :
......
...@@ -15,12 +15,12 @@ std::string QuadricRGBfunctions<REAL>::CGoGNnameOfType() { ...@@ -15,12 +15,12 @@ std::string QuadricRGBfunctions<REAL>::CGoGNnameOfType() {
template <typename REAL> template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions() { QuadricRGBfunctions<REAL>::QuadricRGBfunctions() {
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) = REAL(0) ;
for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) = REAL(0) ;
b[col][i] = REAL(0) ; b[col][i] = REAL(0) ;
} }
...@@ -35,11 +35,13 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(int i) { ...@@ -35,11 +35,13 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(int i) {
template <typename REAL> template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) { QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) {
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) = q.A(i,j) ;
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) = q.A[col](i,j) ;
b[col][i] = q.b[col][i] ; b[col][i] = q.b[col][i] ;
} }
...@@ -58,6 +60,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA ...@@ -58,6 +60,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA
buildIntegralMatrix_c(R2_c,alpha); // Parameterized integral matrix c buildIntegralMatrix_c(R2_c,alpha); // Parameterized integral matrix c
// Quadric (A,b,c) => L*A*Lt - 2*b*Lt + c = ERROR // Quadric (A,b,c) => L*A*Lt - 2*b*Lt + c = ERROR
A = R2_A ; // Matrix A : integral
for (unsigned col = RED; col < BLUE+1; ++col) { for (unsigned col = RED; col < BLUE+1; ++col) {
Geom::Vector<6,REAL> function; // get function coefficients Geom::Vector<6,REAL> function; // get function coefficients
if (!cf.getSubVectorH(col,0,function)) if (!cf.getSubVectorH(col,0,function))
...@@ -65,7 +68,6 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA ...@@ -65,7 +68,6 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, const REA
VEC6 coefs = R1 * function ; // Rotation 1 VEC6 coefs = R1 * function ; // Rotation 1
A[col] = R2_A ; // Matrix A : integral
b[col] = R2_b * function ; // Vector b : integral + rotation on 1 vector b[col] = R2_b * function ; // Vector b : integral + rotation on 1 vector
c[col] = function * (R2_c * function) ; // Scalar c : integral + rotation on 2 vectors c[col] = function * (R2_c * function) ; // Scalar c : integral + rotation on 2 vectors
} }
...@@ -81,7 +83,7 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const { ...@@ -81,7 +83,7 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
assert (!"QuadricRGBfunctions::getSubVectorH") ; assert (!"QuadricRGBfunctions::getSubVectorH") ;
REAL res_local = REAL(0) ; REAL res_local = REAL(0) ;
res_local += function * (A[col] * function) ; // l*A*lt res_local += function * (A * function) ; // l*A*lt
res_local -= 2 * (function * b[col]) ; // -2*l*b res_local -= 2 * (function * b[col]) ; // -2*l*b
res_local += c[col] ; // c res_local += c[col] ; // c
// res = l*A*lT - 2*l*b + c // res = l*A*lT - 2*l*b + c
...@@ -93,13 +95,13 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const { ...@@ -93,13 +95,13 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
template <typename REAL> template <typename REAL>
bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const { bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const {
MATRIX66 Ainv ;
for (unsigned col = RED; col < BLUE+1 ; ++col) { REAL det = A.invert(Ainv) ; // Invert matrix
MATRIX66 Ainv ; if(det > -1e-8 && det < 1e-8)
return false ; // invert failed
REAL det = A[col].invert(Ainv) ; // Invert matrix for (unsigned col = RED; col < BLUE+1 ; ++col) {
if(det > -1e-8 && det < 1e-8)
return false ; // invert failed
VEC6 coefs = Ainv * b[col]; // function = A^(-1) * b VEC6 coefs = Ainv * b[col]; // function = A^(-1) * b
...@@ -528,11 +530,13 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, const REAL gamma) ...@@ -528,11 +530,13 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, const REAL gamma)
template <typename REAL> template <typename REAL>
void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) { void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) {
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) += q.A(i,j);
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) += q.A[col](i,j);
b[col][i] += q.b[col][i]; b[col][i] += q.b[col][i];
} }
c[col] += q.c[col]; c[col] += q.c[col];
...@@ -542,11 +546,13 @@ void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) { ...@@ -542,11 +546,13 @@ void QuadricRGBfunctions<REAL>::operator += (const QuadricRGBfunctions& q) {
template <typename REAL> template <typename REAL>
void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) { void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) {
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) -= q.A(i,j);
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
b[col][i] -= q.b[col][i]; b[col][i] -= q.b[col][i];
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) -= q.A[col](i,j);
} }
c[col] -= q.c[col]; c[col] -= q.c[col];
...@@ -555,11 +561,13 @@ void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) { ...@@ -555,11 +561,13 @@ void QuadricRGBfunctions<REAL>::operator -= (const QuadricRGBfunctions& q) {
template <typename REAL> template <typename REAL>
void QuadricRGBfunctions<REAL>::operator *= (const REAL v) { void QuadricRGBfunctions<REAL>::operator *= (const REAL v) {
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) *= v;
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
b[col][i] *= v; b[col][i] *= v;
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) *= v;
} }
c[col] *= v; c[col] *= v;
...@@ -568,11 +576,13 @@ void QuadricRGBfunctions<REAL>::operator *= (const REAL v) { ...@@ -568,11 +576,13 @@ void QuadricRGBfunctions<REAL>::operator *= (const REAL v) {
template <typename REAL> template <typename REAL>
void QuadricRGBfunctions<REAL>::operator /= (const REAL v) { void QuadricRGBfunctions<REAL>::operator /= (const REAL v) {
for (unsigned i = 0; i < 6; ++i)
for (unsigned j = 0; j < 6; ++j)
A(i,j) /= v;
for (unsigned col = RED; col < BLUE+1 ; ++col) { for (unsigned col = RED; col < BLUE+1 ; ++col) {
for (unsigned i = 0; i < 6; ++i) { for (unsigned i = 0; i < 6; ++i) {
b[col][i] /= v; b[col][i] /= v;
for (unsigned j = 0; j < 6; ++j)
A[col](i,j) /= v;
} }
c[col] /= v; c[col] /= v;
...@@ -581,8 +591,8 @@ void QuadricRGBfunctions<REAL>::operator /= (const REAL v) { ...@@ -581,8 +591,8 @@ void QuadricRGBfunctions<REAL>::operator /= (const REAL v) {
template <typename REAL> template <typename REAL>
void QuadricRGBfunctions<REAL>::zero () { void QuadricRGBfunctions<REAL>::zero () {
A.zero();
for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) { for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) {
A[i].zero();
b[i].zero(); b[i].zero();
c[i] = REAL(0) ; c[i] = REAL(0) ;
} }
......
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