Commit 182790ae authored by Kenneth Vanhoey's avatar Kenneth Vanhoey
Browse files

LF

parent 4faeed7a
...@@ -53,25 +53,28 @@ template <typename PFP> ...@@ -53,25 +53,28 @@ template <typename PFP>
void Approximator_Frame<PFP>::approximate(Dart d) void Approximator_Frame<PFP>::approximate(Dart d)
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
Dart dd = m.phi2(d) ; // get some darts Dart dd = m.phi2(d) ; // get 2 vertices
// if QEM placed new vertex at one of the previous : place same frame
if (this->m_approxPosition[d] == this->m_position[d]) // new Position is position of vertex d if (this->m_approxPosition[d] == this->m_position[d]) // new Position is position of vertex d
this->m_approx[d] = this->m_attrV[d] ; this->m_approx[d] = this->m_attrV[d] ;
else if (this->m_approxPosition[d] == this->m_position[dd]) // new Position is position of vertex dd else if (this->m_approxPosition[d] == this->m_position[dd]) // new Position is position of vertex dd
this->m_approx[d] = this->m_attrV[dd] ; this->m_approx[d] = this->m_attrV[dd] ;
else { else {
// Create two segments : v0-v1 and v0-v
VEC3 segment = this->m_position[dd] ; VEC3 segment = this->m_position[dd] ;
segment -= this->m_position[d] ; segment -= this->m_position[d] ;
VEC3 segmentNew = m_approxPosition[d] ; VEC3 segmentNew = m_approxPosition[d] ;
segmentNew -= this->m_position[d] ; segmentNew -= this->m_position[d] ;
// Orthogonal projection of v0-v onto v0-v1 : get coefficient t
REAL t = (segment * segmentNew) / (segment.norm()*segment.norm()) ; 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 t = std::max (std::min (t , REAL(1)) , REAL(0) ) ; // clamp it to [0,1]
VEC3 n1, n2 ; VEC3 n1, n2 ;
this->m_attrV[d].getSubVectorH(2, 0, n1) ; this->m_attrV[d].getSubVectorH(2, 0, n1) ; // get normal n1
this->m_attrV[dd].getSubVectorH(2, 0, n2) ; this->m_attrV[dd].getSubVectorH(2, 0, n2) ; // get normal n2
VEC3 newN = slerp(n1,n2,t) ; // spherical interpolation VEC3 newN = slerp(n1,n2,t) ; // spherical interpolation
newN.normalize() ; newN.normalize() ;
...@@ -79,9 +82,10 @@ void Approximator_Frame<PFP>::approximate(Dart d) ...@@ -79,9 +82,10 @@ void Approximator_Frame<PFP>::approximate(Dart d)
VEC3 newI = n2 ^ n1 ; // i is perpendicular to newNormal VEC3 newI = n2 ^ n1 ; // i is perpendicular to newNormal
newI.normalize() ; newI.normalize() ;
VEC3 newJ = newN ^ newI ; VEC3 newJ = newN ^ newI ; // (i,j,n) is a direct frame
newJ.normalize() ; newJ.normalize() ;
// save into m_approx
if (!this->m_approx[d].setSubVectorH(0,0,newI) || if (!this->m_approx[d].setSubVectorH(0,0,newI) ||
!this->m_approx[d].setSubVectorH(1,0,newJ) || !this->m_approx[d].setSubVectorH(1,0,newJ) ||
!this->m_approx[d].setSubVectorH(2,0,newN) ) !this->m_approx[d].setSubVectorH(2,0,newN) )
...@@ -99,13 +103,16 @@ void Approximator_Frame<PFP>::approximate(Dart d) ...@@ -99,13 +103,16 @@ void Approximator_Frame<PFP>::approximate(Dart d)
template <typename PFP> template <typename PFP>
bool Approximator_RGBfunctions<PFP>::init() bool Approximator_RGBfunctions<PFP>::init()
{ {
// 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 = new AutoAttributeHandler<QuadricRGBfunctions<REAL> >(this->m_map, EDGE_ORBIT) ;
// 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
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 ;
...@@ -118,13 +125,17 @@ template <typename PFP> ...@@ -118,13 +125,17 @@ template <typename PFP>
void Approximator_RGBfunctions<PFP>::approximate(Dart d) void Approximator_RGBfunctions<PFP>::approximate(Dart d)
{ {
MAP& m = this->m_map ; MAP& m = this->m_map ;
Dart dd = m.phi2(d) ; // get some darts Dart dd = m.phi2(d) ; // get the two vertices
// get hypothetical local frames
VEC3 i,n ; VEC3 i,n ;
VEC3 n1,n2,i1,i2,j1,j2 ;
m_approxFrame[d].getSubVectorH(0,0,i) ; m_approxFrame[d].getSubVectorH(0,0,i) ;
m_approxFrame[d].getSubVectorH(2,0,n) ; m_approxFrame[d].getSubVectorH(2,0,n) ;
// Get previous local frames
VEC3 n1,n2,i1,i2,j1,j2 ;
m_frame[d].getSubVectorH(0,0,i1) ; m_frame[d].getSubVectorH(0,0,i1) ;
m_frame[dd].getSubVectorH(0,0,i2) ; m_frame[dd].getSubVectorH(0,0,i2) ;
...@@ -134,6 +145,7 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d) ...@@ -134,6 +145,7 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
m_frame[d].getSubVectorH(2,0,n1) ; m_frame[d].getSubVectorH(2,0,n1) ;
m_frame[dd].getSubVectorH(2,0,n2) ; m_frame[dd].getSubVectorH(2,0,n2) ;
// Compute j1' and j2'
VEC3 j1pr = n1 ^ i ; VEC3 j1pr = n1 ^ i ;
j1pr.normalize() ; j1pr.normalize() ;
VEC3 j2pr = n2 ^ i ; VEC3 j2pr = n2 ^ i ;
...@@ -151,12 +163,22 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d) ...@@ -151,12 +163,22 @@ void Approximator_RGBfunctions<PFP>::approximate(Dart d)
assert (-3.15 < alpha1 && alpha1 <= 3.15) ; assert (-3.15 < alpha1 && alpha1 <= 3.15) ;
assert (-3.15 < alpha2 && alpha2 <= 3.15) ; assert (-3.15 < alpha2 && alpha2 <= 3.15) ;
// 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) ;
// New RGBf // 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]; this->m_approx[d] = this->m_attrV[d]; // if fail take first one
// std::cout << "Approx of : " <<std::endl ;
// std::cout << "Frame1 : " << m_frame[d] << std::endl ;
// std::cout << "Function1 : "<< this->m_attrV[d] << std::endl ;
// std::cout << "Frame2 : " << m_frame[dd] << std::endl ;
// std::cout << "Function2 : "<< this->m_attrV[dd] << std::endl ;
// std::cout << "is " << std::endl ;
// std::cout << "Frame :" << m_approxFrame[d] << std::endl ;
// std::cout << "Function : " << this->m_approx[d] << std::endl << std::endl ;
} }
} //namespace Decimation } //namespace Decimation
......
...@@ -408,6 +408,8 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, REAL gamma) const ...@@ -408,6 +408,8 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, REAL gamma) const
REAL sinus = sin(gamma), sin2 = sinus*sinus; REAL sinus = sin(gamma), sin2 = sinus*sinus;
REAL sincos = sinus*cosinus; REAL sincos = sinus*cosinus;
// Inverted matrix for left-hand side application
N(0,0) = cos2; N(0,0) = cos2;
N(0,1) = sin2; N(0,1) = sin2;
N(0,2) = -sincos; N(0,2) = -sincos;
...@@ -448,7 +450,8 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, REAL gamma) const ...@@ -448,7 +450,8 @@ void QuadricRGBfunctions<REAL>::buildRotateMatrix(MATRIX66 &N, REAL gamma) const
N(5,2) = REAL(0); N(5,2) = REAL(0);
N(5,3) = REAL(0); N(5,3) = REAL(0);
N(5,4) = REAL(0); N(5,4) = REAL(0);
N(5,5) = 1.0; N(5,5) = REAL(1.0);
} }
template <typename REAL> template <typename REAL>
......
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