scaf.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_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. // Use a similar interface to igl::slim
  16. // Implement ready-to-use 2D version of the algorithm described in
  17. // SCAF: Simplicial Complex Augmentation Framework for Bijective Maps
  18. // Zhongshi Jiang, Scott Schaefer, Daniele Panozzo, ACM Trancaction on Graphics (Proc. SIGGRAPH Asia 2017)
  19. // For a complete implementation and customized UI, please refer to https://github.com/jiangzhongshi/scaffold-map
  20. struct SCAFData
  21. {
  22. double scaffold_factor = 10;
  23. igl::MappingEnergyType scaf_energy = igl::MappingEnergyType::SYMMETRIC_DIRICHLET;
  24. igl::MappingEnergyType slim_energy = igl::MappingEnergyType::SYMMETRIC_DIRICHLET;
  25. // Output
  26. int dim = 2;
  27. double total_energy; // scaffold + isometric
  28. double energy; // objective value
  29. long mv_num = 0, mf_num = 0;
  30. long sv_num = 0, sf_num = 0;
  31. long v_num{}, f_num = 0;
  32. Eigen::MatrixXd m_V; // input initial mesh V
  33. Eigen::MatrixXi m_T; // input initial mesh F/T
  34. // INTERNAL
  35. Eigen::MatrixXd w_uv; // whole domain uv: mesh + free vertices
  36. Eigen::MatrixXi s_T; // scaffold domain tets: scaffold tets
  37. Eigen::MatrixXi w_T;
  38. Eigen::VectorXd m_M; // mesh area or volume
  39. Eigen::VectorXd s_M; // scaffold area or volume
  40. Eigen::VectorXd w_M; // area/volume weights for whole
  41. double mesh_measure; // area or volume
  42. double proximal_p = 0;
  43. Eigen::VectorXi frame_ids;
  44. Eigen::VectorXi fixed_ids;
  45. std::map<int, Eigen::RowVectorXd> soft_cons;
  46. double soft_const_p = 1e4;
  47. Eigen::VectorXi internal_bnd;
  48. Eigen::MatrixXd rect_frame_V;
  49. // multi-chart support
  50. std::vector<int> component_sizes;
  51. std::vector<int> bnd_sizes;
  52. // reweightedARAP interior variables.
  53. bool has_pre_calc = false;
  54. Eigen::SparseMatrix<double> Dx_s, Dy_s, Dz_s;
  55. Eigen::SparseMatrix<double> Dx_m, Dy_m, Dz_m;
  56. Eigen::MatrixXd Ri_m, Ji_m, Ri_s, Ji_s;
  57. Eigen::MatrixXd W_m, W_s;
  58. };
  59. // Compute necessary information to start using SCAF
  60. // Inputs:
  61. // V #V by 3 list of mesh vertex positions
  62. // F #F by 3/3 list of mesh faces (triangles/tets)
  63. // data igl::SCAFData
  64. // slim_energy Energy type to minimize
  65. // b list of boundary indices into V (soft constraint)
  66. // bc #b by dim list of boundary conditions (soft constraint)
  67. // soft_p Soft penalty factor (can be zero)
  68. IGL_INLINE void scaf_precompute(
  69. const Eigen::MatrixXd &V,
  70. const Eigen::MatrixXi &F,
  71. const Eigen::MatrixXd &V_init,
  72. SCAFData &data,
  73. MappingEnergyType slim_energy,
  74. Eigen::VectorXi& b,
  75. Eigen::MatrixXd& bc,
  76. double soft_p);
  77. // Run iter_num iterations of SCAF, with precomputed data
  78. // Outputs:
  79. // V_o (in SLIMData): #V by dim list of mesh vertex positions
  80. IGL_INLINE Eigen::MatrixXd scaf_solve(SCAFData &data, int iter_num);
  81. }
  82. #ifndef IGL_STATIC_LIBRARY
  83. # include "scaf.cpp"
  84. #endif
  85. #endif //IGL_SCAF_H