Blender  V2.93
svd.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2015 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #ifndef __EIGEN3_SVD_C_API_CC__
21 #define __EIGEN3_SVD_C_API_CC__
22 
23 /* Eigen gives annoying huge amount of warnings here, silence them! */
24 #if defined(__GNUC__) && !defined(__clang__)
25 # pragma GCC diagnostic ignored "-Wlogical-op"
26 #endif
27 
28 #ifdef __EIGEN3_SVD_C_API_CC__ /* quiet warning */
29 #endif
30 
31 #include <Eigen/Core>
32 #include <Eigen/Dense>
33 #include <Eigen/SVD>
34 
35 #include "svd.h"
36 
37 using Eigen::JacobiSVD;
38 
39 using Eigen::NoQRPreconditioner;
40 
41 using Eigen::ComputeThinU;
42 using Eigen::ComputeThinV;
43 
44 using Eigen::Map;
45 using Eigen::MatrixXf;
46 using Eigen::VectorXf;
47 
48 using Eigen::Matrix4f;
49 
50 void EIG_svd_square_matrix(const int size, const float *matrix, float *r_U, float *r_S, float *r_V)
51 {
52  /* Since our matrix is squared, we can use thinU/V. */
53  unsigned int flags = (r_U ? ComputeThinU : 0) | (r_V ? ComputeThinV : 0);
54 
55  /* Blender and Eigen matrices are both column-major. */
56  JacobiSVD<MatrixXf, NoQRPreconditioner> svd(Map<MatrixXf>((float *)matrix, size, size), flags);
57 
58  if (r_U) {
59  Map<MatrixXf>(r_U, size, size) = svd.matrixU();
60  }
61 
62  if (r_S) {
63  Map<VectorXf>(r_S, size) = svd.singularValues();
64  }
65 
66  if (r_V) {
67  Map<MatrixXf>(r_V, size, size) = svd.matrixV();
68  }
69 }
70 
71 #endif /* __EIGEN3_SVD_C_API_CC__ */
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void EIG_svd_square_matrix(const int size, const float *matrix, float *r_U, float *r_S, float *r_V)
Definition: svd.cc:50