Commit 31038dc3 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

corrections on lightfield decimation

parent bb6dfa70
......@@ -64,7 +64,7 @@ void decimate(
{
approximators.push_back(new Approximator_QEM<PFP>(map, position)) ;
AttributeHandler<Geom::Matrix<3,3,typename PFP::REAL> > frame = map.template getAttribute<Geom::Matrix<3,3,typename PFP::REAL> >(VERTEX_ORBIT, "frame") ;
AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "RGBfunctions") ;
AttributeHandler<Geom::Matrix<3,6,typename PFP::REAL> > RGBfunctions = map.template getAttribute<Geom::Matrix<3,6,typename PFP::REAL> >(VERTEX_ORBIT, "colorPTM") ;
approximators.push_back(new Approximator_Frame<PFP>(map, frame)) ;
approximators.push_back(new Approximator_RGBfunctions<PFP>(map, RGBfunctions)) ;
break ;
......@@ -105,10 +105,13 @@ void decimate(
unsigned int nbVertices = map.getNbOrbits(VERTEX_ORBIT) ;
bool finished = false ;
Dart d ;
while(!finished)
{
if(!selector->nextEdge(d))
if(!selector->nextEdge(d)) {
std::cout << "out" << std::endl ;
break ;
}
--nbVertices ;
......@@ -130,8 +133,10 @@ void decimate(
selector->updateAfterCollapse(d2, dd2) ;// update selector
if(nbVertices <= nbWantedVertices)
if(nbVertices <= nbWantedVertices) {
finished = true ;
std::cout << "done" << std::endl ;
}
}
delete selector ;
......
......@@ -76,7 +76,7 @@ public:
protected:
AttributeHandler<MATRIX33> m_frame ;
AttributeHandler<MATRIX33> m_approxFrame ;
AttributeHandler<QuadricRGBfunctions<REAL> > m_quadricRGBfunctions ;
AutoAttributeHandler<QuadricRGBfunctions<REAL> > *m_quadricRGBfunctions ;
public:
Approximator_RGBfunctions(MAP& m, AttributeHandler<MATRIX36>& rgbfunctions, Predictor<PFP, MATRIX36>* pred = NULL) :
......
......@@ -64,14 +64,14 @@ void Approximator_Frame<PFP>::approximate(Dart d)
segment -= this->m_position[d] ;
VEC3 segmentNew = m_approxPosition[d] ;
segment -= this->m_position[d] ;
segmentNew -= this->m_position[d] ;
REAL t = std::max (std::min (segment * segmentNew , REAL(1)) , REAL(0) ) ; // Orthogonal projection on segment v1-v2 of new vertex
VEC3 n1, n2 ;
this->m_attrV[d].getSubVectorH(3, 1, n1) ;
this->m_attrV[dd].getSubVectorH(3, 1, n2) ;
this->m_attrV[d].getSubVectorH(2, 0, n1) ;
this->m_attrV[dd].getSubVectorH(2, 0, n2) ;
VEC3 newN = slerp(n1,n2,t) ; // spherical interpolation
newN.normalize() ;
......@@ -82,9 +82,9 @@ void Approximator_Frame<PFP>::approximate(Dart d)
VEC3 newJ = newN ^ newI ;
newJ.normalize() ;
this->m_approx[d].setSubVectorH(1,1,newI) ;
this->m_approx[d].setSubVectorH(2,1,newJ) ;
this->m_approx[d].setSubVectorH(3,1,newN) ;
assert(this->m_approx[d].setSubVectorH(0,0,newI) || !"Approximator_Frame::approximate") ;
assert(this->m_approx[d].setSubVectorH(1,0,newJ) || !"Approximator_Frame::approximate") ;
assert(this->m_approx[d].setSubVectorH(2,0,newN) || !"Approximator_Frame::approximate") ;
}
}
......@@ -97,9 +97,12 @@ bool Approximator_RGBfunctions<PFP>::init()
{
m_frame = this->m_map.template getAttribute<MATRIX33>(VERTEX_ORBIT, "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") ;
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))
(*m_quadricRGBfunctions)[d].zero() ;
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 ;
......@@ -115,17 +118,17 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
VEC3 i,n ;
VEC3 n1,n2,i1,i2,j1,j2 ;
m_approxFrame[d].getSubVectorH(1,1,i) ;
m_approxFrame[d].getSubVectorH(3,1,n) ;
m_approxFrame[d].getSubVectorH(0,0,i) ;
m_approxFrame[d].getSubVectorH(2,0,n) ;
m_frame[d].getSubVectorH(1,1,i1) ;
m_frame[dd].getSubVectorH(1,1,i2) ;
m_frame[d].getSubVectorH(0,0,i1) ;
m_frame[dd].getSubVectorH(0,0,i2) ;
m_frame[d].getSubVectorH(2,1,j1) ;
m_frame[dd].getSubVectorH(2,1,j2) ;
m_frame[d].getSubVectorH(1,0,j1) ;
m_frame[dd].getSubVectorH(1,0,j2) ;
m_frame[d].getSubVectorH(3,1,n1) ;
m_frame[dd].getSubVectorH(3,1,n2) ;
m_frame[d].getSubVectorH(2,0,n1) ;
m_frame[dd].getSubVectorH(2,0,n2) ;
VEC3 j1pr = n1 ^ i ;
VEC3 j2pr = n2 ^ i ;
......@@ -135,11 +138,17 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
REAL gamma1 = ((j1 * i) > 0 ? 1 : -1) * acos( i1 * i ) ;
REAL gamma2 = ((j2 * i) > 0 ? 1 : -1) * acos( i2 * i ) ;
m_quadricRGBfunctions[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d],alpha1,gamma1) ;
m_quadricRGBfunctions[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd],alpha2,gamma2) ;
alpha1 = std::min(REAL(1),std::max(REAL(-1),alpha1)) ;
alpha2 = std::min(REAL(1),std::max(REAL(-1),alpha2)) ;
gamma1 = std::min(REAL(1),std::max(REAL(-1),gamma1)) ;
gamma2 = std::min(REAL(1),std::max(REAL(-1),gamma2)) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d],alpha1,gamma1) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd],alpha2,gamma2) ;
// New RGBf
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];
}
......
......@@ -504,7 +504,7 @@ bool EdgeSelector_Lightfield<PFP>::init()
m_frameApproximator = reinterpret_cast<Approximator<PFP, FRAME>* >(*it) ; // 2) frame (needs position)
++ok ;
}
else if(ok == 2 && (*it)->getApproximatedAttributeName() == "RGBfunctions")
else if(ok == 2 && (*it)->getApproximatedAttributeName() == "colorPTM")
{
m_RGBfunctionsApproximator = reinterpret_cast<Approximator<PFP, RGBFUNCTIONS>* >(*it) ; // 3) functions (needs frame)
++ok ;
......@@ -697,11 +697,11 @@ void EdgeSelector_Lightfield<PFP>::computeEdgeInfo(Dart d, EdgeInfo& einfo)
MATRIX33 newFrame = this->m_frameApproximator->getApprox(d) ; // get newF
VEC3 n1,n2 ;
if (! m_frame[d].getSubVectorH(3,1,n1)) { // get the normals
if (! m_frame[d].getSubVectorH(2,0,n1)) { // get the normals
std::cout << "EdgeSelector_LightField::computeEdgeInfo --> getSubVectorH 1 failed " << std::endl;
exit(2) ;
}
if (!m_frame[dd].getSubVectorH(3,1,n2)) { // of the two vertices
if (!m_frame[dd].getSubVectorH(2,0,n2)) { // of the two vertices
std::cout << "EdgeSelector_LightField::computeEdgeInfo --> getSubVectorH 2 failed " << std::endl;
exit(3) ;
}
......
......@@ -512,9 +512,9 @@ bool MeshTablesSurface<PFP>::importPlyPTM(const std::string& filename, std::vect
{
AttributeHandler<typename PFP::VEC3> positions = m_map.template addAttribute<typename PFP::VEC3>(VERTEX_ORBIT, "position") ;
attrNames.push_back(positions.name()) ;
AttributeHandler<typename PFP::MATRIX33> Frame = m_map.template addAttribute<typename PFP::MATRIX33>(VERTEX_ORBIT, "Frame") ;
AttributeHandler<typename PFP::MATRIX33> Frame = m_map.template addAttribute<typename PFP::MATRIX33>(VERTEX_ORBIT, "frame") ;
attrNames.push_back(Frame.name()) ;
AttributeHandler<typename PFP::MATRIX36> RGBfunctions = m_map.template addAttribute<typename PFP::MATRIX36>(VERTEX_ORBIT, "RGBfunctions") ;
AttributeHandler<typename PFP::MATRIX36> RGBfunctions = m_map.template addAttribute<typename PFP::MATRIX36>(VERTEX_ORBIT, "colorPTM") ;
attrNames.push_back(RGBfunctions.name()) ;
AttribContainer& container = m_map.getAttributeContainer(VERTEX_CELL) ;
......
......@@ -49,22 +49,24 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, REAL alph
MATRIX66 R1,R2_A,R2_b,R2_c;
// Matrice de rotation 1
buildRotateMatrix(R1,gamma);
// std::cout <<"R1 : " << R1 << std::endl ;
// std::cout <<"alpha : " << alpha << std::endl ;
// Matrice de rotation 2 + intégrale
buildIntegralMatrix_A(R2_A,alpha);
buildIntegralMatrix_b(R2_b,alpha);
buildIntegralMatrix_b(R2_c,alpha);
// std::cout << "A : " << R2_A << std::endl ;
// std::cout << "b : " << R2_b << std::endl ;
// std::cout << "c : " << R2_c << std::endl ;
// Quadrique (A,b,c) tel que L*A*Lt - 2*b*Lt + c = ERROR
for (unsigned col = RED; col < BLUE+1; ++col) {
// Rotation 1
Geom::Vector<6,REAL> function;
/*if (!cf.getSubMatrix(col,1,function)) // extract the vector of function col
std::cerr << "getSubMatrix failed" << std::endl;
*/
for (unsigned i = 0 ; i < 6 ; ++i)
function[i] = cf(col,i) ;
assert(cf.getSubVectorH(col,0,function) || !"QuadricRGBfunctions::constructor") ;
VEC6 coefs = R1 * function ; // Multiply coefs
......@@ -90,10 +92,7 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
for (unsigned col = RED; col < BLUE+1; ++col) {
Geom::Vector<6,REAL> function ;
if (!cf.getSubVectorH(col,1,function))
std::cerr << "operator() --> getSubMatrix failed" << std::endl;
// for (unsigned i = 0 ; i < 6 ; ++i)
// function[i] = cf(col,i) ;
assert (cf.getSubVectorH(col,0,function) || !"QuadricRGBfunctions::operator()") ;
VEC6 Al = A[col] * function;
......@@ -124,11 +123,7 @@ bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) cons
coefs = Ainv * b[col];
if (! cf.setSubVectorH(col,1,coefs)) {
std::cerr << "QuadricRGBfunctions::findOptimizedRGBfunctions(cf) setSubVector failed" << std::endl ;
exit(col + 1) ;
}
assert (cf.setSubVectorH(col,0,coefs) || "QuadricRGBfunctions::findOptimizedRGBfunctions(cf) setSubVector failed") ;
}
return true;
......
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