Datasets:

Modalities:
Image
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
ZijunCui commited on
Commit
fe775b6
·
verified ·
1 Parent(s): 6492310

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. vendor/libigl/include/igl/ARAPEnergyType.h +36 -0
  2. vendor/libigl/include/igl/AtA_cached.h +70 -0
  3. vendor/libigl/include/igl/C_STR.h +18 -0
  4. vendor/libigl/include/igl/EPS.cpp +30 -0
  5. vendor/libigl/include/igl/EPS.h +32 -0
  6. vendor/libigl/include/igl/FastWindingNumberForSoups.h +0 -0
  7. vendor/libigl/include/igl/FileEncoding.h +21 -0
  8. vendor/libigl/include/igl/FileMemoryStream.h +63 -0
  9. vendor/libigl/include/igl/HalfEdgeIterator.cpp +162 -0
  10. vendor/libigl/include/igl/Hit.h +29 -0
  11. vendor/libigl/include/igl/LinSpaced.h +61 -0
  12. vendor/libigl/include/igl/MappingEnergyType.h +27 -0
  13. vendor/libigl/include/igl/MeshBooleanType.h +23 -0
  14. vendor/libigl/include/igl/MshLoader.h +190 -0
  15. vendor/libigl/include/igl/MshSaver.cpp +347 -0
  16. vendor/libigl/include/igl/NormalType.h +27 -0
  17. vendor/libigl/include/igl/ONE.h +22 -0
  18. vendor/libigl/include/igl/PI.h +19 -0
  19. vendor/libigl/include/igl/REDRUM.h +55 -0
  20. vendor/libigl/include/igl/STR.h +18 -0
  21. vendor/libigl/include/igl/Singular_Value_Decomposition_Givens_QR_Factorization_Kernel.hpp +128 -0
  22. vendor/libigl/include/igl/Singular_Value_Decomposition_Kernel_Declarations.hpp +137 -0
  23. vendor/libigl/include/igl/Singular_Value_Decomposition_Main_Kernel_Body.hpp +0 -0
  24. vendor/libigl/include/igl/Singular_Value_Decomposition_Preamble.hpp +78 -0
  25. vendor/libigl/include/igl/SortableRow.h +66 -0
  26. vendor/libigl/include/igl/Timer.h +179 -0
  27. vendor/libigl/include/igl/WindingNumberAABB.h +389 -0
  28. vendor/libigl/include/igl/WindingNumberTree.h +501 -0
  29. vendor/libigl/include/igl/accumarray.cpp +52 -0
  30. vendor/libigl/include/igl/accumarray.h +50 -0
  31. vendor/libigl/include/igl/active_set.cpp +370 -0
  32. vendor/libigl/include/igl/adjacency_list.cpp +180 -0
  33. vendor/libigl/include/igl/adjacency_list.h +51 -0
  34. vendor/libigl/include/igl/adjacency_matrix.cpp +125 -0
  35. vendor/libigl/include/igl/adjacency_matrix.h +66 -0
  36. vendor/libigl/include/igl/all.cpp +26 -0
  37. vendor/libigl/include/igl/all.h +36 -0
  38. vendor/libigl/include/igl/all_pairs_distances.cpp +39 -0
  39. vendor/libigl/include/igl/all_pairs_distances.h +41 -0
  40. vendor/libigl/include/igl/ambient_occlusion.cpp +139 -0
  41. vendor/libigl/include/igl/ambient_occlusion.h +80 -0
  42. vendor/libigl/include/igl/angular_distance.cpp +20 -0
  43. vendor/libigl/include/igl/angular_distance.h +30 -0
  44. vendor/libigl/include/igl/any.h +35 -0
  45. vendor/libigl/include/igl/any_of.cpp +20 -0
  46. vendor/libigl/include/igl/any_of.h +26 -0
  47. vendor/libigl/include/igl/arap_dof.cpp +884 -0
  48. vendor/libigl/include/igl/arap_dof.h +244 -0
  49. vendor/libigl/include/igl/arap_linear_block.h +78 -0
  50. vendor/libigl/include/igl/average_onto_faces.h +34 -0
vendor/libigl/include/igl/ARAPEnergyType.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ARAPENERGYTYPE_H
9
+ #define IGL_ARAPENERGYTYPE_H
10
+ namespace igl
11
+ {
12
+ // ARAP_ENERGY_TYPE_SPOKES "As-rigid-as-possible Surface Modeling" by [Sorkine and
13
+ // Alexa 2007], rotations defined at vertices affecting incident edges,
14
+ // default
15
+ // ARAP_ENERGY_TYPE_SPOKES-AND-RIMS Adapted version of "As-rigid-as-possible Surface
16
+ // Modeling" by [Sorkine and Alexa 2007] presented in section 4.2 of or
17
+ // "A simple geometric model for elastic deformation" by [Chao et al.
18
+ // 2010], rotations defined at vertices affecting incident edges and
19
+ // opposite edges
20
+ // ARAP_ENERGY_TYPE_ELEMENTS "A local-global approach to mesh parameterization" by
21
+ // [Liu et al. 2010] or "A simple geometric model for elastic
22
+ // deformation" by [Chao et al. 2010], rotations defined at elements
23
+ // (triangles or tets)
24
+ // ARAP_ENERGY_TYPE_DEFAULT Choose one automatically: spokes and rims
25
+ // for surfaces, elements for planar meshes and tets (not fully
26
+ // supported)
27
+ enum ARAPEnergyType
28
+ {
29
+ ARAP_ENERGY_TYPE_SPOKES = 0,
30
+ ARAP_ENERGY_TYPE_SPOKES_AND_RIMS = 1,
31
+ ARAP_ENERGY_TYPE_ELEMENTS = 2,
32
+ ARAP_ENERGY_TYPE_DEFAULT = 3,
33
+ NUM_ARAP_ENERGY_TYPES = 4
34
+ };
35
+ }
36
+ #endif
vendor/libigl/include/igl/AtA_cached.h ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2017 Daniele Panozzo <daniele.panozzo@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ATA_CACHED_H
9
+ #define IGL_ATA_CACHED_H
10
+ #include "igl_inline.h"
11
+ #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
12
+ #include <Eigen/Dense>
13
+ #include <Eigen/Sparse>
14
+ namespace igl
15
+ {
16
+ struct AtA_cached_data
17
+ {
18
+ // Weights
19
+ Eigen::VectorXd W;
20
+
21
+ // Flatten composition rules
22
+ std::vector<int> I_row;
23
+ std::vector<int> I_col;
24
+ std::vector<int> I_w;
25
+
26
+ // For each entry of AtA, points to the beginning
27
+ // of the composition rules
28
+ std::vector<int> I_outer;
29
+ };
30
+
31
+ // Computes At * W * A, where A is sparse and W is diagonal. Divides the
32
+ // construction in two phases, one
33
+ // for fixing the sparsity pattern, and one to populate it with values. Compared to
34
+ // evaluating it directly, this version is slower for the first time (since it requires a
35
+ // precomputation), but faster to the subsequent evaluations.
36
+ //
37
+ // Input:
38
+ // A m x n sparse matrix
39
+ // data stores the precomputed sparsity pattern, data.W contains the optional diagonal weights (stored as a dense vector). If W is not provided, it is replaced by the identity.
40
+ // Outputs:
41
+ // AtA m by m matrix computed as AtA * W * A
42
+ //
43
+ // Example:
44
+ // AtA_data = igl::AtA_cached_data();
45
+ // AtA_data.W = W;
46
+ // if (s.AtA.rows() == 0)
47
+ // igl::AtA_cached_precompute(s.A,s.AtA_data,s.AtA);
48
+ // else
49
+ // igl::AtA_cached(s.A,s.AtA_data,s.AtA);
50
+ template <typename Scalar>
51
+ IGL_INLINE void AtA_cached_precompute(
52
+ const Eigen::SparseMatrix<Scalar>& A,
53
+ AtA_cached_data& data,
54
+ Eigen::SparseMatrix<Scalar>& AtA
55
+ );
56
+
57
+ template <typename Scalar>
58
+ IGL_INLINE void AtA_cached(
59
+ const Eigen::SparseMatrix<Scalar>& A,
60
+ const AtA_cached_data& data,
61
+ Eigen::SparseMatrix<Scalar>& AtA
62
+ );
63
+
64
+ }
65
+
66
+ #ifndef IGL_STATIC_LIBRARY
67
+ # include "AtA_cached.cpp"
68
+ #endif
69
+
70
+ #endif
vendor/libigl/include/igl/C_STR.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_C_STR_H
9
+ #define IGL_C_STR_H
10
+ // http://stackoverflow.com/a/2433143/148668
11
+ // Suppose you have a function:
12
+ // void func(const char * c);
13
+ // Then you can write:
14
+ // func(C_STR("foo"<<1<<"bar"));
15
+ #include <sstream>
16
+ #include <string>
17
+ #define C_STR(X) static_cast<std::ostringstream&>(std::ostringstream().flush() << X).str().c_str()
18
+ #endif
vendor/libigl/include/igl/EPS.cpp ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "EPS.h"
9
+
10
+ template <> IGL_INLINE float igl::EPS()
11
+ {
12
+ return igl::FLOAT_EPS;
13
+ }
14
+ template <> IGL_INLINE double igl::EPS()
15
+ {
16
+ return igl::DOUBLE_EPS;
17
+ }
18
+
19
+ template <> IGL_INLINE float igl::EPS_SQ()
20
+ {
21
+ return igl::FLOAT_EPS_SQ;
22
+ }
23
+ template <> IGL_INLINE double igl::EPS_SQ()
24
+ {
25
+ return igl::DOUBLE_EPS_SQ;
26
+ }
27
+
28
+ #ifdef IGL_STATIC_LIBRARY
29
+ // Explicit template instantiation
30
+ #endif
vendor/libigl/include/igl/EPS.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_EPS_H
9
+ #define IGL_EPS_H
10
+ #include "igl_inline.h"
11
+ namespace igl
12
+ {
13
+ // Define a standard value for double epsilon
14
+ const double DOUBLE_EPS = 1.0e-14;
15
+ const double DOUBLE_EPS_SQ = 1.0e-28;
16
+ const float FLOAT_EPS = 1.0e-7f;
17
+ const float FLOAT_EPS_SQ = 1.0e-14f;
18
+ // Function returning EPS for corresponding type
19
+ template <typename S_type> IGL_INLINE S_type EPS();
20
+ template <typename S_type> IGL_INLINE S_type EPS_SQ();
21
+ // Template specializations for float and double
22
+ template <> IGL_INLINE float EPS<float>();
23
+ template <> IGL_INLINE double EPS<double>();
24
+ template <> IGL_INLINE float EPS_SQ<float>();
25
+ template <> IGL_INLINE double EPS_SQ<double>();
26
+ }
27
+
28
+ #ifndef IGL_STATIC_LIBRARY
29
+ # include "EPS.cpp"
30
+ #endif
31
+
32
+ #endif
vendor/libigl/include/igl/FastWindingNumberForSoups.h ADDED
The diff for this file is too large to render. See raw diff
 
