shapeup.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/shapeup_local_projections.h>
  11. #include <igl/min_quad_with_fixed.h>
  12. #include <igl/igl_inline.h>
  13. #include <igl/setdiff.h>
  14. #include <igl/cat.h>
  15. #include <Eigen/Core>
  16. #include <vector>
  17. //This file implements the following algorithm:
  18. //Boaziz et al.
  19. //Shape-Up: Shaping Discrete Geometry with Projections
  20. //Computer Graphics Forum (Proc. SGP) 31(5), 2012
  21. namespace igl
  22. {
  23. struct ShapeupData{
  24. //input data
  25. Eigen::MatrixXd P;
  26. Eigen::VectorXi SC;
  27. Eigen::MatrixXi S;
  28. Eigen::VectorXi b;
  29. int maxIterations; //referring to number of local-global pairs.
  30. double pTolerance; //algorithm stops when max(|P_k-P_{k-1}|)<pTolerance.
  31. double shapeCoeff, closeCoeff, smoothCoeff;
  32. //Internally-used matrices
  33. Eigen::SparseMatrix<double> DShape, DClose, DSmooth, Q, A, At, W;
  34. min_quad_with_fixed_data<double> solver_data;
  35. ShapeupData():
  36. maxIterations(50),
  37. pTolerance(10e-6),
  38. shapeCoeff(1.0),
  39. closeCoeff(100.0),
  40. smoothCoeff(0.0){}
  41. };
  42. //This function precomputation the necessary matrices for the ShapeUp process, and prefactorizes them.
  43. //input:
  44. // P #P by 3 point positions
  45. // SC #Set by 1 cardinalities of sets in S
  46. // S #Sets by max(SC) independent sets where the local projection applies. Values beyond column SC(i)-1 in row S(i,:) are "don't care"
  47. // E #E by 2 the "edges" of the set P; used for the smoothness energy.
  48. // b #b by 1 boundary (fixed) vertices from P.
  49. // wShape, #Set by 1
  50. // wSmooth #b by 1 weights for constraints from S and positional constraints (used in the global step)
  51. // Output:
  52. // sudata struct ShapeupData the data necessary to solve the system in shapeup_solve
  53. template <
  54. typename DerivedP,
  55. typename DerivedSC,
  56. typename DerivedS,
  57. typename Derivedw>
  58. IGL_INLINE bool shapeup_precomputation(const Eigen::PlainObjectBase<DerivedP>& P,
  59. const Eigen::PlainObjectBase<DerivedSC>& SC,
  60. const Eigen::PlainObjectBase<DerivedS>& S,
  61. const Eigen::PlainObjectBase<DerivedS>& E,
  62. const Eigen::PlainObjectBase<DerivedSC>& b,
  63. const Eigen::PlainObjectBase<Derivedw>& wShape,
  64. const Eigen::PlainObjectBase<Derivedw>& wSmooth,
  65. ShapeupData & sudata);
  66. //This function solve the shapeup project optimization. shapeup_precompute must be called before with the same sudata, or results are unpredictable
  67. //Input:
  68. //bc #b by 3 fixed point values corresonding to "b" in sudata
  69. //local_projection function pointer taking (P,SC,S,projP),
  70. // 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.
  71. //NOTE: the input values in P0 don't need to correspond to prescribed values in bc; the iterations will project them automatically (by design).
  72. //P0 #P by 3 initial solution (point positions)
  73. //sudata the ShapeUpData structure computed in shapeup_precomputation()
  74. //quietIterations flagging if to output iteration information.
  75. //Output:
  76. //P the solution to the problem, indices corresponding to P0.
  77. template <
  78. typename DerivedP,
  79. typename DerivedSC,
  80. typename DerivedS>
  81. IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase<DerivedP>& bc,
  82. const std::function<bool(const Eigen::PlainObjectBase<DerivedP>&, const Eigen::PlainObjectBase<DerivedSC>&, const Eigen::PlainObjectBase<DerivedS>&, Eigen::PlainObjectBase<DerivedP>&)>& local_projection,
  83. const Eigen::PlainObjectBase<DerivedP>& P0,
  84. const ShapeupData & sudata,
  85. const bool quietIterations,
  86. Eigen::PlainObjectBase<DerivedP>& P);
  87. }
  88. #ifndef IGL_STATIC_LIBRARY
  89. #include "shapeup.cpp"
  90. #endif
  91. #endif