shapeup.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Amir Vaxman <avaxman@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_SHAPEUP_H
  9. #define IGL_SHAPEUP_H
  10. #include <igl/igl_inline.h>
  11. #include <igl/setdiff.h>
  12. #include <igl/cat.h>
  13. #include <Eigen/Core>
  14. #include <vector>
  15. //This file implements the following algorithm:
  16. //Boaziz et al.
  17. //Shape-Up: Shaping Discrete Geometry with Projections
  18. //Computer Graphics Forum (Proc. SGP) 31(5), 2012
  19. namespace igl
  20. {
  21. struct ShapeupData{
  22. //input data
  23. Eigen::MatrixXd P;
  24. Eigen::VectorXi SD;
  25. Eigen::MatrixXi S;
  26. Eigen::VectorXi b;
  27. double shapeCoeff, closeCoeff;
  28. std::function<bool(const MatrixXd&, const VectorXi&, const MatrixXi&, Eigen::MatrixXd&)> local_projection;
  29. //Internally-used matrices
  30. Eigen::SparseMatrix<double> A, Q, C, E, At, W;
  31. min_quad_with_fixed_data<double> solver_data;
  32. };
  33. //This function precomputation the necessary matrices for the ShapeUp process, and prefactorizes them.
  34. //input:
  35. // P #P by 3 point positions
  36. // SC #Set by 1 cardinalities of sets in S
  37. // S #Sets by max(SC) independent sets where the local projection applies. Values beyond column SC(i) in row S(i,:) are "don't care"
  38. // b #b by 1 boundary (fixed) vertices from P.
  39. // w #Set by 1 weight for each set (used in the global step)
  40. // local_projection function pointer taking (P,SC,S,projP),
  41. // where the first three parameters are as defined, and "projP" is the output, as a #S by 3*max(SC) function in format xyzxyzxyz, and where it returns the projected points corresponding to each set in S in the same order.
  42. // shapecoeff,
  43. // closeCoeff,
  44. // smoothCoeff energy coefficients as mentioned in the paper
  45. // Output:
  46. // sudata struct ShapeupData the data necessary to solve the system in shapeup_solve
  47. template <
  48. typename DerivedP,
  49. typename DerivedSC,
  50. typename DerivedS,
  51. typename Derivedb,
  52. typename Derivedw>
  53. IGL_INLINE void shapeup_precomputation(
  54. const Eigen::PlainObjectBase<DerivedP>& P,
  55. const Eigen::PlainObjectBase<DerivedSC>& SC,
  56. const Eigen::PlainObjectBase<DerivedS>& S,
  57. const Eigen::PlainObjectBase<Derivedb>& b,
  58. const Eigen::PlainObjectBase<Derivedw>& w,
  59. const std::function<bool(const Eigen::PlainObjectBase<DerivedP>&, const Eigen::PlainObjectBase<DerivedSX>&, const Eigen::PlainObjectBase<DerivedS>&, Eigen::PlainObjectBase<Derivedb&)>& local_projection,
  60. const double shapeCoeff,
  61. const double closeCoeff,
  62. const double smoothCoeff,
  63. struct ShapeupData& sudata);
  64. //This function solve the shapeup project optimization. shapeup_precompute must be called before with the same sudata, or results are unpredictable
  65. //Input:
  66. //bc #b by 3 fixed point values corresonding to "b" in sudata
  67. //NOTE: the input values in P0 don't need to correspond to prescribed values in bc; the iterations will project them automatically (by design).
  68. //P0 #P by 3 initial solution (point positions)
  69. //maxIterations referring to number of local-global pairs.
  70. //pTolerance algorithm stops when max(|P_k-P_{k-1}|)<pTolerance.
  71. //Output:
  72. //P the solution to the problem, corresponding to P0.
  73. template <
  74. typename Derivedbc,
  75. typename DerivedP>
  76. IGL_INLINE void shapeup_compute(const Eigen::PlainObjectBase<Derivedbc>& bc,
  77. const Eigen::PlainObjectBase<DerivedP>& P0,
  78. const struct ShapeupData& sudata,
  79. const int maxIterations=50,
  80. const double pTolerance=10e-6
  81. const Eigen::PlainObjectBase<DerivedP>& P)
  82. {
  83. }
  84. }
  85. #ifndef IGL_STATIC_LIBRARY
  86. #include "shapeup.cpp"
  87. #endif
  88. #endif