vendor/libigl/include/igl/FileEncoding.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2020 Jérémie Dumas <jeremie.dumas@ens-lyon.org>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_FILEENCODING_H
9
+ #define IGL_FILEENCODING_H
10
+
11
+ namespace igl
12
+ {
13
+
14
+ enum class FileEncoding {
15
+ Binary,
16
+ Ascii
17
+ };
18
+
19
+ }
20
+
21
+ #endif
vendor/libigl/include/igl/FileMemoryStream.h ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2020 Jérémie Dumas <jeremie.dumas@ens-lyon.org>
4
+ // Copyright (C) 2021 Alec Jacobson <alecjacobson@gmail.com>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla Public License
7
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
8
+ // obtain one at http://mozilla.org/MPL/2.0/.
9
+ #ifndef IGL_FILEMEMORYSTREAM_H
10
+ #define IGL_FILEMEMORYSTREAM_H
11
+
12
+ #include "igl_inline.h"
13
+
14
+ #include <streambuf>
15
+ #include <istream>
16
+ #include <string>
17
+
18
+ namespace igl {
19
+ struct FileMemoryBuffer : public std::streambuf
20
+ {
21
+ char *p_start{nullptr};
22
+ char *p_end{nullptr};
23
+ size_t size;
24
+
25
+ FileMemoryBuffer(char const *first_elem, size_t size)
26
+ : p_start(const_cast<char *>(first_elem)), p_end(p_start + size),
27
+ size(size)
28
+ {
29
+ setg(p_start, p_start, p_end);
30
+ }
31
+
32
+ pos_type seekoff(
33
+ off_type off,
34
+ std::ios_base::seekdir dir,
35
+ std::ios_base::openmode which) override
36
+ {
37
+ if (dir == std::ios_base::cur)
38
+ {
39
+ gbump(static_cast<int>(off));
40
+ }else
41
+ {
42
+ setg(p_start,(dir==std::ios_base::beg ? p_start : p_end) + off,p_end);
43
+ }
44
+ return gptr() - p_start;
45
+ }
46
+
47
+ pos_type seekpos(pos_type pos, std::ios_base::openmode which) override
48
+ {
49
+ return seekoff(pos, std::ios_base::beg, which);
50
+ }
51
+ };
52
+
53
+ struct FileMemoryStream : virtual FileMemoryBuffer, public std::istream
54
+ {
55
+ FileMemoryStream( char const *first_elem, size_t size)
56
+ : FileMemoryBuffer(first_elem, size),
57
+ std::istream( static_cast<std::streambuf *>(this))
58
+ {}
59
+ };
60
+ }
61
+
62
+ #endif
63
+
vendor/libigl/include/igl/HalfEdgeIterator.cpp ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+
9
+ #include "HalfEdgeIterator.h"
10
+
11
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
12
+ IGL_INLINE igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::HalfEdgeIterator(
13
+ const Eigen::MatrixBase<DerivedF>& _F,
14
+ const Eigen::MatrixBase<DerivedFF>& _FF,
15
+ const Eigen::MatrixBase<DerivedFFi>& _FFi,
16
+ int _fi,
17
+ int _ei,
18
+ bool _reverse
19
+ )
20
+ : fi(_fi), ei(_ei), reverse(_reverse), F(_F), FF(_FF), FFi(_FFi)
21
+ {}
22
+
23
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
24
+ IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipF()
25
+ {
26
+ if (isBorder())
27
+ return;
28
+
29
+ int fin = (FF)(fi,ei);
30
+ int ein = (FFi)(fi,ei);
31
+
32
+ fi = fin;
33
+ ei = ein;
34
+ reverse = !reverse;
35
+ }
36
+
37
+
38
+ // Change Edge
39
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
40
+ IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipE()
41
+ {
42
+ if (!reverse)
43
+ ei = (ei+2)%3; // ei-1
44
+ else
45
+ ei = (ei+1)%3;
46
+
47
+ reverse = !reverse;
48
+ }
49
+
50
+ // Change Vertex
51
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
52
+ IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipV()
53
+ {
54
+ reverse = !reverse;
55
+ }
56
+
57
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
58
+ IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::isBorder()
59
+ {
60
+ return (FF)(fi,ei) == -1;
61
+ }
62
+
63
+ /*!
64
+ * Returns the next edge skipping the border
65
+ * _________
66
+ * /\ c | b /\
67
+ * / \ | / \
68
+ * / d \ | / a \
69
+ * /______\|/______\
70
+ * v
71
+ * In this example, if a and d are of-border and the pos is iterating counterclockwise, this method iterate through the faces incident on vertex v,
72
+ * producing the sequence a, b, c, d, a, b, c, ...
73
+ */
74
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
75
+ IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::NextFE()
76
+ {
77
+ if ( isBorder() ) // we are on a border
78
+ {
79
+ do
80
+ {
81
+ flipF();
82
+ flipE();
83
+ } while (!isBorder());
84
+ flipE();
85
+ return false;
86
+ }
87
+ else
88
+ {
89
+ flipF();
90
+ flipE();
91
+ return true;
92
+ }
93
+ }
94
+
95
+ // Get vertex index
96
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
97
+ IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Vi()
98
+ {
99
+ assert(fi >= 0);
100
+ assert(fi < F.rows());
101
+ assert(ei >= 0);
102
+ assert(ei <= 2);
103
+
104
+ if (!reverse)
105
+ return (F)(fi,ei);
106
+ else
107
+ return (F)(fi,(ei+1)%3);
108
+ }
109
+
110
+ // Get face index
111
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
112
+ IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Fi()
113
+ {
114
+ return fi;
115
+ }
116
+
117
+ // Get edge index
118
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
119
+ IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Ei()
120
+ {
121
+ return ei;
122
+ }
123
+
124
+
125
+ template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
126
+ IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::operator==(HalfEdgeIterator& p2)
127
+ {
128
+ return
129
+ (
130
+ (fi == p2.fi) &&
131
+ (ei == p2.ei) &&
132
+ (reverse == p2.reverse) &&
133
+ (F == p2.F) &&
134
+ (FF == p2.FF) &&
135
+ (FFi == p2.FFi)
136
+ );
137
+ }
138
+
139
+ #ifdef IGL_STATIC_LIBRARY
140
+ // Explicit template instantiation
141
+ template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::HalfEdgeIterator(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, int, int, bool);
142
+ template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::HalfEdgeIterator(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, int, bool);
143
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::NextFE();
144
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Ei();
145
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Ei();
146
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::Ei();
147
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::Fi();
148
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::NextFE();
149
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Vi();
150
+ template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::HalfEdgeIterator(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, int, bool);
151
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Fi();
152
+ template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipE();
153
+ template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >::flipE();
154
+ template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipF();
155
+ template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >::flipF();
156
+ template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipV();
157
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::operator==(igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
158
+ template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Fi();
159
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::NextFE();
160
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >::isBorder();
161
+ template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::isBorder();
162
+ #endif
vendor/libigl/include/igl/Hit.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
4
+ // 2014 Christian Schüller <schuellchr@gmail.com>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla Public License
7
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
8
+ // obtain one at http://mozilla.org/MPL/2.0/.
9
+ #ifndef IGL_HIT_H
10
+ #define IGL_HIT_H
11
+
12
+ namespace igl
13
+ {
14
+ // Reimplementation of the embree::Hit struct from embree1.0
15
+ //
16
+ // TODO: template on floating point type
17
+ struct Hit
18
+ {
19
+ int id; // primitive id
20
+ int gid; // geometry id (not used)
21
+ // barycentric coordinates so that
22
+ // pos = V.row(F(id,0))*(1-u-v)+V.row(F(id,1))*u+V.row(F(id,2))*v;
23
+ float u,v;
24
+ // parametric distance so that
25
+ // pos = origin + t * dir
26
+ float t;
27
+ };
28
+ }
29
+ #endif
vendor/libigl/include/igl/LinSpaced.h ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef IGL_LINSPACED_H
2
+ #define IGL_LINSPACED_H
3
+ #include <Eigen/Core>
4
+ // This function is not intended to be a permanent function of libigl. Rather
5
+ // it is a "drop-in" workaround for documented bug in Eigen:
6
+ // http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1383
7
+ //
8
+ // Replace:
9
+ //
10
+ // Eigen::VectorXi::LinSpaced(size,low,high);
11
+ //
12
+ // With:
13
+ //
14
+ // igl::LinSpaced<Eigen::VectorXi>(size,low,high);
15
+ //
16
+ // Specifcally, this version will _always_ return an empty vector if size==0,
17
+ // regardless of the values for low and high. If size != 0, then this simply
18
+ // returns the result of Eigen::Derived::LinSpaced.
19
+ //
20
+ // Until this bug is fixed, we should also avoid calls to the member function
21
+ // `.setLinSpaced`. This means replacing:
22
+ //
23
+ // a.setLinSpaced(size,low,high);
24
+ //
25
+ // with
26
+ //
27
+ // a = igl::LinSpaced<decltype(a) >(size,low,high);
28
+ //
29
+ namespace igl
30
+ {
31
+ template <typename Derived>
32
+ //inline typename Eigen::DenseBase< Derived >::RandomAccessLinSpacedReturnType
33
+ inline Derived LinSpaced(
34
+ typename Derived::Index size,
35
+ const typename Derived::Scalar & low,
36
+ const typename Derived::Scalar & high);
37
+ }
38
+
39
+ // Implementation
40
+
41
+ template <typename Derived>
42
+ //inline typename Eigen::DenseBase< Derived >::RandomAccessLinSpacedReturnType
43
+ inline Derived
44
+ igl::LinSpaced(
45
+ typename Derived::Index size,
46
+ const typename Derived::Scalar & low,
47
+ const typename Derived::Scalar & high)
48
+ {
49
+ if(size == 0)
50
+ {
51
+ // Force empty vector with correct "RandomAccessLinSpacedReturnType" type.
52
+ return Derived::LinSpaced(0,0,1);
53
+ }else if(high < low)
54
+ {
55
+ return low-Derived::LinSpaced(size,low-low,low-high).array();
56
+ }else{
57
+ return Derived::LinSpaced(size,low,high);
58
+ }
59
+ }
60
+
61
+ #endif
vendor/libigl/include/igl/MappingEnergyType.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2018 Zhongshi Jiang <jiangzs@nyu.edu>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_MAPPINGENERGYTYPE_H
9
+ #define IGL_MAPPINGENERGYTYPE_H
10
+ namespace igl
11
+ {
12
+ // Energy Types used for Parameterization/Mapping.
13
+ // Refer to SLIM [Rabinovich et al. 2017] for more details
14
+ // Todo: Integrate with ARAPEnergyType
15
+
16
+ enum MappingEnergyType
17
+ {
18
+ ARAP = 0,
19
+ LOG_ARAP = 1,
20
+ SYMMETRIC_DIRICHLET = 2,
21
+ CONFORMAL = 3,
22
+ EXP_CONFORMAL = 4,
23
+ EXP_SYMMETRIC_DIRICHLET = 5,
24
+ NUM_SLIM_ENERGY_TYPES = 6
25
+ };
26
+ }
27
+ #endif
vendor/libigl/include/igl/MeshBooleanType.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_MESH_BOOLEAN_TYPE_H
9
+ #define IGL_MESH_BOOLEAN_TYPE_H
10
+ namespace igl
11
+ {
12
+ enum MeshBooleanType
13
+ {
14
+ MESH_BOOLEAN_TYPE_UNION = 0,
15
+ MESH_BOOLEAN_TYPE_INTERSECT = 1,
16
+ MESH_BOOLEAN_TYPE_MINUS = 2,
17
+ MESH_BOOLEAN_TYPE_XOR = 3,
18
+ MESH_BOOLEAN_TYPE_RESOLVE = 4,
19
+ NUM_MESH_BOOLEAN_TYPES = 5
20
+ };
21
+ };
22
+
23
+ #endif
vendor/libigl/include/igl/MshLoader.h ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // based on MSH reader from PyMesh
2
+
3
+ // Copyright (c) 2015 Qingnan Zhou <qzhou@adobe.com>
4
+ // Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla
7
+ // Public License v. 2.0. If a copy of the MPL was not distributed
8
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ #ifndef IGL_MSH_LOADER_H
10
+ #define IGL_MSH_LOADER_H
11
+ #include "igl_inline.h"
12
+
13
+ #include <fstream>
14
+ #include <map>
15
+ #include <string>
16
+ #include <vector>
17
+ #include <algorithm>
18
+
19
+ namespace igl {
20
+
21
+ // Class for loading information from .msh file
22
+ // depends only on c++stl library
23
+ class MshLoader {
24
+ public:
25
+
26
+ struct msh_struct {
27
+ int tag,el_type;
28
+ msh_struct(int _tag=0,int _type=0):
29
+ tag(_tag),el_type(_type){}
30
+ bool operator== (const msh_struct& a) const {
31
+ return this->tag==a.tag &&
32
+ this->el_type==a.el_type;
33
+ }
34
+
35
+ bool operator< (const msh_struct& a) const {
36
+ return (this->tag*100+this->el_type) <
37
+ (a.tag*100+a.el_type);
38
+ }
39
+ };
40
+
41
+ typedef double Float;
42
+
43
+ typedef std::vector<int> IndexVector;
44
+ typedef std::vector<int> IntVector;
45
+ typedef std::vector<Float> FloatVector;
46
+ typedef std::vector<FloatVector> FloatField;
47
+ typedef std::vector<IntVector> IntField;
48
+ typedef std::vector<std::string> FieldNames;
49
+ typedef std::multimap<msh_struct,int> StructIndex;
50
+ typedef std::vector<msh_struct> StructVector;
51
+
52
+ enum {ELEMENT_LINE=1, ELEMENT_TRI=2, ELEMENT_QUAD=3,
53
+ ELEMENT_TET=4, ELEMENT_HEX=5, ELEMENT_PRISM=6,
54
+ ELEMENT_PYRAMID=7,
55
+ // 2nd order elements
56
+ ELEMENT_LINE_2ND_ORDER=8, ELEMENT_TRI_2ND_ORDER=9,
57
+ ELEMENT_QUAD_2ND_ORDER=10,ELEMENT_TET_2ND_ORDER=11,
58
+ ELEMENT_HEX_2ND_ORDER=12, ELEMENT_PRISM_2ND_ORDER=13,
59
+ ELEMENT_PYRAMID_2ND_ORDER=14,
60
+ // other elements
61
+ ELEMENT_POINT=15 };
62
+ public:
63
+ MshLoader(const std::string &filename);
64
+
65
+ public:
66
+
67
+ // get nodes , x,y,z sequentially
68
+ const FloatVector& get_nodes() const { return m_nodes; }
69
+ // get elements , identifying nodes that create an element
70
+ // variable length per element
71
+ const IndexVector& get_elements() const { return m_elements; }
72
+
73
+ // get element types
74
+ const IntVector& get_elements_types() const { return m_elements_types; }
75
+ // get element lengths
76
+ const IntVector& get_elements_lengths() const { return m_elements_lengths; }
77
+ // get element tags ( physical (0) and elementary (1) )
78
+ const IntField& get_elements_tags() const { return m_elements_tags; }
79
+ // get element IDs
80
+ const IntVector& get_elements_ids() const { return m_elements_ids; }
81
+
82
+ // get reverse index from node to element
83
+ const IndexVector& get_elements_nodes_idx() const { return m_elements_nodes_idx; }
84
+
85
+ // get fields assigned per node, all fields and components sequentially
86
+ const FloatField& get_node_fields() const { return m_node_fields;}
87
+ // get node field names,
88
+ const FieldNames& get_node_fields_names() const { return m_node_fields_names;}
89
+ // get number of node field components
90
+ const IntVector& get_node_fields_components() const {return m_node_fields_components;}
91
+
92
+ int get_node_field_components(size_t c) const
93
+ {
94
+ return m_node_fields_components[c];
95
+ }
96
+
97
+ // get fields assigned per element, all fields and components sequentially
98
+ const FloatField& get_element_fields() const { return m_element_fields;}
99
+ // get element field names
100
+ const FieldNames& get_element_fields_names() const { return m_element_fields_names;}
101
+ // get number of element field components
102
+ const IntVector& get_element_fields_components() const {return m_element_fields_components;}
103
+
104
+ int get_element_field_components(size_t c) const {
105
+ return m_element_fields_components[c];
106
+ }
107
+ // check if field is present at node level
108
+ bool is_node_field(const std::string& fieldname) const {
109
+ return (std::find(std::begin(m_node_fields_names),
110
+ std::end(m_node_fields_names),
111
+ fieldname) != std::end(m_node_fields_names) );
112
+ }
113
+ // check if field is present at element level
114
+ bool is_element_field(const std::string& fieldname) const {
115
+ return (std::find(std::begin(m_element_fields_names),
116
+ std::end(m_element_fields_names),
117
+ fieldname) != std::end(m_node_fields_names) );
118
+ }
119
+
120
+ // check if all elements have ids assigned sequentially
121
+ bool is_element_map_identity() const ;
122
+
123
+ // create tag index
124
+ // tag_column: ( physical (0) or elementary (1) ) specifying which tag to use
125
+ void index_structures(int tag_column);
126
+
127
+ // get tag index, call index_structure_tags first
128
+ const StructIndex& get_structure_index() const
129
+ {
130
+ return m_structure_index;
131
+ }
132
+
133
+ // get size of a structure identified by tag and element type
134
+ const StructIndex& get_structure_length() const
135
+ {
136
+ return m_structure_length;
137
+ }
138
+
139
+ //! get list of structures
140
+ const StructVector& get_structures() const
141
+ {
142
+ return m_structures;
143
+ }
144
+
145
+ public:
146
+ // helper function, calculate number of nodes associated with an element
147
+ static int num_nodes_per_elem_type(int elem_type);
148
+
149
+ private:
150
+ void parse_nodes(std::ifstream& fin);
151
+ void parse_elements(std::ifstream& fin);
152
+ void parse_node_field(std::ifstream& fin);
153
+ void parse_element_field(std::ifstream& fin);
154
+ void parse_unknown_field(std::ifstream& fin,
155
+ const std::string& fieldname);
156
+
157
+ private:
158
+ bool m_binary;
159
+ size_t m_data_size;
160
+
161
+ FloatVector m_nodes; // len x 3 vector
162
+
163
+ IndexVector m_elements; // linear array for nodes corresponding to each element
164
+ IndexVector m_elements_nodes_idx; // element indexes
165
+
166
+ IntVector m_elements_ids; // element id's
167
+ IntVector m_elements_types; // Element types
168
+ IntVector m_elements_lengths; // Element lengths
169
+ IntField m_elements_tags; // Element tags, currently 2xtags per element
170
+
171
+ FloatField m_node_fields; // Float field defined at each node
172
+ IntVector m_node_fields_components; // Number of components for node field
173
+ FieldNames m_node_fields_names; // Node field name
174
+
175
+ FloatField m_element_fields; // Float field defined at each element
176
+ IntVector m_element_fields_components; // Number of components for element field
177
+ FieldNames m_element_fields_names; // Element field name
178
+
179
+ StructIndex m_structure_index; // index tag ids
180
+ StructVector m_structures; // unique structures
181
+ StructIndex m_structure_length; // length of structures with consistent element type
182
+ };
183
+
184
+ } //igl
185
+
186
+ #ifndef IGL_STATIC_LIBRARY
187
+ # include "MshLoader.cpp"
188
+ #endif
189
+
190
+ #endif //IGL_MSH_LOADER_H
vendor/libigl/include/igl/MshSaver.cpp ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // based on MSH writer from PyMesh
2
+
3
+ // Copyright (c) 2015 Qingnan Zhou <qzhou@adobe.com>
4
+ // Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla
7
+ // Public License v. 2.0. If a copy of the MPL was not distributed
8
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
10
+ #include "MshSaver.h"
11
+
12
+ #include <cassert>
13
+ #include <iostream>
14
+ #include <sstream>
15
+ #include <exception>
16
+
17
+
18
+ IGL_INLINE igl::MshSaver::MshSaver(const std::string& filename, bool binary) :
19
+ m_binary(binary), m_num_nodes(0), m_num_elements(0) {
20
+ if (!m_binary) {
21
+ fout.open(filename.c_str(), std::fstream::out);
22
+ } else {
23
+ fout.open(filename.c_str(), std::fstream::binary);
24
+ }
25
+ if (!fout) {
26
+ std::stringstream err_msg;
27
+ err_msg << "Error opening " << filename << " to write msh file." << std::endl;
28
+ throw std::ios_base::failure(err_msg.str());
29
+ }
30
+ }
31
+
32
+ IGL_INLINE igl::MshSaver::~MshSaver() {
33
+ fout.close();
34
+ }
35
+
36
+ IGL_INLINE void igl::MshSaver::save_mesh(
37
+ const FloatVector& nodes,
38
+ const IndexVector& elements,
39
+ const IntVector& element_lengths,
40
+ const IntVector& element_types,
41
+ const IntVector& element_tags
42
+ ) {
43
+
44
+ save_header();
45
+
46
+ save_nodes(nodes);
47
+
48
+ save_elements(elements, element_lengths, element_types, element_tags );
49
+ }
50
+
51
+ IGL_INLINE void igl::MshSaver::save_header() {
52
+ if (!m_binary) {
53
+ fout << "$MeshFormat" << std::endl;
54
+ fout << "2.2 0 " << sizeof(double) << std::endl;
55
+ fout << "$EndMeshFormat" << std::endl;
56
+ fout.precision(17);
57
+ } else {
58
+ fout << "$MeshFormat" << std::endl;
59
+ fout << "2.2 1 " << sizeof(double) << std::endl;
60
+ int one = 1;
61
+ fout.write((char*)&one, sizeof(int));
62
+ fout << "\n$EndMeshFormat" << std::endl;
63
+ }
64
+ fout.flush();
65
+ }
66
+
67
+ IGL_INLINE void igl::MshSaver::save_nodes(const FloatVector& nodes) {
68
+ // Save nodes.
69
+ // 3D hadrcoded
70
+ m_num_nodes = nodes.size() / 3;
71
+ fout << "$Nodes" << std::endl;
72
+ fout << m_num_nodes << std::endl;
73
+ if (!m_binary) {
74
+ for (size_t i=0; i<nodes.size(); i+=3) {
75
+ //const VectorF& v = nodes.segment(i,m_dim);
76
+ int node_idx = i/3 + 1;
77
+ fout << node_idx << " " << nodes[i] << " " << nodes[i+1] << " " << nodes[i+2] << std::endl;
78
+ }
79
+ } else {
80
+ for (size_t i=0; i<nodes.size(); i+=3) {
81
+ //const VectorF& v = nodes.segment(i,m_dim);
82
+ int node_idx = i/3 + 1;
83
+ fout.write((const char*)&node_idx, sizeof(int));
84
+ fout.write((const char*)&nodes[i], sizeof(Float)*3);
85
+ }
86
+ }
87
+ fout << "$EndNodes" << std::endl;
88
+ fout.flush();
89
+ }
90
+
91
+ IGL_INLINE void igl::MshSaver::save_elements(const IndexVector& elements,
92
+ const IntVector& element_lengths,
93
+ const IntVector& element_types,
94
+ const IntVector& element_tags)
95
+ {
96
+
97
+ m_num_elements = element_tags.size();
98
+ assert(element_lengths.size() == element_types.size() );
99
+ assert(element_lengths.size() == element_tags.size() );
100
+ // TODO: sum up all lengths
101
+ // Save elements.
102
+ // node inxes are 1-based
103
+ fout << "$Elements" << std::endl;
104
+ fout << m_num_elements << std::endl;
105
+
106
+ if (m_num_elements > 0) {
107
+ //int elem_type = el_type;
108
+ int num_elems = m_num_elements;
109
+ //int tags = 0;
110
+ if (!m_binary) {
111
+ size_t el_ptr=0;
112
+ for (size_t i=0;i<m_num_elements;++i) {
113
+
114
+ int elem_num = (int) i + 1;
115
+ ///VectorI elem = elements.segment(i, nodes_per_element) + VectorI::Ones(nodes_per_element);
116
+ // hardcoded: duplicate tags (I don't know why)
117
+ fout << elem_num << " " << element_types[i] << " " << 2 << " "<< element_tags[i] << " "<< element_tags[i] << " ";
118
+ for (size_t j=0; j<element_lengths[i]; j++) {
119
+ fout << elements[el_ptr + j] + 1 << " ";
120
+ }
121
+ fout << std::endl;
122
+ el_ptr+=element_lengths[i];
123
+ }
124
+ } else {
125
+ size_t el_ptr=0,i=0;
126
+ while(i<m_num_elements) {
127
+
128
+ // write elements in consistent chunks
129
+ // TODO: refactor this code to be able to specify different elements
130
+ // more effeciently
131
+
132
+ int elem_type=-1;
133
+ int elem_len=-1;
134
+ size_t j=i;
135
+ for(;j<m_num_elements;++j)
136
+ {
137
+ if( elem_type==-1 )
138
+ {
139
+ elem_type=element_types[j];
140
+ elem_len=element_lengths[j];
141
+ } else if( elem_type!=element_types[j] ||
142
+ elem_len!=element_lengths[j]) {
143
+ break; // found the edge of the segment
144
+ }
145
+ }
146
+
147
+ //hardcoded: 2 tags
148
+ int num_elems=j-i, num_tags=2;
149
+
150
+ fout.write((const char*)& elem_type, sizeof(int));
151
+ fout.write((const char*)& num_elems, sizeof(int));
152
+ fout.write((const char*)& num_tags, sizeof(int));
153
+
154
+ for(int k=0;k<num_elems; ++k,++i){
155
+ int elem_num = (int )i + 1;
156
+ fout.write((const char*)&elem_num, sizeof(int));
157
+
158
+ // HACK: hardcoded 2 tags
159
+ fout.write((const char*)& element_tags[i], sizeof(int));
160
+ fout.write((const char*)& element_tags[i], sizeof(int));
161
+
162
+ for (size_t e=0; e<elem_len; e++) {
163
+ int _elem = static_cast<int>( elements[el_ptr + e] )+1;
164
+ fout.write((const char*)&_elem, sizeof(int));
165
+ }
166
+ el_ptr+=elem_len;
167
+ }
168
+ }
169
+ }
170
+ }
171
+ fout << "$EndElements" << std::endl;
172
+ fout.flush();
173
+ }
174
+
175
+ IGL_INLINE void igl::MshSaver::save_scalar_field(const std::string& fieldname, const FloatVector& field) {
176
+ assert(field.size() == m_num_nodes);
177
+ fout << "$NodeData" << std::endl;
178
+ fout << "1" << std::endl; // num string tags.
179
+ fout << "\"" << fieldname << "\"" << std::endl;
180
+ fout << "1" << std::endl; // num real tags.
181
+ fout << "0.0" << std::endl; // time value.
182
+ fout << "3" << std::endl; // num int tags.
183
+ fout << "0" << std::endl; // the time step
184
+ fout << "1" << std::endl; // 1-component scalar field.
185
+ fout << m_num_nodes << std::endl; // number of nodes
186
+
187
+ if (m_binary) {
188
+ for (size_t i=0; i<m_num_nodes; i++) {
189
+ int node_idx = i+1;
190
+ fout.write((char*)&node_idx, sizeof(int));
191
+ fout.write((char*)&field[i], sizeof(Float));
192
+ }
193
+ } else {
194
+ for (size_t i=0; i<m_num_nodes; i++) {
195
+ int node_idx = i+1;
196
+ fout << node_idx << " " << field[i] << std::endl;
197
+ }
198
+ }
199
+ fout << "$EndNodeData" << std::endl;
200
+ fout.flush();
201
+ }
202
+
203
+ IGL_INLINE void igl::MshSaver::save_vector_field(const std::string& fieldname, const FloatVector& field) {
204
+ assert(field.size() == 3 * m_num_nodes);
205
+
206
+ fout << "$NodeData" << std::endl;
207
+ fout << "1" << std::endl; // num string tags.
208
+ fout << "\"" << fieldname << "\"" << std::endl;
209
+ fout << "1" << std::endl; // num real tags.
210
+ fout << "0.0" << std::endl; // time value.
211
+ fout << "3" << std::endl; // num int tags.
212
+ fout << "0" << std::endl; // the time step
213
+ fout << "3" << std::endl; // 3-component vector field.
214
+ fout << m_num_nodes << std::endl; // number of nodes
215
+
216
+ const Float zero = 0.0;
217
+ if (m_binary) {
218
+ for (size_t i=0; i<m_num_nodes; i++) {
219
+ int node_idx = i+1;
220
+ fout.write((const char*)&node_idx, sizeof(int));
221
+ fout.write((const char*)&field[i*3], sizeof(Float)*3);
222
+ }
223
+ } else {
224
+ for (size_t i=0; i<m_num_nodes; i++) {
225
+ int node_idx = i+1;
226
+ fout << node_idx
227
+ << " " << field[i*3]
228
+ << " " << field[i*3+1]
229
+ << " " << field[i*3+2]
230
+ << std::endl;
231
+ }
232
+ }
233
+ fout << "$EndNodeData" << std::endl;
234
+ fout.flush();
235
+ }
236
+
237
+ IGL_INLINE void igl::MshSaver::save_elem_scalar_field(const std::string& fieldname, const FloatVector& field) {
238
+ assert(field.size() == m_num_elements);
239
+ fout << "$ElementData" << std::endl;
240
+ fout << 1 << std::endl; // num string tags.
241
+ fout << "\"" << fieldname << "\"" << std::endl;
242
+ fout << "1" << std::endl; // num real tags.
243
+ fout << "0.0" << std::endl; // time value.
244
+ fout << "3" << std::endl; // num int tags.
245
+ fout << "0" << std::endl; // the time step
246
+ fout << "1" << std::endl; // 1-component scalar field.
247
+ fout << m_num_elements << std::endl; // number of elements
248
+
249
+ if (m_binary) {
250
+ for (size_t i=0; i<m_num_elements; i++) {
251
+ int elem_idx = i+1;
252
+ fout.write((const char*)&elem_idx, sizeof(int));
253
+ fout.write((const char*)&field[i], sizeof(Float));
254
+ }
255
+ } else {
256
+ for (size_t i=0; i<m_num_elements; i++) {
257
+ int elem_idx = i+1;
258
+ fout << elem_idx << " " << field[i] << std::endl;
259
+ }
260
+ }
261
+
262
+ fout << "$EndElementData" << std::endl;
263
+ fout.flush();
264
+ }
265
+
266
+ IGL_INLINE void igl::MshSaver::save_elem_vector_field(const std::string& fieldname, const FloatVector& field) {
267
+ assert(field.size() == m_num_elements * 3);
268
+ fout << "$ElementData" << std::endl;
269
+ fout << 1 << std::endl; // num string tags.
270
+ fout << "\"" << fieldname << "\"" << std::endl;
271
+ fout << "1" << std::endl; // num real tags.
272
+ fout << "0.0" << std::endl; // time value.
273
+ fout << "3" << std::endl; // num int tags.
274
+ fout << "0" << std::endl; // the time step
275
+ fout << "3" << std::endl; // 3-component vector field.
276
+ fout << m_num_elements << std::endl; // number of elements
277
+
278
+ const Float zero = 0.0;
279
+ if (m_binary) {
280
+ for (size_t i=0; i<m_num_elements; ++i) {
281
+ int elem_idx = i+1;
282
+ fout.write((const char*)&elem_idx, sizeof(int));
283
+ fout.write((const char*)&field[i*3], sizeof(Float) * 3);
284
+ }
285
+ } else {
286
+ for (size_t i=0; i<m_num_elements; ++i) {
287
+ int elem_idx = i+1;
288
+ fout << elem_idx
289
+ << " " << field[i*3]
290
+ << " " << field[i*3+1]
291
+ << " " << field[i*3+2]
292
+ << std::endl;
293
+ }
294
+ }
295
+
296
+ fout << "$EndElementData" << std::endl;
297
+ fout.flush();
298
+ }
299
+
300
+
301
+ IGL_INLINE void igl::MshSaver::save_elem_tensor_field(const std::string& fieldname, const FloatVector& field) {
302
+ assert(field.size() == m_num_elements * 3 * (3 + 1) / 2);
303
+ fout << "$ElementData" << std::endl;
304
+ fout << 1 << std::endl; // num string tags.
305
+ fout << "\"" << fieldname << "\"" << std::endl;
306
+ fout << "1" << std::endl; // num real tags.
307
+ fout << "0.0" << std::endl; // time value.
308
+ fout << "3" << std::endl; // num int tags.
309
+ fout << "0" << std::endl; // the time step
310
+ fout << "9" << std::endl; // 9-component tensor field.
311
+ fout << m_num_elements << std::endl; // number of elements
312
+
313
+ const Float zero = 0.0;
314
+
315
+ if (m_binary) {
316
+ for (size_t i=0; i<m_num_elements; i++) {
317
+ int elem_idx = i+1;
318
+ fout.write((char*)&elem_idx, sizeof(int));
319
+ //const VectorF& val = field.segment(i*6, 6);
320
+ const Float* val = &field[i*6];
321
+ Float tensor[9] = {
322
+ val[0], val[5], val[4],
323
+ val[5], val[1], val[3],
324
+ val[4], val[3], val[2] };
325
+ fout.write((char*)tensor, sizeof(Float) * 9);
326
+ }
327
+ } else {
328
+ for (size_t i=0; i<m_num_elements; i++) {
329
+ int elem_idx = i+1;
330
+ const Float* val = &field[i*6];
331
+ fout << elem_idx
332
+ << " " << val[0]
333
+ << " " << val[5]
334
+ << " " << val[4]
335
+ << " " << val[5]
336
+ << " " << val[1]
337
+ << " " << val[3]
338
+ << " " << val[4]
339
+ << " " << val[3]
340
+ << " " << val[2]
341
+ << std::endl;
342
+ }
343
+ }
344
+
345
+ fout << "$EndElementData" << std::endl;
346
+ fout.flush();
347
+ }
vendor/libigl/include/igl/NormalType.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_NORMALTYPE_H
9
+ #define IGL_NORMALTYPE_H
10
+
11
+ namespace igl
12
+ {
13
+ // PER_VERTEX_NORMALS Normals computed per vertex based on incident faces
14
+ // PER_FACE_NORMALS Normals computed per face
15
+ // PER_CORNER_NORMALS Normals computed per corner (aka wedge) based on
16
+ // incident faces without sharp edge
17
+ enum NormalType
18
+ {
19
+ PER_VERTEX_NORMALS,
20
+ PER_FACE_NORMALS,
21
+ PER_CORNER_NORMALS
22
+ };
23
+ # define NUM_NORMAL_TYPE 3
24
+ }
25
+
26
+ #endif
27
+
vendor/libigl/include/igl/ONE.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ONE_H
9
+ #define IGL_ONE_H
10
+ namespace igl
11
+ {
12
+ // Often one needs a reference to a dummy variable containing one as its
13
+ // value, for example when using AntTweakBar's
14
+ // TwSetParam( "3D View", "opened", TW_PARAM_INT32, 1, &INT_ONE);
15
+ const char CHAR_ONE = 1;
16
+ const int INT_ONE = 1;
17
+ const unsigned int UNSIGNED_INT_ONE = 1;
18
+ const double DOUBLE_ONE = 1;
19
+ const float FLOAT_ONE = 1;
20
+ }
21
+ #endif
22
+
vendor/libigl/include/igl/PI.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_PI_H
9
+ #define IGL_PI_H
10
+ namespace igl
11
+ {
12
+ // Use standard mathematical constants' M_PI if available
13
+ #ifdef M_PI
14
+ constexpr double PI = M_PI;
15
+ #else
16
+ constexpr double PI = 3.1415926535897932384626433832795;
17
+ #endif
18
+ }
19
+ #endif
vendor/libigl/include/igl/REDRUM.h ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_REDRUM_H
9
+ #define IGL_REDRUM_H
10
+
11
+ // Q: These should probably be inside the igl namespace. What's the correct
12
+ // way to do that?
13
+ // A: I guess the right way is to not use a macro but a proper function with
14
+ // streams as input and output.
15
+
16
+ // ANSI color codes for formatting iostream style output
17
+
18
+ #ifdef IGL_REDRUM_NOOP
19
+
20
+ // Bold Red, etc.
21
+ #define NORUM(X) X
22
+ #define REDRUM(X) X
23
+ #define GREENRUM(X) X
24
+ #define YELLOWRUM(X) X
25
+ #define BLUERUM(X) X
26
+ #define MAGENTARUM(X) X
27
+ #define CYANRUM(X) X
28
+ // Regular Red, etc.
29
+ #define REDGIN(X) X
30
+ #define GREENGIN(X) X
31
+ #define YELLOWGIN(X) X
32
+ #define BLUEGIN(X) X
33
+ #define MAGENTAGIN(X) X
34
+ #define CYANGIN(X) X
35
+
36
+ #else
37
+
38
+ // Bold Red, etc.
39
+ #define NORUM(X) ""<<X<<""
40
+ #define REDRUM(X) "\e[1m\e[31m"<<X<<"\e[m"
41
+ #define GREENRUM(X) "\e[1m\e[32m"<<X<<"\e[m"
42
+ #define YELLOWRUM(X) "\e[1m\e[33m"<<X<<"\e[m"
43
+ #define BLUERUM(X) "\e[1m\e[34m"<<X<<"\e[m"
44
+ #define MAGENTARUM(X) "\e[1m\e[35m"<<X<<"\e[m"
45
+ #define CYANRUM(X) "\e[1m\e[36m"<<X<<"\e[m"
46
+ // Regular Red, etc.
47
+ #define REDGIN(X) "\e[31m"<<X<<"\e[m"
48
+ #define GREENGIN(X) "\e[32m"<<X<<"\e[m"
49
+ #define YELLOWGIN(X) "\e[33m"<<X<<"\e[m"
50
+ #define BLUEGIN(X) "\e[34m"<<X<<"\e[m"
51
+ #define MAGENTAGIN(X) "\e[35m"<<X<<"\e[m"
52
+ #define CYANGIN(X) "\e[36m"<<X<<"\e[m"
53
+ #endif
54
+
55
+ #endif
vendor/libigl/include/igl/STR.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_STR_H
9
+ #define IGL_STR_H
10
+ // http://stackoverflow.com/a/2433143/148668
11
+ #include <string>
12
+ #include <sstream>
13
+ // Suppose you have a function:
14
+ // void func(std::string c);
15
+ // Then you can write:
16
+ // func(STR("foo"<<1<<"bar"));
17
+ #define STR(X) static_cast<std::ostringstream&>(std::ostringstream().flush() << X).str()
18
+ #endif
vendor/libigl/include/igl/Singular_Value_Decomposition_Givens_QR_Factorization_Kernel.hpp ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#####################################################################
2
+ // Copyright (c) 2010-2011, Eftychios Sifakis.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+ // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
7
+ // other materials provided with the distribution.
8
+ //
9
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
10
+ // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
11
+ // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
12
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
13
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
14
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ //#####################################################################
16
+
17
+ //###########################################################
18
+ // Compute the Givens half-angle, construct the Givens quaternion and the rotation sine/cosine (for the full angle)
19
+ //###########################################################
20
+
21
+ #ifdef _WIN32
22
+ #undef max
23
+ #undef min
24
+ #endif
25
+
26
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.f=SANPIVOT.f*SANPIVOT.f;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_mul_ps(VANPIVOT,VANPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_mul_ps(VANPIVOT,VANPIVOT);)
27
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=(Ssh.f>=Ssmall_number.f)?0xffffffff:0;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_cmpge_ps(Vsh,Vsmall_number);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_cmp_ps(Vsh,Vsmall_number, _CMP_GE_OS);) //ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_cmpge_ps(Vsh,Vsmall_number);)
28
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Ssh.ui&SANPIVOT.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_and_ps(Vsh,VANPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_and_ps(Vsh,VANPIVOT);)
29
+
30
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp5.f=0.;) ENABLE_SSE_IMPLEMENTATION(Vtmp5=_mm_xor_ps(Vtmp5,Vtmp5);) ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_xor_ps(Vtmp5,Vtmp5);)
31
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Stmp5.f-SAPIVOT.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_sub_ps(Vtmp5,VAPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_sub_ps(Vtmp5,VAPIVOT);)
32
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.f=std::max(Sch.f,SAPIVOT.f);) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_max_ps(Vch,VAPIVOT);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_max_ps(Vch,VAPIVOT);)
33
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.f=std::max(Sch.f,Ssmall_number.f);) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_max_ps(Vch,Vsmall_number);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_max_ps(Vch,Vsmall_number);)
34
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp5.ui=(SAPIVOT.f>=Stmp5.f)?0xffffffff:0;) ENABLE_SSE_IMPLEMENTATION(Vtmp5=_mm_cmpge_ps(VAPIVOT,Vtmp5);) ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_cmp_ps(VAPIVOT,Vtmp5, _CMP_GE_OS);) //ENABLE_AVX_IMPLEMENTATION(Vtmp5=_mm256_cmpge_ps(VAPIVOT,Vtmp5);)
35
+
36
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vch,Vch);)
37
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vsh,Vsh);)
38
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Stmp1.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_add_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_add_ps(Vtmp1,Vtmp2);)
39
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=rsqrt(Stmp2.f);) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_rsqrt_ps(Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_rsqrt_ps(Vtmp2);)
40
+
41
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp4.f=Stmp1.f*Sone_half.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp4=_mm_mul_ps(Vtmp1,Vone_half);) ENABLE_AVX_IMPLEMENTATION(Vtmp4=_mm256_mul_ps(Vtmp1,Vone_half);)
42
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp4);)
43
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp3);)
44
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp2.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp2,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp2,Vtmp3);)
45
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f+Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_add_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_add_ps(Vtmp1,Vtmp4);)
46
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f-Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_sub_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_sub_ps(Vtmp1,Vtmp3);)
47
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f*Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vtmp1,Vtmp2);)
48
+
49
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Sch.f+Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_add_ps(Vch,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_add_ps(Vch,Vtmp1);)
50
+
51
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.ui=~Stmp5.ui&Ssh.ui;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_andnot_ps(Vtmp5,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=Vch;)
52
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.ui=~Stmp5.ui&Sch.ui;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_andnot_ps(Vtmp5,Vch);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_blendv_ps(Vsh,Vch,Vtmp5);)
53
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.ui=Stmp5.ui&Sch.ui;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_and_ps(Vtmp5,Vch);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_blendv_ps(Vtmp1,Vsh,Vtmp5);)
54
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Stmp5.ui&Ssh.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_and_ps(Vtmp5,Vsh);)
55
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.ui=Sch.ui|Stmp1.ui;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_or_ps(Vch,Vtmp1);)
56
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.ui=Ssh.ui|Stmp2.ui;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_or_ps(Vsh,Vtmp2);)
57
+
58
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vch,Vch);)
59
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vsh,Vsh);)
60
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Stmp1.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_add_ps(Vtmp1,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_add_ps(Vtmp1,Vtmp2);)
61
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=rsqrt(Stmp2.f);) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_rsqrt_ps(Vtmp2);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_rsqrt_ps(Vtmp2);)
62
+
63
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp4.f=Stmp1.f*Sone_half.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp4=_mm_mul_ps(Vtmp1,Vone_half);) ENABLE_AVX_IMPLEMENTATION(Vtmp4=_mm256_mul_ps(Vtmp1,Vone_half);)
64
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp4);)
65
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp1.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp1,Vtmp3);)
66
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp3.f=Stmp2.f*Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp3=_mm_mul_ps(Vtmp2,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp3=_mm256_mul_ps(Vtmp2,Vtmp3);)
67
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f+Stmp4.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_add_ps(Vtmp1,Vtmp4);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_add_ps(Vtmp1,Vtmp4);)
68
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Stmp1.f-Stmp3.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_sub_ps(Vtmp1,Vtmp3);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_sub_ps(Vtmp1,Vtmp3);)
69
+
70
+ ENABLE_SCALAR_IMPLEMENTATION(Sch.f=Sch.f*Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vch=_mm_mul_ps(Vch,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vch=_mm256_mul_ps(Vch,Vtmp1);)
71
+ ENABLE_SCALAR_IMPLEMENTATION(Ssh.f=Ssh.f*Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(Vsh=_mm_mul_ps(Vsh,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(Vsh=_mm256_mul_ps(Vsh,Vtmp1);)
72
+
73
+ ENABLE_SCALAR_IMPLEMENTATION(Sc.f=Sch.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vc=_mm_mul_ps(Vch,Vch);) ENABLE_AVX_IMPLEMENTATION(Vc=_mm256_mul_ps(Vch,Vch);)ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ssh.f*Ssh.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_mul_ps(Vsh,Vsh);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_mul_ps(Vsh,Vsh);)
74
+ ENABLE_SCALAR_IMPLEMENTATION(Sc.f=Sc.f-Ss.f;) ENABLE_SSE_IMPLEMENTATION(Vc=_mm_sub_ps(Vc,Vs);) ENABLE_AVX_IMPLEMENTATION(Vc=_mm256_sub_ps(Vc,Vs);)
75
+ ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ssh.f*Sch.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_mul_ps(Vsh,Vch);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_mul_ps(Vsh,Vch);)
76
+ ENABLE_SCALAR_IMPLEMENTATION(Ss.f=Ss.f+Ss.f;) ENABLE_SSE_IMPLEMENTATION(Vs=_mm_add_ps(Vs,Vs);) ENABLE_AVX_IMPLEMENTATION(Vs=_mm256_add_ps(Vs,Vs);)
77
+
78
+ //###########################################################
79
+ // Rotate matrix A
80
+ //###########################################################
81
+
82
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA11.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA11);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA11);)
83
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA21);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA21);)
84
+ ENABLE_SCALAR_IMPLEMENTATION(SA11.f=Sc.f*SA11.f;) ENABLE_SSE_IMPLEMENTATION(VA11=_mm_mul_ps(Vc,VA11);) ENABLE_AVX_IMPLEMENTATION(VA11=_mm256_mul_ps(Vc,VA11);)
85
+ ENABLE_SCALAR_IMPLEMENTATION(SA21.f=Sc.f*SA21.f;) ENABLE_SSE_IMPLEMENTATION(VA21=_mm_mul_ps(Vc,VA21);) ENABLE_AVX_IMPLEMENTATION(VA21=_mm256_mul_ps(Vc,VA21);)
86
+ ENABLE_SCALAR_IMPLEMENTATION(SA11.f=SA11.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA11=_mm_add_ps(VA11,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA11=_mm256_add_ps(VA11,Vtmp2);)
87
+ ENABLE_SCALAR_IMPLEMENTATION(SA21.f=SA21.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA21=_mm_sub_ps(VA21,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA21=_mm256_sub_ps(VA21,Vtmp1);)
88
+
89
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA12.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA12);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA12);)
90
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA22);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA22);)
91
+ ENABLE_SCALAR_IMPLEMENTATION(SA12.f=Sc.f*SA12.f;) ENABLE_SSE_IMPLEMENTATION(VA12=_mm_mul_ps(Vc,VA12);) ENABLE_AVX_IMPLEMENTATION(VA12=_mm256_mul_ps(Vc,VA12);)
92
+ ENABLE_SCALAR_IMPLEMENTATION(SA22.f=Sc.f*SA22.f;) ENABLE_SSE_IMPLEMENTATION(VA22=_mm_mul_ps(Vc,VA22);) ENABLE_AVX_IMPLEMENTATION(VA22=_mm256_mul_ps(Vc,VA22);)
93
+ ENABLE_SCALAR_IMPLEMENTATION(SA12.f=SA12.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA12=_mm_add_ps(VA12,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA12=_mm256_add_ps(VA12,Vtmp2);)
94
+ ENABLE_SCALAR_IMPLEMENTATION(SA22.f=SA22.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA22=_mm_sub_ps(VA22,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA22=_mm256_sub_ps(VA22,Vtmp1);)
95
+
96
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SA13.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VA13);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VA13);)
97
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SA23.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VA23);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VA23);)
98
+ ENABLE_SCALAR_IMPLEMENTATION(SA13.f=Sc.f*SA13.f;) ENABLE_SSE_IMPLEMENTATION(VA13=_mm_mul_ps(Vc,VA13);) ENABLE_AVX_IMPLEMENTATION(VA13=_mm256_mul_ps(Vc,VA13);)
99
+ ENABLE_SCALAR_IMPLEMENTATION(SA23.f=Sc.f*SA23.f;) ENABLE_SSE_IMPLEMENTATION(VA23=_mm_mul_ps(Vc,VA23);) ENABLE_AVX_IMPLEMENTATION(VA23=_mm256_mul_ps(Vc,VA23);)
100
+ ENABLE_SCALAR_IMPLEMENTATION(SA13.f=SA13.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VA13=_mm_add_ps(VA13,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VA13=_mm256_add_ps(VA13,Vtmp2);)
101
+ ENABLE_SCALAR_IMPLEMENTATION(SA23.f=SA23.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VA23=_mm_sub_ps(VA23,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VA23=_mm256_sub_ps(VA23,Vtmp1);)
102
+
103
+ //###########################################################
104
+ // Update matrix U
105
+ //###########################################################
106
+
107
+ #ifdef COMPUTE_U_AS_MATRIX
108
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU11.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU11);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU11);)
109
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU12.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU12);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU12);)
110
+ ENABLE_SCALAR_IMPLEMENTATION(SU11.f=Sc.f*SU11.f;) ENABLE_SSE_IMPLEMENTATION(VU11=_mm_mul_ps(Vc,VU11);) ENABLE_AVX_IMPLEMENTATION(VU11=_mm256_mul_ps(Vc,VU11);)
111
+ ENABLE_SCALAR_IMPLEMENTATION(SU12.f=Sc.f*SU12.f;) ENABLE_SSE_IMPLEMENTATION(VU12=_mm_mul_ps(Vc,VU12);) ENABLE_AVX_IMPLEMENTATION(VU12=_mm256_mul_ps(Vc,VU12);)
112
+ ENABLE_SCALAR_IMPLEMENTATION(SU11.f=SU11.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU11=_mm_add_ps(VU11,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU11=_mm256_add_ps(VU11,Vtmp2);)
113
+ ENABLE_SCALAR_IMPLEMENTATION(SU12.f=SU12.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU12=_mm_sub_ps(VU12,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU12=_mm256_sub_ps(VU12,Vtmp1);)
114
+
115
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU21.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU21);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU21);)
116
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU22.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU22);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU22);)
117
+ ENABLE_SCALAR_IMPLEMENTATION(SU21.f=Sc.f*SU21.f;) ENABLE_SSE_IMPLEMENTATION(VU21=_mm_mul_ps(Vc,VU21);) ENABLE_AVX_IMPLEMENTATION(VU21=_mm256_mul_ps(Vc,VU21);)
118
+ ENABLE_SCALAR_IMPLEMENTATION(SU22.f=Sc.f*SU22.f;) ENABLE_SSE_IMPLEMENTATION(VU22=_mm_mul_ps(Vc,VU22);) ENABLE_AVX_IMPLEMENTATION(VU22=_mm256_mul_ps(Vc,VU22);)
119
+ ENABLE_SCALAR_IMPLEMENTATION(SU21.f=SU21.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU21=_mm_add_ps(VU21,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU21=_mm256_add_ps(VU21,Vtmp2);)
120
+ ENABLE_SCALAR_IMPLEMENTATION(SU22.f=SU22.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU22=_mm_sub_ps(VU22,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU22=_mm256_sub_ps(VU22,Vtmp1);)
121
+
122
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp1.f=Ss.f*SU31.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp1=_mm_mul_ps(Vs,VU31);) ENABLE_AVX_IMPLEMENTATION(Vtmp1=_mm256_mul_ps(Vs,VU31);)
123
+ ENABLE_SCALAR_IMPLEMENTATION(Stmp2.f=Ss.f*SU32.f;) ENABLE_SSE_IMPLEMENTATION(Vtmp2=_mm_mul_ps(Vs,VU32);) ENABLE_AVX_IMPLEMENTATION(Vtmp2=_mm256_mul_ps(Vs,VU32);)
124
+ ENABLE_SCALAR_IMPLEMENTATION(SU31.f=Sc.f*SU31.f;) ENABLE_SSE_IMPLEMENTATION(VU31=_mm_mul_ps(Vc,VU31);) ENABLE_AVX_IMPLEMENTATION(VU31=_mm256_mul_ps(Vc,VU31);)
125
+ ENABLE_SCALAR_IMPLEMENTATION(SU32.f=Sc.f*SU32.f;) ENABLE_SSE_IMPLEMENTATION(VU32=_mm_mul_ps(Vc,VU32);) ENABLE_AVX_IMPLEMENTATION(VU32=_mm256_mul_ps(Vc,VU32);)
126
+ ENABLE_SCALAR_IMPLEMENTATION(SU31.f=SU31.f+Stmp2.f;) ENABLE_SSE_IMPLEMENTATION(VU31=_mm_add_ps(VU31,Vtmp2);) ENABLE_AVX_IMPLEMENTATION(VU31=_mm256_add_ps(VU31,Vtmp2);)
127
+ ENABLE_SCALAR_IMPLEMENTATION(SU32.f=SU32.f-Stmp1.f;) ENABLE_SSE_IMPLEMENTATION(VU32=_mm_sub_ps(VU32,Vtmp1);) ENABLE_AVX_IMPLEMENTATION(VU32=_mm256_sub_ps(VU32,Vtmp1);)
128
+ #endif
vendor/libigl/include/igl/Singular_Value_Decomposition_Kernel_Declarations.hpp ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#####################################################################
2
+ // Copyright (c) 2010-2011, Eftychios Sifakis.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+ // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
7
+ // other materials provided with the distribution.
8
+ //
9
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
10
+ // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
11
+ // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
12
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
13
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
14
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ //#####################################################################
16
+
17
+ //###########################################################
18
+ // Local variable declarations
19
+ //###########################################################
20
+
21
+ #ifdef PRINT_DEBUGGING_OUTPUT
22
+
23
+ #ifdef USE_SSE_IMPLEMENTATION
24
+ float buf[4];
25
+ float A11,A21,A31,A12,A22,A32,A13,A23,A33;
26
+ float S11,S21,S31,S22,S32,S33;
27
+ #ifdef COMPUTE_V_AS_QUATERNION
28
+ float QVS,QVVX,QVVY,QVVZ;
29
+ #endif
30
+ #ifdef COMPUTE_V_AS_MATRIX
31
+ float V11,V21,V31,V12,V22,V32,V13,V23,V33;
32
+ #endif
33
+ #ifdef COMPUTE_U_AS_QUATERNION
34
+ float QUS,QUVX,QUVY,QUVZ;
35
+ #endif
36
+ #ifdef COMPUTE_U_AS_MATRIX
37
+ float U11,U21,U31,U12,U22,U32,U13,U23,U33;
38
+ #endif
39
+ #endif
40
+
41
+ #ifdef USE_AVX_IMPLEMENTATION
42
+ float buf[8];
43
+ float A11,A21,A31,A12,A22,A32,A13,A23,A33;
44
+ float S11,S21,S31,S22,S32,S33;
45
+ #ifdef COMPUTE_V_AS_QUATERNION
46
+ float QVS,QVVX,QVVY,QVVZ;
47
+ #endif
48
+ #ifdef COMPUTE_V_AS_MATRIX
49
+ float V11,V21,V31,V12,V22,V32,V13,V23,V33;
50
+ #endif
51
+ #ifdef COMPUTE_U_AS_QUATERNION
52
+ float QUS,QUVX,QUVY,QUVZ;
53
+ #endif
54
+ #ifdef COMPUTE_U_AS_MATRIX
55
+ float U11,U21,U31,U12,U22,U32,U13,U23,U33;
56
+ #endif
57
+ #endif
58
+
59
+ #endif
60
+
61
+ const float Four_Gamma_Squared=sqrt(8.)+3.;
62
+ const float Sine_Pi_Over_Eight=.5*sqrt(2.-sqrt(2.));
63
+ const float Cosine_Pi_Over_Eight=.5*sqrt(2.+sqrt(2.));
64
+
65
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sfour_gamma_squared;) ENABLE_SSE_IMPLEMENTATION(__m128 Vfour_gamma_squared;) ENABLE_AVX_IMPLEMENTATION(__m256 Vfour_gamma_squared;)
66
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssine_pi_over_eight;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsine_pi_over_eight;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsine_pi_over_eight;)
67
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Scosine_pi_over_eight;) ENABLE_SSE_IMPLEMENTATION(__m128 Vcosine_pi_over_eight;) ENABLE_AVX_IMPLEMENTATION(__m256 Vcosine_pi_over_eight;)
68
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sone_half;) ENABLE_SSE_IMPLEMENTATION(__m128 Vone_half;) ENABLE_AVX_IMPLEMENTATION(__m256 Vone_half;)
69
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sone;) ENABLE_SSE_IMPLEMENTATION(__m128 Vone;) ENABLE_AVX_IMPLEMENTATION(__m256 Vone;)
70
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stiny_number;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtiny_number;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtiny_number;)
71
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssmall_number;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsmall_number;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsmall_number;)
72
+
73
+ ENABLE_SCALAR_IMPLEMENTATION(Sfour_gamma_squared.f=Four_Gamma_Squared;) ENABLE_SSE_IMPLEMENTATION(Vfour_gamma_squared=_mm_set1_ps(Four_Gamma_Squared);) ENABLE_AVX_IMPLEMENTATION(Vfour_gamma_squared=_mm256_set1_ps(Four_Gamma_Squared);)
74
+ ENABLE_SCALAR_IMPLEMENTATION(Ssine_pi_over_eight.f=Sine_Pi_Over_Eight;) ENABLE_SSE_IMPLEMENTATION(Vsine_pi_over_eight=_mm_set1_ps(Sine_Pi_Over_Eight);) ENABLE_AVX_IMPLEMENTATION(Vsine_pi_over_eight=_mm256_set1_ps(Sine_Pi_Over_Eight);)
75
+ ENABLE_SCALAR_IMPLEMENTATION(Scosine_pi_over_eight.f=Cosine_Pi_Over_Eight;) ENABLE_SSE_IMPLEMENTATION(Vcosine_pi_over_eight=_mm_set1_ps(Cosine_Pi_Over_Eight);) ENABLE_AVX_IMPLEMENTATION(Vcosine_pi_over_eight=_mm256_set1_ps(Cosine_Pi_Over_Eight);)
76
+ ENABLE_SCALAR_IMPLEMENTATION(Sone_half.f=.5;) ENABLE_SSE_IMPLEMENTATION(Vone_half=_mm_set1_ps(.5);) ENABLE_AVX_IMPLEMENTATION(Vone_half=_mm256_set1_ps(.5);)
77
+ ENABLE_SCALAR_IMPLEMENTATION(Sone.f=1.;) ENABLE_SSE_IMPLEMENTATION(Vone=_mm_set1_ps(1.);) ENABLE_AVX_IMPLEMENTATION(Vone=_mm256_set1_ps(1.);)
78
+ ENABLE_SCALAR_IMPLEMENTATION(Stiny_number.f=1.e-20;) ENABLE_SSE_IMPLEMENTATION(Vtiny_number=_mm_set1_ps(1.e-20);) ENABLE_AVX_IMPLEMENTATION(Vtiny_number=_mm256_set1_ps(1.e-20);)
79
+ ENABLE_SCALAR_IMPLEMENTATION(Ssmall_number.f=1.e-12;) ENABLE_SSE_IMPLEMENTATION(Vsmall_number=_mm_set1_ps(1.e-12);) ENABLE_AVX_IMPLEMENTATION(Vsmall_number=_mm256_set1_ps(1.e-12);)
80
+
81
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa11;) ENABLE_SSE_IMPLEMENTATION(__m128 Va11;) ENABLE_AVX_IMPLEMENTATION(__m256 Va11;)
82
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa21;) ENABLE_SSE_IMPLEMENTATION(__m128 Va21;) ENABLE_AVX_IMPLEMENTATION(__m256 Va21;)
83
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa31;) ENABLE_SSE_IMPLEMENTATION(__m128 Va31;) ENABLE_AVX_IMPLEMENTATION(__m256 Va31;)
84
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa12;) ENABLE_SSE_IMPLEMENTATION(__m128 Va12;) ENABLE_AVX_IMPLEMENTATION(__m256 Va12;)
85
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa22;) ENABLE_SSE_IMPLEMENTATION(__m128 Va22;) ENABLE_AVX_IMPLEMENTATION(__m256 Va22;)
86
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa32;) ENABLE_SSE_IMPLEMENTATION(__m128 Va32;) ENABLE_AVX_IMPLEMENTATION(__m256 Va32;)
87
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa13;) ENABLE_SSE_IMPLEMENTATION(__m128 Va13;) ENABLE_AVX_IMPLEMENTATION(__m256 Va13;)
88
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa23;) ENABLE_SSE_IMPLEMENTATION(__m128 Va23;) ENABLE_AVX_IMPLEMENTATION(__m256 Va23;)
89
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sa33;) ENABLE_SSE_IMPLEMENTATION(__m128 Va33;) ENABLE_AVX_IMPLEMENTATION(__m256 Va33;)
90
+
91
+ #ifdef COMPUTE_V_AS_MATRIX
92
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv11;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv11;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv11;)
93
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv21;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv21;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv21;)
94
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv31;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv31;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv31;)
95
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv12;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv12;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv12;)
96
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv22;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv22;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv22;)
97
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv32;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv32;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv32;)
98
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv13;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv13;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv13;)
99
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv23;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv23;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv23;)
100
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sv33;) ENABLE_SSE_IMPLEMENTATION(__m128 Vv33;) ENABLE_AVX_IMPLEMENTATION(__m256 Vv33;)
101
+ #endif
102
+
103
+ #ifdef COMPUTE_V_AS_QUATERNION
104
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvs;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvs;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvs;)
105
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvx;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvx;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvx;)
106
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvy;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvy;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvy;)
107
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sqvvz;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqvvz;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqvvz;)
108
+ #endif
109
+
110
+ #ifdef COMPUTE_U_AS_MATRIX
111
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su11;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu11;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu11;)
112
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su21;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu21;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu21;)
113
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su31;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu31;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu31;)
114
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su12;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu12;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu12;)
115
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su22;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu22;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu22;)
116
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su32;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu32;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu32;)
117
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su13;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu13;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu13;)
118
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su23;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu23;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu23;)
119
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Su33;) ENABLE_SSE_IMPLEMENTATION(__m128 Vu33;) ENABLE_AVX_IMPLEMENTATION(__m256 Vu33;)
120
+ #endif
121
+
122
+ #ifdef COMPUTE_U_AS_QUATERNION
123
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squs;) ENABLE_SSE_IMPLEMENTATION(__m128 Vqus;) ENABLE_AVX_IMPLEMENTATION(__m256 Vqus;)
124
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvx;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvx;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvx;)
125
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvy;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvy;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvy;)
126
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Squvz;) ENABLE_SSE_IMPLEMENTATION(__m128 Vquvz;) ENABLE_AVX_IMPLEMENTATION(__m256 Vquvz;)
127
+ #endif
128
+
129
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sc;) ENABLE_SSE_IMPLEMENTATION(__m128 Vc;) ENABLE_AVX_IMPLEMENTATION(__m256 Vc;)
130
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ss;) ENABLE_SSE_IMPLEMENTATION(__m128 Vs;) ENABLE_AVX_IMPLEMENTATION(__m256 Vs;)
131
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Sch;) ENABLE_SSE_IMPLEMENTATION(__m128 Vch;) ENABLE_AVX_IMPLEMENTATION(__m256 Vch;)
132
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Ssh;) ENABLE_SSE_IMPLEMENTATION(__m128 Vsh;) ENABLE_AVX_IMPLEMENTATION(__m256 Vsh;)
133
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp1;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp1;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp1;)
134
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp2;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp2;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp2;)
135
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp3;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp3;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp3;)
136
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp4;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp4;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp4;)
137
+ ENABLE_SCALAR_IMPLEMENTATION(union {float f;unsigned int ui;} Stmp5;) ENABLE_SSE_IMPLEMENTATION(__m128 Vtmp5;) ENABLE_AVX_IMPLEMENTATION(__m256 Vtmp5;)
vendor/libigl/include/igl/Singular_Value_Decomposition_Main_Kernel_Body.hpp ADDED
The diff for this file is too large to render. See raw diff
 
