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