LIBS: updated glm
parent
c8d0f2137f
commit
c3b9a93c53
|
@ -142,6 +142,8 @@
|
|||
// Android has multiple STLs but C++11 STL detection doesn't always work #284 #564
|
||||
#if GLM_PLATFORM == GLM_PLATFORM_ANDROID && !defined(GLM_LANG_STL11_FORCED)
|
||||
# define GLM_HAS_CXX11_STL 0
|
||||
#elif (GLM_COMPILER & GLM_COMPILER_CUDA_RTC) == GLM_COMPILER_CUDA_RTC
|
||||
# define GLM_HAS_CXX11_STL 0
|
||||
#elif GLM_COMPILER & GLM_COMPILER_CLANG
|
||||
# if (defined(_LIBCPP_VERSION) || (GLM_LANG & GLM_LANG_CXX11_FLAG) || defined(GLM_LANG_STL11_FORCED))
|
||||
# define GLM_HAS_CXX11_STL 1
|
||||
|
|
|
@ -42,19 +42,19 @@ namespace glm
|
|||
# if GLM_LANG & GLM_LANG_CXXMS_FLAG
|
||||
union
|
||||
{
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
struct { T w, x, y, z; };
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
struct { T x, y, z, w; };
|
||||
# else
|
||||
struct { T w, x, y, z; };
|
||||
# endif
|
||||
|
||||
typename detail::storage<4, T, detail::is_aligned<Q>::value>::type data;
|
||||
};
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
T w, x, y, z;
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
T x, y, z, w;
|
||||
# else
|
||||
T w, x, y, z;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
|
@ -88,7 +88,12 @@ namespace glm
|
|||
// -- Explicit basic constructors --
|
||||
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR qua(T s, vec<3, T, Q> const& v);
|
||||
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR qua(T x, T y, T z, T w);
|
||||
# else
|
||||
GLM_FUNC_DECL GLM_CONSTEXPR qua(T w, T x, T y, T z);
|
||||
# endif
|
||||
|
||||
// -- Conversion constructors --
|
||||
|
||||
|
|
|
@ -75,10 +75,10 @@ namespace detail
|
|||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & qua<T, Q>::operator[](typename qua<T, Q>::length_type i)
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
return (&w)[i];
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
return (&x)[i];
|
||||
# else
|
||||
return (&w)[i];
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -86,10 +86,10 @@ namespace detail
|
|||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& qua<T, Q>::operator[](typename qua<T, Q>::length_type i) const
|
||||
{
|
||||
assert(i >= 0 && i < this->length());
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
return (&w)[i];
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
return (&x)[i];
|
||||
# else
|
||||
return (&w)[i];
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -99,10 +99,10 @@ namespace detail
|
|||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua()
|
||||
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(1), x(0), y(0), z(0)
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
: x(0), y(0), z(0), w(1)
|
||||
# else
|
||||
: w(1), x(0), y(0), z(0)
|
||||
# endif
|
||||
# endif
|
||||
{}
|
||||
|
@ -111,10 +111,10 @@ namespace detail
|
|||
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(qua<T, Q> const& q)
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(q.w), x(q.x), y(q.y), z(q.z)
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
: x(q.x), y(q.y), z(q.z), w(q.w)
|
||||
# else
|
||||
: w(q.w), x(q.x), y(q.y), z(q.z)
|
||||
# endif
|
||||
{}
|
||||
# endif
|
||||
|
@ -122,10 +122,10 @@ namespace detail
|
|||
template<typename T, qualifier Q>
|
||||
template<qualifier P>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(qua<T, P> const& q)
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(q.w), x(q.x), y(q.y), z(q.z)
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
: x(q.x), y(q.y), z(q.z), w(q.w)
|
||||
# else
|
||||
: w(q.w), x(q.x), y(q.y), z(q.z)
|
||||
# endif
|
||||
{}
|
||||
|
||||
|
@ -133,20 +133,21 @@ namespace detail
|
|||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(T s, vec<3, T, Q> const& v)
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(s), x(v.x), y(v.y), z(v.z)
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
: x(v.x), y(v.y), z(v.z), w(s)
|
||||
# else
|
||||
: w(s), x(v.x), y(v.y), z(v.z)
|
||||
# endif
|
||||
{}
|
||||
|
||||
template <typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(T _w, T _x, T _y, T _z)
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(_w), x(_x), y(_y), z(_z)
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(T _x, T _y, T _z, T _w)
|
||||
: x(_x), y(_y), z(_z), w(_w)
|
||||
# endif
|
||||
# else
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(T _w, T _x, T _y, T _z)
|
||||
: w(_w), x(_x), y(_y), z(_z)
|
||||
# endif
|
||||
{}
|
||||
|
||||
// -- Conversion constructors --
|
||||
|
@ -154,10 +155,10 @@ namespace detail
|
|||
template<typename T, qualifier Q>
|
||||
template<typename U, qualifier P>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua(qua<U, P> const& q)
|
||||
# ifdef GLM_FORCE_QUAT_DATA_WXYZ
|
||||
: w(static_cast<T>(q.w)), x(static_cast<T>(q.x)), y(static_cast<T>(q.y)), z(static_cast<T>(q.z))
|
||||
# else
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
: x(static_cast<T>(q.x)), y(static_cast<T>(q.y)), z(static_cast<T>(q.z)), w(static_cast<T>(q.w))
|
||||
# else
|
||||
: w(static_cast<T>(q.w)), x(static_cast<T>(q.x)), y(static_cast<T>(q.y)), z(static_cast<T>(q.z))
|
||||
# endif
|
||||
{}
|
||||
|
||||
|
|
|
@ -172,12 +172,18 @@ namespace detail
|
|||
j = Next[i];
|
||||
k = Next[j];
|
||||
|
||||
# ifdef GLM_FORCE_QUAT_DATA_XYZW
|
||||
int off = 0;
|
||||
# else
|
||||
int off = 1;
|
||||
# endif
|
||||
|
||||
root = sqrt(Row[i][i] - Row[j][j] - Row[k][k] + static_cast<T>(1.0));
|
||||
|
||||
Orientation[i] = static_cast<T>(0.5) * root;
|
||||
Orientation[i + off] = static_cast<T>(0.5) * root;
|
||||
root = static_cast<T>(0.5) / root;
|
||||
Orientation[j] = root * (Row[i][j] + Row[j][i]);
|
||||
Orientation[k] = root * (Row[i][k] + Row[k][i]);
|
||||
Orientation[j + off] = root * (Row[i][j] + Row[j][i]);
|
||||
Orientation[k + off] = root * (Row[i][k] + Row[k][i]);
|
||||
Orientation.w = root * (Row[j][k] - Row[k][j]);
|
||||
} // End if <= 0
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/// @ref gtx_pca
|
||||
/// @file glm/gtx/pca.hpp
|
||||
///
|
||||
/// @see core (dependence)
|
||||
/// @see ext_scalar_relational (dependence)
|
||||
///
|
||||
/// @defgroup gtx_pca GLM_GTX_pca
|
||||
/// @ingroup gtx
|
||||
///
|
||||
/// Include <glm/gtx/pca.hpp> to use the features of this extension.
|
||||
///
|
||||
/// Implements functions required for fundamental 'princple component analysis' in 2D, 3D, and 4D:
|
||||
/// 1) Computing a covariance matrics from a list of _relative_ position vectors
|
||||
/// 2) Compute the eigenvalues and eigenvectors of the covariance matrics
|
||||
/// This is useful, e.g., to compute an object-aligned bounding box from vertices of an object.
|
||||
/// https://en.wikipedia.org/wiki/Principal_component_analysis
|
||||
///
|
||||
/// Example:
|
||||
/// ```
|
||||
/// std::vector<glm::dvec3> ptData;
|
||||
/// // ... fill ptData with some point data, e.g. vertices
|
||||
///
|
||||
/// glm::dvec3 center = computeCenter(ptData);
|
||||
///
|
||||
/// glm::dmat3 covarMat = glm::computeCovarianceMatrix(ptData.data(), ptData.size(), center);
|
||||
///
|
||||
/// glm::dvec3 evals;
|
||||
/// glm::dmat3 evecs;
|
||||
/// int evcnt = glm::findEigenvaluesSymReal(covarMat, evals, evecs);
|
||||
///
|
||||
/// if(evcnt != 3)
|
||||
/// // ... error handling
|
||||
///
|
||||
/// glm::sortEigenvalues(evals, evecs);
|
||||
///
|
||||
/// // ... now evecs[0] points in the direction (symmetric) of the largest spatial distribuion within ptData
|
||||
/// ```
|
||||
|
||||
#pragma once
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../ext/scalar_relational.hpp"
|
||||
|
||||
|
||||
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
||||
# ifndef GLM_ENABLE_EXPERIMENTAL
|
||||
# pragma message("GLM: GLM_GTX_pca is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it.")
|
||||
# else
|
||||
# pragma message("GLM: GLM_GTX_pca extension included")
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace glm {
|
||||
/// @addtogroup gtx_pca
|
||||
/// @{
|
||||
|
||||
/// Compute a covariance matrix form an array of relative coordinates `v` (e.g., relative to the center of gravity of the object)
|
||||
/// @param v Points to a memory holding `n` times vectors
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_INLINE mat<D, D, T, Q> computeCovarianceMatrix(vec<D, T, Q> const* v, size_t n);
|
||||
|
||||
/// Compute a covariance matrix form an array of absolute coordinates `v` and a precomputed center of gravity `c`
|
||||
/// @param v Points to a memory holding `n` times vectors
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_INLINE mat<D, D, T, Q> computeCovarianceMatrix(vec<D, T, Q> const* v, size_t n, vec<D, T, Q> const& c);
|
||||
|
||||
/// Compute a covariance matrix form a pair of iterators `b` (begin) and `e` (end) of a container with relative coordinates (e.g., relative to the center of gravity of the object)
|
||||
/// Dereferencing an iterator of type I must yield a `vec<D, T, Q%gt;`
|
||||
template<length_t D, typename T, qualifier Q, typename I>
|
||||
GLM_FUNC_DECL mat<D, D, T, Q> computeCovarianceMatrix(I const& b, I const& e);
|
||||
|
||||
/// Compute a covariance matrix form a pair of iterators `b` (begin) and `e` (end) of a container with absolute coordinates and a precomputed center of gravity `c`
|
||||
/// Dereferencing an iterator of type I must yield a `vec<D, T, Q%gt;`
|
||||
template<length_t D, typename T, qualifier Q, typename I>
|
||||
GLM_FUNC_DECL mat<D, D, T, Q> computeCovarianceMatrix(I const& b, I const& e, vec<D, T, Q> const& c);
|
||||
|
||||
/// Assuming the provided covariance matrix `covarMat` is symmetric and real-valued, this function find the `D` Eigenvalues of the matrix, and also provides the corresponding Eigenvectors.
|
||||
/// Note: the data in `outEigenvalues` and `outEigenvectors` are in matching order, i.e. `outEigenvector[i]` is the Eigenvector of the Eigenvalue `outEigenvalue[i]`.
|
||||
/// This is a numeric implementation to find the Eigenvalues, using 'QL decomposition` (variant of QR decomposition: https://en.wikipedia.org/wiki/QR_decomposition).
|
||||
/// @param covarMat A symmetric, real-valued covariance matrix, e.g. computed from `computeCovarianceMatrix`.
|
||||
/// @param outEigenvalues Vector to receive the found eigenvalues
|
||||
/// @param outEigenvectors Matrix to receive the found eigenvectors corresponding to the found eigenvalues, as column vectors
|
||||
/// @return The number of eigenvalues found, usually D if the precondition of the covariance matrix is met.
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL unsigned int findEigenvaluesSymReal
|
||||
(
|
||||
mat<D, D, T, Q> const& covarMat,
|
||||
vec<D, T, Q>& outEigenvalues,
|
||||
mat<D, D, T, Q>& outEigenvectors
|
||||
);
|
||||
|
||||
/// Sorts a group of Eigenvalues&Eigenvectors, for largest Eigenvalue to smallest Eigenvalue.
|
||||
/// The data in `outEigenvalues` and `outEigenvectors` are assumed to be matching order, i.e. `outEigenvector[i]` is the Eigenvector of the Eigenvalue `outEigenvalue[i]`.
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<2, T, Q>& eigenvalues, mat<2, 2, T, Q>& eigenvectors);
|
||||
|
||||
/// Sorts a group of Eigenvalues&Eigenvectors, for largest Eigenvalue to smallest Eigenvalue.
|
||||
/// The data in `outEigenvalues` and `outEigenvectors` are assumed to be matching order, i.e. `outEigenvector[i]` is the Eigenvector of the Eigenvalue `outEigenvalue[i]`.
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<3, T, Q>& eigenvalues, mat<3, 3, T, Q>& eigenvectors);
|
||||
|
||||
/// Sorts a group of Eigenvalues&Eigenvectors, for largest Eigenvalue to smallest Eigenvalue.
|
||||
/// The data in `outEigenvalues` and `outEigenvectors` are assumed to be matching order, i.e. `outEigenvector[i]` is the Eigenvector of the Eigenvalue `outEigenvalue[i]`.
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<4, T, Q>& eigenvalues, mat<4, 4, T, Q>& eigenvectors);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
#include "pca.inl"
|
|
@ -0,0 +1,343 @@
|
|||
/// @ref gtx_pca
|
||||
|
||||
#ifndef GLM_HAS_CXX11_STL
|
||||
#include <algorithm>
|
||||
#else
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace glm {
|
||||
|
||||
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_INLINE mat<D, D, T, Q> computeCovarianceMatrix(vec<D, T, Q> const* v, size_t n)
|
||||
{
|
||||
return computeCovarianceMatrix<D, T, Q, vec<D, T, Q> const*>(v, v + n);
|
||||
}
|
||||
|
||||
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_INLINE mat<D, D, T, Q> computeCovarianceMatrix(vec<D, T, Q> const* v, size_t n, vec<D, T, Q> const& c)
|
||||
{
|
||||
return computeCovarianceMatrix<D, T, Q, vec<D, T, Q> const*>(v, v + n, c);
|
||||
}
|
||||
|
||||
|
||||
template<length_t D, typename T, qualifier Q, typename I>
|
||||
GLM_FUNC_DECL mat<D, D, T, Q> computeCovarianceMatrix(I const& b, I const& e)
|
||||
{
|
||||
glm::mat<D, D, T, Q> m(0);
|
||||
|
||||
size_t cnt = 0;
|
||||
for(I i = b; i != e; i++)
|
||||
{
|
||||
vec<D, T, Q> const& v = *i;
|
||||
for(length_t x = 0; x < D; ++x)
|
||||
for(length_t y = 0; y < D; ++y)
|
||||
m[x][y] += static_cast<T>(v[x] * v[y]);
|
||||
cnt++;
|
||||
}
|
||||
if(cnt > 0)
|
||||
m /= static_cast<T>(cnt);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
template<length_t D, typename T, qualifier Q, typename I>
|
||||
GLM_FUNC_DECL mat<D, D, T, Q> computeCovarianceMatrix(I const& b, I const& e, vec<D, T, Q> const& c)
|
||||
{
|
||||
glm::mat<D, D, T, Q> m(0);
|
||||
glm::vec<D, T, Q> v;
|
||||
|
||||
size_t cnt = 0;
|
||||
for(I i = b; i != e; i++)
|
||||
{
|
||||
v = *i - c;
|
||||
for(length_t x = 0; x < D; ++x)
|
||||
for(length_t y = 0; y < D; ++y)
|
||||
m[x][y] += static_cast<T>(v[x] * v[y]);
|
||||
cnt++;
|
||||
}
|
||||
if(cnt > 0)
|
||||
m /= static_cast<T>(cnt);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
namespace _internal_
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
GLM_INLINE T transferSign(T const& v, T const& s)
|
||||
{
|
||||
return ((s) >= 0 ? glm::abs(v) : -glm::abs(v));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
GLM_INLINE T pythag(T const& a, T const& b) {
|
||||
static const T epsilon = static_cast<T>(0.0000001);
|
||||
T absa = glm::abs(a);
|
||||
T absb = glm::abs(b);
|
||||
if(absa > absb) {
|
||||
absb /= absa;
|
||||
absb *= absb;
|
||||
return absa * glm::sqrt(static_cast<T>(1) + absb);
|
||||
}
|
||||
if(glm::equal<T>(absb, 0, epsilon)) return static_cast<T>(0);
|
||||
absa /= absb;
|
||||
absa *= absa;
|
||||
return absb * glm::sqrt(static_cast<T>(1) + absa);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<length_t D, typename T, qualifier Q>
|
||||
GLM_FUNC_DECL unsigned int findEigenvaluesSymReal
|
||||
(
|
||||
mat<D, D, T, Q> const& covarMat,
|
||||
vec<D, T, Q>& outEigenvalues,
|
||||
mat<D, D, T, Q>& outEigenvectors
|
||||
)
|
||||
{
|
||||
using _internal_::transferSign;
|
||||
using _internal_::pythag;
|
||||
|
||||
T a[D * D]; // matrix -- input and workspace for algorithm (will be changed inplace)
|
||||
T d[D]; // diagonal elements
|
||||
T e[D]; // off-diagonal elements
|
||||
|
||||
for(length_t r = 0; r < D; r++)
|
||||
for(length_t c = 0; c < D; c++)
|
||||
a[(r) * D + (c)] = covarMat[c][r];
|
||||
|
||||
// 1. Householder reduction.
|
||||
length_t l, k, j, i;
|
||||
T scale, hh, h, g, f;
|
||||
static const T epsilon = static_cast<T>(0.0000001);
|
||||
|
||||
for(i = D; i >= 2; i--)
|
||||
{
|
||||
l = i - 1;
|
||||
h = scale = 0;
|
||||
if(l > 1)
|
||||
{
|
||||
for(k = 1; k <= l; k++)
|
||||
{
|
||||
scale += glm::abs(a[(i - 1) * D + (k - 1)]);
|
||||
}
|
||||
if(glm::equal<T>(scale, 0, epsilon))
|
||||
{
|
||||
e[i - 1] = a[(i - 1) * D + (l - 1)];
|
||||
}
|
||||
else
|
||||
{
|
||||
for(k = 1; k <= l; k++)
|
||||
{
|
||||
a[(i - 1) * D + (k - 1)] /= scale;
|
||||
h += a[(i - 1) * D + (k - 1)] * a[(i - 1) * D + (k - 1)];
|
||||
}
|
||||
f = a[(i - 1) * D + (l - 1)];
|
||||
g = ((f >= 0) ? -glm::sqrt(h) : glm::sqrt(h));
|
||||
e[i - 1] = scale * g;
|
||||
h -= f * g;
|
||||
a[(i - 1) * D + (l - 1)] = f - g;
|
||||
f = 0;
|
||||
for(j = 1; j <= l; j++)
|
||||
{
|
||||
a[(j - 1) * D + (i - 1)] = a[(i - 1) * D + (j - 1)] / h;
|
||||
g = 0;
|
||||
for(k = 1; k <= j; k++)
|
||||
{
|
||||
g += a[(j - 1) * D + (k - 1)] * a[(i - 1) * D + (k - 1)];
|
||||
}
|
||||
for(k = j + 1; k <= l; k++)
|
||||
{
|
||||
g += a[(k - 1) * D + (j - 1)] * a[(i - 1) * D + (k - 1)];
|
||||
}
|
||||
e[j - 1] = g / h;
|
||||
f += e[j - 1] * a[(i - 1) * D + (j - 1)];
|
||||
}
|
||||
hh = f / (h + h);
|
||||
for(j = 1; j <= l; j++)
|
||||
{
|
||||
f = a[(i - 1) * D + (j - 1)];
|
||||
e[j - 1] = g = e[j - 1] - hh * f;
|
||||
for(k = 1; k <= j; k++)
|
||||
{
|
||||
a[(j - 1) * D + (k - 1)] -= (f * e[k - 1] + g * a[(i - 1) * D + (k - 1)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e[i - 1] = a[(i - 1) * D + (l - 1)];
|
||||
}
|
||||
d[i - 1] = h;
|
||||
}
|
||||
d[0] = 0;
|
||||
e[0] = 0;
|
||||
for(i = 1; i <= D; i++)
|
||||
{
|
||||
l = i - 1;
|
||||
if(!glm::equal<T>(d[i - 1], 0, epsilon))
|
||||
{
|
||||
for(j = 1; j <= l; j++)
|
||||
{
|
||||
g = 0;
|
||||
for(k = 1; k <= l; k++)
|
||||
{
|
||||
g += a[(i - 1) * D + (k - 1)] * a[(k - 1) * D + (j - 1)];
|
||||
}
|
||||
for(k = 1; k <= l; k++)
|
||||
{
|
||||
a[(k - 1) * D + (j - 1)] -= g * a[(k - 1) * D + (i - 1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
d[i - 1] = a[(i - 1) * D + (i - 1)];
|
||||
a[(i - 1) * D + (i - 1)] = 1;
|
||||
for(j = 1; j <= l; j++)
|
||||
{
|
||||
a[(j - 1) * D + (i - 1)] = a[(i - 1) * D + (j - 1)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Calculation of eigenvalues and eigenvectors (QL algorithm)
|
||||
length_t m, iter;
|
||||
T s, r, p, dd, c, b;
|
||||
const length_t MAX_ITER = 30;
|
||||
|
||||
for(i = 2; i <= D; i++)
|
||||
{
|
||||
e[i - 2] = e[i - 1];
|
||||
}
|
||||
e[D - 1] = 0;
|
||||
|
||||
for(l = 1; l <= D; l++)
|
||||
{
|
||||
iter = 0;
|
||||
do
|
||||
{
|
||||
for(m = l; m <= D - 1; m++)
|
||||
{
|
||||
dd = glm::abs(d[m - 1]) + glm::abs(d[m - 1 + 1]);
|
||||
if(glm::equal<T>(glm::abs(e[m - 1]) + dd, dd, epsilon))
|
||||
break;
|
||||
}
|
||||
if(m != l)
|
||||
{
|
||||
if(iter++ == MAX_ITER)
|
||||
{
|
||||
return 0; // Too many iterations in FindEigenvalues
|
||||
}
|
||||
g = (d[l - 1 + 1] - d[l - 1]) / (2 * e[l - 1]);
|
||||
r = pythag<T>(g, 1);
|
||||
g = d[m - 1] - d[l - 1] + e[l - 1] / (g + transferSign(r, g));
|
||||
s = c = 1;
|
||||
p = 0;
|
||||
for(i = m - 1; i >= l; i--)
|
||||
{
|
||||
f = s * e[i - 1];
|
||||
b = c * e[i - 1];
|
||||
e[i - 1 + 1] = r = pythag(f, g);
|
||||
if(glm::equal<T>(r, 0, epsilon))
|
||||
{
|
||||
d[i - 1 + 1] -= p;
|
||||
e[m - 1] = 0;
|
||||
break;
|
||||
}
|
||||
s = f / r;
|
||||
c = g / r;
|
||||
g = d[i - 1 + 1] - p;
|
||||
r = (d[i - 1] - g) * s + 2 * c * b;
|
||||
d[i - 1 + 1] = g + (p = s * r);
|
||||
g = c * r - b;
|
||||
for(k = 1; k <= D; k++)
|
||||
{
|
||||
f = a[(k - 1) * D + (i - 1 + 1)];
|
||||
a[(k - 1) * D + (i - 1 + 1)] = s * a[(k - 1) * D + (i - 1)] + c * f;
|
||||
a[(k - 1) * D + (i - 1)] = c * a[(k - 1) * D + (i - 1)] - s * f;
|
||||
}
|
||||
}
|
||||
if(glm::equal<T>(r, 0, epsilon) && (i >= l))
|
||||
continue;
|
||||
d[l - 1] -= p;
|
||||
e[l - 1] = g;
|
||||
e[m - 1] = 0;
|
||||
}
|
||||
} while(m != l);
|
||||
}
|
||||
|
||||
// 3. output
|
||||
for(i = 0; i < D; i++)
|
||||
outEigenvalues[i] = d[i];
|
||||
for(i = 0; i < D; i++)
|
||||
for(j = 0; j < D; j++)
|
||||
outEigenvectors[i][j] = a[(j) * D + (i)];
|
||||
|
||||
return D;
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<2, T, Q>& eigenvalues, mat<2, 2, T, Q>& eigenvectors)
|
||||
{
|
||||
if (eigenvalues[0] < eigenvalues[1])
|
||||
{
|
||||
std::swap(eigenvalues[0], eigenvalues[1]);
|
||||
std::swap(eigenvectors[0], eigenvectors[1]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<3, T, Q>& eigenvalues, mat<3, 3, T, Q>& eigenvectors)
|
||||
{
|
||||
if (eigenvalues[0] < eigenvalues[1])
|
||||
{
|
||||
std::swap(eigenvalues[0], eigenvalues[1]);
|
||||
std::swap(eigenvectors[0], eigenvectors[1]);
|
||||
}
|
||||
if (eigenvalues[0] < eigenvalues[2])
|
||||
{
|
||||
std::swap(eigenvalues[0], eigenvalues[2]);
|
||||
std::swap(eigenvectors[0], eigenvectors[2]);
|
||||
}
|
||||
if (eigenvalues[1] < eigenvalues[2])
|
||||
{
|
||||
std::swap(eigenvalues[1], eigenvalues[2]);
|
||||
std::swap(eigenvectors[1], eigenvectors[2]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
GLM_INLINE void sortEigenvalues(vec<4, T, Q>& eigenvalues, mat<4, 4, T, Q>& eigenvectors)
|
||||
{
|
||||
if (eigenvalues[0] < eigenvalues[2])
|
||||
{
|
||||
std::swap(eigenvalues[0], eigenvalues[2]);
|
||||
std::swap(eigenvectors[0], eigenvectors[2]);
|
||||
}
|
||||
if (eigenvalues[1] < eigenvalues[3])
|
||||
{
|
||||
std::swap(eigenvalues[1], eigenvalues[3]);
|
||||
std::swap(eigenvectors[1], eigenvectors[3]);
|
||||
}
|
||||
if (eigenvalues[0] < eigenvalues[1])
|
||||
{
|
||||
std::swap(eigenvalues[0], eigenvalues[1]);
|
||||
std::swap(eigenvectors[0], eigenvectors[1]);
|
||||
}
|
||||
if (eigenvalues[2] < eigenvalues[3])
|
||||
{
|
||||
std::swap(eigenvalues[2], eigenvalues[3]);
|
||||
std::swap(eigenvectors[2], eigenvectors[3]);
|
||||
}
|
||||
if (eigenvalues[1] < eigenvalues[2])
|
||||
{
|
||||
std::swap(eigenvalues[1], eigenvalues[2]);
|
||||
std::swap(eigenvectors[1], eigenvectors[2]);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace glm
|
|
@ -20,14 +20,15 @@ namespace glm
|
|||
return acos(clamp(dot(x, y), T(-1), T(1)));
|
||||
}
|
||||
|
||||
//! \todo epsilon is hard coded to 0.01
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T orientedAngle(vec<2, T, Q> const& x, vec<2, T, Q> const& y)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
|
||||
T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
|
||||
|
||||
if(all(epsilonEqual(y, glm::rotate(x, Angle), T(0.0001))))
|
||||
T const partialCross = x.x * y.y - y.x * x.y;
|
||||
|
||||
if (partialCross > T(0))
|
||||
return Angle;
|
||||
else
|
||||
return -Angle;
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
#define GLM_COMPILER_CUDA75 0x10000001
|
||||
#define GLM_COMPILER_CUDA80 0x10000002
|
||||
#define GLM_COMPILER_CUDA90 0x10000004
|
||||
#define GLM_COMPILER_CUDA_RTC 0x10000100
|
||||
|
||||
// SYCL
|
||||
#define GLM_COMPILER_SYCL 0x00300000
|
||||
|
@ -122,7 +123,9 @@
|
|||
# if !defined(CUDA_VERSION) && !defined(GLM_FORCE_CUDA)
|
||||
# include <cuda.h> // make sure version is defined since nvcc does not define it itself!
|
||||
# endif
|
||||
# if CUDA_VERSION >= 8000
|
||||
# if defined(__CUDACC_RTC__)
|
||||
# define GLM_COMPILER GLM_COMPILER_CUDA_RTC
|
||||
# elif CUDA_VERSION >= 8000
|
||||
# define GLM_COMPILER GLM_COMPILER_CUDA80
|
||||
# elif CUDA_VERSION >= 7500
|
||||
# define GLM_COMPILER GLM_COMPILER_CUDA75
|
||||
|
|
Loading…
Reference in New Issue