slim.h 2.8 KB

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