Blender V4.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
22
23namespace libmv {
24
25Mat3 RotationAroundX(double angle) {
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
37Mat3 RotationAroundY(double angle) {
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
49Mat3 RotationAroundZ(double angle) {
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
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
69Mat3 LookAt(Vec3 center) {
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
116void 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
127void MatrixColumn(const Mat& A, int i, Vec2* v) {
128 assert(A.rows() == 2);
129 *v << A(0, i), A(1, i);
130}
131void 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}
135void 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
#define X
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define A
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define Square(a, x, y)
ccl_device_inline float3 cos(float3 v)
static int left
#define R
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