16#ifdef WITH_CXX_GUARDEDALLOC
39template<
class T, u
int N>
class Vec {
46 for (
uint i = 0; i <
N; i++) {
56 template<
class U>
explicit inline Vec(
const U tab[
N])
58 for (
uint i = 0; i <
N; i++) {
63 template<
class U>
explicit inline Vec(
const std::vector<U> &tab)
65 for (
uint i = 0; i <
N; i++) {
72 for (
uint i = 0; i <
N; i++) {
101 return (*
this) * (*this);
107 for (
uint i = 0; i <
N; i++) {
117 for (
uint i = 0; i <
N; i++) {
159 for (
uint i = 0; i <
N; i++) {
160 sum += (*this)[i] *
v[i];
168 for (
uint i = 0; i <
N; i++) {
177 for (
uint i = 0; i <
N; i++) {
185 for (
uint i = 0; i <
N; i++) {
193 for (
uint i = 0; i <
N; i++) {
202 for (
uint i = 0; i <
N; i++) {
211 for (
uint i = 0; i <
N; i++) {
221 for (
uint i = 0; i <
N; i++) {
231 for (
uint i = 0; i <
N; i++) {
247 for (
uint i = 0; i <
N; i++) {
267#ifdef WITH_CXX_GUARDEDALLOC
268 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:VecMat:Vec")
278template<
class T>
class Vec2 :
public Vec<T, 2> {
284 template<
class U>
explicit inline Vec2(
const U tab[2]) :
Vec<T, 2>(tab) {}
286 template<
class U>
explicit inline Vec2(
const std::vector<U> &tab) :
Vec<T, 2>(tab) {}
292 this->_coord[0] = (
T)x;
293 this->_coord[1] = (
T)y;
298 return this->_coord[0];
303 return this->_coord[0];
308 return this->_coord[1];
313 return this->_coord[1];
361 for (
uint i = 0; i < 2; i++) {
362 sum += (*this)[i] *
v[i];
380 template<
class U>
explicit inline HVec3(
const U tab[4]) :
Vec<T, 4>(tab) {}
382 template<
class U>
explicit inline HVec3(
const std::vector<U> &tab) :
Vec<T, 4>(tab) {}
391 this->_coord[0] =
sx;
392 this->_coord[1] =
sy;
393 this->_coord[2] =
sz;
399 this->_coord[0] = (
T)sv[0];
400 this->_coord[1] = (
T)sv[1];
401 this->_coord[2] = (
T)sv[2];
402 this->_coord[3] = (
T)s;
407 return this->_coord[0];
412 return this->_coord[0];
417 return this->_coord[1];
422 return this->_coord[1];
427 return this->_coord[2];
432 return this->_coord[2];
437 return this->_coord[3];
442 return this->_coord[3];
448 return this->_coord[0] / this->_coord[3];
453 return this->_coord[1] / this->_coord[3];
458 return this->_coord[2] / this->_coord[3];
467template<
class T>
class Vec3 :
public Vec<T, 3> {
473 template<
class U>
explicit inline Vec3(
const U tab[3]) :
Vec<T, 3>(tab) {}
475 template<
class U>
explicit inline Vec3(
const std::vector<U> &tab) :
Vec<T, 3>(tab) {}
481 this->_coord[0] = (
T)
v.x();
482 this->_coord[1] = (
T)
v.y();
483 this->_coord[2] = (
T)
v.z();
495 return this->_coord[0];
500 return this->_coord[0];
505 return this->_coord[1];
510 return this->_coord[1];
515 return this->_coord[2];
520 return this->_coord[2];
574 for (
uint i = 0; i < 3; i++) {
575 sum += (*this)[i] *
v[i];
584 Vec3<T> res((*
this)[1] *
v[2] - (*
this)[2] *
v[1],
585 (*
this)[2] *
v[0] - (*
this)[0] *
v[2],
586 (*
this)[0] *
v[1] - (*
this)[1] *
v[0]);
593 Vec3<T> res((*
this)[1] *
v[2] - (*
this)[2] *
v[1],
594 (*
this)[2] *
v[0] - (*
this)[0] *
v[2],
595 (*
this)[0] *
v[1] - (*
this)[1] *
v[0]);
611template<
class T, u
int M, u
int N>
class Matrix {
631 this->_coord[i] = tab[i];
635 template<
class U>
explicit inline Matrix(
const std::vector<U> &tab)
638 this->_coord[i] = tab[i];
644 for (
uint i = 0; i <
M; i++) {
645 for (
uint j = 0; j <
N; j++) {
646 this->_coord[i *
N + j] = (
T)m(i, j);
653 return this->_coord[i *
N + j];
658 return this->_coord[i *
N + j];
674 for (
uint i = 0; i <
M; i++) {
675 for (
uint j = 0; j <
N; j++) {
676 res(j, i) = this->_coord[i *
N + j];
686 for (
uint i = 0; i <
M; i++) {
687 for (
uint j = 0; j <
N; j++) {
688 this->_coord[i *
N + j] = (
T)m(i, j);
697 for (
uint i = 0; i <
M; i++) {
698 for (
uint j = 0; j <
N; j++) {
699 this->_coord[i *
N + j] += (
T)m(i, j);
707 for (
uint i = 0; i <
M; i++) {
708 for (
uint j = 0; j <
N; j++) {
709 this->_coord[i *
N + j] -= (
T)m(i, j);
717 for (
uint i = 0; i <
M; i++) {
718 for (
uint j = 0; j <
N; j++) {
719 this->_coord[i *
N + j] *= lambda;
728 for (
uint i = 0; i <
M; i++) {
729 for (
uint j = 0; j <
N; j++) {
730 this->_coord[i *
N + j] /= lambda;
740#ifdef WITH_CXX_GUARDEDALLOC
741 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:VecMat:Matrix")
774 for (
uint i = 0; i <
N; i++) {
789template<
class T, u
int N>
inline Vec<T, N>
operator+(
const Vec<T, N> &v1,
const Vec<T, N> &
v2)
796template<
class T, u
int N>
inline Vec<T, N>
operator-(
const Vec<T, N> &v1,
const Vec<T, N> &
v2)
803template<
class T, u
int N>
812template<
class T, u
int N>
821template<
class T, u
int N>
832template<
class T, u
int N>
836 for (
uint i = 0; i <
N; i++) {
837 sum += v1[i] *
v2[i];
843template<
typename T>
inline Vec3<T>
operator^(
const Vec<T, 3> &v1,
const Vec<T, 3> &
v2)
846 v1[1] *
v2[2] - v1[2] *
v2[1], v1[2] *
v2[0] - v1[0] *
v2[2], v1[0] *
v2[1] - v1[1] *
v2[0]);
856 for (i = 0; i <
N - 1; i++) {
868template<
class T, u
int M, u
int N>
876template<
class T, u
int M, u
int N>
884template<
class T, u
int M, u
int N>
893template<
class T, u
int M, u
int N>
902template<
class T, u
int M, u
int N>
911template<
class T, u
int M, u
int N, u
int P>
918 for (j = 0; j <
P; j++) {
919 for (k = 0; k <
N; k++) {
921 for (i = 0; i <
N; i++) {
922 res(i, j) += m1(i, k) * scale;
929template<
class T, u
int M, u
int N>
935 for (
uint j = 0; j <
M; j++) {
937 for (
uint i = 0; i <
N; i++) {
938 res[i] += m(i, j) * scale;
945template<
class T, u
int M, u
int N>
949 for (i = 0; i <
M; i++) {
951 for (j = 0; j <
N - 1; j++) {
952 s << m(i, j) <<
", ";
954 s << m(i, j) <<
"]" << std::endl;
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static T sum(const btAlignedObjectArray< T > &items)
HVec3(const Vec< U, 4 > &v)
HVec3(const std::vector< U > &tab)
HVec3(const Vec< U, 3 > &sv, const U s=1)
HVec3(const value_type sx, const value_type sy=0, const value_type sz=0, const value_type s=1)
Vec< T, 4 >::value_type value_type
Matrix(const std::vector< U > &tab)
Matrix(const Matrix< U, M, N > &m)
Matrix< T, M, N > & operator-=(const Matrix< U, M, N > &m)
Matrix< T, M, N > & operator*=(const U lambda)
Matrix(const U tab[_SIZE])
Matrix< T, M, N > & operator/=(const U lambda)
value_type operator()(const uint i, const uint j) const
value_type & operator()(const uint i, const uint j)
Matrix< T, M, N > & operator+=(const Matrix< U, M, N > &m)
Matrix< T, M, N > & transpose() const
Matrix< T, M, N > & operator=(const Matrix< U, M, N > &m)
static SquareMatrix< T, N > identity()
SquareMatrix(const std::vector< U > &tab)
SquareMatrix(const Matrix< U, N, N > &m)
SquareMatrix(const U tab[_SIZE])
Vec2< T > operator*(const value_type r) const
value_type operator*(const Vec2< T > &v) const
Vec< T, 2 >::value_type value_type
void setX(const value_type v)
Vec2(const Vec< U, 2 > &v)
Vec2< T > operator/(const value_type r) const
Vec2< T > operator+(const Vec2< T > &v) const
void setY(const value_type v)
Vec2< T > operator-(const Vec2< T > &v) const
Vec2(const value_type x, const value_type y=0)
Vec2(const std::vector< U > &tab)
Vec3(const std::vector< U > &tab)
Vec3< T > operator^(const Vec3< T > &v) const
Vec< T, 3 >::value_type value_type
void setX(const value_type v)
value_type operator*(const Vec3< T > &v) const
Vec3< T > operator-(const Vec3< T > &v) const
void setY(const value_type v)
Vec3< T > operator/(const value_type r) const
Vec3< T > operator*(const value_type r) const
Vec3(const value_type x, const value_type y=0, const value_type z=0)
Vec3(const HVec3< U > &v)
Vec3< T > operator^(const Vec< U, 3 > &v) const
void setZ(const value_type v)
Vec3(const Vec< U, 3 > &v)
Vec3< T > operator+(const Vec3< T > &v) const
Vec< T, N > operator+(const Vec< T, N > &v) const
Vec< T, N > & normalizeSafe()
value_type squareNorm() const
Vec< T, N > & operator*=(const U r)
Vec< T, N > & operator+=(const Vec< U, N > &v)
Vec< T, N > & operator=(const Vec< U, N > &v)
value_type operator[](const uint i) const
Vec< T, N > operator/(const typename Vec< T, N >::value_type r) const
value_type & operator[](const uint i)
Vec< T, N > & operator-=(const Vec< U, N > &v)
Vec< T, N > & operator/=(const U r)
Vec< T, N > operator*(const typename Vec< T, N >::value_type r) const
bool operator>(const Vec< T, N > &v) const
Vec< T, N > operator-(const Vec< T, N > &v) const
Vec(const Vec< U, N > &v)
bool operator!=(const Vec< T, N > &v) const
Vec< T, N > & normalize()
bool operator==(const Vec< T, N > &v) const
value_type operator*(const Vec< T, N > &v) const
Vec(const std::vector< U > &tab)
bool operator<(const Vec< T, N > &v) const
ccl_device_inline const float4 operator^(const float4 a, const float4 b)
Matrix< T, M, N > operator/(const Matrix< T, M, N > &m1, const typename Matrix< T, M, N >::value_type lambda)
Matrix< T, M, N > operator+(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)
std::ostream & operator<<(std::ostream &s, const Vec< T, N > &v)
Vec< T, N > operator*(const typename Vec< T, N >::value_type r, const Vec< T, N > &v)
Matrix< T, M, N > operator-(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)