Commit 686246fe authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

No more need for GSL in CGoGN (replaced by Eigen)

parent 47bab8b9
...@@ -32,9 +32,8 @@ ...@@ -32,9 +32,8 @@
#include "Geometry/matrix.h" #include "Geometry/matrix.h"
#include "Geometry/plane_3d.h" #include "Geometry/plane_3d.h"
// GSL includes // Eigen includes
#include <gsl/gsl_vector.h> #include <Eigen/Dense>
#include <gsl/gsl_matrix.h>
namespace CGoGN { namespace CGoGN {
...@@ -326,51 +325,41 @@ public: ...@@ -326,51 +325,41 @@ public:
QuadricHF() QuadricHF()
{ {
m_A = gsl_matrix_alloc(0,0) ; m_A.resize(0,0) ;
m_b = gsl_vector_alloc(0) ; m_b.resize(0) ;
m_c = 0 ; m_c = 0 ;
} }
QuadricHF(int i): QuadricHF(int i)
m_A(NULL),
m_b(NULL),
m_c(0)
{ {
m_A = gsl_matrix_calloc(i, i) ; m_A.resize(i,i) ;
m_b = gsl_vector_calloc(i) ; m_b.resize(i) ;
m_c = 0 ; m_c = 0 ;
} }
QuadricHF(const std::vector<VEC3>& coefs, const REAL& gamma, const REAL& alpha) QuadricHF(const std::vector<VEC3>& coefs, const REAL& gamma, const REAL& alpha)
{ {
m_A = gsl_matrix_calloc(coefs.size(), coefs.size()) ; m_A.resize(coefs.size(),coefs.size()) ;
m_b = gsl_vector_calloc(coefs.size()) ; m_b.resize(coefs.size()) ;
m_c = 0 ; m_c = 0 ;
// TODO : build A, b and c // TODO : build A, b and c
assert(false || !"todo") ; assert(false || !"todo") ;
} }
~QuadricHF() ~QuadricHF()
{ {}
gsl_matrix_free(m_A) ;
gsl_vector_free(m_b) ;
}
void zero() void zero()
{ {
gsl_matrix_set_zero(m_A) ; m_A.setZero() ;
gsl_vector_set_zero(m_b) ; m_b.setZero() ;
m_c = 0 ; m_c = 0 ;
} }
QuadricHF& operator= (const QuadricHF<REAL>& q) QuadricHF& operator= (const QuadricHF<REAL>& q)
{ {
m_A = gsl_matrix_alloc(q.m_A->size1,q.m_A->size1) ; m_A = q.m_A ;
gsl_matrix_memcpy(m_A,q.m_A) ; m_b = q.m_b ;
m_b = gsl_vector_alloc(m_b->size) ;
gsl_vector_memcpy(m_b,q.m_b) ;
m_c = q.m_c ; m_c = q.m_c ;
return *this ; return *this ;
...@@ -378,12 +367,12 @@ public: ...@@ -378,12 +367,12 @@ public:
QuadricHF& operator+= (const QuadricHF<REAL>& q) QuadricHF& operator+= (const QuadricHF<REAL>& q)
{ {
assert(((m_A->size1 == q.m_A->size1) && (m_A->size2 == q.m_A->size2) && m_b->size == q.m_b->size) || !"Incompatible add of matrices") ; assert(((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && m_b.size() == q.m_b.size()) || !"Incompatible add of matrices") ;
if ((m_A->size1 == q.m_A->size1) && (m_A->size2 == q.m_A->size2) && (m_b->size == q.m_b->size)) if ((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && (m_b.size() == q.m_b.size()))
return *this ; return *this ;
gsl_matrix_add(m_A,q.m_A) ; m_A += q.m_A ;
gsl_vector_add(m_b,q.m_b) ; m_b += q.m_b ;
m_c += q.m_c ; m_c += q.m_c ;
return *this ; return *this ;
...@@ -391,12 +380,12 @@ public: ...@@ -391,12 +380,12 @@ public:
QuadricHF& operator -= (const QuadricHF<REAL>& q) QuadricHF& operator -= (const QuadricHF<REAL>& q)
{ {
assert(((m_A->size1 == q.m_A->size1) && (m_A->size2 == q.m_A->size2) && m_b->size == q.m_b->size) || !"Incompatible add of matrices") ; assert(((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && m_b.size() == q.m_b.size()) || !"Incompatible add of matrices") ;
if ((m_A->size1 == q.m_A->size1) && (m_A->size2 == q.m_A->size2) && (m_b->size == q.m_b->size)) if ((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && (m_b.size() == q.m_b.size()))
return *this ; return *this ;
gsl_matrix_sub(m_A,q.m_A) ; m_A -= q.m_A ;
gsl_vector_sub(m_b,q.m_b) ; m_b -= q.m_b ;
m_c -= q.m_c ; m_c -= q.m_c ;
return *this ; return *this ;
...@@ -404,8 +393,8 @@ public: ...@@ -404,8 +393,8 @@ public:
QuadricHF& operator *= (const REAL& v) QuadricHF& operator *= (const REAL& v)
{ {
gsl_matrix_scale(m_A,v) ; m_A *= v ;
gsl_vector_scale(m_b,v) ; m_b *= v ;
m_c *= v ; m_c *= v ;
return *this ; return *this ;
...@@ -455,8 +444,8 @@ public: ...@@ -455,8 +444,8 @@ public:
private: private:
// Double computation is crucial for stability // Double computation is crucial for stability
gsl_matrix *m_A ; Eigen::MatrixXd m_A ;
gsl_vector *m_b ; Eigen::VectorXd m_b ;
double m_c ; double m_c ;
REAL evaluate(const std::vector<VEC3>& coefs) const REAL evaluate(const std::vector<VEC3>& coefs) const
...@@ -468,7 +457,7 @@ private: ...@@ -468,7 +457,7 @@ private:
bool optimize(std::vector<VEC3>& coefs) const bool optimize(std::vector<VEC3>& coefs) const
{ {
coefs.reserve(m_b->size) ; coefs.reserve(m_b.size()) ;
// TODO // TODO
/* if (std::isnan(A(0,0))) /* if (std::isnan(A(0,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