Blender  V2.93
normal_cycle.cpp
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:
17  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
18  * Copyright (C) 2000 Bruno Levy
19  * Contact: Bruno Levy
20  * <levy@loria.fr>
21  * ISA Project
22  * LORIA, INRIA Lorraine,
23  * Campus Scientifique, BP 239
24  * 54506 VANDOEUVRE LES NANCY CEDEX
25  * FRANCE
26  */
27 
32 #include "normal_cycle.h"
33 #include "matrix_util.h"
34 
35 namespace Freestyle::OGF {
36 
37 //_________________________________________________________
38 
40 {
41  M_[0] = M_[1] = M_[2] = M_[3] = M_[4] = M_[5] = 0;
42 }
43 
45 {
46  double eigen_vectors[9];
47  MatrixUtil::semi_definite_symmetric_eigen(M_, 3, eigen_vectors, eigen_value_);
48 
49  axis_[0] = Vec3r(eigen_vectors[0], eigen_vectors[1], eigen_vectors[2]);
50 
51  axis_[1] = Vec3r(eigen_vectors[3], eigen_vectors[4], eigen_vectors[5]);
52 
53  axis_[2] = Vec3r(eigen_vectors[6], eigen_vectors[7], eigen_vectors[8]);
54 
55  // Normalize the eigen vectors
56  for (int i = 0; i < 3; i++) {
57  axis_[i].normalize();
58  }
59 
60  // Sort the eigen vectors
61  i_[0] = 0;
62  i_[1] = 1;
63  i_[2] = 2;
64 
65  double l0 = ::fabs(eigen_value_[0]);
66  double l1 = ::fabs(eigen_value_[1]);
67  double l2 = ::fabs(eigen_value_[2]);
68 
69  if (l1 > l0) {
70  ogf_swap(l0, l1);
71  ogf_swap(i_[0], i_[1]);
72  }
73  if (l2 > l1) {
74  ogf_swap(l1, l2);
75  ogf_swap(i_[1], i_[2]);
76  }
77  if (l1 > l0) {
78  ogf_swap(l0, l1);
79  ogf_swap(i_[0], i_[1]);
80  }
81 }
82 
83 //_________________________________________________________
84 
85 } // namespace Freestyle::OGF
Vec< T, N > & normalize()
Definition: VecMat.h:119
VecMat::Vec3< real > Vec3r
Definition: Geom.h:42
void semi_definite_symmetric_eigen(const double *mat, int n, double *eigen_vec, double *eigen_val)
Definition: matrix_util.cpp:41
void ogf_swap(T &x, T &y)
Definition: normal_cycle.h:48
ccl_device_inline float2 fabs(const float2 &a)