Blender  V3.3
numeric.cc
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #include "libmv/numeric/numeric.h"
22 
23 namespace libmv {
24 
26  double c, s;
27  sincos(angle, &s, &c);
28  Mat3 R;
29  // clang-format off
30  R << 1, 0, 0,
31  0, c, -s,
32  0, s, c;
33  // clang-format on
34  return R;
35 }
36 
38  double c, s;
39  sincos(angle, &s, &c);
40  Mat3 R;
41  // clang-format off
42  R << c, 0, s,
43  0, 1, 0,
44  -s, 0, c;
45  // clang-format on
46  return R;
47 }
48 
50  double c, s;
51  sincos(angle, &s, &c);
52  Mat3 R;
53  // clang-format off
54  R << c, -s, 0,
55  s, c, 0,
56  0, 0, 1;
57  // clang-format on
58  return R;
59 }
60 
61 Mat3 RotationRodrigues(const Vec3& axis) {
62  double theta = axis.norm();
63  Vec3 w = axis / theta;
65 
66  return Mat3::Identity() + sin(theta) * W + (1 - cos(theta)) * W * W;
67 }
68 
70  Vec3 zc = center.normalized();
71  Vec3 xc = Vec3::UnitY().cross(zc).normalized();
72  Vec3 yc = zc.cross(xc);
73  Mat3 R;
74  R.row(0) = xc;
75  R.row(1) = yc;
76  R.row(2) = zc;
77  return R;
78 }
79 
81  Mat3 X;
82  // clang-format off
83  X << 0, -x(2), x(1),
84  x(2), 0, -x(0),
85  -x(1), x(0), 0;
86  // clang-format on
87  return X;
88 }
89 
91  Vec* mean_pointer,
92  Vec* variance_pointer) {
93  Vec& mean = *mean_pointer;
94  Vec& variance = *variance_pointer;
95  int n = A.rows();
96  int m = A.cols();
97  mean.resize(n);
98  variance.resize(n);
99 
100  for (int i = 0; i < n; ++i) {
101  mean(i) = 0;
102  variance(i) = 0;
103  for (int j = 0; j < m; ++j) {
104  double x = A(i, j);
105  mean(i) += x;
106  variance(i) += x * x;
107  }
108  }
109 
110  mean /= m;
111  for (int i = 0; i < n; ++i) {
112  variance(i) = variance(i) / m - Square(mean(i));
113  }
114 }
115 
116 void HorizontalStack(const Mat& left, const Mat& right, Mat* stacked) {
117  assert(left.rows() == right.rows());
118  int n = left.rows();
119  int m1 = left.cols();
120  int m2 = right.cols();
121 
122  stacked->resize(n, m1 + m2);
123  stacked->block(0, 0, n, m1) = left;
124  stacked->block(0, m1, n, m2) = right;
125 }
126 
127 void MatrixColumn(const Mat& A, int i, Vec2* v) {
128  assert(A.rows() == 2);
129  *v << A(0, i), A(1, i);
130 }
131 void MatrixColumn(const Mat& A, int i, Vec3* v) {
132  assert(A.rows() == 3);
133  *v << A(0, i), A(1, i), A(2, i);
134 }
135 void MatrixColumn(const Mat& A, int i, Vec4* v) {
136  assert(A.rows() == 4);
137  *v << A(0, i), A(1, i), A(2, i), A(3, i);
138 }
139 
140 } // namespace libmv
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble right
#define X
Definition: GeomUtils.cpp:199
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define A
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
static int left
#define R
static unsigned c
Definition: RandGen.cpp:83
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
T Square(T x)
Definition: numeric.h:247
Eigen::VectorXd Vec
Definition: numeric.h:61
Eigen::Vector4d Vec4
Definition: numeric.h:107
Mat3 CrossProductMatrix(const Vec3 &x)
Definition: numeric.cc:80
Eigen::Matrix< double, 3, 3 > Mat3
Definition: numeric.h:72
Eigen::Vector2d Vec2
Definition: numeric.h:105
Mat3 RotationAroundX(double angle)
Definition: numeric.cc:25
Eigen::MatrixXd Mat
Definition: numeric.h:60
void MatrixColumn(const Mat &A, int i, Vec2 *v)
Definition: numeric.cc:127
void MeanAndVarianceAlongRows(const Mat &A, Vec *mean_pointer, Vec *variance_pointer)
Definition: numeric.cc:90
Mat3 RotationRodrigues(const Vec3 &axis)
Definition: numeric.cc:61
Eigen::Vector3d Vec3
Definition: numeric.h:106
void HorizontalStack(const Mat &left, const Mat &right, Mat *stacked)
Definition: numeric.cc:116
Mat3 RotationAroundZ(double angle)
Definition: numeric.cc:49
Mat3 RotationAroundY(double angle)
Definition: numeric.cc:37
Mat3 LookAt(Vec3 center)
Definition: numeric.cc:69