From ddefd8699ccad06bcc38e2a44c80c48ea001720a Mon Sep 17 00:00:00 2001 From: Kenneth Vanhoey Date: Tue, 22 Feb 2011 19:26:44 +0100 Subject: [PATCH] lf decimation --- .../Algo/Decimation/lightfieldApproximator.h | 4 +- .../Decimation/lightfieldApproximator.hpp | 16 +++--- include/Algo/Decimation/selector.hpp | 3 +- include/Utils/quadricRGBfunctions.h | 12 ++++- include/Utils/quadricRGBfunctions.hpp | 54 +++++++++++-------- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/include/Algo/Decimation/lightfieldApproximator.h b/include/Algo/Decimation/lightfieldApproximator.h index de40727a..a015dd8a 100644 --- a/include/Algo/Decimation/lightfieldApproximator.h +++ b/include/Algo/Decimation/lightfieldApproximator.h @@ -76,12 +76,12 @@ public: protected: AttributeHandler m_frame ; AttributeHandler m_approxFrame ; - AutoAttributeHandler > *m_quadricRGBfunctions ; + AttributeHandler > m_quadricRGBfunctions ; public: Approximator_RGBfunctions(MAP& m, AttributeHandler& rgbfunctions, Predictor* pred = NULL) : Approximator(m, rgbfunctions, EDGE_ORBIT, pred) - {} + { } ~Approximator_RGBfunctions() {} ApproximatorType getType() const { return A_LightfieldFull ; } diff --git a/include/Algo/Decimation/lightfieldApproximator.hpp b/include/Algo/Decimation/lightfieldApproximator.hpp index e6439e75..bfc1e9e1 100644 --- a/include/Algo/Decimation/lightfieldApproximator.hpp +++ b/include/Algo/Decimation/lightfieldApproximator.hpp @@ -104,14 +104,14 @@ bool Approximator_RGBfunctions::init() // get actual frames and hypothetical approximated frames m_frame = this->m_map.template getAttribute(VERTEX_ORBIT, "frame") ; m_approxFrame = this->m_map.template getAttribute(EDGE_ORBIT, "approx_frame") ; + m_quadricRGBfunctions = this->m_map.template getAttribute >(EDGE_ORBIT, "quadricRGBfunctions") ; // create quadric embedding for computing and set them to 0 - m_quadricRGBfunctions = new AutoAttributeHandler >(this->m_map, EDGE_ORBIT) ; 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 - 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 ; return false ; @@ -162,12 +162,16 @@ void Approximator_RGBfunctions::approximate(Dart d) assert (-3.15 < alpha2 && alpha2 <= 3.15) ; // Create and sum quadrics - (*m_quadricRGBfunctions)[d] += QuadricRGBfunctions(this->m_attrV[d], gamma1, alpha1) ; - (*m_quadricRGBfunctions)[d] += QuadricRGBfunctions(this->m_attrV[dd], gamma2, alpha2) ; + m_quadricRGBfunctions[d] += QuadricRGBfunctions(this->m_attrV[d], gamma1, alpha1) ; + m_quadricRGBfunctions[d] += QuadricRGBfunctions(this->m_attrV[dd], gamma2, alpha2) ; + + std::cout << "plop" << std::endl ; + std::cout << m_quadricRGBfunctions[d] << std::endl ; // 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 + } // std::cout << "Approx of : " <::computeEdgeInfo(Dart d, EdgeInfo& einfo) MATRIX36 newRGBf = this->m_RGBfunctionsApproximator->getApprox(d) ; // get newRGBf QuadricRGBfunctions quadRGBf = quadricRGBfunctions[d]; // get quadricRGBf - // ?? test if quadRGBf is valid // Compute error 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.valid = true ; } diff --git a/include/Utils/quadricRGBfunctions.h b/include/Utils/quadricRGBfunctions.h index 1c0bbd0a..020cbf1f 100644 --- a/include/Utils/quadricRGBfunctions.h +++ b/include/Utils/quadricRGBfunctions.h @@ -30,7 +30,7 @@ public: typedef Geom::Matrix<3,6,REAL> RGBFUNCTIONS; private: - MATRIX66 A[COLCHANNELS]; + MATRIX66 A; VEC6 b[COLCHANNELS]; REAL c[COLCHANNELS]; @@ -56,7 +56,15 @@ public: 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["<::operator() (const RGBFUNCTIONS& cf) const { template bool QuadricRGBfunctions::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) const { + MATRIX66 Ainv ; - for (unsigned col = RED; col < BLUE+1 ; ++col) { - MATRIX66 Ainv ; + REAL det = A.invert(Ainv) ; // Invert matrix + if(det > -1e-8 && det < 1e-8) + return false ; // invert failed - REAL det = A[col].invert(Ainv) ; // Invert matrix - if(det > -1e-8 && det < 1e-8) - return false ; // invert failed + for (unsigned col = RED; col < BLUE+1 ; ++col) { VEC6 coefs = Ainv * b[col]; // function = A^(-1) * b @@ -528,11 +530,13 @@ void QuadricRGBfunctions::buildRotateMatrix(MATRIX66 &N, const REAL gamma) template void QuadricRGBfunctions::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 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]; } c[col] += q.c[col]; @@ -542,11 +546,13 @@ void QuadricRGBfunctions::operator += (const QuadricRGBfunctions& q) { template void QuadricRGBfunctions::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 i = 0; i < 6; ++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]; @@ -555,11 +561,13 @@ void QuadricRGBfunctions::operator -= (const QuadricRGBfunctions& q) { template void QuadricRGBfunctions::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 i = 0; i < 6; ++i) { b[col][i] *= v; - for (unsigned j = 0; j < 6; ++j) - A[col](i,j) *= v; } c[col] *= v; @@ -568,11 +576,13 @@ void QuadricRGBfunctions::operator *= (const REAL v) { template void QuadricRGBfunctions::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 i = 0; i < 6; ++i) { b[col][i] /= v; - for (unsigned j = 0; j < 6; ++j) - A[col](i,j) /= v; } c[col] /= v; @@ -581,8 +591,8 @@ void QuadricRGBfunctions::operator /= (const REAL v) { template void QuadricRGBfunctions::zero () { + A.zero(); for (unsigned int i = 0 ; i < COLCHANNELS ; ++i) { - A[i].zero(); b[i].zero(); c[i] = REAL(0) ; } -- GitLab