vendor/libigl/include/igl/Singular_Value_Decomposition_Preamble.hpp ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#####################################################################
2
+ // Copyright (c) 2010-2011, Eftychios Sifakis.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+ // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
7
+ // other materials provided with the distribution.
8
+ //
9
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
10
+ // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
11
+ // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
12
+ // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
13
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
14
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ //#####################################################################
16
+
17
+ #ifdef PRINT_DEBUGGING_OUTPUT
18
+ #include <iomanip>
19
+ #include <iostream>
20
+ #endif
21
+
22
+ // Prevent warnings
23
+ #ifdef ENABLE_SCALAR_IMPLEMENTATION
24
+ # undef ENABLE_SCALAR_IMPLEMENTATION
25
+ #endif
26
+ #ifdef ENABLE_SSE_IMPLEMENTATION
27
+ # undef ENABLE_SSE_IMPLEMENTATION
28
+ #endif
29
+ #ifdef ENABLE_AVX_IMPLEMENTATION
30
+ # undef ENABLE_AVX_IMPLEMENTATION
31
+ #endif
32
+
33
+ #ifdef USE_SCALAR_IMPLEMENTATION
34
+ #define ENABLE_SCALAR_IMPLEMENTATION(X) X
35
+ #else
36
+ #define ENABLE_SCALAR_IMPLEMENTATION(X)
37
+ #endif
38
+
39
+ #ifdef USE_SSE_IMPLEMENTATION
40
+ #define ENABLE_SSE_IMPLEMENTATION(X) X
41
+ #else
42
+ #define ENABLE_SSE_IMPLEMENTATION(X)
43
+ #endif
44
+
45
+ #ifdef USE_AVX_IMPLEMENTATION
46
+ #include <immintrin.h>
47
+ #define ENABLE_AVX_IMPLEMENTATION(X) X
48
+ #else
49
+ // Stefan: removed include. Why does it import MMX instructions, shouldn't this be under the #ifdef USE_SSE_IMPLEMENTATION above?
50
+ //#include <xmmintrin.h>
51
+ #define ENABLE_AVX_IMPLEMENTATION(X)
52
+ #endif
53
+
54
+ #ifdef USE_SCALAR_IMPLEMENTATION
55
+ // Alec: Why is this using sse intrinsics if it's supposed to be the scalar
56
+ // implementation?
57
+ #ifdef __SSE__
58
+ #include <mmintrin.h>
59
+ // Changed to inline
60
+ inline float rsqrt(const float f)
61
+ {
62
+ float buf[4];
63
+ buf[0]=f;
64
+ __m128 v=_mm_loadu_ps(buf);
65
+ v=_mm_rsqrt_ss(v);
66
+ _mm_storeu_ps(buf,v);
67
+ return buf[0];
68
+ }
69
+ #else
70
+ #include <cmath>
71
+ inline float rsqrt(const float f)
72
+ {
73
+ return 1./sqrtf(f);
74
+ }
75
+ #endif
76
+ #endif
77
+
78
+
vendor/libigl/include/igl/SortableRow.h ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_SORTABLE_ROW_H
9
+ #define IGL_SORTABLE_ROW_H
10
+
11
+ // Simple class to contain a rowvector which allows rowwise sorting and
12
+ // reordering
13
+ #include <Eigen/Core>
14
+
15
+ namespace igl
16
+ {
17
+ // Templates:
18
+ // T should be a matrix that implements .size(), and operator(int i)
19
+ template <typename T>
20
+ class SortableRow
21
+ {
22
+ public:
23
+ T data;
24
+ public:
25
+ SortableRow():data(){};
26
+ SortableRow(const T & data):data(data){};
27
+ bool operator<(const SortableRow & that) const
28
+ {
29
+ // Lexicographical
30
+ int minc = (this->data.size() < that.data.size()?
31
+ this->data.size() : that.data.size());
32
+ // loop over columns
33
+ for(int i = 0;i<minc;i++)
34
+ {
35
+ if(this->data(i) == that.data(i))
36
+ {
37
+ continue;
38
+ }
39
+ return this->data(i) < that.data(i);
40
+ }
41
+ // All characters the same, comes done to length
42
+ return this->data.size()<that.data.size();
43
+ };
44
+ bool operator==(const SortableRow & that) const
45
+ {
46
+ if(this->data.size() != that.data.size())
47
+ {
48
+ return false;
49
+ }
50
+ for(int i = 0;i<this->data.size();i++)
51
+ {
52
+ if(this->data(i) != that.data(i))
53
+ {
54
+ return false;
55
+ }
56
+ }
57
+ return true;
58
+ };
59
+ bool operator!=(const SortableRow & that) const
60
+ {
61
+ return !(*this == that);
62
+ };
63
+ };
64
+ }
65
+
66
+ #endif
vendor/libigl/include/igl/Timer.h ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ // High Resolution Timer.
9
+ //
10
+ // Resolution on Mac (clock tick)
11
+ // Resolution on Linux (1 us not tested)
12
+ // Resolution on Windows (clock tick not tested)
13
+
14
+ #ifndef IGL_TIMER_H
15
+ #define IGL_TIMER_H
16
+
17
+ #ifdef WIN32 // Windows system specific
18
+ #include <windows.h>
19
+ #elif __APPLE__ // Unix based system specific
20
+ #include <mach/mach_time.h> // for mach_absolute_time
21
+ #else
22
+ #include <sys/time.h>
23
+ #endif
24
+ #include <cstddef>
25
+
26
+ namespace igl
27
+ {
28
+ class Timer
29
+ {
30
+ public:
31
+ // default constructor
32
+ Timer():
33
+ stopped(0),
34
+ #ifdef WIN32
35
+ frequency(),
36
+ startCount(),
37
+ endCount()
38
+ #elif __APPLE__
39
+ startCount(0),
40
+ endCount(0)
41
+ #else
42
+ startCount(),
43
+ endCount()
44
+ #endif
45
+ {
46
+ #ifdef WIN32
47
+ QueryPerformanceFrequency(&frequency);
48
+ startCount.QuadPart = 0;
49
+ endCount.QuadPart = 0;
50
+ #elif __APPLE__
51
+ startCount = 0;
52
+ endCount = 0;
53
+ #else
54
+ startCount.tv_sec = startCount.tv_usec = 0;
55
+ endCount.tv_sec = endCount.tv_usec = 0;
56
+ #endif
57
+
58
+ stopped = 0;
59
+ }
60
+ // default destructor
61
+ ~Timer()
62
+ {
63
+
64
+ }
65
+
66
+ #ifdef __APPLE__
67
+ //Raw mach_absolute_times going in, difference in seconds out
68
+ double subtractTimes( uint64_t endTime, uint64_t startTime )
69
+ {
70
+ uint64_t difference = endTime - startTime;
71
+ static double conversion = 0.0;
72
+
73
+ if( conversion == 0.0 )
74
+ {
75
+ mach_timebase_info_data_t info;
76
+ kern_return_t err = mach_timebase_info( &info );
77
+
78
+ //Convert the timebase into seconds
79
+ if( err == 0 )
80
+ conversion = 1e-9 * (double) info.numer / (double) info.denom;
81
+ }
82
+
83
+ return conversion * (double) difference;
84
+ }
85
+ #endif
86
+
87
+ // start timer
88
+ void start()
89
+ {
90
+ stopped = 0; // reset stop flag
91
+ #ifdef WIN32
92
+ QueryPerformanceCounter(&startCount);
93
+ #elif __APPLE__
94
+ startCount = mach_absolute_time();
95
+ #else
96
+ gettimeofday(&startCount, NULL);
97
+ #endif
98
+
99
+ }
100
+
101
+ // stop the timer
102
+ void stop()
103
+ {
104
+ stopped = 1; // set timer stopped flag
105
+
106
+ #ifdef WIN32
107
+ QueryPerformanceCounter(&endCount);
108
+ #elif __APPLE__
109
+ endCount = mach_absolute_time();
110
+ #else
111
+ gettimeofday(&endCount, NULL);
112
+ #endif
113
+
114
+ }
115
+ // get elapsed time in second
116
+ double getElapsedTime()
117
+ {
118
+ return this->getElapsedTimeInSec();
119
+ }
120
+ // get elapsed time in second (same as getElapsedTime)
121
+ double getElapsedTimeInSec()
122
+ {
123
+ return this->getElapsedTimeInMicroSec() * 0.000001;
124
+ }
125
+
126
+ // get elapsed time in milli-second
127
+ double getElapsedTimeInMilliSec()
128
+ {
129
+ return this->getElapsedTimeInMicroSec() * 0.001;
130
+ }
131
+ // get elapsed time in micro-second
132
+ double getElapsedTimeInMicroSec()
133
+ {
134
+ double startTimeInMicroSec = 0;
135
+ double endTimeInMicroSec = 0;
136
+
137
+ #ifdef WIN32
138
+ if(!stopped)
139
+ QueryPerformanceCounter(&endCount);
140
+
141
+ startTimeInMicroSec =
142
+ startCount.QuadPart * (1000000.0 / frequency.QuadPart);
143
+ endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart);
144
+ #elif __APPLE__
145
+ if (!stopped)
146
+ endCount = mach_absolute_time();
147
+
148
+ return subtractTimes(endCount,startCount)/1e-6;
149
+ #else
150
+ if(!stopped)
151
+ gettimeofday(&endCount, NULL);
152
+
153
+ startTimeInMicroSec =
154
+ (startCount.tv_sec * 1000000.0) + startCount.tv_usec;
155
+ endTimeInMicroSec = (endCount.tv_sec * 1000000.0) + endCount.tv_usec;
156
+ #endif
157
+
158
+ return endTimeInMicroSec - startTimeInMicroSec;
159
+ }
160
+
161
+ private:
162
+ // stop flag
163
+ int stopped;
164
+ #ifdef WIN32
165
+ // ticks per second
166
+ LARGE_INTEGER frequency;
167
+ LARGE_INTEGER startCount;
168
+ LARGE_INTEGER endCount;
169
+ #elif __APPLE__
170
+ uint64_t startCount;
171
+ uint64_t endCount;
172
+ #else
173
+ timeval startCount;
174
+ timeval endCount;
175
+ #endif
176
+ };
177
+ }
178
+ #endif // TIMER_H_DEF
179
+
vendor/libigl/include/igl/WindingNumberAABB.h ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+
9
+ // # MUTUAL DEPENDENCY ISSUE FOR HEADER ONLY VERSION
10
+ // MUST INCLUDE winding_number.h first before guard:
11
+ #include "winding_number.h"
12
+
13
+ #ifndef IGL_WINDINGNUMBERAABB_H
14
+ #define IGL_WINDINGNUMBERAABB_H
15
+ #include "WindingNumberTree.h"
16
+
17
+ namespace igl
18
+ {
19
+ template <
20
+ typename Point,
21
+ typename DerivedV,
22
+ typename DerivedF >
23
+ class WindingNumberAABB : public WindingNumberTree<Point,DerivedV,DerivedF>
24
+ {
25
+ protected:
26
+ Point min_corner;
27
+ Point max_corner;
28
+ typename DerivedV::Scalar total_positive_area;
29
+ public:
30
+ enum SplitMethod
31
+ {
32
+ CENTER_ON_LONGEST_AXIS = 0,
33
+ MEDIAN_ON_LONGEST_AXIS = 1,
34
+ NUM_SPLIT_METHODS = 2
35
+ } split_method;
36
+ public:
37
+ inline WindingNumberAABB():
38
+ total_positive_area(std::numeric_limits<typename DerivedV::Scalar>::infinity()),
39
+ split_method(MEDIAN_ON_LONGEST_AXIS)
40
+ {}
41
+ inline WindingNumberAABB(
42
+ const Eigen::MatrixBase<DerivedV> & V,
43
+ const Eigen::MatrixBase<DerivedF> & F);
44
+ inline WindingNumberAABB(
45
+ const WindingNumberTree<Point,DerivedV,DerivedF> & parent,
46
+ const Eigen::MatrixBase<DerivedF> & F);
47
+ // Initialize some things
48
+ inline void set_mesh(
49
+ const Eigen::MatrixBase<DerivedV> & V,
50
+ const Eigen::MatrixBase<DerivedF> & F);
51
+ inline void init();
52
+ inline bool inside(const Point & p) const;
53
+ inline virtual void grow();
54
+ // Compute min and max corners
55
+ inline void compute_min_max_corners();
56
+ inline typename DerivedV::Scalar max_abs_winding_number(const Point & p) const;
57
+ inline typename DerivedV::Scalar max_simple_abs_winding_number(const Point & p) const;
58
+ };
59
+ }
60
+
61
+ // Implementation
62
+
63
+ #include "winding_number.h"
64
+
65
+ #include "barycenter.h"
66
+ #include "median.h"
67
+ #include "doublearea.h"
68
+ #include "per_face_normals.h"
69
+
70
+ #include <limits>
71
+ #include <vector>
72
+ #include <iostream>
73
+
74
+ // Minimum number of faces in a hierarchy element (this is probably dependent
75
+ // on speed of machine and compiler optimization)
76
+ #ifndef WindingNumberAABB_MIN_F
77
+ # define WindingNumberAABB_MIN_F 100
78
+ #endif
79
+
80
+ template <typename Point, typename DerivedV, typename DerivedF>
81
+ inline void igl::WindingNumberAABB<Point,DerivedV,DerivedF>::set_mesh(
82
+ const Eigen::MatrixBase<DerivedV> & V,
83
+ const Eigen::MatrixBase<DerivedF> & F)
84
+ {
85
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::set_mesh(V,F);
86
+ init();
87
+ }
88
+
89
+ template <typename Point, typename DerivedV, typename DerivedF>
90
+ inline void igl::WindingNumberAABB<Point,DerivedV,DerivedF>::init()
91
+ {
92
+ using namespace Eigen;
93
+ assert(max_corner.size() == 3);
94
+ assert(min_corner.size() == 3);
95
+ compute_min_max_corners();
96
+ Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,1> dblA;
97
+ doublearea(this->getV(),this->getF(),dblA);
98
+ total_positive_area = dblA.sum()/2.0;
99
+ }
100
+
101
+ template <typename Point, typename DerivedV, typename DerivedF>
102
+ inline igl::WindingNumberAABB<Point,DerivedV,DerivedF>::WindingNumberAABB(
103
+ const Eigen::MatrixBase<DerivedV> & V,
104
+ const Eigen::MatrixBase<DerivedF> & F):
105
+ WindingNumberTree<Point,DerivedV,DerivedF>(V,F),
106
+ min_corner(),
107
+ max_corner(),
108
+ total_positive_area(
109
+ std::numeric_limits<typename DerivedV::Scalar>::infinity()),
110
+ split_method(MEDIAN_ON_LONGEST_AXIS)
111
+ {
112
+ init();
113
+ }
114
+
115
+ template <typename Point, typename DerivedV, typename DerivedF>
116
+ inline igl::WindingNumberAABB<Point,DerivedV,DerivedF>::WindingNumberAABB(
117
+ const WindingNumberTree<Point,DerivedV,DerivedF> & parent,
118
+ const Eigen::MatrixBase<DerivedF> & F):
119
+ WindingNumberTree<Point,DerivedV,DerivedF>(parent,F),
120
+ min_corner(),
121
+ max_corner(),
122
+ total_positive_area(
123
+ std::numeric_limits<typename DerivedV::Scalar>::infinity()),
124
+ split_method(MEDIAN_ON_LONGEST_AXIS)
125
+ {
126
+ init();
127
+ }
128
+
129
+ template <typename Point, typename DerivedV, typename DerivedF>
130
+ inline void igl::WindingNumberAABB<Point,DerivedV,DerivedF>::grow()
131
+ {
132
+ using namespace std;
133
+ using namespace Eigen;
134
+ // Clear anything that already exists
135
+ this->delete_children();
136
+
137
+ //cout<<"cap.rows(): "<<this->getcap().rows()<<endl;
138
+ //cout<<"F.rows(): "<<this->getF().rows()<<endl;
139
+
140
+ // Base cases
141
+ if(
142
+ this->getF().rows() <= (WindingNumberAABB_MIN_F>0?WindingNumberAABB_MIN_F:0) ||
143
+ (this->getcap().rows() - 2) >= this->getF().rows())
144
+ {
145
+ // Don't grow
146
+ return;
147
+ }
148
+
149
+ // Compute longest direction
150
+ int max_d = -1;
151
+ typename DerivedV::Scalar max_len =
152
+ -numeric_limits<typename DerivedV::Scalar>::infinity();
153
+ for(int d = 0;d<min_corner.size();d++)
154
+ {
155
+ if( (max_corner[d] - min_corner[d]) > max_len )
156
+ {
157
+ max_len = (max_corner[d] - min_corner[d]);
158
+ max_d = d;
159
+ }
160
+ }
161
+ // Compute facet barycenters
162
+ Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,Eigen::Dynamic> BC;
163
+ barycenter(this->getV(),this->getF(),BC);
164
+
165
+
166
+ // Blerg, why is selecting rows so difficult
167
+
168
+ typename DerivedV::Scalar split_value;
169
+ // Split in longest direction
170
+ switch(split_method)
171
+ {
172
+ case MEDIAN_ON_LONGEST_AXIS:
173
+ // Determine median
174
+ median(BC.col(max_d),split_value);
175
+ break;
176
+ default:
177
+ assert(false);
178
+ case CENTER_ON_LONGEST_AXIS:
179
+ split_value = 0.5*(max_corner[max_d] + min_corner[max_d]);
180
+ break;
181
+ }
182
+ //cout<<"c: "<<0.5*(max_corner[max_d] + min_corner[max_d])<<" "<<
183
+ // "m: "<<split_value<<endl;;
184
+
185
+ vector<int> id( this->getF().rows());
186
+ for(int i = 0;i<this->getF().rows();i++)
187
+ {
188
+ if(BC(i,max_d) <= split_value)
189
+ {
190
+ id[i] = 0; //left
191
+ }else
192
+ {
193
+ id[i] = 1; //right
194
+ }
195
+ }
196
+
197
+ const int lefts = (int) count(id.begin(),id.end(),0);
198
+ const int rights = (int) count(id.begin(),id.end(),1);
199
+ if(lefts == 0 || rights == 0)
200
+ {
201
+ // badly balanced base case (could try to recut)
202
+ return;
203
+ }
204
+ assert(lefts+rights == this->getF().rows());
205
+ DerivedF leftF(lefts, this->getF().cols());
206
+ DerivedF rightF(rights,this->getF().cols());
207
+ int left_i = 0;
208
+ int right_i = 0;
209
+ for(int i = 0;i<this->getF().rows();i++)
210
+ {
211
+ if(id[i] == 0)
212
+ {
213
+ leftF.row(left_i++) = this->getF().row(i);
214
+ }else if(id[i] == 1)
215
+ {
216
+ rightF.row(right_i++) = this->getF().row(i);
217
+ }else
218
+ {
219
+ assert(false);
220
+ }
221
+ }
222
+ assert(right_i == rightF.rows());
223
+ assert(left_i == leftF.rows());
224
+ // Finally actually grow children and Recursively grow
225
+ WindingNumberAABB<Point,DerivedV,DerivedF> * leftWindingNumberAABB =
226
+ new WindingNumberAABB<Point,DerivedV,DerivedF>(*this,leftF);
227
+ leftWindingNumberAABB->grow();
228
+ this->children.push_back(leftWindingNumberAABB);
229
+ WindingNumberAABB<Point,DerivedV,DerivedF> * rightWindingNumberAABB =
230
+ new WindingNumberAABB<Point,DerivedV,DerivedF>(*this,rightF);
231
+ rightWindingNumberAABB->grow();
232
+ this->children.push_back(rightWindingNumberAABB);
233
+ }
234
+
235
+ template <typename Point, typename DerivedV, typename DerivedF>
236
+ inline bool igl::WindingNumberAABB<Point,DerivedV,DerivedF>::inside(const Point & p) const
237
+ {
238
+ assert(p.size() == max_corner.size());
239
+ assert(p.size() == min_corner.size());
240
+ for(int i = 0;i<p.size();i++)
241
+ {
242
+ //// Perfect matching is **not** robust
243
+ //if( p(i) < min_corner(i) || p(i) >= max_corner(i))
244
+ // **MUST** be conservative
245
+ if( p(i) < min_corner(i) || p(i) > max_corner(i))
246
+ {
247
+ return false;
248
+ }
249
+ }
250
+ return true;
251
+ }
252
+
253
+ template <typename Point, typename DerivedV, typename DerivedF>
254
+ inline void igl::WindingNumberAABB<Point,DerivedV,DerivedF>::compute_min_max_corners()
255
+ {
256
+ using namespace std;
257
+ // initialize corners
258
+ for(int d = 0;d<min_corner.size();d++)
259
+ {
260
+ min_corner[d] = numeric_limits<typename Point::Scalar>::infinity();
261
+ max_corner[d] = -numeric_limits<typename Point::Scalar>::infinity();
262
+ }
263
+
264
+ this->center = Point(0,0,0);
265
+ // Loop over facets
266
+ for(int i = 0;i<this->getF().rows();i++)
267
+ {
268
+ for(int j = 0;j<this->getF().cols();j++)
269
+ {
270
+ for(int d = 0;d<min_corner.size();d++)
271
+ {
272
+ min_corner[d] =
273
+ this->getV()(this->getF()(i,j),d) < min_corner[d] ?
274
+ this->getV()(this->getF()(i,j),d) : min_corner[d];
275
+ max_corner[d] =
276
+ this->getV()(this->getF()(i,j),d) > max_corner[d] ?
277
+ this->getV()(this->getF()(i,j),d) : max_corner[d];
278
+ }
279
+ // This is biased toward vertices incident on more than one face, but
280
+ // perhaps that's good
281
+ this->center += this->getV().row(this->getF()(i,j));
282
+ }
283
+ }
284
+ // Average
285
+ this->center.array() /= this->getF().size();
286
+
287
+ //cout<<"min_corner: "<<this->min_corner.transpose()<<endl;
288
+ //cout<<"Center: "<<this->center.transpose()<<endl;
289
+ //cout<<"max_corner: "<<this->max_corner.transpose()<<endl;
290
+ //cout<<"Diag center: "<<((this->max_corner + this->min_corner)*0.5).transpose()<<endl;
291
+ //cout<<endl;
292
+
293
+ this->radius = (max_corner-min_corner).norm()/2.0;
294
+ }
295
+
296
+ template <typename Point, typename DerivedV, typename DerivedF>
297
+ inline typename DerivedV::Scalar
298
+ igl::WindingNumberAABB<Point,DerivedV,DerivedF>::max_abs_winding_number(const Point & p) const
299
+ {
300
+ using namespace std;
301
+ // Only valid if not inside
302
+ if(inside(p))
303
+ {
304
+ return numeric_limits<typename DerivedV::Scalar>::infinity();
305
+ }
306
+ // Q: we know the total positive area so what's the most this could project
307
+ // to? Remember it could be layered in the same direction.
308
+ return numeric_limits<typename DerivedV::Scalar>::infinity();
309
+ }
310
+
311
+ template <typename Point, typename DerivedV, typename DerivedF>
312
+ inline typename DerivedV::Scalar
313
+ igl::WindingNumberAABB<Point,DerivedV,DerivedF>::max_simple_abs_winding_number(
314
+ const Point & p) const
315
+ {
316
+ using namespace std;
317
+ using namespace Eigen;
318
+ // Only valid if not inside
319
+ if(inside(p))
320
+ {
321
+ return numeric_limits<typename DerivedV::Scalar>::infinity();
322
+ }
323
+ // Max simple is the same as sum of positive winding number contributions of
324
+ // bounding box
325
+
326
+ // begin precomputation
327
+ //MatrixXd BV((int)pow(2,3),3);
328
+ typedef
329
+ Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,Eigen::Dynamic>
330
+ MatrixXS;
331
+ typedef
332
+ Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,Eigen::Dynamic>
333
+ MatrixXF;
334
+ MatrixXS BV((int)(1<<3),3);
335
+ BV <<
336
+ min_corner[0],min_corner[1],min_corner[2],
337
+ min_corner[0],min_corner[1],max_corner[2],
338
+ min_corner[0],max_corner[1],min_corner[2],
339
+ min_corner[0],max_corner[1],max_corner[2],
340
+ max_corner[0],min_corner[1],min_corner[2],
341
+ max_corner[0],min_corner[1],max_corner[2],
342
+ max_corner[0],max_corner[1],min_corner[2],
343
+ max_corner[0],max_corner[1],max_corner[2];
344
+ MatrixXF BF(2*2*3,3);
345
+ BF <<
346
+ 0,6,4,
347
+ 0,2,6,
348
+ 0,3,2,
349
+ 0,1,3,
350
+ 2,7,6,
351
+ 2,3,7,
352
+ 4,6,7,
353
+ 4,7,5,
354
+ 0,4,5,
355
+ 0,5,1,
356
+ 1,5,7,
357
+ 1,7,3;
358
+ MatrixXS BFN;
359
+ per_face_normals(BV,BF,BFN);
360
+ // end of precomputation
361
+
362
+ // Only keep those with positive dot products
363
+ MatrixXF PBF(BF.rows(),BF.cols());
364
+ int pbfi = 0;
365
+ Point p2c = 0.5*(min_corner+max_corner)-p;
366
+ for(int i = 0;i<BFN.rows();i++)
367
+ {
368
+ if(p2c.dot(BFN.row(i)) > 0)
369
+ {
370
+ PBF.row(pbfi++) = BF.row(i);
371
+ }
372
+ }
373
+ PBF.conservativeResize(pbfi,PBF.cols());
374
+ return igl::winding_number(BV,PBF,p);
375
+ }
376
+
377
+ // This is a bullshit template because AABB annoyingly needs templates for bad
378
+ // combinations of 3D V with DIM=2 AABB
379
+ //
380
+ // _Define_ as a no-op rather than monkeying around with the proper code above
381
+ namespace igl
382
+ {
383
+ template <> inline igl::WindingNumberAABB<Eigen::Matrix<double, 1, 3, 1, 1, 3>,Eigen::Matrix<double, -1, 2, 0, -1, 2>,Eigen::Matrix<int, -1, 2, 0, -1, 2>>::WindingNumberAABB(const Eigen::MatrixBase<Eigen::Matrix<double, -1, 2, 0, -1, 2>> & V, const Eigen::MatrixBase<Eigen::Matrix<int, -1, 2, 0, -1, 2>> & F){};
384
+ template <> inline void igl::WindingNumberAABB<Eigen::Matrix<double, 1, 3, 1, 1, 3>,Eigen::Matrix<double, -1, 2, 0, -1, 2>,Eigen::Matrix<int, -1, 2, 0, -1, 2>>::grow(){};
385
+ template <> inline void igl::WindingNumberAABB<Eigen::Matrix<double, 1, 3, 1, 1, 3>,Eigen::Matrix<double, -1, 2, 0, -1, 2>,Eigen::Matrix<int, -1, 2, 0, -1, 2>>::init(){};
386
+
387
+ }
388
+
389
+ #endif
vendor/libigl/include/igl/WindingNumberTree.h ADDED
@@ -0,0 +1,501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_WINDINGNUMBERTREE_H
9
+ #define IGL_WINDINGNUMBERTREE_H
10
+ #include <list>
11
+ #include <map>
12
+ #include <Eigen/Dense>
13
+ #include "WindingNumberMethod.h"
14
+
15
+ namespace igl
16
+ {
17
+ // Space partitioning tree for computing winding number hierarchically.
18
+ //
19
+ // Templates:
20
+ // Point type for points in space, e.g. Eigen::Vector3d
21
+ template <
22
+ typename Point,
23
+ typename DerivedV,
24
+ typename DerivedF >
25
+ class WindingNumberTree
26
+ {
27
+ public:
28
+ // Method to use (see enum above)
29
+ //static double min_max_w;
30
+ static std::map<
31
+ std::pair<const WindingNumberTree*,const WindingNumberTree*>,
32
+ typename DerivedV::Scalar>
33
+ cached;
34
+ // This is only need to fill in references, it should never actually be touched
35
+ // and shouldn't cause race conditions. (This is a hack, but I think it's "safe")
36
+ static DerivedV dummyV;
37
+ protected:
38
+ WindingNumberMethod method;
39
+ const WindingNumberTree * parent;
40
+ std::list<WindingNumberTree * > children;
41
+ typedef
42
+ Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,Eigen::Dynamic>
43
+ MatrixXS;
44
+ typedef
45
+ Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,Eigen::Dynamic>
46
+ MatrixXF;
47
+ //// List of boundary edges (recall edges are vertices in 2d)
48
+ //const Eigen::MatrixXi boundary;
49
+ // Base mesh vertices
50
+ DerivedV & V;
51
+ // Base mesh vertices with duplicates removed
52
+ MatrixXS SV;
53
+ // Facets in this bounding volume
54
+ MatrixXF F;
55
+ // Tessellated boundary curve
56
+ MatrixXF cap;
57
+ // Upper Bound on radius of enclosing ball
58
+ typename DerivedV::Scalar radius;
59
+ // (Approximate) center (of mass)
60
+ Point center;
61
+ public:
62
+ inline WindingNumberTree();
63
+ // For root
64
+ inline WindingNumberTree(
65
+ const Eigen::MatrixBase<DerivedV> & V,
66
+ const Eigen::MatrixBase<DerivedF> & F);
67
+ // For chilluns
68
+ inline WindingNumberTree(
69
+ const WindingNumberTree<Point,DerivedV,DerivedF> & parent,
70
+ const Eigen::MatrixBase<DerivedF> & F);
71
+ inline virtual ~WindingNumberTree();
72
+ inline void delete_children();
73
+ inline virtual void set_mesh(
74
+ const Eigen::MatrixBase<DerivedV> & V,
75
+ const Eigen::MatrixBase<DerivedF> & F);
76
+ // Set method
77
+ inline void set_method( const WindingNumberMethod & m);
78
+ public:
79
+ inline const DerivedV & getV() const;
80
+ inline const MatrixXF & getF() const;
81
+ inline const MatrixXF & getcap() const;
82
+ // Grow the Tree recursively
83
+ inline virtual void grow();
84
+ // Determine whether a given point is inside the bounding
85
+ //
86
+ // Inputs:
87
+ // p query point
88
+ // Returns true if the point p is inside this bounding volume
89
+ inline virtual bool inside(const Point & p) const;
90
+ // Compute the (partial) winding number of a given point p
91
+ // According to method
92
+ //
93
+ // Inputs:
94
+ // p query point
95
+ // Returns winding number
96
+ inline typename DerivedV::Scalar winding_number(const Point & p) const;
97
+ // Same as above, but always computes winding number using exact method
98
+ // (sum over every facet)
99
+ inline typename DerivedV::Scalar winding_number_all(const Point & p) const;
100
+ // Same as above, but always computes using sum over tessllated boundary
101
+ inline typename DerivedV::Scalar winding_number_boundary(const Point & p) const;
102
+ //// Same as winding_number above, but if max_simple_abs_winding_number is
103
+ //// less than some threshold min_max_w just return 0 (colloquially the "fast
104
+ //// multipole method)
105
+ ////
106
+ ////
107
+ //// Inputs:
108
+ //// p query point
109
+ //// min_max_w minimum max simple w to be processed
110
+ //// Returns approximate winding number
111
+ //double winding_number_approx_simple(
112
+ // const Point & p,
113
+ // const double min_max_w);
114
+ // Print contents of Tree
115
+ //
116
+ // Optional input:
117
+ // tab tab to show depth
118
+ inline void print(const char * tab="");
119
+ // Determine max absolute winding number
120
+ //
121
+ // Inputs:
122
+ // p query point
123
+ // Returns max winding number of
124
+ inline virtual typename DerivedV::Scalar max_abs_winding_number(const Point & p) const;
125
+ // Same as above, but stronger assumptions on (V,F). Assumes (V,F) is a
126
+ // simple polyhedron
127
+ inline virtual typename DerivedV::Scalar max_simple_abs_winding_number(const Point & p) const;
128
+ // Compute or read cached winding number for point p with respect to mesh
129
+ // in bounding box, recursing according to approximation criteria
130
+ //
131
+ // Inputs:
132
+ // p query point
133
+ // that WindingNumberTree containing mesh w.r.t. which we're computing w.n.
134
+ // Returns cached winding number
135
+ inline virtual typename DerivedV::Scalar cached_winding_number(const WindingNumberTree & that, const Point & p) const;
136
+ };
137
+ }
138
+
139
+ // Implementation
140
+
141
+ #include "WindingNumberTree.h"
142
+ #include "winding_number.h"
143
+ #include "triangle_fan.h"
144
+ #include "exterior_edges.h"
145
+
146
+ #include <igl/PI.h>
147
+ #include <igl/remove_duplicate_vertices.h>
148
+
149
+ #include <iostream>
150
+ #include <limits>
151
+
152
+ //template <typename Point, typename DerivedV, typename DerivedF>
153
+ //WindingNumberMethod WindingNumberTree<Point,DerivedV,DerivedF>::method = EXACT_WINDING_NUMBER_METHOD;
154
+ //template <typename Point, typename DerivedV, typename DerivedF>
155
+ //double WindingNumberTree<Point,DerivedV,DerivedF>::min_max_w = 0;
156
+ template <typename Point, typename DerivedV, typename DerivedF>
157
+ std::map< std::pair<const igl::WindingNumberTree<Point,DerivedV,DerivedF>*,const igl::WindingNumberTree<Point,DerivedV,DerivedF>*>, typename DerivedV::Scalar>
158
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::cached;
159
+
160
+ template <typename Point, typename DerivedV, typename DerivedF>
161
+ inline igl::WindingNumberTree<Point,DerivedV,DerivedF>::WindingNumberTree():
162
+ method(EXACT_WINDING_NUMBER_METHOD),
163
+ parent(NULL),
164
+ V(dummyV),
165
+ SV(),
166
+ F(),
167
+ cap(),
168
+ radius(std::numeric_limits<typename DerivedV::Scalar>::infinity()),
169
+ center(0,0,0)
170
+ {
171
+ }
172
+
173
+ template <typename Point, typename DerivedV, typename DerivedF>
174
+ inline igl::WindingNumberTree<Point,DerivedV,DerivedF>::WindingNumberTree(
175
+ const Eigen::MatrixBase<DerivedV> & _V,
176
+ const Eigen::MatrixBase<DerivedF> & _F):
177
+ method(EXACT_WINDING_NUMBER_METHOD),
178
+ parent(NULL),
179
+ V(dummyV),
180
+ SV(),
181
+ F(),
182
+ cap(),
183
+ radius(std::numeric_limits<typename DerivedV::Scalar>::infinity()),
184
+ center(0,0,0)
185
+ {
186
+ set_mesh(_V,_F);
187
+ }
188
+
189
+ template <typename Point, typename DerivedV, typename DerivedF>
190
+ inline void igl::WindingNumberTree<Point,DerivedV,DerivedF>::set_mesh(
191
+ const Eigen::MatrixBase<DerivedV> & _V,
192
+ const Eigen::MatrixBase<DerivedF> & _F)
193
+ {
194
+ using namespace std;
195
+ // Remove any exactly duplicate vertices
196
+ // Q: Can this ever increase the complexity of the boundary?
197
+ // Q: Would we gain even more by remove almost exactly duplicate vertices?
198
+ MatrixXF SF,SVI,SVJ;
199
+ igl::remove_duplicate_vertices(_V,_F,0.0,SV,SVI,SVJ,F);
200
+ triangle_fan(igl::exterior_edges(F),cap);
201
+ V = SV;
202
+ }
203
+
204
+ template <typename Point, typename DerivedV, typename DerivedF>
205
+ inline igl::WindingNumberTree<Point,DerivedV,DerivedF>::WindingNumberTree(
206
+ const igl::WindingNumberTree<Point,DerivedV,DerivedF> & parent,
207
+ const Eigen::MatrixBase<DerivedF> & _F):
208
+ method(parent.method),
209
+ parent(&parent),
210
+ V(parent.V),
211
+ SV(),
212
+ F(_F),
213
+ cap(triangle_fan(igl::exterior_edges(_F)))
214
+ {
215
+ }
216
+
217
+ template <typename Point, typename DerivedV, typename DerivedF>
218
+ inline igl::WindingNumberTree<Point,DerivedV,DerivedF>::~WindingNumberTree()
219
+ {
220
+ delete_children();
221
+ }
222
+
223
+ template <typename Point, typename DerivedV, typename DerivedF>
224
+ inline void igl::WindingNumberTree<Point,DerivedV,DerivedF>::delete_children()
225
+ {
226
+ using namespace std;
227
+ // Delete children
228
+ typename list<WindingNumberTree<Point,DerivedV,DerivedF>* >::iterator cit = children.begin();
229
+ while(cit != children.end())
230
+ {
231
+ // clear the memory of this item
232
+ delete (* cit);
233
+ // erase from list, returns next element in iterator
234
+ cit = children.erase(cit);
235
+ }
236
+ }
237
+
238
+ template <typename Point, typename DerivedV, typename DerivedF>
239
+ inline void igl::WindingNumberTree<Point,DerivedV,DerivedF>::set_method(const WindingNumberMethod & m)
240
+ {
241
+ this->method = m;
242
+ for(auto child : children)
243
+ {
244
+ child->set_method(m);
245
+ }
246
+ }
247
+
248
+ template <typename Point, typename DerivedV, typename DerivedF>
249
+ inline const DerivedV & igl::WindingNumberTree<Point,DerivedV,DerivedF>::getV() const
250
+ {
251
+ return V;
252
+ }
253
+
254
+ template <typename Point, typename DerivedV, typename DerivedF>
255
+ inline const typename igl::WindingNumberTree<Point,DerivedV,DerivedF>::MatrixXF&
256
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::getF() const
257
+ {
258
+ return F;
259
+ }
260
+
261
+ template <typename Point, typename DerivedV, typename DerivedF>
262
+ inline const typename igl::WindingNumberTree<Point,DerivedV,DerivedF>::MatrixXF&
263
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::getcap() const
264
+ {
265
+ return cap;
266
+ }
267
+
268
+ template <typename Point, typename DerivedV, typename DerivedF>
269
+ inline void igl::WindingNumberTree<Point,DerivedV,DerivedF>::grow()
270
+ {
271
+ // Don't grow
272
+ return;
273
+ }
274
+
275
+ template <typename Point, typename DerivedV, typename DerivedF>
276
+ inline bool igl::WindingNumberTree<Point,DerivedV,DerivedF>::inside(const Point & /*p*/) const
277
+ {
278
+ return true;
279
+ }
280
+
281
+ template <typename Point, typename DerivedV, typename DerivedF>
282
+ inline typename DerivedV::Scalar
283
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::winding_number(const Point & p) const
284
+ {
285
+ using namespace std;
286
+ //cout<<"+"<<boundary.rows();
287
+ // If inside then we need to be careful
288
+ if(inside(p))
289
+ {
290
+ // If not a leaf then recurse
291
+ if(children.size()>0)
292
+ {
293
+ // Recurse on each child and accumulate
294
+ typename DerivedV::Scalar sum = 0;
295
+ for(
296
+ typename list<WindingNumberTree<Point,DerivedV,DerivedF>* >::const_iterator cit = children.begin();
297
+ cit != children.end();
298
+ cit++)
299
+ {
300
+ switch(method)
301
+ {
302
+ case EXACT_WINDING_NUMBER_METHOD:
303
+ sum += (*cit)->winding_number(p);
304
+ break;
305
+ case APPROX_SIMPLE_WINDING_NUMBER_METHOD:
306
+ case APPROX_CACHE_WINDING_NUMBER_METHOD:
307
+ //if((*cit)->max_simple_abs_winding_number(p) > min_max_w)
308
+ //{
309
+ sum += (*cit)->winding_number(p);
310
+ //}
311
+ break;
312
+ default:
313
+ assert(false);
314
+ break;
315
+ }
316
+ }
317
+ return sum;
318
+ }else
319
+ {
320
+ return winding_number_all(p);
321
+ }
322
+ }else{
323
+ // Otherwise we can just consider boundary
324
+ // Q: If we using the "multipole" method should we also subdivide the
325
+ // boundary case?
326
+ if((cap.rows() - 2) < F.rows())
327
+ {
328
+ switch(method)
329
+ {
330
+ case EXACT_WINDING_NUMBER_METHOD:
331
+ return winding_number_boundary(p);
332
+ case APPROX_SIMPLE_WINDING_NUMBER_METHOD:
333
+ {
334
+ typename DerivedV::Scalar dist = (p-center).norm();
335
+ // Radius is already an overestimate of inside
336
+ if(dist>1.0*radius)
337
+ {
338
+ return 0;
339
+ }else
340
+ {
341
+ return winding_number_boundary(p);
342
+ }
343
+ }
344
+ case APPROX_CACHE_WINDING_NUMBER_METHOD:
345
+ {
346
+ return parent->cached_winding_number(*this,p);
347
+ }
348
+ default: assert(false);break;
349
+ }
350
+ }else
351
+ {
352
+ // doesn't pay off to use boundary
353
+ return winding_number_all(p);
354
+ }
355
+ }
356
+ return 0;
357
+ }
358
+
359
+ template <typename Point, typename DerivedV, typename DerivedF>
360
+ inline typename DerivedV::Scalar
361
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::winding_number_all(const Point & p) const
362
+ {
363
+ return igl::winding_number(V,F,p);
364
+ }
365
+
366
+ template <typename Point, typename DerivedV, typename DerivedF>
367
+ inline typename DerivedV::Scalar
368
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::winding_number_boundary(const Point & p) const
369
+ {
370
+ using namespace Eigen;
371
+ using namespace std;
372
+ return igl::winding_number(V,cap,p);
373
+ }
374
+
375
+ //template <typename Point, typename DerivedV, typename DerivedF>
376
+ //inline double igl::WindingNumberTree<Point,DerivedV,DerivedF>::winding_number_approx_simple(
377
+ // const Point & p,
378
+ // const double min_max_w)
379
+ //{
380
+ // using namespace std;
381
+ // if(max_simple_abs_winding_number(p) > min_max_w)
382
+ // {
383
+ // return winding_number(p);
384
+ // }else
385
+ // {
386
+ // cout<<"Skipped! "<<max_simple_abs_winding_number(p)<<"<"<<min_max_w<<endl;
387
+ // return 0;
388
+ // }
389
+ //}
390
+
391
+ template <typename Point, typename DerivedV, typename DerivedF>
392
+ inline void igl::WindingNumberTree<Point,DerivedV,DerivedF>::print(const char * tab)
393
+ {
394
+ using namespace std;
395
+ // Print all facets
396
+ cout<<tab<<"["<<endl<<F<<endl<<"]";
397
+ // Print children
398
+ for(
399
+ typename list<WindingNumberTree<Point,DerivedV,DerivedF>* >::iterator cit = children.begin();
400
+ cit != children.end();
401
+ cit++)
402
+ {
403
+ cout<<","<<endl;
404
+ (*cit)->print((string(tab)+"").c_str());
405
+ }
406
+ }
407
+
408
+ template <typename Point, typename DerivedV, typename DerivedF>
409
+ inline typename DerivedV::Scalar
410
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::max_abs_winding_number(const Point & /*p*/) const
411
+ {
412
+ return std::numeric_limits<typename DerivedV::Scalar>::infinity();
413
+ }
414
+
415
+ template <typename Point, typename DerivedV, typename DerivedF>
416
+ inline typename DerivedV::Scalar
417
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::max_simple_abs_winding_number(
418
+ const Point & /*p*/) const
419
+ {
420
+ using namespace std;
421
+ return numeric_limits<typename DerivedV::Scalar>::infinity();
422
+ }
423
+
424
+ template <typename Point, typename DerivedV, typename DerivedF>
425
+ inline typename DerivedV::Scalar
426
+ igl::WindingNumberTree<Point,DerivedV,DerivedF>::cached_winding_number(
427
+ const igl::WindingNumberTree<Point,DerivedV,DerivedF> & that,
428
+ const Point & p) const
429
+ {
430
+ using namespace std;
431
+ // Simple metric for `is_far`
432
+ //
433
+ // this that
434
+ // --------
435
+ // ----- / | \ .
436
+ // / r \ / R \ .
437
+ // | p ! | | ! |
438
+ // \_____/ \ /
439
+ // \________/
440
+ //
441
+ //
442
+ // a = angle formed by trapazoid formed by raising sides with lengths r and R
443
+ // at respective centers.
444
+ //
445
+ // a = atan2(R-r,d), where d is the distance between centers
446
+
447
+ // That should be bigger (what about parent? what about sister?)
448
+ bool is_far = this->radius<that.radius;
449
+ if(is_far)
450
+ {
451
+ typename DerivedV::Scalar a = atan2(
452
+ that.radius - this->radius,
453
+ (that.center - this->center).norm());
454
+ assert(a>0);
455
+ is_far = (a<PI/8.0);
456
+ }
457
+
458
+ if(is_far)
459
+ {
460
+ // Not implemented yet
461
+ pair<const WindingNumberTree*,const WindingNumberTree*> this_that(this,&that);
462
+ // Need to compute it for first time?
463
+ if(cached.count(this_that)==0)
464
+ {
465
+ cached[this_that] =
466
+ that.winding_number_boundary(this->center);
467
+ }
468
+ return cached[this_that];
469
+ }else if(children.size() == 0)
470
+ {
471
+ // not far and hierarchy ended too soon: can't use cache
472
+ return that.winding_number_boundary(p);
473
+ }else
474
+ {
475
+ for(
476
+ typename list<WindingNumberTree<Point,DerivedV,DerivedF>* >::const_iterator cit = children.begin();
477
+ cit != children.end();
478
+ cit++)
479
+ {
480
+ if((*cit)->inside(p))
481
+ {
482
+ return (*cit)->cached_winding_number(that,p);
483
+ }
484
+ }
485
+ // Not inside any children? This can totally happen because bounding boxes
486
+ // are set to bound contained facets. So sibilings may overlap and their
487
+ // union may not contain their parent (though, their union is certainly a
488
+ // subset of their parent).
489
+ assert(false);
490
+ }
491
+ return 0;
492
+ }
493
+
494
+ // Explicit instantiation of static variable
495
+ template <
496
+ typename Point,
497
+ typename DerivedV,
498
+ typename DerivedF >
499
+ DerivedV igl::WindingNumberTree<Point,DerivedV,DerivedF>::dummyV;
500
+
501
+ #endif
vendor/libigl/include/igl/accumarray.cpp ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "accumarray.h"
9
+ #include <cassert>
10
+
11
+ template <
12
+ typename DerivedS,
13
+ typename DerivedV,
14
+ typename DerivedA
15
+ >
16
+ void igl::accumarray(
17
+ const Eigen::MatrixBase<DerivedS> & S,
18
+ const Eigen::MatrixBase<DerivedV> & V,
19
+ Eigen::PlainObjectBase<DerivedA> & A)
20
+ {
21
+ assert(V.size() == S.size() && "S and V should be same size");
22
+ if(S.size() == 0) { A.resize(0,1); return; }
23
+ A.setZero(S.maxCoeff()+1,1);
24
+ for(int s = 0;s<S.size();s++)
25
+ {
26
+ A(S(s)) += V(s);
27
+ }
28
+ }
29
+
30
+ template <
31
+ typename DerivedS,
32
+ typename DerivedA
33
+ >
34
+ void igl::accumarray(
35
+ const Eigen::MatrixBase<DerivedS> & S,
36
+ const typename DerivedA::Scalar V,
37
+ Eigen::PlainObjectBase<DerivedA> & A)
38
+ {
39
+ if(S.size() == 0) { A.resize(0,1); return; }
40
+ A.setZero(S.maxCoeff()+1,1);
41
+ for(int s = 0;s<S.size();s++)
42
+ {
43
+ A(S(s)) += V;
44
+ }
45
+ }
46
+
47
+ #ifdef IGL_STATIC_LIBRARY
48
+ // Explicit template instantiation
49
+ // generated by autoexplicit.sh
50
+ template void igl::accumarray<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1>::Scalar, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
51
+ template void igl::accumarray<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
52
+ #endif
vendor/libigl/include/igl/accumarray.h ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2018 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef ACCUMARRY_H
9
+ #define ACCUMARRY_H
10
+ #include "igl_inline.h"
11
+ #include <Eigen/Core>
12
+ namespace igl
13
+ {
14
+ // ACCUMARRY Like Matlab's accumarray. Accumulate values in V using subscripts
15
+ // in S.
16
+ //
17
+ // Inputs:
18
+ // S #S list of subscripts
19
+ // V #V list of values
20
+ // Outputs:
21
+ // A max(subs)+1 list of accumulated values
22
+ template <
23
+ typename DerivedS,
24
+ typename DerivedV,
25
+ typename DerivedA
26
+ >
27
+ void accumarray(
28
+ const Eigen::MatrixBase<DerivedS> & S,
29
+ const Eigen::MatrixBase<DerivedV> & V,
30
+ Eigen::PlainObjectBase<DerivedA> & A);
31
+ // Inputs:
32
+ // S #S list of subscripts
33
+ // V single value used for all
34
+ // Outputs:
35
+ // A max(subs)+1 list of accumulated values
36
+ template <
37
+ typename DerivedS,
38
+ typename DerivedA
39
+ >
40
+ void accumarray(
41
+ const Eigen::MatrixBase<DerivedS> & S,
42
+ const typename DerivedA::Scalar V,
43
+ Eigen::PlainObjectBase<DerivedA> & A);
44
+ }
45
+
46
+ #ifndef IGL_STATIC_LIBRARY
47
+ # include "accumarray.cpp"
48
+ #endif
49
+
50
+ #endif
vendor/libigl/include/igl/active_set.cpp ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "active_set.h"
9
+ #include "min_quad_with_fixed.h"
10
+ #include "slice.h"
11
+ #include "slice_into.h"
12
+ #include "cat.h"
13
+ //#include "matlab_format.h"
14
+
15
+ #include <iostream>
16
+ #include <limits>
17
+ #include <algorithm>
18
+
19
+ template <
20
+ typename AT,
21
+ typename DerivedB,
22
+ typename Derivedknown,
23
+ typename DerivedY,
24
+ typename AeqT,
25
+ typename DerivedBeq,
26
+ typename AieqT,
27
+ typename DerivedBieq,
28
+ typename Derivedlx,
29
+ typename Derivedux,
30
+ typename DerivedZ
31
+ >
32
+ IGL_INLINE igl::SolverStatus igl::active_set(
33
+ const Eigen::SparseMatrix<AT>& A,
34
+ const Eigen::PlainObjectBase<DerivedB> & B,
35
+ const Eigen::PlainObjectBase<Derivedknown> & known,
36
+ const Eigen::PlainObjectBase<DerivedY> & Y,
37
+ const Eigen::SparseMatrix<AeqT>& Aeq,
38
+ const Eigen::PlainObjectBase<DerivedBeq> & Beq,
39
+ const Eigen::SparseMatrix<AieqT>& Aieq,
40
+ const Eigen::PlainObjectBase<DerivedBieq> & Bieq,
41
+ const Eigen::PlainObjectBase<Derivedlx> & p_lx,
42
+ const Eigen::PlainObjectBase<Derivedux> & p_ux,
43
+ const igl::active_set_params & params,
44
+ Eigen::PlainObjectBase<DerivedZ> & Z
45
+ )
46
+ {
47
+ //#define ACTIVE_SET_CPP_DEBUG
48
+ #if defined(ACTIVE_SET_CPP_DEBUG) && !defined(_MSC_VER)
49
+ # warning "ACTIVE_SET_CPP_DEBUG"
50
+ #endif
51
+ using namespace Eigen;
52
+ using namespace std;
53
+ SolverStatus ret = SOLVER_STATUS_ERROR;
54
+ const int n = A.rows();
55
+ assert(n == A.cols() && "A must be square");
56
+ // Discard const qualifiers
57
+ //if(B.size() == 0)
58
+ //{
59
+ // B = DerivedB::Zero(n,1);
60
+ //}
61
+ assert(n == B.rows() && "B.rows() must match A.rows()");
62
+ assert(B.cols() == 1 && "B must be a column vector");
63
+ assert(Y.cols() == 1 && "Y must be a column vector");
64
+ assert((Aeq.size() == 0 && Beq.size() == 0) || Aeq.cols() == n);
65
+ assert((Aeq.size() == 0 && Beq.size() == 0) || Aeq.rows() == Beq.rows());
66
+ assert((Aeq.size() == 0 && Beq.size() == 0) || Beq.cols() == 1);
67
+ assert((Aieq.size() == 0 && Bieq.size() == 0) || Aieq.cols() == n);
68
+ assert((Aieq.size() == 0 && Bieq.size() == 0) || Aieq.rows() == Bieq.rows());
69
+ assert((Aieq.size() == 0 && Bieq.size() == 0) || Bieq.cols() == 1);
70
+ Eigen::Matrix<typename Derivedlx::Scalar,Eigen::Dynamic,1> lx;
71
+ Eigen::Matrix<typename Derivedux::Scalar,Eigen::Dynamic,1> ux;
72
+ if(p_lx.size() == 0)
73
+ {
74
+ lx = Derivedlx::Constant(
75
+ n,1,-numeric_limits<typename Derivedlx::Scalar>::max());
76
+ }else
77
+ {
78
+ lx = p_lx;
79
+ }
80
+ if(p_ux.size() == 0)
81
+ {
82
+ ux = Derivedux::Constant(
83
+ n,1,numeric_limits<typename Derivedux::Scalar>::max());
84
+ }else
85
+ {
86
+ ux = p_ux;
87
+ }
88
+ assert(lx.rows() == n && "lx must have n rows");
89
+ assert(ux.rows() == n && "ux must have n rows");
90
+ assert(ux.cols() == 1 && "lx must be a column vector");
91
+ assert(lx.cols() == 1 && "ux must be a column vector");
92
+ assert((ux.array()-lx.array()).minCoeff() > 0 && "ux(i) must be > lx(i)");
93
+ if(Z.size() != 0)
94
+ {
95
+ // Initial guess should have correct size
96
+ assert(Z.rows() == n && "Z must have n rows");
97
+ assert(Z.cols() == 1 && "Z must be a column vector");
98
+ }
99
+ assert(known.cols() == 1 && "known must be a column vector");
100
+ // Number of knowns
101
+ const int nk = known.size();
102
+
103
+ // Initialize active sets
104
+ typedef int BOOL;
105
+ #define TRUE 1
106
+ #define FALSE 0
107
+ Matrix<BOOL,Dynamic,1> as_lx = Matrix<BOOL,Dynamic,1>::Constant(n,1,FALSE);
108
+ Matrix<BOOL,Dynamic,1> as_ux = Matrix<BOOL,Dynamic,1>::Constant(n,1,FALSE);
109
+ Matrix<BOOL,Dynamic,1> as_ieq = Matrix<BOOL,Dynamic,1>::Constant(Aieq.rows(),1,FALSE);
110
+
111
+ // Keep track of previous Z for comparison
112
+ DerivedZ old_Z;
113
+ old_Z = DerivedZ::Constant(
114
+ n,1,numeric_limits<typename DerivedZ::Scalar>::max());
115
+
116
+ int iter = 0;
117
+ while(true)
118
+ {
119
+ #ifdef ACTIVE_SET_CPP_DEBUG
120
+ cout<<"Iteration: "<<iter<<":"<<endl;
121
+ cout<<" pre"<<endl;
122
+ #endif
123
+ // FIND BREACHES OF CONSTRAINTS
124
+ int new_as_lx = 0;
125
+ int new_as_ux = 0;
126
+ int new_as_ieq = 0;
127
+ if(Z.size() > 0)
128
+ {
129
+ for(int z = 0;z < n;z++)
130
+ {
131
+ if(Z(z) < lx(z))
132
+ {
133
+ new_as_lx += (as_lx(z)?0:1);
134
+ //new_as_lx++;
135
+ as_lx(z) = TRUE;
136
+ }
137
+ if(Z(z) > ux(z))
138
+ {
139
+ new_as_ux += (as_ux(z)?0:1);
140
+ //new_as_ux++;
141
+ as_ux(z) = TRUE;
142
+ }
143
+ }
144
+ if(Aieq.rows() > 0)
145
+ {
146
+ DerivedZ AieqZ;
147
+ AieqZ = Aieq*Z;
148
+ for(int a = 0;a<Aieq.rows();a++)
149
+ {
150
+ if(AieqZ(a) > Bieq(a))
151
+ {
152
+ new_as_ieq += (as_ieq(a)?0:1);
153
+ as_ieq(a) = TRUE;
154
+ }
155
+ }
156
+ }
157
+ #ifdef ACTIVE_SET_CPP_DEBUG
158
+ cout<<" new_as_lx: "<<new_as_lx<<endl;
159
+ cout<<" new_as_ux: "<<new_as_ux<<endl;
160
+ #endif
161
+ const double diff = (Z-old_Z).squaredNorm();
162
+ #ifdef ACTIVE_SET_CPP_DEBUG
163
+ cout<<"diff: "<<diff<<endl;
164
+ #endif
165
+ if(diff < params.solution_diff_threshold)
166
+ {
167
+ ret = SOLVER_STATUS_CONVERGED;
168
+ break;
169
+ }
170
+ old_Z = Z;
171
+ }
172
+
173
+ const int as_lx_count = std::count(as_lx.data(),as_lx.data()+n,TRUE);
174
+ const int as_ux_count = std::count(as_ux.data(),as_ux.data()+n,TRUE);
175
+ const int as_ieq_count =
176
+ std::count(as_ieq.data(),as_ieq.data()+as_ieq.size(),TRUE);
177
+ #ifndef NDEBUG
178
+ {
179
+ int count = 0;
180
+ for(int a = 0;a<as_ieq.size();a++)
181
+ {
182
+ if(as_ieq(a))
183
+ {
184
+ assert(as_ieq(a) == TRUE);
185
+ count++;
186
+ }
187
+ }
188
+ assert(as_ieq_count == count);
189
+ }
190
+ #endif
191
+
192
+ // PREPARE FIXED VALUES
193
+ Derivedknown known_i;
194
+ known_i.resize(nk + as_lx_count + as_ux_count,1);
195
+ DerivedY Y_i;
196
+ Y_i.resize(nk + as_lx_count + as_ux_count,1);
197
+ {
198
+ known_i.block(0,0,known.rows(),known.cols()) = known;
199
+ Y_i.block(0,0,Y.rows(),Y.cols()) = Y;
200
+ int k = nk;
201
+ // Then all lx
202
+ for(int z = 0;z < n;z++)
203
+ {
204
+ if(as_lx(z))
205
+ {
206
+ known_i(k) = z;
207
+ Y_i(k) = lx(z);
208
+ k++;
209
+ }
210
+ }
211
+ // Finally all ux
212
+ for(int z = 0;z < n;z++)
213
+ {
214
+ if(as_ux(z))
215
+ {
216
+ known_i(k) = z;
217
+ Y_i(k) = ux(z);
218
+ k++;
219
+ }
220
+ }
221
+ assert(k==Y_i.size());
222
+ assert(k==known_i.size());
223
+ }
224
+ //cout<<matlab_format((known_i.array()+1).eval(),"known_i")<<endl;
225
+ // PREPARE EQUALITY CONSTRAINTS
226
+ Eigen::Matrix<typename DerivedY::Scalar, Eigen::Dynamic, 1> as_ieq_list(as_ieq_count,1);
227
+ // Gather active constraints and resp. rhss
228
+ DerivedBeq Beq_i;
229
+ Beq_i.resize(Beq.rows()+as_ieq_count,1);
230
+ Beq_i.head(Beq.rows()) = Beq;
231
+ {
232
+ int k =0;
233
+ for(int a=0;a<as_ieq.size();a++)
234
+ {
235
+ if(as_ieq(a))
236
+ {
237
+ assert(k<as_ieq_list.size());
238
+ as_ieq_list(k)=a;
239
+ Beq_i(Beq.rows()+k,0) = Bieq(k,0);
240
+ k++;
241
+ }
242
+ }
243
+ assert(k == as_ieq_count);
244
+ }
245
+ // extract active constraint rows
246
+ SparseMatrix<AeqT> Aeq_i,Aieq_i;
247
+ slice(Aieq,as_ieq_list,1,Aieq_i);
248
+ // Append to equality constraints
249
+ cat(1,Aeq,Aieq_i,Aeq_i);
250
+
251
+
252
+ min_quad_with_fixed_data<AT> data;
253
+ #ifndef NDEBUG
254
+ {
255
+ // NO DUPES!
256
+ Matrix<BOOL,Dynamic,1> fixed = Matrix<BOOL,Dynamic,1>::Constant(n,1,FALSE);
257
+ for(int k = 0;k<known_i.size();k++)
258
+ {
259
+ assert(!fixed[known_i(k)]);
260
+ fixed[known_i(k)] = TRUE;
261
+ }
262
+ }
263
+ #endif
264
+
265
+ DerivedZ sol;
266
+ if(known_i.size() == A.rows())
267
+ {
268
+ // Everything's fixed?
269
+ #ifdef ACTIVE_SET_CPP_DEBUG
270
+ cout<<" everything's fixed."<<endl;
271
+ #endif
272
+ Z.resize(A.rows(),Y_i.cols());
273
+ slice_into(Y_i,known_i,1,Z);
274
+ sol.resize(0,Y_i.cols());
275
+ assert(Aeq_i.rows() == 0 && "All fixed but linearly constrained");
276
+ }else
277
+ {
278
+ #ifdef ACTIVE_SET_CPP_DEBUG
279
+ cout<<" min_quad_with_fixed_precompute"<<endl;
280
+ #endif
281
+ if(!min_quad_with_fixed_precompute(A,known_i,Aeq_i,params.Auu_pd,data))
282
+ {
283
+ cerr<<"Error: min_quad_with_fixed precomputation failed."<<endl;
284
+ if(iter > 0 && Aeq_i.rows() > Aeq.rows())
285
+ {
286
+ cerr<<" *Are you sure rows of [Aeq;Aieq] are linearly independent?*"<<
287
+ endl;
288
+ }
289
+ ret = SOLVER_STATUS_ERROR;
290
+ break;
291
+ }
292
+ #ifdef ACTIVE_SET_CPP_DEBUG
293
+ cout<<" min_quad_with_fixed_solve"<<endl;
294
+ #endif
295
+ if(!min_quad_with_fixed_solve(data,B,Y_i,Beq_i,Z,sol))
296
+ {
297
+ cerr<<"Error: min_quad_with_fixed solve failed."<<endl;
298
+ ret = SOLVER_STATUS_ERROR;
299
+ break;
300
+ }
301
+ //cout<<matlab_format((Aeq*Z-Beq).eval(),"cr")<<endl;
302
+ //cout<<matlab_format(Z,"Z")<<endl;
303
+ #ifdef ACTIVE_SET_CPP_DEBUG
304
+ cout<<" post"<<endl;
305
+ #endif
306
+ // Computing Lagrange multipliers needs to be adjusted slightly if A is not symmetric
307
+ assert(data.Auu_sym);
308
+ }
309
+
310
+ // Compute Lagrange multiplier values for known_i
311
+ SparseMatrix<AT> Ak;
312
+ // Slow
313
+ slice(A,known_i,1,Ak);
314
+ DerivedB Bk;
315
+ slice(B,known_i,Bk);
316
+ MatrixXd Lambda_known_i = -(0.5*Ak*Z + 0.5*Bk);
317
+ // reverse the lambda values for lx
318
+ Lambda_known_i.block(nk,0,as_lx_count,1) =
319
+ (-1*Lambda_known_i.block(nk,0,as_lx_count,1)).eval();
320
+
321
+ // Extract Lagrange multipliers for Aieq_i (always at back of sol)
322
+ VectorXd Lambda_Aieq_i(Aieq_i.rows(),1);
323
+ for(int l = 0;l<Aieq_i.rows();l++)
324
+ {
325
+ Lambda_Aieq_i(Aieq_i.rows()-1-l) = sol(sol.rows()-1-l);
326
+ }
327
+
328
+ // Remove from active set
329
+ for(int l = 0;l<as_lx_count;l++)
330
+ {
331
+ if(Lambda_known_i(nk + l) < params.inactive_threshold)
332
+ {
333
+ as_lx(known_i(nk + l)) = FALSE;
334
+ }
335
+ }
336
+ for(int u = 0;u<as_ux_count;u++)
337
+ {
338
+ if(Lambda_known_i(nk + as_lx_count + u) <
339
+ params.inactive_threshold)
340
+ {
341
+ as_ux(known_i(nk + as_lx_count + u)) = FALSE;
342
+ }
343
+ }
344
+ for(int a = 0;a<as_ieq_count;a++)
345
+ {
346
+ if(Lambda_Aieq_i(a) < params.inactive_threshold)
347
+ {
348
+ as_ieq(int(as_ieq_list(a))) = FALSE;
349
+ }
350
+ }
351
+
352
+ iter++;
353
+ //cout<<iter<<endl;
354
+ if(params.max_iter>0 && iter>=params.max_iter)
355
+ {
356
+ ret = SOLVER_STATUS_MAX_ITER;
357
+ break;
358
+ }
359
+
360
+ }
361
+
362
+ return ret;
363
+ }
364
+
365
+
366
+ #ifdef IGL_STATIC_LIBRARY
367
+ // Explicit template instantiation
368
+ template igl::SolverStatus igl::active_set<double, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, double, Eigen::Matrix<double, -1, 1, 0, -1, 1>, double, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, igl::active_set_params const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
369
+ template igl::SolverStatus igl::active_set<double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, -1, 1, 0, -1, 1>, double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, igl::active_set_params const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
370
+ #endif
vendor/libigl/include/igl/adjacency_list.cpp ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "adjacency_list.h"
9
+
10
+ #include "verbose.h"
11
+ #include <algorithm>
12
+
13
+ template <typename Index, typename IndexVector>
14
+ IGL_INLINE void igl::adjacency_list(
15
+ const Eigen::MatrixBase<Index> & F,
16
+ std::vector<std::vector<IndexVector> >& A,
17
+ bool sorted)
18
+ {
19
+ A.clear();
20
+ A.resize(F.maxCoeff()+1);
21
+
22
+ // Loop over faces
23
+ for(int i = 0;i<F.rows();i++)
24
+ {
25
+ // Loop over this face
26
+ for(int j = 0;j<F.cols();j++)
27
+ {
28
+ // Get indices of edge: s --> d
29
+ int s = F(i,j);
30
+ int d = F(i,(j+1)%F.cols());
31
+ A.at(s).push_back(d);
32
+ A.at(d).push_back(s);
33
+ }
34
+ }
35
+
36
+ // Remove duplicates
37
+ for(int i=0; i<(int)A.size();++i)
38
+ {
39
+ std::sort(A[i].begin(), A[i].end());
40
+ A[i].erase(std::unique(A[i].begin(), A[i].end()), A[i].end());
41
+ }
42
+
43
+ // If needed, sort every VV
44
+ if (sorted)
45
+ {
46
+ // Loop over faces
47
+
48
+ // for every vertex v store a set of ordered edges not incident to v that belongs to triangle incident on v.
49
+ std::vector<std::vector<std::vector<int> > > SR;
50
+ SR.resize(A.size());
51
+
52
+ for(int i = 0;i<F.rows();i++)
53
+ {
54
+ // Loop over this face
55
+ for(int j = 0;j<F.cols();j++)
56
+ {
57
+ // Get indices of edge: s --> d
58
+ int s = F(i,j);
59
+ int d = F(i,(j+1)%F.cols());
60
+ // Get index of opposing vertex v
61
+ int v = F(i,(j+2)%F.cols());
62
+
63
+ std::vector<int> e(2);
64
+ e[0] = d;
65
+ e[1] = v;
66
+ SR[s].push_back(e);
67
+ }
68
+ }
69
+
70
+ for(int v=0; v<(int)SR.size();++v)
71
+ {
72
+ std::vector<IndexVector>& vv = A.at(v);
73
+ std::vector<std::vector<int> >& sr = SR[v];
74
+
75
+ std::vector<std::vector<int> > pn = sr;
76
+
77
+ // Compute previous/next for every element in sr
78
+ for(int i=0;i<(int)sr.size();++i)
79
+ {
80
+ int a = sr[i][0];
81
+ int b = sr[i][1];
82
+
83
+ // search for previous
84
+ int p = -1;
85
+ for(int j=0;j<(int)sr.size();++j)
86
+ if(sr[j][1] == a)
87
+ p = j;
88
+ pn[i][0] = p;
89
+
90
+ // search for next
91
+ int n = -1;
92
+ for(int j=0;j<(int)sr.size();++j)
93
+ if(sr[j][0] == b)
94
+ n = j;
95
+ pn[i][1] = n;
96
+
97
+ }
98
+
99
+ // assume manifoldness (look for beginning of a single chain)
100
+ int c = 0;
101
+ for(int j=0; j<=(int)sr.size();++j)
102
+ if (pn[c][0] != -1)
103
+ c = pn[c][0];
104
+
105
+ if (pn[c][0] == -1) // border case
106
+ {
107
+ // finally produce the new vv relation
108
+ for(int j=0; j<(int)sr.size();++j)
109
+ {
110
+ vv[j] = sr[c][0];
111
+ if (pn[c][1] != -1)
112
+ c = pn[c][1];
113
+ }
114
+ vv.back() = sr[c][1];
115
+ }
116
+ else
117
+ {
118
+ // finally produce the new vv relation
119
+ for(int j=0; j<(int)sr.size();++j)
120
+ {
121
+ vv[j] = sr[c][0];
122
+
123
+ c = pn[c][1];
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ template <typename Index>
131
+ IGL_INLINE void igl::adjacency_list(
132
+ const std::vector<std::vector<Index> > & F,
133
+ std::vector<std::vector<Index> >& A)
134
+ {
135
+ A.clear();
136
+
137
+ // Find maxCoeff
138
+ Index maxCoeff = 0;
139
+ for(const auto &vec : F)
140
+ {
141
+ for(int coeff : vec)
142
+ {
143
+ maxCoeff = std::max(coeff, maxCoeff);
144
+ }
145
+ }
146
+ A.resize(maxCoeff + 1);
147
+
148
+ // Loop over faces
149
+ for(int i = 0;i<F.size();i++)
150
+ {
151
+ // Loop over this face
152
+ for(int j = 0;j<F[i].size();j++)
153
+ {
154
+ // Get indices of edge: s --> d
155
+ int s = F[i][j];
156
+ int d = F[i][(j+1)%F[i].size()];
157
+ A.at(s).push_back(d);
158
+ A.at(d).push_back(s);
159
+ }
160
+ }
161
+
162
+ // Remove duplicates
163
+ for(int i=0; i<(int)A.size();++i)
164
+ {
165
+ std::sort(A[i].begin(), A[i].end());
166
+ A[i].erase(std::unique(A[i].begin(), A[i].end()), A[i].end());
167
+ }
168
+
169
+ }
170
+
171
+ #ifdef IGL_STATIC_LIBRARY
172
+ // Explicit template instantiation
173
+ // generated by autoexplicit.sh
174
+ template void igl::adjacency_list<Eigen::Matrix<int, -1, 2, 0, -1, 2>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, bool);
175
+ // generated by autoexplicit.sh
176
+ template void igl::adjacency_list<Eigen::Matrix<int, -1, -1, 0, -1, -1>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, bool);
177
+ template void igl::adjacency_list<Eigen::Matrix<int, -1, 3, 0, -1, 3>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, bool);
178
+ template void igl::adjacency_list<class Eigen::Matrix<int, -1, -1, 0, -1, -1>, unsigned int>(class Eigen::MatrixBase<class Eigen::Matrix<int, -1, -1, 0, -1, -1> > const &, class std::vector<class std::vector<unsigned int, class std::allocator<unsigned int> >, class std::allocator<class std::vector<unsigned int, class std::allocator<unsigned int> > > > &, bool);
179
+ template void igl::adjacency_list<int>(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
180
+ #endif
vendor/libigl/include/igl/adjacency_list.h ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ADJACENCY_LIST_H
9
+ #define IGL_ADJACENCY_LIST_H
10
+ #include "igl_inline.h"
11
+
12
+ #include <Eigen/Dense>
13
+ #include <Eigen/Sparse>
14
+ #include <vector>
15
+ namespace igl
16
+ {
17
+ // Constructs the graph adjacency list of a given mesh (V,F)
18
+ // Templates:
19
+ // T should be a eigen sparse matrix primitive type like int or double
20
+ // Inputs:
21
+ // F #F by dim list of mesh faces (must be triangles)
22
+ // sorted flag that indicates if the list should be sorted counter-clockwise
23
+ // Outputs:
24
+ // A vector<vector<T> > containing at row i the adjacent vertices of vertex i
25
+ //
26
+ // Example:
27
+ // // Mesh in (V,F)
28
+ // vector<vector<double> > A;
29
+ // adjacency_list(F,A);
30
+ //
31
+ // See also: edges, cotmatrix, diag
32
+ template <typename Index, typename IndexVector>
33
+ IGL_INLINE void adjacency_list(
34
+ const Eigen::MatrixBase<Index> & F,
35
+ std::vector<std::vector<IndexVector> >& A,
36
+ bool sorted = false);
37
+
38
+ // Variant that accepts polygonal faces.
39
+ // Each element of F is a set of indices of a polygonal face.
40
+ template <typename Index>
41
+ IGL_INLINE void adjacency_list(
42
+ const std::vector<std::vector<Index> > & F,
43
+ std::vector<std::vector<Index> >& A);
44
+
45
+ }
46
+
47
+ #ifndef IGL_STATIC_LIBRARY
48
+ # include "adjacency_list.cpp"
49
+ #endif
50
+
51
+ #endif
vendor/libigl/include/igl/adjacency_matrix.cpp ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "adjacency_matrix.h"
9
+
10
+ #include "verbose.h"
11
+
12
+ #include <vector>
13
+
14
+ template <typename DerivedF, typename T>
15
+ IGL_INLINE void igl::adjacency_matrix(
16
+ const Eigen::MatrixBase<DerivedF> & F,
17
+ Eigen::SparseMatrix<T>& A)
18
+ {
19
+ using namespace std;
20
+ using namespace Eigen;
21
+ typedef typename DerivedF::Scalar Index;
22
+
23
+ typedef Triplet<T> IJV;
24
+ vector<IJV > ijv;
25
+ ijv.reserve(F.size()*2);
26
+ // Loop over **simplex** (i.e., **not quad**)
27
+ for(int i = 0;i<F.rows();i++)
28
+ {
29
+ // Loop over this **simplex**
30
+ for(int j = 0;j<F.cols();j++)
31
+ for(int k = j+1;k<F.cols();k++)
32
+ {
33
+ // Get indices of edge: s --> d
34
+ Index s = F(i,j);
35
+ Index d = F(i,k);
36
+ ijv.push_back(IJV(s,d,1));
37
+ ijv.push_back(IJV(d,s,1));
38
+ }
39
+ }
40
+
41
+ const Index n = F.maxCoeff()+1;
42
+ A.resize(n,n);
43
+ switch(F.cols())
44
+ {
45
+ case 3:
46
+ A.reserve(6*(F.maxCoeff()+1));
47
+ break;
48
+ case 4:
49
+ A.reserve(26*(F.maxCoeff()+1));
50
+ break;
51
+ }
52
+ A.setFromTriplets(ijv.begin(),ijv.end());
53
+
54
+ // Force all non-zeros to be one
55
+
56
+ // Iterate over outside
57
+ for(int k=0; k<A.outerSize(); ++k)
58
+ {
59
+ // Iterate over inside
60
+ for(typename Eigen::SparseMatrix<T>::InnerIterator it (A,k); it; ++it)
61
+ {
62
+ assert(it.value() != 0);
63
+ A.coeffRef(it.row(),it.col()) = 1;
64
+ }
65
+ }
66
+ }
67
+
68
+ template <typename DerivedI, typename DerivedC, typename T>
69
+ IGL_INLINE void igl::adjacency_matrix(
70
+ const Eigen::MatrixBase<DerivedI> & I,
71
+ const Eigen::MatrixBase<DerivedC> & C,
72
+ Eigen::SparseMatrix<T>& A)
73
+ {
74
+ using namespace std;
75
+ using namespace Eigen;
76
+
77
+ typedef Triplet<T> IJV;
78
+ vector<IJV > ijv;
79
+ ijv.reserve(C(C.size()-1)*2);
80
+ typedef typename DerivedI::Scalar Index;
81
+ const Index n = I.maxCoeff()+1;
82
+ {
83
+ // loop over polygons
84
+ for(Index p = 0;p<C.size()-1;p++)
85
+ {
86
+ // number of edges
87
+ const Index np = C(p+1)-C(p);
88
+ // loop over edges
89
+ for(Index c = 0;c<np;c++)
90
+ {
91
+ const Index i = I(C(p)+c);
92
+ const Index j = I(C(p)+((c+1)%np));
93
+ ijv.emplace_back(i,j,1);
94
+ ijv.emplace_back(j,i,1);
95
+ }
96
+ }
97
+ }
98
+
99
+ A.resize(n,n);
100
+ A.reserve(6*n);
101
+ A.setFromTriplets(ijv.begin(),ijv.end());
102
+
103
+ // Force all non-zeros to be one
104
+
105
+ // Iterate over outside
106
+ for(int k=0; k<A.outerSize(); ++k)
107
+ {
108
+ // Iterate over inside
109
+ for(typename Eigen::SparseMatrix<T>::InnerIterator it (A,k); it; ++it)
110
+ {
111
+ assert(it.value() != 0);
112
+ A.coeffRef(it.row(),it.col()) = 1;
113
+ }
114
+ }
115
+ }
116
+
117
+ #ifdef IGL_STATIC_LIBRARY
118
+ // Explicit template instantiation
119
+ template void igl::adjacency_matrix<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<int, 0, int>& );
120
+ // generated by autoexplicit.sh
121
+ template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, bool>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<bool, 0, int>&);
122
+ template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int>&);
123
+ template void igl::adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<int, 0, int>&);
124
+ template void igl::adjacency_matrix<Eigen::Matrix<int, -1, 3, 0, -1, 3>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::SparseMatrix<int, 0, int>&);
125
+ #endif
vendor/libigl/include/igl/adjacency_matrix.h ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ADJACENCY_MATRIX_H
9
+ #define IGL_ADJACENCY_MATRIX_H
10
+ #include "igl_inline.h"
11
+
12
+ #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
13
+ #include <Eigen/Dense>
14
+ #include <Eigen/Sparse>
15
+
16
+ namespace igl
17
+ {
18
+ // Constructs the graph adjacency matrix of a given mesh (V,F)
19
+ // Templates:
20
+ // T should be a eigen sparse matrix primitive type like int or double
21
+ // Inputs:
22
+ // F #F by dim list of mesh simplices
23
+ // Outputs:
24
+ // A max(F)+1 by max(F)+1 adjacency matrix, each row i corresponding to V(i,:)
25
+ //
26
+ // Example:
27
+ // // Mesh in (V,F)
28
+ // Eigen::SparseMatrix<double> A;
29
+ // adjacency_matrix(F,A);
30
+ // // sum each row
31
+ // SparseVector<double> Asum;
32
+ // sum(A,1,Asum);
33
+ // // Convert row sums into diagonal of sparse matrix
34
+ // SparseMatrix<double> Adiag;
35
+ // diag(Asum,Adiag);
36
+ // // Build uniform laplacian
37
+ // SparseMatrix<double> U;
38
+ // U = A-Adiag;
39
+ //
40
+ // See also: edges, cotmatrix, diag
41
+ template <typename DerivedF, typename T>
42
+ IGL_INLINE void adjacency_matrix(
43
+ const Eigen::MatrixBase<DerivedF> & F,
44
+ Eigen::SparseMatrix<T>& A);
45
+ // Constructs an vertex adjacency for a polygon mesh.
46
+ //
47
+ // Inputs:
48
+ // I #I vectorized list of polygon corner indices into rows of some matrix V
49
+ // C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) =
50
+ // size of the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the
51
+ // indices of the ith polygon
52
+ // Outputs:
53
+ // A max(I)+1 by max(I)+1 adjacency matrix, each row i corresponding to V(i,:)
54
+ //
55
+ template <typename DerivedI, typename DerivedC, typename T>
56
+ IGL_INLINE void adjacency_matrix(
57
+ const Eigen::MatrixBase<DerivedI> & I,
58
+ const Eigen::MatrixBase<DerivedC> & C,
59
+ Eigen::SparseMatrix<T>& A);
60
+ }
61
+
62
+ #ifndef IGL_STATIC_LIBRARY
63
+ # include "adjacency_matrix.cpp"
64
+ #endif
65
+
66
+ #endif
vendor/libigl/include/igl/all.cpp ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2016 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "all.h"
9
+ #include "redux.h"
10
+
11
+
12
+ template <typename AType, typename DerivedB>
13
+ IGL_INLINE void igl::all(
14
+ const Eigen::SparseMatrix<AType> & A,
15
+ const int dim,
16
+ Eigen::PlainObjectBase<DerivedB>& B)
17
+ {
18
+ typedef typename DerivedB::Scalar Scalar;
19
+ igl::redux(A,dim,[](Scalar a, Scalar b){ return a && b!=0;},B);
20
+ }
21
+
22
+ #ifdef IGL_STATIC_LIBRARY
23
+ // Explicit template instantiation
24
+ #endif
25
+
26
+
vendor/libigl/include/igl/all.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2016 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ALL_H
9
+ #define IGL_ALL_H
10
+ #include "igl_inline.h"
11
+ #include <Eigen/Core>
12
+ #include <Eigen/Sparse>
13
+ namespace igl
14
+ {
15
+ // For Dense matrices use: A.rowwise().all() or A.colwise().all()
16
+ //
17
+ // Inputs:
18
+ // A m by n sparse matrix
19
+ // dim dimension along which to check for all (1 or 2)
20
+ // Output:
21
+ // B n-long vector (if dim == 1)
22
+ // or
23
+ // B m-long vector (if dim == 2)
24
+ //
25
+ template <typename AType, typename DerivedB>
26
+ IGL_INLINE void all(
27
+ const Eigen::SparseMatrix<AType> & A,
28
+ const int dim,
29
+ Eigen::PlainObjectBase<DerivedB>& B);
30
+ }
31
+ #ifndef IGL_STATIC_LIBRARY
32
+ # include "all.cpp"
33
+ #endif
34
+ #endif
35
+
36
+
vendor/libigl/include/igl/all_pairs_distances.cpp ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "all_pairs_distances.h"
9
+ #include <Eigen/Dense>
10
+
11
+ template <typename Mat>
12
+ IGL_INLINE void igl::all_pairs_distances(
13
+ const Mat & V,
14
+ const Mat & U,
15
+ const bool squared,
16
+ Mat & D)
17
+ {
18
+ // dimension should be the same
19
+ assert(V.cols() == U.cols());
20
+ // resize output
21
+ D.resize(V.rows(),U.rows());
22
+ for(int i = 0;i<V.rows();i++)
23
+ {
24
+ for(int j=0;j<U.rows();j++)
25
+ {
26
+ D(i,j) = (V.row(i)-U.row(j)).squaredNorm();
27
+ if(!squared)
28
+ {
29
+ D(i,j) = sqrt(D(i,j));
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ #ifdef IGL_STATIC_LIBRARY
36
+ // Explicit template instantiation
37
+ // generated by autoexplicit.sh
38
+ template void igl::all_pairs_distances<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, bool, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
39
+ #endif
vendor/libigl/include/igl/all_pairs_distances.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ALL_PAIRS_DISTANCES_H
9
+ #define IGL_ALL_PAIRS_DISTANCES_H
10
+ #include "igl_inline.h"
11
+
12
+ namespace igl
13
+ {
14
+ // ALL_PAIRS_DISTANCES compute distances between each point i in V and point j
15
+ // in U
16
+ //
17
+ // D = all_pairs_distances(V,U)
18
+ //
19
+ // Templates:
20
+ // Mat matrix class like MatrixXd
21
+ // Inputs:
22
+ // V #V by dim list of points
23
+ // U #U by dim list of points
24
+ // squared whether to return squared distances
25
+ // Outputs:
26
+ // D #V by #U matrix of distances, where D(i,j) gives the distance or
27
+ // squareed distance between V(i,:) and U(j,:)
28
+ //
29
+ template <typename Mat>
30
+ IGL_INLINE void all_pairs_distances(
31
+ const Mat & V,
32
+ const Mat & U,
33
+ const bool squared,
34
+ Mat & D);
35
+ }
36
+
37
+ #ifndef IGL_STATIC_LIBRARY
38
+ # include "all_pairs_distances.cpp"
39
+ #endif
40
+
41
+ #endif
vendor/libigl/include/igl/ambient_occlusion.cpp ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "ambient_occlusion.h"
9
+ #include "random_dir.h"
10
+ #include "ray_mesh_intersect.h"
11
+ #include "EPS.h"
12
+ #include "Hit.h"
13
+ #include "parallel_for.h"
14
+ #include <functional>
15
+ #include <vector>
16
+ #include <algorithm>
17
+
18
+ template <
19
+ typename DerivedP,
20
+ typename DerivedN,
21
+ typename DerivedS >
22
+ IGL_INLINE void igl::ambient_occlusion(
23
+ const std::function<
24
+ bool(
25
+ const Eigen::Vector3f&,
26
+ const Eigen::Vector3f&)
27
+ > & shoot_ray,
28
+ const Eigen::MatrixBase<DerivedP> & P,
29
+ const Eigen::MatrixBase<DerivedN> & N,
30
+ const int num_samples,
31
+ Eigen::PlainObjectBase<DerivedS> & S)
32
+ {
33
+ using namespace Eigen;
34
+ const int n = P.rows();
35
+ // Resize output
36
+ S.resize(n,1);
37
+ // Embree seems to be parallel when constructing but not when tracing rays
38
+ const MatrixXf D = random_dir_stratified(num_samples).cast<float>();
39
+
40
+ const auto & inner = [&P,&N,&num_samples,&D,&S,&shoot_ray](const int p)
41
+ {
42
+ const Vector3f origin = P.row(p).template cast<float>();
43
+ const Vector3f normal = N.row(p).template cast<float>();
44
+ int num_hits = 0;
45
+ for(int s = 0;s<num_samples;s++)
46
+ {
47
+ Vector3f d = D.row(s);
48
+ if(d.dot(normal) < 0)
49
+ {
50
+ // reverse ray
51
+ d *= -1;
52
+ }
53
+ if(shoot_ray(origin,d))
54
+ {
55
+ num_hits++;
56
+ }
57
+ }
58
+ S(p) = (double)num_hits/(double)num_samples;
59
+ };
60
+ parallel_for(n,inner,1000);
61
+ }
62
+
63
+ template <
64
+ typename DerivedV,
65
+ int DIM,
66
+ typename DerivedF,
67
+ typename DerivedP,
68
+ typename DerivedN,
69
+ typename DerivedS >
70
+ IGL_INLINE void igl::ambient_occlusion(
71
+ const igl::AABB<DerivedV,DIM> & aabb,
72
+ const Eigen::MatrixBase<DerivedV> & V,
73
+ const Eigen::MatrixBase<DerivedF> & F,
74
+ const Eigen::MatrixBase<DerivedP> & P,
75
+ const Eigen::MatrixBase<DerivedN> & N,
76
+ const int num_samples,
77
+ Eigen::PlainObjectBase<DerivedS> & S)
78
+ {
79
+ const auto & shoot_ray = [&aabb,&V,&F](
80
+ const Eigen::Vector3f& _s,
81
+ const Eigen::Vector3f& dir)->bool
82
+ {
83
+ Eigen::Vector3f s = _s+1e-4*dir;
84
+ igl::Hit hit;
85
+ return aabb.intersect_ray(
86
+ V,
87
+ F,
88
+ s .cast<typename DerivedV::Scalar>().eval(),
89
+ dir.cast<typename DerivedV::Scalar>().eval(),
90
+ hit);
91
+ };
92
+ return ambient_occlusion(shoot_ray,P,N,num_samples,S);
93
+
94
+ }
95
+
96
+ template <
97
+ typename DerivedV,
98
+ typename DerivedF,
99
+ typename DerivedP,
100
+ typename DerivedN,
101
+ typename DerivedS >
102
+ IGL_INLINE void igl::ambient_occlusion(
103
+ const Eigen::MatrixBase<DerivedV> & V,
104
+ const Eigen::MatrixBase<DerivedF> & F,
105
+ const Eigen::MatrixBase<DerivedP> & P,
106
+ const Eigen::MatrixBase<DerivedN> & N,
107
+ const int num_samples,
108
+ Eigen::PlainObjectBase<DerivedS> & S)
109
+ {
110
+ if(F.rows() < 100)
111
+ {
112
+ // Super naive
113
+ const auto & shoot_ray = [&V,&F](
114
+ const Eigen::Vector3f& _s,
115
+ const Eigen::Vector3f& dir)->bool
116
+ {
117
+ Eigen::Vector3f s = _s+1e-4*dir;
118
+ igl::Hit hit;
119
+ return ray_mesh_intersect(s,dir,V,F,hit);
120
+ };
121
+ return ambient_occlusion(shoot_ray,P,N,num_samples,S);
122
+ }
123
+ AABB<DerivedV,3> aabb;
124
+ aabb.init(V,F);
125
+ return ambient_occlusion(aabb,V,F,P,N,num_samples,S);
126
+ }
127
+
128
+ #ifdef IGL_STATIC_LIBRARY
129
+ // Explicit template instantiation
130
+ // generated by autoexplicit.sh
131
+ template void igl::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
132
+ // generated by autoexplicit.sh
133
+ template void igl::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<bool (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
134
+ // generated by autoexplicit.sh
135
+ template void igl::ambient_occlusion<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<bool (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
136
+ // generated by autoexplicit.sh
137
+ template void igl::ambient_occlusion<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<bool (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
138
+ template void igl::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::function<bool (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
139
+ #endif
vendor/libigl/include/igl/ambient_occlusion.h ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_AMBIENT_OCCLUSION_H
9
+ #define IGL_AMBIENT_OCCLUSION_H
10
+ #include "igl_inline.h"
11
+ #include "AABB.h"
12
+ #include <Eigen/Core>
13
+ #include <functional>
14
+ namespace igl
15
+ {
16
+ // Compute ambient occlusion per given point
17
+ //
18
+ // Inputs:
19
+ // shoot_ray function handle that outputs hits of a given ray against a
20
+ // mesh (embedded in function handles as captured variable/data)
21
+ // P #P by 3 list of origin points
22
+ // N #P by 3 list of origin normals
23
+ // Outputs:
24
+ // S #P list of ambient occlusion values between 1 (fully occluded) and
25
+ // 0 (not occluded)
26
+ //
27
+ template <
28
+ typename DerivedP,
29
+ typename DerivedN,
30
+ typename DerivedS >
31
+ IGL_INLINE void ambient_occlusion(
32
+ const std::function<
33
+ bool(
34
+ const Eigen::Vector3f&,
35
+ const Eigen::Vector3f&)
36
+ > & shoot_ray,
37
+ const Eigen::MatrixBase<DerivedP> & P,
38
+ const Eigen::MatrixBase<DerivedN> & N,
39
+ const int num_samples,
40
+ Eigen::PlainObjectBase<DerivedS> & S);
41
+ // Inputs:
42
+ // AABB axis-aligned bounding box hierarchy around (V,F)
43
+ template <
44
+ typename DerivedV,
45
+ int DIM,
46
+ typename DerivedF,
47
+ typename DerivedP,
48
+ typename DerivedN,
49
+ typename DerivedS >
50
+ IGL_INLINE void ambient_occlusion(
51
+ const igl::AABB<DerivedV,DIM> & aabb,
52
+ const Eigen::MatrixBase<DerivedV> & V,
53
+ const Eigen::MatrixBase<DerivedF> & F,
54
+ const Eigen::MatrixBase<DerivedP> & P,
55
+ const Eigen::MatrixBase<DerivedN> & N,
56
+ const int num_samples,
57
+ Eigen::PlainObjectBase<DerivedS> & S);
58
+ // Inputs:
59
+ // V #V by 3 list of mesh vertex positions
60
+ // F #F by 3 list of mesh face indices into V
61
+ template <
62
+ typename DerivedV,
63
+ typename DerivedF,
64
+ typename DerivedP,
65
+ typename DerivedN,
66
+ typename DerivedS >
67
+ IGL_INLINE void ambient_occlusion(
68
+ const Eigen::MatrixBase<DerivedV> & V,
69
+ const Eigen::MatrixBase<DerivedF> & F,
70
+ const Eigen::MatrixBase<DerivedP> & P,
71
+ const Eigen::MatrixBase<DerivedN> & N,
72
+ const int num_samples,
73
+ Eigen::PlainObjectBase<DerivedS> & S);
74
+
75
+ };
76
+ #ifndef IGL_STATIC_LIBRARY
77
+ # include "ambient_occlusion.cpp"
78
+ #endif
79
+
80
+ #endif
vendor/libigl/include/igl/angular_distance.cpp ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "angular_distance.h"
9
+ #include <igl/EPS.h>
10
+ #include <igl/PI.h>
11
+ IGL_INLINE double igl::angular_distance(
12
+ const Eigen::Quaterniond & A,
13
+ const Eigen::Quaterniond & B)
14
+ {
15
+ assert(fabs(A.norm()-1)<FLOAT_EPS && "A should be unit norm");
16
+ assert(fabs(B.norm()-1)<FLOAT_EPS && "B should be unit norm");
17
+ //// acos is always in [0,2*pi)
18
+ //return acos(fabs(A.dot(B)));
19
+ return fmod(2.*acos(A.dot(B)),2.*PI);
20
+ }
vendor/libigl/include/igl/angular_distance.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ANGULAR_DISTANCE_H
9
+ #define IGL_ANGULAR_DISTANCE_H
10
+ #include "igl_inline.h"
11
+ #include <Eigen/Geometry>
12
+ namespace igl
13
+ {
14
+ // The "angular distance" between two unit quaternions is the angle of the
15
+ // smallest rotation (treated as an Axis and Angle) that takes A to B.
16
+ //
17
+ // Inputs:
18
+ // A unit quaternion
19
+ // B unit quaternion
20
+ // Returns angular distance
21
+ IGL_INLINE double angular_distance(
22
+ const Eigen::Quaterniond & A,
23
+ const Eigen::Quaterniond & B);
24
+ }
25
+
26
+ #ifndef IGL_STATIC_LIBRARY
27
+ #include "angular_distance.cpp"
28
+ #endif
29
+
30
+ #endif
vendor/libigl/include/igl/any.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2016 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ANY_H
9
+ #define IGL_ANY_H
10
+ #include "igl_inline.h"
11
+ #include <Eigen/Core>
12
+ #include <Eigen/Sparse>
13
+ namespace igl
14
+ {
15
+ // For Dense matrices use: A.rowwise().any() or A.colwise().any()
16
+ //
17
+ // Inputs:
18
+ // A m by n sparse matrix
19
+ // dim dimension along which to check for any (1 or 2)
20
+ // Output:
21
+ // B n-long vector (if dim == 1)
22
+ // or
23
+ // B m-long vector (if dim == 2)
24
+ //
25
+ template <typename AType, typename DerivedB>
26
+ IGL_INLINE void any(
27
+ const Eigen::SparseMatrix<AType> & A,
28
+ const int dim,
29
+ Eigen::PlainObjectBase<DerivedB>& B);
30
+ }
31
+ #ifndef IGL_STATIC_LIBRARY
32
+ # include "any.cpp"
33
+ #endif
34
+ #endif
35
+
vendor/libigl/include/igl/any_of.cpp ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "any_of.h"
9
+ #include <Eigen/Core>
10
+ template <typename Mat>
11
+ IGL_INLINE bool igl::any_of(const Mat & S)
12
+ {
13
+ return std::any_of(S.data(),S.data()+S.size(),[](bool s){return s;});
14
+ }
15
+
16
+ #ifdef IGL_STATIC_LIBRARY
17
+ // Explicit template instantiation
18
+ template bool igl::any_of<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&);
19
+ #endif
20
+
vendor/libigl/include/igl/any_of.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ANY_OF_H
9
+ #define IGL_ANY_OF_H
10
+ #include "igl_inline.h"
11
+ namespace igl
12
+ {
13
+ // Wrapper for STL `any_of` for matrix types
14
+ //
15
+ // Inputs:
16
+ // S matrix
17
+ // Returns whether any entries are true
18
+ //
19
+ // Seems that Eigen (now) implements this for `Eigen::Array`
20
+ template <typename Mat>
21
+ IGL_INLINE bool any_of(const Mat & S);
22
+ }
23
+ #ifndef IGL_STATIC_LIBRARY
24
+ # include "any_of.cpp"
25
+ #endif
26
+ #endif
vendor/libigl/include/igl/arap_dof.cpp ADDED
@@ -0,0 +1,884 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #include "arap_dof.h"
9
+
10
+ #include "cotmatrix.h"
11
+ #include "massmatrix.h"
12
+ #include "speye.h"
13
+ #include "repdiag.h"
14
+ #include "repmat.h"
15
+ #include "slice.h"
16
+ #include "colon.h"
17
+ #include "is_sparse.h"
18
+ #include "mode.h"
19
+ #include "is_symmetric.h"
20
+ #include "group_sum_matrix.h"
21
+ #include "arap_rhs.h"
22
+ #include "covariance_scatter_matrix.h"
23
+ #include "fit_rotations.h"
24
+
25
+ #include "verbose.h"
26
+ #include "print_ijv.h"
27
+
28
+ #include "get_seconds_hires.h"
29
+ //#include "MKLEigenInterface.h"
30
+ #include "kkt_inverse.h"
31
+ #include "get_seconds.h"
32
+ #include "columnize.h"
33
+
34
+ // defined if no early exit is supported, i.e., always take a fixed number of iterations
35
+ #define IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
36
+
37
+ // A careful derivation of this implementation is given in the corresponding
38
+ // matlab function arap_dof.m
39
+ template <typename LbsMatrixType, typename SSCALAR>
40
+ IGL_INLINE bool igl::arap_dof_precomputation(
41
+ const Eigen::MatrixXd & V,
42
+ const Eigen::MatrixXi & F,
43
+ const LbsMatrixType & M,
44
+ const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
45
+ ArapDOFData<LbsMatrixType, SSCALAR> & data)
46
+ {
47
+ using namespace Eigen;
48
+ typedef Matrix<SSCALAR, Dynamic, Dynamic> MatrixXS;
49
+ // number of mesh (domain) vertices
50
+ int n = V.rows();
51
+ // cache problem size
52
+ data.n = n;
53
+ // dimension of mesh
54
+ data.dim = V.cols();
55
+ assert(data.dim == M.rows()/n);
56
+ assert(data.dim*n == M.rows());
57
+ if(data.dim == 3)
58
+ {
59
+ // Check if z-coordinate is all zeros
60
+ if(V.col(2).minCoeff() == 0 && V.col(2).maxCoeff() == 0)
61
+ {
62
+ data.effective_dim = 2;
63
+ }
64
+ }else
65
+ {
66
+ data.effective_dim = data.dim;
67
+ }
68
+ // Number of handles
69
+ data.m = M.cols()/data.dim/(data.dim+1);
70
+ assert(data.m*data.dim*(data.dim+1) == M.cols());
71
+ //assert(m == C.rows());
72
+
73
+ //printf("n=%d; dim=%d; m=%d;\n",n,data.dim,data.m);
74
+
75
+ // Build cotangent laplacian
76
+ SparseMatrix<double> Lcot;
77
+ //printf("cotmatrix()\n");
78
+ cotmatrix(V,F,Lcot);
79
+ // Discrete laplacian (should be minus matlab version)
80
+ SparseMatrix<double> Lapl = -2.0*Lcot;
81
+ #ifdef EXTREME_VERBOSE
82
+ cout<<"LaplIJV=["<<endl;print_ijv(Lapl,1);cout<<endl<<"];"<<
83
+ endl<<"Lapl=sparse(LaplIJV(:,1),LaplIJV(:,2),LaplIJV(:,3),"<<
84
+ Lapl.rows()<<","<<Lapl.cols()<<");"<<endl;
85
+ #endif
86
+
87
+ // Get group sum scatter matrix, when applied sums all entries of the same
88
+ // group according to G
89
+ SparseMatrix<double> G_sum;
90
+ if(G.size() == 0)
91
+ {
92
+ speye(n,G_sum);
93
+ }else
94
+ {
95
+ // groups are defined per vertex, convert to per face using mode
96
+ Eigen::Matrix<int,Eigen::Dynamic,1> GG;
97
+ if(data.energy == ARAP_ENERGY_TYPE_ELEMENTS)
98
+ {
99
+ MatrixXi GF(F.rows(),F.cols());
100
+ for(int j = 0;j<F.cols();j++)
101
+ {
102
+ Matrix<int,Eigen::Dynamic,1> GFj;
103
+ slice(G,F.col(j),GFj);
104
+ GF.col(j) = GFj;
105
+ }
106
+ mode<int>(GF,2,GG);
107
+ }else
108
+ {
109
+ GG=G;
110
+ }
111
+ //printf("group_sum_matrix()\n");
112
+ group_sum_matrix(GG,G_sum);
113
+ }
114
+
115
+ #ifdef EXTREME_VERBOSE
116
+ cout<<"G_sumIJV=["<<endl;print_ijv(G_sum,1);cout<<endl<<"];"<<
117
+ endl<<"G_sum=sparse(G_sumIJV(:,1),G_sumIJV(:,2),G_sumIJV(:,3),"<<
118
+ G_sum.rows()<<","<<G_sum.cols()<<");"<<endl;
119
+ #endif
120
+
121
+ // Get covariance scatter matrix, when applied collects the covariance matrices
122
+ // used to fit rotations to during optimization
123
+ SparseMatrix<double> CSM;
124
+ //printf("covariance_scatter_matrix()\n");
125
+ covariance_scatter_matrix(V,F,data.energy,CSM);
126
+ #ifdef EXTREME_VERBOSE
127
+ cout<<"CSMIJV=["<<endl;print_ijv(CSM,1);cout<<endl<<"];"<<
128
+ endl<<"CSM=sparse(CSMIJV(:,1),CSMIJV(:,2),CSMIJV(:,3),"<<
129
+ CSM.rows()<<","<<CSM.cols()<<");"<<endl;
130
+ #endif
131
+
132
+
133
+ // Build the covariance matrix "constructor". This is a set of *scatter*
134
+ // matrices that when multiplied on the right by column of the transformation
135
+ // matrix entries (the degrees of freedom) L, we get a stack of dim by 1
136
+ // covariance matrix column, with a column in the stack for each rotation
137
+ // *group*. The output is a list of matrices because we construct each column
138
+ // in the stack of covariance matrices with an independent matrix-vector
139
+ // multiplication.
140
+ //
141
+ // We want to build S which is a stack of dim by dim covariance matrices.
142
+ // Thus S is dim*g by dim, where dim is the number of dimensions and g is the
143
+ // number of groups. We can precompute dim matrices CSM_M such that column i
144
+ // in S is computed as S(:,i) = CSM_M{i} * L, where L is a column of the
145
+ // skinning transformation matrix values. To be clear, the covariance matrix
146
+ // for group k is then given as the dim by dim matrix pulled from the stack:
147
+ // S((k-1)*dim + 1:dim,:)
148
+
149
+ // Apply group sum to each dimension's block of covariance scatter matrix
150
+ SparseMatrix<double> G_sum_dim;
151
+ repdiag(G_sum,data.dim,G_sum_dim);
152
+ CSM = (G_sum_dim * CSM).eval();
153
+ #ifdef EXTREME_VERBOSE
154
+ cout<<"CSMIJV=["<<endl;print_ijv(CSM,1);cout<<endl<<"];"<<
155
+ endl<<"CSM=sparse(CSMIJV(:,1),CSMIJV(:,2),CSMIJV(:,3),"<<
156
+ CSM.rows()<<","<<CSM.cols()<<");"<<endl;
157
+ #endif
158
+
159
+ //printf("CSM_M()\n");
160
+ // Precompute CSM times M for each dimension
161
+ data.CSM_M.resize(data.dim);
162
+ #ifdef EXTREME_VERBOSE
163
+ cout<<"data.CSM_M = cell("<<data.dim<<",1);"<<endl;
164
+ #endif
165
+ // span of integers from 0 to n-1
166
+ Eigen::Matrix<int,Eigen::Dynamic,1> span_n(n);
167
+ for(int i = 0;i<n;i++)
168
+ {
169
+ span_n(i) = i;
170
+ }
171
+
172
+ // span of integers from 0 to M.cols()-1
173
+ Eigen::Matrix<int,Eigen::Dynamic,1> span_mlbs_cols(M.cols());
174
+ for(int i = 0;i<M.cols();i++)
175
+ {
176
+ span_mlbs_cols(i) = i;
177
+ }
178
+
179
+ // number of groups
180
+ int k = CSM.rows()/data.dim;
181
+ for(int i = 0;i<data.dim;i++)
182
+ {
183
+ //printf("CSM_M(): Mi\n");
184
+ LbsMatrixType M_i;
185
+ //printf("CSM_M(): slice\n");
186
+ slice(M,(span_n.array()+i*n).matrix().eval(),span_mlbs_cols,M_i);
187
+ LbsMatrixType M_i_dim;
188
+ data.CSM_M[i].resize(k*data.dim,data.m*data.dim*(data.dim+1));
189
+ assert(data.CSM_M[i].cols() == M.cols());
190
+ for(int j = 0;j<data.dim;j++)
191
+ {
192
+ SparseMatrix<double> CSMj;
193
+ //printf("CSM_M(): slice\n");
194
+ slice(
195
+ CSM,
196
+ colon<int>(j*k,(j+1)*k-1),
197
+ colon<int>(j*n,(j+1)*n-1),
198
+ CSMj);
199
+ assert(CSMj.rows() == k);
200
+ assert(CSMj.cols() == n);
201
+ LbsMatrixType CSMjM_i = CSMj * M_i;
202
+ if(is_sparse(CSMjM_i))
203
+ {
204
+ // Convert to full
205
+ //printf("CSM_M(): full\n");
206
+ MatrixXd CSMjM_ifull(CSMjM_i);
207
+ // printf("CSM_M[%d]: %d %d\n",i,data.CSM_M[i].rows(),data.CSM_M[i].cols());
208
+ // printf("CSM_M[%d].block(%d*%d=%d,0,%d,%d): %d %d\n",i,j,k,CSMjM_i.rows(),CSMjM_i.cols(),
209
+ // data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()).rows(),
210
+ // data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()).cols());
211
+ // printf("CSM_MjMi: %d %d\n",i,CSMjM_i.rows(),CSMjM_i.cols());
212
+ // printf("CSM_MjM_ifull: %d %d\n",i,CSMjM_ifull.rows(),CSMjM_ifull.cols());
213
+ data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()) = CSMjM_ifull;
214
+ }else
215
+ {
216
+ data.CSM_M[i].block(j*k,0,CSMjM_i.rows(),CSMjM_i.cols()) = CSMjM_i;
217
+ }
218
+ }
219
+ #ifdef EXTREME_VERBOSE
220
+ cout<<"CSM_Mi=["<<endl<<data.CSM_M[i]<<endl<<"];"<<endl;
221
+ #endif
222
+ }
223
+
224
+ // precompute arap_rhs matrix
225
+ //printf("arap_rhs()\n");
226
+ SparseMatrix<double> K;
227
+ arap_rhs(V,F,V.cols(),data.energy,K);
228
+ //#ifdef EXTREME_VERBOSE
229
+ // cout<<"KIJV=["<<endl;print_ijv(K,1);cout<<endl<<"];"<<
230
+ // endl<<"K=sparse(KIJV(:,1),KIJV(:,2),KIJV(:,3),"<<
231
+ // K.rows()<<","<<K.cols()<<");"<<endl;
232
+ //#endif
233
+ // Precompute left muliplication by M and right multiplication by G_sum
234
+ SparseMatrix<double> G_sumT = G_sum.transpose();
235
+ SparseMatrix<double> G_sumT_dim_dim;
236
+ repdiag(G_sumT,data.dim*data.dim,G_sumT_dim_dim);
237
+ LbsMatrixType MT = M.transpose();
238
+ // If this is a bottle neck then consider reordering matrix multiplication
239
+ data.M_KG = -4.0 * (MT * (K * G_sumT_dim_dim));
240
+ //#ifdef EXTREME_VERBOSE
241
+ // cout<<"data.M_KGIJV=["<<endl;print_ijv(data.M_KG,1);cout<<endl<<"];"<<
242
+ // endl<<"data.M_KG=sparse(data.M_KGIJV(:,1),data.M_KGIJV(:,2),data.M_KGIJV(:,3),"<<
243
+ // data.M_KG.rows()<<","<<data.M_KG.cols()<<");"<<endl;
244
+ //#endif
245
+
246
+ // Precompute system matrix
247
+ //printf("A()\n");
248
+ SparseMatrix<double> A;
249
+ repdiag(Lapl,data.dim,A);
250
+ data.Q = MT * (A * M);
251
+ //#ifdef EXTREME_VERBOSE
252
+ // cout<<"QIJV=["<<endl;print_ijv(data.Q,1);cout<<endl<<"];"<<
253
+ // endl<<"Q=sparse(QIJV(:,1),QIJV(:,2),QIJV(:,3),"<<
254
+ // data.Q.rows()<<","<<data.Q.cols()<<");"<<endl;
255
+ //#endif
256
+
257
+ // Always do dynamics precomputation so we can hot-switch
258
+ //if(data.with_dynamics)
259
+ //{
260
+ // Build cotangent laplacian
261
+ SparseMatrix<double> Mass;
262
+ //printf("massmatrix()\n");
263
+ massmatrix(V,F,(F.cols()>3?MASSMATRIX_TYPE_BARYCENTRIC:MASSMATRIX_TYPE_VORONOI),Mass);
264
+ //cout<<"MIJV=["<<endl;print_ijv(Mass,1);cout<<endl<<"];"<<
265
+ // endl<<"M=sparse(MIJV(:,1),MIJV(:,2),MIJV(:,3),"<<
266
+ // Mass.rows()<<","<<Mass.cols()<<");"<<endl;
267
+ //speye(data.n,Mass);
268
+ SparseMatrix<double> Mass_rep;
269
+ repdiag(Mass,data.dim,Mass_rep);
270
+
271
+ // Multiply either side by weights matrix (should be dense)
272
+ data.Mass_tilde = MT * Mass_rep * M;
273
+ MatrixXd ones(data.dim*data.n,data.dim);
274
+ for(int i = 0;i<data.n;i++)
275
+ {
276
+ for(int d = 0;d<data.dim;d++)
277
+ {
278
+ ones(i+d*data.n,d) = 1;
279
+ }
280
+ }
281
+ data.fgrav = MT * (Mass_rep * ones);
282
+ data.fext = MatrixXS::Zero(MT.rows(),1);
283
+ //data.fgrav = MT * (ones);
284
+ //}
285
+
286
+
287
+ // This may/should be superfluous
288
+ //printf("is_symmetric()\n");
289
+ if(!is_symmetric(data.Q))
290
+ {
291
+ //printf("Fixing symmetry...\n");
292
+ // "Fix" symmetry
293
+ LbsMatrixType QT = data.Q.transpose();
294
+ LbsMatrixType Q_copy = data.Q;
295
+ data.Q = 0.5*(Q_copy+QT);
296
+ // Check that ^^^ this really worked. It doesn't always
297
+ //assert(is_symmetric(*Q));
298
+ }
299
+
300
+ //printf("arap_dof_precomputation() succeeded... so far...\n");
301
+ verbose("Number of handles: %i\n", data.m);
302
+ return true;
303
+ }
304
+
305
+ /////////////////////////////////////////////////////////////////////////
306
+ //
307
+ // STATIC FUNCTIONS (These should be removed or properly defined)
308
+ //
309
+ /////////////////////////////////////////////////////////////////////////
310
+ namespace igl
311
+ {
312
+ // returns maximal difference of 'blok' from scalar times 3x3 identity:
313
+ template <typename SSCALAR>
314
+ inline static SSCALAR maxBlokErr(const Eigen::Matrix3f &blok)
315
+ {
316
+ SSCALAR mD;
317
+ SSCALAR value = blok(0,0);
318
+ SSCALAR diff1 = fabs(blok(1,1) - value);
319
+ SSCALAR diff2 = fabs(blok(2,2) - value);
320
+ if (diff1 > diff2) mD = diff1;
321
+ else mD = diff2;
322
+
323
+ for (int v=0; v<3; v++)
324
+ {
325
+ for (int w=0; w<3; w++)
326
+ {
327
+ if (v == w)
328
+ {
329
+ continue;
330
+ }
331
+ if (mD < fabs(blok(v, w)))
332
+ {
333
+ mD = fabs(blok(v, w));
334
+ }
335
+ }
336
+ }
337
+
338
+ return mD;
339
+ }
340
+
341
+ // converts CSM_M_SSCALAR[0], CSM_M_SSCALAR[1], CSM_M_SSCALAR[2] into one
342
+ // "condensed" matrix CSM while checking we're not losing any information by
343
+ // this process; specifically, returns maximal difference from scaled 3x3
344
+ // identity blocks, which should be pretty small number
345
+ template <typename MatrixXS>
346
+ static typename MatrixXS::Scalar condense_CSM(
347
+ const std::vector<MatrixXS> &CSM_M_SSCALAR,
348
+ int numBones,
349
+ int dim,
350
+ MatrixXS &CSM)
351
+ {
352
+ const int numRows = CSM_M_SSCALAR[0].rows();
353
+ assert(CSM_M_SSCALAR[0].cols() == dim*(dim+1)*numBones);
354
+ assert(CSM_M_SSCALAR[1].cols() == dim*(dim+1)*numBones);
355
+ assert(CSM_M_SSCALAR[2].cols() == dim*(dim+1)*numBones);
356
+ assert(CSM_M_SSCALAR[1].rows() == numRows);
357
+ assert(CSM_M_SSCALAR[2].rows() == numRows);
358
+
359
+ const int numCols = (dim + 1)*numBones;
360
+ CSM.resize(numRows, numCols);
361
+
362
+ typedef typename MatrixXS::Scalar SSCALAR;
363
+ SSCALAR maxDiff = 0.0f;
364
+
365
+ for (int r=0; r<numRows; r++)
366
+ {
367
+ for (int coord=0; coord<dim+1; coord++)
368
+ {
369
+ for (int b=0; b<numBones; b++)
370
+ {
371
+ // this is just a test if we really have a multiple of 3x3 identity
372
+ Eigen::Matrix3f blok;
373
+ for (int v=0; v<3; v++)
374
+ {
375
+ for (int w=0; w<3; w++)
376
+ {
377
+ blok(v,w) = CSM_M_SSCALAR[v](r, coord*(numBones*dim) + b + w*numBones);
378
+ }
379
+ }
380
+
381
+ //SSCALAR value[3];
382
+ //for (int v=0; v<3; v++)
383
+ // CSM_M_SSCALAR[v](r, coord*(numBones*dim) + b + v*numBones);
384
+
385
+ SSCALAR mD = maxBlokErr<SSCALAR>(blok);
386
+ if (mD > maxDiff) maxDiff = mD;
387
+
388
+ // use the first value:
389
+ CSM(r, coord*numBones + b) = blok(0,0);
390
+ }
391
+ }
392
+ }
393
+
394
+ return maxDiff;
395
+ }
396
+
397
+ // splits x_0, ... , x_dim coordinates in column vector 'L' into a numBones*(dimp1) x dim matrix 'Lsep';
398
+ // assumes 'Lsep' has already been preallocated
399
+ //
400
+ // is this the same as uncolumnize? no.
401
+ template <typename MatL, typename MatLsep>
402
+ static void splitColumns(
403
+ const MatL &L,
404
+ int numBones,
405
+ int dim,
406
+ int dimp1,
407
+ MatLsep &Lsep)
408
+ {
409
+ assert(L.cols() == 1);
410
+ assert(L.rows() == dim*(dimp1)*numBones);
411
+
412
+ assert(Lsep.rows() == (dimp1)*numBones && Lsep.cols() == dim);
413
+
414
+ for (int b=0; b<numBones; b++)
415
+ {
416
+ for (int coord=0; coord<dimp1; coord++)
417
+ {
418
+ for (int c=0; c<dim; c++)
419
+ {
420
+ Lsep(coord*numBones + b, c) = L(coord*numBones*dim + c*numBones + b, 0);
421
+ }
422
+ }
423
+ }
424
+ }
425
+
426
+
427
+ // the inverse of splitColumns, i.e., takes numBones*(dimp1) x dim matrix 'Lsep' and merges the dimensions
428
+ // into columns vector 'L' (which is assumed to be already allocated):
429
+ //
430
+ // is this the same as columnize? no.
431
+ template <typename MatrixXS>
432
+ static void mergeColumns(const MatrixXS &Lsep, int numBones, int dim, int dimp1, MatrixXS &L)
433
+ {
434
+ assert(L.cols() == 1);
435
+ assert(L.rows() == dim*(dimp1)*numBones);
436
+
437
+ assert(Lsep.rows() == (dimp1)*numBones && Lsep.cols() == dim);
438
+
439
+ for (int b=0; b<numBones; b++)
440
+ {
441
+ for (int coord=0; coord<dimp1; coord++)
442
+ {
443
+ for (int c=0; c<dim; c++)
444
+ {
445
+ L(coord*numBones*dim + c*numBones + b, 0) = Lsep(coord*numBones + b, c);
446
+ }
447
+ }
448
+ }
449
+ }
450
+
451
+ // converts "Solve1" the "rotations" part of FullSolve matrix (the first part)
452
+ // into one "condensed" matrix CSolve1 while checking we're not losing any
453
+ // information by this process; specifically, returns maximal difference from
454
+ // scaled 3x3 identity blocks, which should be pretty small number
455
+ template <typename MatrixXS>
456
+ static typename MatrixXS::Scalar condense_Solve1(MatrixXS &Solve1, int numBones, int numGroups, int dim, MatrixXS &CSolve1)
457
+ {
458
+ assert(Solve1.rows() == dim*(dim + 1)*numBones);
459
+ assert(Solve1.cols() == dim*dim*numGroups);
460
+
461
+ typedef typename MatrixXS::Scalar SSCALAR;
462
+ SSCALAR maxDiff = 0.0f;
463
+
464
+ CSolve1.resize((dim + 1)*numBones, dim*numGroups);
465
+ for (int rowCoord=0; rowCoord<dim+1; rowCoord++)
466
+ {
467
+ for (int b=0; b<numBones; b++)
468
+ {
469
+ for (int colCoord=0; colCoord<dim; colCoord++)
470
+ {
471
+ for (int g=0; g<numGroups; g++)
472
+ {
473
+ Eigen::Matrix3f blok;
474
+ for (int r=0; r<3; r++)
475
+ {
476
+ for (int c=0; c<3; c++)
477
+ {
478
+ blok(r, c) = Solve1(rowCoord*numBones*dim + r*numBones + b, colCoord*numGroups*dim + c*numGroups + g);
479
+ }
480
+ }
481
+
482
+ SSCALAR mD = maxBlokErr<SSCALAR>(blok);
483
+ if (mD > maxDiff) maxDiff = mD;
484
+
485
+ CSolve1(rowCoord*numBones + b, colCoord*numGroups + g) = blok(0,0);
486
+ }
487
+ }
488
+ }
489
+ }
490
+
491
+ return maxDiff;
492
+ }
493
+ }
494
+
495
+ template <typename LbsMatrixType, typename SSCALAR>
496
+ IGL_INLINE bool igl::arap_dof_recomputation(
497
+ const Eigen::Matrix<int,Eigen::Dynamic,1> & fixed_dim,
498
+ const Eigen::SparseMatrix<double> & A_eq,
499
+ ArapDOFData<LbsMatrixType, SSCALAR> & data)
500
+ {
501
+ using namespace Eigen;
502
+ typedef Matrix<SSCALAR, Dynamic, Dynamic> MatrixXS;
503
+
504
+ LbsMatrixType * Q;
505
+ LbsMatrixType Qdyn;
506
+ if(data.with_dynamics)
507
+ {
508
+ // multiply by 1/timestep and to quadratic coefficients matrix
509
+ // Might be missing a 0.5 here
510
+ LbsMatrixType Q_copy = data.Q;
511
+ Qdyn = Q_copy + (1.0/(data.h*data.h))*data.Mass_tilde;
512
+ Q = &Qdyn;
513
+
514
+ // This may/should be superfluous
515
+ //printf("is_symmetric()\n");
516
+ if(!is_symmetric(*Q))
517
+ {
518
+ //printf("Fixing symmetry...\n");
519
+ // "Fix" symmetry
520
+ LbsMatrixType QT = (*Q).transpose();
521
+ LbsMatrixType Q_copy = *Q;
522
+ *Q = 0.5*(Q_copy+QT);
523
+ // Check that ^^^ this really worked. It doesn't always
524
+ //assert(is_symmetric(*Q));
525
+ }
526
+ }else
527
+ {
528
+ Q = &data.Q;
529
+ }
530
+
531
+ assert((int)data.CSM_M.size() == data.dim);
532
+ assert(A_eq.cols() == data.m*data.dim*(data.dim+1));
533
+ data.fixed_dim = fixed_dim;
534
+
535
+ if(fixed_dim.size() > 0)
536
+ {
537
+ assert(fixed_dim.maxCoeff() < data.m*data.dim*(data.dim+1));
538
+ assert(fixed_dim.minCoeff() >= 0);
539
+ }
540
+
541
+ #ifdef EXTREME_VERBOSE
542
+ cout<<"data.fixed_dim=["<<endl<<data.fixed_dim<<endl<<"]+1;"<<endl;
543
+ #endif
544
+
545
+ // Compute dense solve matrix (alternative of matrix factorization)
546
+ //printf("kkt_inverse()\n");
547
+ MatrixXd Qfull(*Q);
548
+ MatrixXd A_eqfull(A_eq);
549
+ MatrixXd M_Solve;
550
+
551
+ double timer0_start = get_seconds_hires();
552
+ bool use_lu = data.effective_dim != 2;
553
+ //use_lu = false;
554
+ //printf("use_lu: %s\n",(use_lu?"TRUE":"FALSE"));
555
+ kkt_inverse(Qfull, A_eqfull, use_lu,M_Solve);
556
+ double timer0_end = get_seconds_hires();
557
+ verbose("Bob timing: %.20f\n", (timer0_end - timer0_start)*1000.0);
558
+
559
+ // Precompute full solve matrix:
560
+ const int fsRows = data.m * data.dim * (data.dim + 1); // 12 * number_of_bones
561
+ const int fsCols1 = data.M_KG.cols(); // 9 * number_of_posConstraints
562
+ const int fsCols2 = A_eq.rows(); // number_of_posConstraints
563
+ data.M_FullSolve.resize(fsRows, fsCols1 + fsCols2);
564
+ // note the magical multiplicative constant "-0.5", I've no idea why it has
565
+ // to be there :)
566
+ data.M_FullSolve <<
567
+ (-0.5 * M_Solve.block(0, 0, fsRows, fsRows) * data.M_KG).template cast<SSCALAR>(),
568
+ M_Solve.block(0, fsRows, fsRows, fsCols2).template cast<SSCALAR>();
569
+
570
+ if(data.with_dynamics)
571
+ {
572
+ printf(
573
+ "---------------------------------------------------------------------\n"
574
+ "\n\n\nWITH DYNAMICS recomputation\n\n\n"
575
+ "---------------------------------------------------------------------\n"
576
+ );
577
+ // Also need to save Π1 before it gets multiplied by Ktilde (aka M_KG)
578
+ data.Pi_1 = M_Solve.block(0, 0, fsRows, fsRows).template cast<SSCALAR>();
579
+ }
580
+
581
+ // Precompute condensed matrices,
582
+ // first CSM:
583
+ std::vector<MatrixXS> CSM_M_SSCALAR;
584
+ CSM_M_SSCALAR.resize(data.dim);
585
+ for (int i=0; i<data.dim; i++) CSM_M_SSCALAR[i] = data.CSM_M[i].template cast<SSCALAR>();
586
+ SSCALAR maxErr1 = condense_CSM(CSM_M_SSCALAR, data.m, data.dim, data.CSM);
587
+ verbose("condense_CSM maxErr = %.15f (this should be close to zero)\n", maxErr1);
588
+ assert(fabs(maxErr1) < 1e-5);
589
+
590
+ // and then solveBlock1:
591
+ // number of groups
592
+ const int k = data.CSM_M[0].rows()/data.dim;
593
+ MatrixXS SolveBlock1 = data.M_FullSolve.block(0, 0, data.M_FullSolve.rows(), data.dim * data.dim * k);
594
+ SSCALAR maxErr2 = condense_Solve1(SolveBlock1, data.m, k, data.dim, data.CSolveBlock1);
595
+ verbose("condense_Solve1 maxErr = %.15f (this should be close to zero)\n", maxErr2);
596
+ assert(fabs(maxErr2) < 1e-5);
597
+
598
+ return true;
599
+ }
600
+
601
+ template <typename LbsMatrixType, typename SSCALAR>
602
+ IGL_INLINE bool igl::arap_dof_update(
603
+ const ArapDOFData<LbsMatrixType, SSCALAR> & data,
604
+ const Eigen::Matrix<double,Eigen::Dynamic,1> & B_eq,
605
+ const Eigen::MatrixXd & L0,
606
+ const int max_iters,
607
+ const double
608
+ #ifdef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
609
+ tol,
610
+ #else
611
+ /*tol*/,
612
+ #endif
613
+ Eigen::MatrixXd & L
614
+ )
615
+ {
616
+ using namespace Eigen;
617
+ typedef Matrix<SSCALAR, Dynamic, Dynamic> MatrixXS;
618
+ #ifdef ARAP_GLOBAL_TIMING
619
+ double timer_start = get_seconds_hires();
620
+ #endif
621
+
622
+ // number of dimensions
623
+ assert((int)data.CSM_M.size() == data.dim);
624
+ assert((int)L0.size() == (data.m)*data.dim*(data.dim+1));
625
+ assert(max_iters >= 0);
626
+ assert(tol >= 0);
627
+
628
+ // timing variables
629
+ double
630
+ sec_start,
631
+ sec_covGather,
632
+ sec_fitRotations,
633
+ //sec_rhs,
634
+ sec_prepMult,
635
+ sec_solve, sec_end;
636
+
637
+ assert(L0.cols() == 1);
638
+ #ifdef EXTREME_VERBOSE
639
+ cout<<"dim="<<data.dim<<";"<<endl;
640
+ cout<<"m="<<data.m<<";"<<endl;
641
+ #endif
642
+
643
+ // number of groups
644
+ const int k = data.CSM_M[0].rows()/data.dim;
645
+ for(int i = 0;i<data.dim;i++)
646
+ {
647
+ assert(data.CSM_M[i].rows()/data.dim == k);
648
+ }
649
+ #ifdef EXTREME_VERBOSE
650
+ cout<<"k="<<k<<";"<<endl;
651
+ #endif
652
+
653
+ // resize output and initialize with initial guess
654
+ L = L0;
655
+ #ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
656
+ // Keep track of last solution
657
+ MatrixXS L_prev;
658
+ #endif
659
+ // We will be iterating on L_SSCALAR, only at the end we convert back to double
660
+ MatrixXS L_SSCALAR = L.cast<SSCALAR>();
661
+
662
+ int iters = 0;
663
+ #ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
664
+ double max_diff = tol+1;
665
+ #endif
666
+
667
+ MatrixXS S(k*data.dim,data.dim);
668
+ MatrixXS R(data.dim,data.dim*k);
669
+ Eigen::Matrix<SSCALAR,Eigen::Dynamic,1> Rcol(data.dim * data.dim * k);
670
+ Matrix<SSCALAR,Dynamic,1> B_eq_SSCALAR = B_eq.cast<SSCALAR>();
671
+ Matrix<SSCALAR,Dynamic,1> B_eq_fix_SSCALAR;
672
+ Matrix<SSCALAR,Dynamic,1> L0SSCALAR = L0.cast<SSCALAR>();
673
+ slice(L0SSCALAR, data.fixed_dim, B_eq_fix_SSCALAR);
674
+ //MatrixXS rhsFull(Rcol.rows() + B_eq.rows() + B_eq_fix_SSCALAR.rows(), 1);
675
+
676
+ MatrixXS Lsep(data.m*(data.dim + 1), 3);
677
+ const MatrixXS L_part2 =
678
+ data.M_FullSolve.block(0, Rcol.rows(), data.M_FullSolve.rows(), B_eq_SSCALAR.rows()) * B_eq_SSCALAR;
679
+ const MatrixXS L_part3 =
680
+ data.M_FullSolve.block(0, Rcol.rows() + B_eq_SSCALAR.rows(), data.M_FullSolve.rows(), B_eq_fix_SSCALAR.rows()) * B_eq_fix_SSCALAR;
681
+ MatrixXS L_part2and3 = L_part2 + L_part3;
682
+
683
+ // preallocate workspace variables:
684
+ MatrixXS Rxyz(k*data.dim, data.dim);
685
+ MatrixXS L_part1xyz((data.dim + 1) * data.m, data.dim);
686
+ MatrixXS L_part1(data.dim * (data.dim + 1) * data.m, 1);
687
+
688
+ #ifdef ARAP_GLOBAL_TIMING
689
+ double timer_prepFinished = get_seconds_hires();
690
+ #endif
691
+
692
+ #ifdef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
693
+ while(iters < max_iters)
694
+ #else
695
+ while(iters < max_iters && max_diff > tol)
696
+ #endif
697
+ {
698
+ if(data.print_timings)
699
+ {
700
+ sec_start = get_seconds_hires();
701
+ }
702
+
703
+ #ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
704
+ L_prev = L_SSCALAR;
705
+ #endif
706
+ ///////////////////////////////////////////////////////////////////////////
707
+ // Local step: Fix positions, fit rotations
708
+ ///////////////////////////////////////////////////////////////////////////
709
+
710
+ // Gather covariance matrices
711
+
712
+ splitColumns(L_SSCALAR, data.m, data.dim, data.dim + 1, Lsep);
713
+
714
+ S = data.CSM * Lsep;
715
+ // interestingly, this doesn't seem to be so slow, but
716
+ //MKL is still 2x faster (probably due to AVX)
717
+ //#ifdef IGL_ARAP_DOF_DOUBLE_PRECISION_SOLVE
718
+ // MKL_matMatMult_double(S, data.CSM, Lsep);
719
+ //#else
720
+ // MKL_matMatMult_single(S, data.CSM, Lsep);
721
+ //#endif
722
+
723
+ if(data.print_timings)
724
+ {
725
+ sec_covGather = get_seconds_hires();
726
+ }
727
+
728
+ #ifdef EXTREME_VERBOSE
729
+ cout<<"S=["<<endl<<S<<endl<<"];"<<endl;
730
+ #endif
731
+ // Fit rotations to covariance matrices
732
+ if(data.effective_dim == 2)
733
+ {
734
+ fit_rotations_planar(S,R);
735
+ }else
736
+ {
737
+ #ifdef __SSE__ // fit_rotations_SSE will convert to float if necessary
738
+ fit_rotations_SSE(S,R);
739
+ #else
740
+ fit_rotations(S,false,R);
741
+ #endif
742
+ }
743
+
744
+ #ifdef EXTREME_VERBOSE
745
+ cout<<"R=["<<endl<<R<<endl<<"];"<<endl;
746
+ #endif
747
+
748
+ if(data.print_timings)
749
+ {
750
+ sec_fitRotations = get_seconds_hires();
751
+ }
752
+
753
+ ///////////////////////////////////////////////////////////////////////////
754
+ // "Global" step: fix rotations per mesh vertex, solve for
755
+ // linear transformations at handles
756
+ ///////////////////////////////////////////////////////////////////////////
757
+
758
+ // all this shuffling is retarded and not completely negligible time-wise;
759
+ // TODO: change fit_rotations_XXX so it returns R in the format ready for
760
+ // CSolveBlock1 multiplication
761
+ columnize(R, k, 2, Rcol);
762
+ #ifdef EXTREME_VERBOSE
763
+ cout<<"Rcol=["<<endl<<Rcol<<endl<<"];"<<endl;
764
+ #endif
765
+ splitColumns(Rcol, k, data.dim, data.dim, Rxyz);
766
+
767
+ if(data.print_timings)
768
+ {
769
+ sec_prepMult = get_seconds_hires();
770
+ }
771
+
772
+ L_part1xyz = data.CSolveBlock1 * Rxyz;
773
+ //#ifdef IGL_ARAP_DOF_DOUBLE_PRECISION_SOLVE
774
+ // MKL_matMatMult_double(L_part1xyz, data.CSolveBlock1, Rxyz);
775
+ //#else
776
+ // MKL_matMatMult_single(L_part1xyz, data.CSolveBlock1, Rxyz);
777
+ //#endif
778
+ mergeColumns(L_part1xyz, data.m, data.dim, data.dim + 1, L_part1);
779
+
780
+ if(data.with_dynamics)
781
+ {
782
+ // Consider reordering or precomputing matrix multiplications
783
+ MatrixXS L_part1_dyn(data.dim * (data.dim + 1) * data.m, 1);
784
+ // Eigen can't parse this:
785
+ //L_part1_dyn =
786
+ // -(2.0/(data.h*data.h)) * data.Pi_1 * data.Mass_tilde * data.L0 +
787
+ // (1.0/(data.h*data.h)) * data.Pi_1 * data.Mass_tilde * data.Lm1;
788
+ // -1.0 because we've moved these linear terms to the right hand side
789
+ //MatrixXS temp = -1.0 *
790
+ // ((-2.0/(data.h*data.h)) * data.L0.array() +
791
+ // (1.0/(data.h*data.h)) * data.Lm1.array()).matrix();
792
+ //MatrixXS temp = -1.0 *
793
+ // ( (-1.0/(data.h*data.h)) * data.L0.array() +
794
+ // (1.0/(data.h*data.h)) * data.Lm1.array()
795
+ // (-1.0/(data.h*data.h)) * data.L0.array() +
796
+ // ).matrix();
797
+ //Lvel0 = (1.0/(data.h)) * data.Lm1.array() - data.L0.array();
798
+ MatrixXS temp = -1.0 *
799
+ ( (-1.0/(data.h*data.h)) * data.L0.array() +
800
+ (1.0/(data.h)) * data.Lvel0.array()
801
+ ).matrix();
802
+ MatrixXd temp_d = temp.template cast<double>();
803
+
804
+ MatrixXd temp_g = data.fgrav*(data.grav_mag*data.grav_dir);
805
+
806
+ assert(data.fext.rows() == temp_g.rows());
807
+ assert(data.fext.cols() == temp_g.cols());
808
+ MatrixXd temp2 = data.Mass_tilde * temp_d + temp_g + data.fext.template cast<double>();
809
+ MatrixXS temp2_f = temp2.template cast<SSCALAR>();
810
+ L_part1_dyn = data.Pi_1 * temp2_f;
811
+ L_part1.array() = L_part1.array() + L_part1_dyn.array();
812
+ }
813
+
814
+ //L_SSCALAR = L_part1 + L_part2and3;
815
+ assert(L_SSCALAR.rows() == L_part1.rows() && L_SSCALAR.rows() == L_part2and3.rows());
816
+ for (int i=0; i<L_SSCALAR.rows(); i++)
817
+ {
818
+ L_SSCALAR(i, 0) = L_part1(i, 0) + L_part2and3(i, 0);
819
+ }
820
+
821
+ #ifdef EXTREME_VERBOSE
822
+ cout<<"L=["<<endl<<L<<endl<<"];"<<endl;
823
+ #endif
824
+
825
+ if(data.print_timings)
826
+ {
827
+ sec_solve = get_seconds_hires();
828
+ }
829
+
830
+ #ifndef IGL_ARAP_DOF_FIXED_ITERATIONS_COUNT
831
+ // Compute maximum absolute difference with last iteration's solution
832
+ max_diff = (L_SSCALAR-L_prev).eval().array().abs().matrix().maxCoeff();
833
+ #endif
834
+ iters++;
835
+
836
+ if(data.print_timings)
837
+ {
838
+ sec_end = get_seconds_hires();
839
+ #ifndef WIN32
840
+ // trick to get sec_* variables to compile without warning on mac
841
+ if(false)
842
+ #endif
843
+ printf(
844
+ "\ntotal iteration time = %f "
845
+ "[local: covGather = %f, "
846
+ "fitRotations = %f, "
847
+ "global: prep = %f, "
848
+ "solve = %f, "
849
+ "error = %f [ms]]\n",
850
+ (sec_end - sec_start)*1000.0,
851
+ (sec_covGather - sec_start)*1000.0,
852
+ (sec_fitRotations - sec_covGather)*1000.0,
853
+ (sec_prepMult - sec_fitRotations)*1000.0,
854
+ (sec_solve - sec_prepMult)*1000.0,
855
+ (sec_end - sec_solve)*1000.0 );
856
+ }
857
+ }
858
+
859
+
860
+ L = L_SSCALAR.template cast<double>();
861
+ assert(L.cols() == 1);
862
+
863
+ #ifdef ARAP_GLOBAL_TIMING
864
+ double timer_finito = get_seconds_hires();
865
+ printf(
866
+ "ARAP preparation = %f, "
867
+ "all %i iterations = %f [ms]\n",
868
+ (timer_prepFinished - timer_start)*1000.0,
869
+ max_iters,
870
+ (timer_finito - timer_prepFinished)*1000.0);
871
+ #endif
872
+
873
+ return true;
874
+ }
875
+
876
+ #ifdef IGL_STATIC_LIBRARY
877
+ // Explicit template instantiation
878
+ template bool igl::arap_dof_update<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double>(ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, int, double, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
879
+ template bool igl::arap_dof_recomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double>(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::SparseMatrix<double, 0, int> const&, ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double>&);
880
+ template bool igl::arap_dof_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, double>&);
881
+ template bool igl::arap_dof_update<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float>(igl::ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, int, double, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
882
+ template bool igl::arap_dof_recomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float>(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::SparseMatrix<double, 0, int> const&, igl::ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float>&);
883
+ template bool igl::arap_dof_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, igl::ArapDOFData<Eigen::Matrix<double, -1, -1, 0, -1, -1>, float>&);
884
+ #endif
vendor/libigl/include/igl/arap_dof.h ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ARAP_ENERGY_TYPE_DOF_H
9
+ #define IGL_ARAP_ENERGY_TYPE_DOF_H
10
+ #include "igl_inline.h"
11
+
12
+ #include <Eigen/Dense>
13
+ #include <Eigen/Sparse>
14
+ #include "ARAPEnergyType.h"
15
+ #include <vector>
16
+
17
+ namespace igl
18
+ {
19
+ // Caller example:
20
+ //
21
+ // Once:
22
+ // arap_dof_precomputation(...)
23
+ //
24
+ // Each frame:
25
+ // while(not satisfied)
26
+ // arap_dof_update(...)
27
+ // end
28
+
29
+ template <typename LbsMatrixType, typename SSCALAR>
30
+ struct ArapDOFData;
31
+
32
+ ///////////////////////////////////////////////////////////////////////////
33
+ //
34
+ // Arap DOF precomputation consists of two parts the computation. The first is
35
+ // that which depends solely on the mesh (V,F), the linear blend skinning
36
+ // weights (M) and the groups G. Then there's the part that depends on the
37
+ // previous precomputation and the list of free and fixed vertices.
38
+ //
39
+ ///////////////////////////////////////////////////////////////////////////
40
+
41
+
42
+ // The code and variables differ from the description in Section 3 of "Fast
43
+ // Automatic Skinning Transformations" by [Jacobson et al. 2012]
44
+ //
45
+ // Here is a useful conversion table:
46
+ //
47
+ // [article] [code]
48
+ // S = \tilde{K} T S = CSM * Lsep
49
+ // S --> R S --> R --shuffled--> Rxyz
50
+ // Gamma_solve RT = Pi_1 \tilde{K} RT L_part1xyz = CSolveBlock1 * Rxyz
51
+ // Pi_1 \tilde{K} CSolveBlock1
52
+ // Peq = [T_full; P_pos]
53
+ // T_full B_eq_fix <--- L0
54
+ // P_pos B_eq
55
+ // Pi_2 * P_eq = Lpart2and3 = Lpart2 + Lpart3
56
+ // Pi_2_left T_full + Lpart3 = M_fullsolve(right) * B_eq_fix
57
+ // Pi_2_right P_pos Lpart2 = M_fullsolve(left) * B_eq
58
+ // T = [Pi_1 Pi_2] [\tilde{K}TRT P_eq] L = Lpart1 + Lpart2and3
59
+ //
60
+
61
+ // Precomputes the system we are going to optimize. This consists of building
62
+ // constructor matrices (to compute covariance matrices from transformations
63
+ // and to build the poisson solve right hand side from rotation matrix entries)
64
+ // and also prefactoring the poisson system.
65
+ //
66
+ // Inputs:
67
+ // V #V by dim list of vertex positions
68
+ // F #F by {3|4} list of face indices
69
+ // M #V * dim by #handles * dim * (dim+1) matrix such that
70
+ // new_V(:) = LBS(V,W,A) = reshape(M * A,size(V)), where A is a column
71
+ // vectors formed by the entries in each handle's dim by dim+1
72
+ // transformation matrix. Specifcally, A =
73
+ // reshape(permute(Astack,[3 1 2]),n*dim*(dim+1),1)
74
+ // or A = [Lxx;Lyx;Lxy;Lyy;tx;ty], and likewise for other dim
75
+ // if Astack(:,:,i) is the dim by (dim+1) transformation at handle i
76
+ // handles are ordered according to P then BE (point handles before bone
77
+ // handles)
78
+ // G #V list of group indices (1 to k) for each vertex, such that vertex i
79
+ // is assigned to group G(i)
80
+ // Outputs:
81
+ // data structure containing all necessary precomputation for calling
82
+ // arap_dof_update
83
+ // Returns true on success, false on error
84
+ //
85
+ // See also: lbs_matrix_column
86
+ template <typename LbsMatrixType, typename SSCALAR>
87
+ IGL_INLINE bool arap_dof_precomputation(
88
+ const Eigen::MatrixXd & V,
89
+ const Eigen::MatrixXi & F,
90
+ const LbsMatrixType & M,
91
+ const Eigen::Matrix<int,Eigen::Dynamic,1> & G,
92
+ ArapDOFData<LbsMatrixType, SSCALAR> & data);
93
+
94
+ // Should always be called after arap_dof_precomputation, but may be called in
95
+ // between successive calls to arap_dof_update, recomputes precomputation
96
+ // given that there are only changes in free and fixed
97
+ //
98
+ // Inputs:
99
+ // fixed_dim list of transformation element indices for fixed (or partailly
100
+ // fixed) handles: not necessarily the complement of 'free'
101
+ // NOTE: the constraints for fixed transformations still need to be
102
+ // present in A_eq
103
+ // A_eq dim*#constraint_points by m*dim*(dim+1) matrix of linear equality
104
+ // constraint coefficients. Each row corresponds to a linear constraint,
105
+ // so that A_eq * L = Beq says that the linear transformation entries in
106
+ // the column L should produce the user supplied positional constraints
107
+ // for each handle in Beq. The row A_eq(i*dim+d) corresponds to the
108
+ // constrain on coordinate d of position i
109
+ // Outputs:
110
+ // data structure containing all necessary precomputation for calling
111
+ // arap_dof_update
112
+ // Returns true on success, false on error
113
+ //
114
+ // See also: lbs_matrix_column
115
+ template <typename LbsMatrixType, typename SSCALAR>
116
+ IGL_INLINE bool arap_dof_recomputation(
117
+ const Eigen::Matrix<int,Eigen::Dynamic,1> & fixed_dim,
118
+ const Eigen::SparseMatrix<double> & A_eq,
119
+ ArapDOFData<LbsMatrixType, SSCALAR> & data);
120
+
121
+ // Optimizes the transformations attached to each weight function based on
122
+ // precomputed system.
123
+ //
124
+ // Inputs:
125
+ // data precomputation data struct output from arap_dof_precomputation
126
+ // Beq dim*#constraint_points constraint values.
127
+ // L0 #handles * dim * dim+1 list of initial guess transformation entries,
128
+ // also holds fixed transformation entries for fixed handles
129
+ // max_iters maximum number of iterations
130
+ // tol stopping criteria parameter. If variables (linear transformation
131
+ // matrix entries) change by less than 'tol' the optimization terminates,
132
+ // 0.75 (weak tolerance)
133
+ // 0.0 (extreme tolerance)
134
+ // Outputs:
135
+ // L #handles * dim * dim+1 list of final optimized transformation entries,
136
+ // allowed to be the same as L
137
+ template <typename LbsMatrixType, typename SSCALAR>
138
+ IGL_INLINE bool arap_dof_update(
139
+ const ArapDOFData<LbsMatrixType,SSCALAR> & data,
140
+ const Eigen::Matrix<double,Eigen::Dynamic,1> & B_eq,
141
+ const Eigen::MatrixXd & L0,
142
+ const int max_iters,
143
+ const double tol,
144
+ Eigen::MatrixXd & L
145
+ );
146
+
147
+ // Structure that contains fields for all precomputed data or data that needs
148
+ // to be remembered at update
149
+ template <typename LbsMatrixType, typename SSCALAR>
150
+ struct ArapDOFData
151
+ {
152
+ typedef Eigen::Matrix<SSCALAR, Eigen::Dynamic, Eigen::Dynamic> MatrixXS;
153
+ // Type of arap energy we're solving
154
+ igl::ARAPEnergyType energy;
155
+ //// LU decomposition precomptation data; note: not used by araf_dop_update
156
+ //// any more, replaced by M_FullSolve
157
+ //igl::min_quad_with_fixed_data<double> lu_data;
158
+ // List of indices of fixed transformation entries
159
+ Eigen::Matrix<int,Eigen::Dynamic,1> fixed_dim;
160
+ // List of precomputed covariance scatter matrices multiplied by lbs
161
+ // matrices
162
+ //std::vector<Eigen::SparseMatrix<double> > CSM_M;
163
+ std::vector<Eigen::MatrixXd> CSM_M;
164
+ LbsMatrixType M_KG;
165
+ // Number of mesh vertices
166
+ int n;
167
+ // Number of weight functions
168
+ int m;
169
+ // Number of dimensions
170
+ int dim;
171
+ // Effective dimensions
172
+ int effective_dim;
173
+ // List of indices into C of positional constraints
174
+ Eigen::Matrix<int,Eigen::Dynamic,1> interpolated;
175
+ std::vector<bool> free_mask;
176
+ // Full quadratic coefficients matrix before lagrangian (should be dense)
177
+ LbsMatrixType Q;
178
+
179
+
180
+ //// Solve matrix for the global step
181
+ //Eigen::MatrixXd M_Solve; // TODO: remove from here
182
+
183
+ // Full solve matrix that contains also conversion from rotations to the right hand side,
184
+ // i.e., solves Poisson transformations just from rotations and positional constraints
185
+ MatrixXS M_FullSolve;
186
+
187
+ // Precomputed condensed matrices (3x3 commutators folded to 1x1):
188
+ MatrixXS CSM;
189
+ MatrixXS CSolveBlock1;
190
+
191
+ // Print timings at each update
192
+ bool print_timings;
193
+
194
+ // Dynamics
195
+ bool with_dynamics;
196
+ // I'm hiding the extra dynamics stuff in this struct, which sort of defeats
197
+ // the purpose of this function-based coding style...
198
+
199
+ // Time step
200
+ double h;
201
+
202
+ // L0 #handles * dim * dim+1 list of transformation entries from
203
+ // previous solve
204
+ MatrixXS L0;
205
+ //// Lm1 #handles * dim * dim+1 list of transformation entries from
206
+ //// previous-previous solve
207
+ //MatrixXS Lm1;
208
+ // "Velocity"
209
+ MatrixXS Lvel0;
210
+
211
+ // #V by dim matrix of external forces
212
+ // fext
213
+ MatrixXS fext;
214
+
215
+ // Mass_tilde: MT * Mass * M
216
+ LbsMatrixType Mass_tilde;
217
+
218
+ // Force due to gravity (premultiplier)
219
+ Eigen::MatrixXd fgrav;
220
+ // Direction of gravity
221
+ Eigen::Vector3d grav_dir;
222
+ // Magnitude of gravity
223
+ double grav_mag;
224
+
225
+ // Π1 from the paper
226
+ MatrixXS Pi_1;
227
+
228
+ // Default values
229
+ ArapDOFData():
230
+ energy(igl::ARAP_ENERGY_TYPE_SPOKES),
231
+ with_dynamics(false),
232
+ h(1),
233
+ grav_dir(0,-1,0),
234
+ grav_mag(0)
235
+ {
236
+ }
237
+ };
238
+ }
239
+
240
+ #ifndef IGL_STATIC_LIBRARY
241
+ # include "arap_dof.cpp"
242
+ #endif
243
+
244
+ #endif
vendor/libigl/include/igl/arap_linear_block.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_ARAP_LINEAR_BLOCK_H
9
+ #define IGL_ARAP_LINEAR_BLOCK_H
10
+ #include "igl_inline.h"
11
+
12
+ #include <Eigen/Sparse>
13
+ #include <igl/ARAPEnergyType.h>
14
+
15
+ namespace igl
16
+ {
17
+ // ARAP_LINEAR_BLOCK constructs a block of the matrix which constructs the
18
+ // linear terms of a given arap energy. When treating rotations as knowns
19
+ // (arranged in a column) then this constructs Kd of K such that the linear
20
+ // portion of the energy is as a column:
21
+ // K * R = [Kx Z ... Ky Z ...
22
+ // Z Kx ... Z Ky ...
23
+ // ... ]
24
+ // These blocks are also used to build the "covariance scatter matrices".
25
+ // Here we want to build a scatter matrix that multiplies against positions
26
+ // (treated as known) producing covariance matrices to fit each rotation.
27
+ // Notice that in the case of the RHS of the poisson solve the rotations are
28
+ // known and the positions unknown, and vice versa for rotation fitting.
29
+ // These linear block just relate the rotations to the positions, linearly in
30
+ // each.
31
+ //
32
+ // Templates:
33
+ // MatV vertex position matrix, e.g. Eigen::MatrixXd
34
+ // MatF face index matrix, e.g. Eigen::MatrixXd
35
+ // Scalar e.g. double
36
+ // Inputs:
37
+ // V #V by dim list of initial domain positions
38
+ // F #F by #simplex size list of triangle indices into V
39
+ // d coordinate of linear constructor to build
40
+ // energy ARAPEnergyType enum value defining which energy is being used.
41
+ // See ARAPEnergyType.h for valid options and explanations.
42
+ // Outputs:
43
+ // Kd #V by #V/#F block of the linear constructor matrix corresponding to
44
+ // coordinate d
45
+ //
46
+ template <typename MatV, typename MatF, typename MatK>
47
+ IGL_INLINE void arap_linear_block(
48
+ const MatV & V,
49
+ const MatF & F,
50
+ const int d,
51
+ const igl::ARAPEnergyType energy,
52
+ MatK & Kd);
53
+ // Helper functions for each energy type
54
+ template <typename MatV, typename MatF, typename MatK>
55
+ IGL_INLINE void arap_linear_block_spokes(
56
+ const MatV & V,
57
+ const MatF & F,
58
+ const int d,
59
+ MatK & Kd);
60
+ template <typename MatV, typename MatF, typename MatK>
61
+ IGL_INLINE void arap_linear_block_spokes_and_rims(
62
+ const MatV & V,
63
+ const MatF & F,
64
+ const int d,
65
+ MatK & Kd);
66
+ template <typename MatV, typename MatF, typename MatK>
67
+ IGL_INLINE void arap_linear_block_elements(
68
+ const MatV & V,
69
+ const MatF & F,
70
+ const int d,
71
+ MatK & Kd);
72
+ }
73
+
74
+ #ifndef IGL_STATIC_LIBRARY
75
+ # include "arap_linear_block.cpp"
76
+ #endif
77
+
78
+ #endif
vendor/libigl/include/igl/average_onto_faces.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This file is part of libigl, a simple c++ geometry processing library.
2
+ //
3
+ // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4
+ //
5
+ // This Source Code Form is subject to the terms of the Mozilla Public License
6
+ // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
+ // obtain one at http://mozilla.org/MPL/2.0/.
8
+ #ifndef IGL_AVERAGE_ONTO_FACES_H
9
+ #define IGL_AVERAGE_ONTO_FACES_H
10
+ #include "igl_inline.h"
11
+
12
+ #include <Eigen/Dense>
13
+ namespace igl
14
+ {
15
+ // average_onto_vertices
16
+ // Move a scalar field defined on faces to vertices by averaging
17
+ //
18
+ // Input:
19
+ // F #F by ss list of simples/faces
20
+ // S #V by dim list of per-vertex values
21
+ // Output:
22
+ // SF #F by dim list of per-face values
23
+ template <typename DerivedF, typename DerivedS, typename DerivedSF>
24
+ IGL_INLINE void average_onto_faces(
25
+ const Eigen::MatrixBase<DerivedF> & F,
26
+ const Eigen::MatrixBase<DerivedS> & S,
27
+ Eigen::PlainObjectBase<DerivedSF> & SF);
28
+ }
29
+
30
+ #ifndef IGL_STATIC_LIBRARY
31
+ # include "average_onto_faces.cpp"
32
+ #endif
33
+
34
+ #endif