slim.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Michael Rabinovich
  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 SLIM_H
  9. #define SLIM_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Sparse>
  13. #define SLIM_FAST
  14. #ifdef SLIM_FAST
  15. #include <igl/sparse_AtA_fast.h>
  16. #endif
  17. namespace igl
  18. {
  19. // Compute a SLIM map as derived in "Scalable Locally Injective Maps" [Rabinovich et al. 2016].
  20. struct SLIMData
  21. {
  22. // Input
  23. Eigen::MatrixXd V; // #V by 3 list of mesh vertex positions
  24. Eigen::MatrixXi F; // #F by 3/3 list of mesh faces (triangles/tets)
  25. enum SLIM_ENERGY
  26. {
  27. ARAP,
  28. LOG_ARAP,
  29. SYMMETRIC_DIRICHLET,
  30. CONFORMAL,
  31. EXP_CONFORMAL,
  32. EXP_SYMMETRIC_DIRICHLET
  33. };
  34. SLIM_ENERGY slim_energy;
  35. // Optional Input
  36. // soft constraints
  37. Eigen::VectorXi b;
  38. Eigen::MatrixXd bc;
  39. double soft_const_p;
  40. double exp_factor; // used for exponential energies, ignored otherwise
  41. bool mesh_improvement_3d; // only supported for 3d
  42. // Output
  43. Eigen::MatrixXd V_o; // #V by dim list of mesh vertex positions (dim = 2 for parametrization, 3 otherwise)
  44. double energy; // objective value
  45. // INTERNAL
  46. Eigen::VectorXd M;
  47. double mesh_area;
  48. double avg_edge_length;
  49. int v_num;
  50. int f_num;
  51. double proximal_p;
  52. Eigen::VectorXd WGL_M;
  53. Eigen::VectorXd rhs;
  54. Eigen::MatrixXd Ri,Ji;
  55. Eigen::VectorXd W_11; Eigen::VectorXd W_12; Eigen::VectorXd W_13;
  56. Eigen::VectorXd W_21; Eigen::VectorXd W_22; Eigen::VectorXd W_23;
  57. Eigen::VectorXd W_31; Eigen::VectorXd W_32; Eigen::VectorXd W_33;
  58. Eigen::SparseMatrix<double> Dx,Dy,Dz;
  59. int f_n,v_n;
  60. bool first_solve;
  61. bool has_pre_calc = false;
  62. int dim;
  63. #ifdef SLIM_FAST
  64. Eigen::SparseMatrix<double> A;
  65. Eigen::VectorXi A_data;
  66. Eigen::SparseMatrix<double> AtA;
  67. igl::sparse_AtA_fast_data AtA_data;
  68. #endif
  69. };
  70. // Compute necessary information to start using SLIM
  71. // Inputs:
  72. // V #V by 3 list of mesh vertex positions
  73. // F #F by 3/3 list of mesh faces (triangles/tets)
  74. // b list of boundary indices into V
  75. // bc #b by dim list of boundary conditions
  76. // soft_p Soft penalty factor (can be zero)
  77. // slim_energy Energy to minimize
  78. IGL_INLINE void slim_precompute(
  79. const Eigen::MatrixXd& V,
  80. const Eigen::MatrixXi& F,
  81. const Eigen::MatrixXd& V_init,
  82. SLIMData& data,
  83. SLIMData::SLIM_ENERGY slim_energy,
  84. Eigen::VectorXi& b,
  85. Eigen::MatrixXd& bc,
  86. double soft_p);
  87. // Run iter_num iterations of SLIM
  88. // Outputs:
  89. // V_o (in SLIMData): #V by dim list of mesh vertex positions
  90. IGL_INLINE Eigen::MatrixXd slim_solve(SLIMData& data, int iter_num);
  91. } // END NAMESPACE
  92. #ifndef IGL_STATIC_LIBRARY
  93. # include "slim.cpp"
  94. #endif
  95. #endif // SLIM_H