Blender V4.3
normal_cycle.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2000 `Bruno Levy <levy@loria.fr>`
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 *
5 * The Original Code is:
6 * - OGF/Graphite: Geometry and Graphics Programming Library + Utilities.
7 */
8
13#include "normal_cycle.h"
14#include "matrix_util.h"
15
16namespace Freestyle::OGF {
17
18//_________________________________________________________
19
21{
22 M_[0] = M_[1] = M_[2] = M_[3] = M_[4] = M_[5] = 0;
23}
24
26{
27 double eigen_vectors[9];
28 MatrixUtil::semi_definite_symmetric_eigen(M_, 3, eigen_vectors, eigen_value_);
29
30 axis_[0] = Vec3r(eigen_vectors[0], eigen_vectors[1], eigen_vectors[2]);
31
32 axis_[1] = Vec3r(eigen_vectors[3], eigen_vectors[4], eigen_vectors[5]);
33
34 axis_[2] = Vec3r(eigen_vectors[6], eigen_vectors[7], eigen_vectors[8]);
35
36 // Normalize the eigen vectors
37 for (int i = 0; i < 3; i++) {
38 axis_[i].normalize();
39 }
40
41 // Sort the eigen vectors
42 i_[0] = 0;
43 i_[1] = 1;
44 i_[2] = 2;
45
46 double l0 = ::fabs(eigen_value_[0]);
47 double l1 = ::fabs(eigen_value_[1]);
48 double l2 = ::fabs(eigen_value_[2]);
49
50 if (l1 > l0) {
51 ogf_swap(l0, l1);
52 ogf_swap(i_[0], i_[1]);
53 }
54 if (l2 > l1) {
55 ogf_swap(l1, l2);
56 ogf_swap(i_[1], i_[2]);
57 }
58 if (l1 > l0) {
59 ogf_swap(l0, l1);
60 ogf_swap(i_[0], i_[1]);
61 }
62}
63
64//_________________________________________________________
65
66} // namespace Freestyle::OGF
Vec< T, N > & normalize()
Definition VecMat.h:104
ccl_device_inline float2 fabs(const float2 a)
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val)
void ogf_swap(T &x, T &y)