scaf.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Zhongshi Jiang <[email protected]>
  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_SCAF_H
  9. #define IGL_SCAF_H
  10. #include "../slim.h"
  11. #include "../igl_inline.h"
  12. #include "../MappingEnergyType.h"
  13. namespace igl
  14. {
  15. namespace triangle
  16. {
  17. /// Use a similar interface to igl::slim
  18. /// Implement ready-to-use 2D version of the algorithm described in
  19. /// SCAF: Simplicial Complex Augmentation Framework for Bijective Maps
  20. /// Zhongshi Jiang, Scott Schaefer, Daniele Panozzo, ACM Trancaction on Graphics (Proc. SIGGRAPH Asia 2017)
  21. /// For a complete implementation and customized UI, please refer to https://github.com/jiangzhongshi/scaffold-map
  22. struct SCAFData
  23. {
  24. double scaffold_factor = 10;
  25. igl::MappingEnergyType scaf_energy = igl::MappingEnergyType::SYMMETRIC_DIRICHLET;
  26. igl::MappingEnergyType slim_energy = igl::MappingEnergyType::SYMMETRIC_DIRICHLET;
  27. // Output
  28. int dim = 2;
  29. /// scaffold + isometric
  30. double total_energy;
  31. /// objective value
  32. double energy;
  33. long mv_num = 0, mf_num = 0;
  34. long sv_num = 0, sf_num = 0;
  35. long v_num{}, f_num = 0;
  36. /// input initial mesh V
  37. Eigen::MatrixXd m_V;
  38. /// input initial mesh F/T
  39. Eigen::MatrixXi m_T;
  40. // INTERNAL
  41. /// whole domain uv: mesh + free vertices
  42. Eigen::MatrixXd w_uv;
  43. /// scaffold domain tets: scaffold tets
  44. Eigen::MatrixXi s_T;
  45. Eigen::MatrixXi w_T;
  46. /// mesh area or volume
  47. Eigen::VectorXd m_M;
  48. /// scaffold area or volume
  49. Eigen::VectorXd s_M;
  50. /// area/volume weights for whole
  51. Eigen::VectorXd w_M;
  52. /// area or volume
  53. double mesh_measure = 0;
  54. double proximal_p = 0;
  55. Eigen::VectorXi frame_ids;
  56. Eigen::VectorXi fixed_ids;
  57. std::map<int, Eigen::RowVectorXd> soft_cons;
  58. double soft_const_p = 1e4;
  59. Eigen::VectorXi internal_bnd;
  60. Eigen::MatrixXd rect_frame_V;
  61. // multi-chart support
  62. std::vector<int> component_sizes;
  63. std::vector<int> bnd_sizes;
  64. // reweightedARAP interior variables.
  65. bool has_pre_calc = false;
  66. Eigen::SparseMatrix<double> Dx_s, Dy_s, Dz_s;
  67. Eigen::SparseMatrix<double> Dx_m, Dy_m, Dz_m;
  68. Eigen::MatrixXd Ri_m, Ji_m, Ri_s, Ji_s;
  69. Eigen::MatrixXd W_m, W_s;
  70. };
  71. /// Compute necessary information to start using SCAF
  72. ///
  73. /// @param[in] V #V by 3 list of mesh vertex positions
  74. /// @param[in] F #F by 3 list of mesh triangles
  75. /// @param[in] V_init #V by 2 list of initial mesh vertex positions
  76. /// @param[in,out] data resulting precomputed data
  77. /// @param[in] slim_energy Energy type to minimize
  78. /// @param[in] b list of boundary indices into V (soft constraint)
  79. /// @param[in] bc #b by dim list of boundary conditions (soft constraint)
  80. /// @param[in] soft_p Soft penalty factor (can be zero)
  81. ///
  82. /// \fileinfo
  83. IGL_INLINE void scaf_precompute(
  84. const Eigen::MatrixXd &V,
  85. const Eigen::MatrixXi &F,
  86. const Eigen::MatrixXd &V_init,
  87. const MappingEnergyType slim_energy,
  88. const Eigen::VectorXi& b,
  89. const Eigen::MatrixXd& bc,
  90. const double soft_p,
  91. triangle::SCAFData &data);
  92. /// Run iter_num iterations of SCAF, with precomputed data
  93. /// @param[in] data precomputed data
  94. /// @param[in] iter_num number of iterations to run
  95. /// @returns resulting V_o (in SLIMData): #V by dim list of mesh vertex positions
  96. IGL_INLINE Eigen::MatrixXd scaf_solve(const int iter_num, triangle::SCAFData &data);
  97. /// Set up the SCAF system L * uv = rhs, without solving it.
  98. /// @param[in] s: igl::SCAFData. Will be modified by energy and Jacobian computation.
  99. /// @param[out] L: m by m matrix
  100. /// @param[out] rhs: m by 1 vector
  101. /// with m = dim * (#V_mesh + #V_scaf - #V_frame)
  102. IGL_INLINE void scaf_system(triangle::SCAFData &s, Eigen::SparseMatrix<double> &L, Eigen::VectorXd &rhs);
  103. namespace scaf
  104. {
  105. /// Compute SCAF energy
  106. /// @param[in] s: igl::SCAFData
  107. /// @param[in] w_uv: (#V_mesh + #V_scaf) by dim matrix
  108. /// @param[in] whole: Include scaffold if true
  109. /// @returns energy
  110. IGL_INLINE double compute_energy(SCAFData &s, const Eigen::MatrixXd &w_uv, bool whole);
  111. }
  112. }
  113. }
  114. #ifndef IGL_STATIC_LIBRARY
  115. # include "scaf.cpp"
  116. #endif
  117. #endif //IGL_SCAF_H