Commit 4faeed7a authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Corrections et ameliorations decimation lightfield

parent ec1c89e8
...@@ -66,7 +66,8 @@ void Approximator_Frame<PFP>::approximate(Dart d) ...@@ -66,7 +66,8 @@ void Approximator_Frame<PFP>::approximate(Dart d)
VEC3 segmentNew = m_approxPosition[d] ; VEC3 segmentNew = m_approxPosition[d] ;
segmentNew -= 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 REAL t = (segment * segmentNew) / (segment.norm()*segment.norm()) ;
t = std::max (std::min (t , REAL(1)) , REAL(0) ) ; // Orthogonal projection on segment v1-v2 of new vertex
VEC3 n1, n2 ; VEC3 n1, n2 ;
this->m_attrV[d].getSubVectorH(2, 0, n1) ; this->m_attrV[d].getSubVectorH(2, 0, n1) ;
...@@ -81,10 +82,14 @@ void Approximator_Frame<PFP>::approximate(Dart d) ...@@ -81,10 +82,14 @@ void Approximator_Frame<PFP>::approximate(Dart d)
VEC3 newJ = newN ^ newI ; VEC3 newJ = newN ^ newI ;
newJ.normalize() ; newJ.normalize() ;
assert(this->m_approx[d].setSubVectorH(0,0,newI) || !"Approximator_Frame::approximate") ; if (!this->m_approx[d].setSubVectorH(0,0,newI) ||
assert(this->m_approx[d].setSubVectorH(1,0,newJ) || !"Approximator_Frame::approximate") ; !this->m_approx[d].setSubVectorH(1,0,newJ) ||
assert(this->m_approx[d].setSubVectorH(2,0,newN) || !"Approximator_Frame::approximate") ; !this->m_approx[d].setSubVectorH(2,0,newN) )
assert(!"Approximator_Frame::approximate") ;
} }
// AutoAttributeHandler<VEC3> normals = this->m_map.template getAttribute<VEC3>(VERTEX_ORBIT, "normals") ;
// this->m_approx[d].getSubVectorH(2,0,normals[d]) ;
} }
/************************************************************************************ /************************************************************************************
...@@ -130,21 +135,24 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d) ...@@ -130,21 +135,24 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
m_frame[dd].getSubVectorH(2,0,n2) ; m_frame[dd].getSubVectorH(2,0,n2) ;
VEC3 j1pr = n1 ^ i ; VEC3 j1pr = n1 ^ i ;
j1pr.normalize() ;
VEC3 j2pr = n2 ^ i ; VEC3 j2pr = n2 ^ i ;
j2pr.normalize() ;
REAL alpha1 = ((n * j1pr) > 0 ? 1 : -1) * acos(n * n1) ;
REAL alpha2 = ((n * j2pr) > 0 ? 1 : -1) * acos(n * n2) ; // Rotation dans sens trigo dans le plan tangent autour de n (i1->i)
REAL gamma1 = ((j1 * i) > 0 ? 1 : -1) * acos( i1 * i ) ; REAL gamma1 = ((j1 * i) > 0 ? 1 : -1) * acos( std::max(std::min(1.0f, i1 * i ), -1.0f)) ; // angle positif ssi
REAL gamma2 = ((j2 * i) > 0 ? 1 : -1) * acos( i2 * i ) ; REAL gamma2 = ((j2 * i) > 0 ? 1 : -1) * acos( std::max(std::min(1.0f, i2 * i ), -1.0f)) ; // -PI/2 < angle(i,j1) < PI/2 ssi i*j1 > 0
// Rotation dans le sens trigo autour de l'axe i (n1->n)
alpha1 = std::min(REAL(1),std::max(REAL(-1),alpha1)) ; REAL alpha1 = ((n * j1pr) > 0 ? -1 : 1) * acos( std::max(std::min(1.0f, n * n1), -1.0f) ) ; // angle positif ssi
alpha2 = std::min(REAL(1),std::max(REAL(-1),alpha2)) ; REAL alpha2 = ((n * j2pr) > 0 ? -1 : 1) * acos( std::max(std::min(1.0f, n * n2), -1.0f) ) ; // PI/2 < angle(j1',n) < -PI/2 ssi j1'*n < 0
gamma1 = std::min(REAL(1),std::max(REAL(-1),gamma1)) ; assert (-3.15 < gamma1 && gamma1 <= 3.15) ;
gamma2 = std::min(REAL(1),std::max(REAL(-1),gamma2)) ; assert (-3.15 < gamma2 && gamma2 <= 3.15) ;
assert (-3.15 < alpha1 && alpha1 <= 3.15) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d],alpha1,gamma1) ; assert (-3.15 < alpha2 && alpha2 <= 3.15) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd],alpha2,gamma2) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[d],gamma1, alpha1) ;
(*m_quadricRGBfunctions)[d] += QuadricRGBfunctions<REAL>(this->m_attrV[dd],gamma2, alpha2) ;
// New RGBf // New RGBf
if (! (*m_quadricRGBfunctions)[d].findOptimizedRGBfunctions(this->m_approx[d])) if (! (*m_quadricRGBfunctions)[d].findOptimizedRGBfunctions(this->m_approx[d]))
......
...@@ -320,17 +320,17 @@ template <unsigned int DIM, typename T> ...@@ -320,17 +320,17 @@ template <unsigned int DIM, typename T>
inline Vector<DIM,T> slerp(const Vector<DIM,T> &v1, const Vector<DIM,T> &v2, const T &t) { inline Vector<DIM,T> slerp(const Vector<DIM,T> &v1, const Vector<DIM,T> &v2, const T &t) {
Vector<DIM,T> res ; Vector<DIM,T> res ;
T omega = acos(v1 * v2); T omega = acos(v1 * v2) ;
T den = sin(omega); T den = sin(omega) ;
if (-1e-8 < den || den < 1e-8) if (-1e-8 < den && den < 1e-8)
return v1; return t < 0.5 ? v1 : v2 ;
T f1 = sin(( T(1)-t ) * omega ) / den; T f1 = sin(( T(1)-t ) * omega ) / den ;
T f2 = sin( t * omega ) / den; T f2 = sin( t * omega ) / den ;
res += f1 * v1; res += f1 * v1 ;
res += f2 * v2; res += f2 * v2 ;
return res ; return res ;
} }
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
QuadricRGBfunctions(); QuadricRGBfunctions();
QuadricRGBfunctions(int i); QuadricRGBfunctions(int i);
QuadricRGBfunctions(const QuadricRGBfunctions&); QuadricRGBfunctions(const QuadricRGBfunctions&);
QuadricRGBfunctions(const RGBFUNCTIONS&, REAL alpha = REAL(0), REAL gamma = REAL(0)); QuadricRGBfunctions(const RGBFUNCTIONS&, REAL gamma = REAL(0), REAL alpha = REAL(0));
virtual ~QuadricRGBfunctions(); virtual ~QuadricRGBfunctions();
......
...@@ -45,7 +45,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) { ...@@ -45,7 +45,7 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const QuadricRGBfunctions& q) {
} }
template <typename REAL> template <typename REAL>
QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, REAL alpha, REAL gamma) { QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, REAL gamma, REAL alpha) {
MATRIX66 R1,R2_A,R2_b,R2_c; MATRIX66 R1,R2_A,R2_b,R2_c;
// Matrice de rotation 1 // Matrice de rotation 1
buildRotateMatrix(R1,gamma); buildRotateMatrix(R1,gamma);
...@@ -66,7 +66,9 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, REAL alph ...@@ -66,7 +66,9 @@ QuadricRGBfunctions<REAL>::QuadricRGBfunctions(const RGBFUNCTIONS& cf, REAL alph
// Rotation 1 // Rotation 1
Geom::Vector<6,REAL> function; Geom::Vector<6,REAL> function;
assert(cf.getSubVectorH(col,0,function) || !"QuadricRGBfunctions::constructor") ;
if (!cf.getSubVectorH(col,0,function))
assert(!"QuadricRGBfunctions::constructor") ;
VEC6 coefs = R1 * function ; // Multiply coefs VEC6 coefs = R1 * function ; // Multiply coefs
...@@ -92,7 +94,8 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const { ...@@ -92,7 +94,8 @@ REAL QuadricRGBfunctions<REAL>::operator() (const RGBFUNCTIONS& cf) const {
for (unsigned col = RED; col < BLUE+1; ++col) { for (unsigned col = RED; col < BLUE+1; ++col) {
Geom::Vector<6,REAL> function ; Geom::Vector<6,REAL> function ;
assert (cf.getSubVectorH(col,0,function) || !"QuadricRGBfunctions::operator()") ; if (!cf.getSubVectorH(col,0,function))
assert (!"QuadricRGBfunctions::getSubVectorH") ;
VEC6 Al = A[col] * function; VEC6 Al = A[col] * function;
...@@ -123,7 +126,8 @@ bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) cons ...@@ -123,7 +126,8 @@ bool QuadricRGBfunctions<REAL>::findOptimizedRGBfunctions(RGBFUNCTIONS& cf) cons
coefs = Ainv * b[col]; coefs = Ainv * b[col];
assert (cf.setSubVectorH(col,0,coefs) || !"QuadricRGBfunctions::findOptimizedRGBfunctions(cf) setSubVector failed") ; if (!cf.setSubVectorH(col,0,coefs))
assert (!"QuadricRGBfunctions::findOptimizedRGBfunctions(cf) setSubVector failed") ;
} }
return true; 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