17 qem(
int d = -1) :
vec<T>((d+1)*(d+2)/2)
36 unsigned int i,j,k=n.
size()+1;
37 for (i=0;i<n.
size(); ++i) {
38 (*this)(i+1) = d*n(i);
39 for (j=i;j<n.
size(); ++j, ++k)
40 (*
this)(k) = n(i)*n(j);
46 return (
unsigned int)sqrt(2.0*this->
size())-1;
51 *
static_cast<vec<T>*
>(
this) = v;
63 for (
unsigned int i=0; i<v.
size(); ++i)
70 unsigned int d =
dim();
72 unsigned int i,j,k=d+1;
74 for (j=i; j<d; ++j,++k)
75 m(i,j) = m(j,i) = (*this)(k);
85 for (
unsigned int i=0; i<p.
size(); ++i) {
98 vec<T> minarg(
const vec<T>& p_ref, T relative_epsilon, T max_distance = -1, T epsilon = 1e-10)
const
100 unsigned int d = p_ref.
size();
102 T max_distance2 = max_distance*max_distance;
109 vec<T> y_ref = transpose(V)*p_ref;
111 for (
unsigned int i = d; i > 0; ) {
113 if (fabs(W(i)) > epsilon && fabs(W(i)*iW(0)) > relative_epsilon) {
115 for (j = 0; j <= i; ++j)
120 if (max_distance != -1 && (p-p_ref).
sqr_length() <= max_distance2)
127 template <
typename S>
131 for (
unsigned i=0;i<this->
size();++i) (*
this)(i) += v(i);
return *
this;
135 template <
typename S>
139 for (
unsigned i=0;i<this->
size();++i) (*
this)(i) -= v(i);
return *
this;
143 template <
typename S>
146 vec<T> r = *
this; r += v;
return r;
150 template <
typename S>
153 qem<T> r = *
this; r -= v;
return r;
167 qem<T> r = *
this; r *= s;
return r;
186 template <
typename S>
189 for (
unsigned i=0;i<this->
size();++i)
190 if((*
this)(i) != (T)v(i))
return false;
195 template <
typename S>
198 for (
unsigned i=0;i<this->
size();++i)
199 if((*
this)(i) != (T)v(i))
return true;
207const qem<T> operator * (
const T& s,
const qem<T>& v)
209 qem<T> r = v; r *= s;
return r;
A matrix type (full column major storage) The matrix can be loaded directly into OpenGL without need ...
void transpose()
transpose matrix
dimension independent implementation of quadric error metrics
const T & scalar_part() const
return the scalar part of the qem
const qem< T > operator+(const qem< S > &v) const
qem addition
qem< T > & operator-=(const qem< S > &v)
in place qem subtraction
void set(const vec< T > &n, T d)
set from normal and distance to origin
void resize(unsigned d)
resize the vector
T evaluate(const vec< T > &p) const
evaluate the quadric error metric at given location
bool operator!=(const qem< S > &v) const
test for inequality
qem< T > & operator=(const qem< T > &v)
assignment of a vector v
unsigned dim() const
number of elements
qem(const vec< T > &p, const vec< T > &n)
construct from point and normal
qem< T > operator/(const T &s) const
divides vector by scalar s
vec< T > minarg(const vec< T > &p_ref, T relative_epsilon, T max_distance=-1, T epsilon=1e-10) const
compute point that minimizes distance to qem and is inside the sphere of radius max_distance around p...
qem< T > operator*(const T &s) const
multiplication with scalar s
qem< T > operator-(void) const
negates the qem
qem(int d=-1)
standard constructor initializes qem based on dimension
bool operator==(const qem< S > &v) const
test for equality
qem(const vec< T > &n, T d)
construct from normal and distance to origin
mat< T > matrix_part() const
return matrix part
vec< T > vector_part() const
return the vector part of the qem
qem< T > & operator+=(const qem< S > &v)
in place qem addition
T & first()
element accessor for the first element
void resize(unsigned dim)
resize the vector
unsigned size() const
number of elements
void zeros()
fill the vector with zeros
T sqr_length() const
square length of vector
T & y()
element accessor for the second element
A diagonal matrix type which internally stores the elements on the main diagonal in a vector.