lim.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Christian Schüller <schuellchr@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_LIM_LIM_H
  9. #define IGL_LIM_LIM_H
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. namespace lim
  16. {
  17. // Computes a locally injective mapping of a triangle or tet-mesh based on
  18. // a deformation energy subject to some provided linear positional
  19. // constraints Cv-d.
  20. //
  21. // Inputs:
  22. // vertices vx3 matrix containing vertex position of the mesh
  23. // initialVertices vx3 matrix containing vertex position of initial
  24. // rest pose mesh
  25. // elements exd matrix containing vertex indices of all elements
  26. // borderVertices (only needed for 2D LSCM) vector containing indices
  27. // of border vertices
  28. // gradients (only needed for 2D Poisson) vector containing
  29. // partial derivatives of target element gradients
  30. // (structure is: [xx_0, xy_0, xx_1, xy_1, ..., xx_v,
  31. // xy_v, yx_0, yy_0, yx_1, yy_1, ..., yx_v, yy_v]')
  32. // constraintMatrix C: (c)x(v*(d-1)) sparse linear positional constraint
  33. // matrix. X an Y-coordinates are alternatingly stacked
  34. // per row (structure for triangles: [x_1, y_1, x_2,
  35. // y_2, ..., x_v,y_v])
  36. // constraintTargets d: c vector target positions
  37. // energyType type of used energy:
  38. // Dirichlet, Laplacian, Green, ARAP, LSCM, Poisson (only 2D), UniformLaplacian, Identity
  39. // tolerance max squared positional constraints error
  40. // maxIteration max number of iterations
  41. // findLocalMinima iterating until a local minima is found. If not
  42. // enabled only tolerance must be fulfilled.
  43. // enableOutput (optional) enables the output (#iteration / hessian correction / step size / positional constraints / barrier constraints / deformation energy) (default : true)
  44. // enableBarriers (optional) enables the non-flip constraints (default = true)
  45. // enableAlphaUpdate (optional) enables dynamic alpha weight adjustment (default = true)
  46. // beta (optional) steepness factor of barrier slopes (default: ARAP/LSCM = 0.01, Green = 1)
  47. // eps (optional) smallest valid triangle area (default: 1e-5 * smallest triangle)
  48. //
  49. // where:
  50. // v : # vertices
  51. // c : # linear constraints
  52. // e : # elements of mesh
  53. // d : # vertices per element (triangle = 3, tet = 4)
  54. //--------------------------------------------------------------------------
  55. // Output:
  56. // vertices vx3 matrix containing resulting vertex position of the
  57. // mesh
  58. //--------------------------------------------------------------------------
  59. // Return values:
  60. // Succeeded : Successful optimization with fulfilled tolerance
  61. // LocalMinima : Convergenged to a local minima / tolerance not fullfilled
  62. // IterationLimit : Max iteration reached before tolerance was fulfilled
  63. // Infeasible : not feasible -> has inverted elements (decrease eps?)
  64. enum Energy { Dirichlet = 0, Laplacian=1, Green=2, ARAP=3, LSCM=4, Poisson=5, UniformLaplacian=6, Identity=7 };
  65. enum State { Uninitialized = -4, Infeasible = -3, IterationLimit = -2, LocalMinima = -1, Running = 0, Succeeded = 1 };
  66. State lim(
  67. Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
  68. const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
  69. const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
  70. const Eigen::SparseMatrix<double>& constraintMatrix,
  71. const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
  72. Energy energyType,
  73. double tolerance,
  74. int maxIteration,
  75. bool findLocalMinima);
  76. State lim(
  77. Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
  78. const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
  79. const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
  80. const Eigen::SparseMatrix<double>& constraintMatrix,
  81. const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
  82. Energy energyType,
  83. double tolerance,
  84. int maxIteration,
  85. bool findLocalMinima,
  86. bool enableOuput,
  87. bool enableBarriers,
  88. bool enableAlphaUpdate,
  89. double beta,
  90. double eps);
  91. State lim(
  92. Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
  93. const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
  94. const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
  95. const std::vector<int>& borderVertices,
  96. const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
  97. const Eigen::SparseMatrix<double>& constraintMatrix,
  98. const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
  99. Energy energyType,
  100. double tolerance,
  101. int maxIteration,
  102. bool findLocalMinima);
  103. State lim(
  104. Eigen::Matrix<double,Eigen::Dynamic,3>& vertices,
  105. const Eigen::Matrix<double,Eigen::Dynamic,3>& initialVertices,
  106. const Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic>& elements,
  107. const std::vector<int>& borderVertices,
  108. const Eigen::Matrix<double,Eigen::Dynamic,1>& gradients,
  109. const Eigen::SparseMatrix<double>& constraintMatrix,
  110. const Eigen::Matrix<double,Eigen::Dynamic,1>& constraintTargets,
  111. Energy energyType,
  112. double tolerance,
  113. int maxIteration,
  114. bool findLocalMinima,
  115. bool enableOuput,
  116. bool enableBarriers,
  117. bool enableAlphaUpdate,
  118. double beta,
  119. double eps);
  120. }
  121. }
  122. #ifndef IGL_STATIC_LIBRARY
  123. # include "lim.cpp"
  124. #endif
  125. #endif