shapeup.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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) in row S(i,:) are "don't care"
  47. // E #E by 2 the "edges" of a mesh; used for the smoothness energy.
  48. // b #b by 1 boundary (fixed) vertices from P.
  49. // w #Set by 1 weight for each set (used in the global step)
  50. // local_projection function pointer taking (P,SC,S,projP),
  51. // 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.
  52. // Output:
  53. // sudata struct ShapeupData the data necessary to solve the system in shapeup_solve
  54. template <
  55. typename DerivedP,
  56. typename DerivedSC,
  57. typename DerivedS,
  58. typename Derivedw>
  59. IGL_INLINE bool shapeup_precomputation(const Eigen::PlainObjectBase<DerivedP>& P,
  60. const Eigen::PlainObjectBase<DerivedSC>& SC,
  61. const Eigen::PlainObjectBase<DerivedS>& S,
  62. const Eigen::PlainObjectBase<DerivedS>& E,
  63. const Eigen::PlainObjectBase<DerivedSC>& b,
  64. const Eigen::PlainObjectBase<Derivedw>& w,
  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. //NOTE: the input values in P0 don't need to correspond to prescribed values in bc; the iterations will project them automatically (by design).
  70. //P0 #P by 3 initial solution (point positions)
  71. //Output:
  72. //P the solution to the problem, corresponding to P0.
  73. template <
  74. typename DerivedP,
  75. typename DerivedSC,
  76. typename DerivedS>
  77. IGL_INLINE bool shapeup_solve(const Eigen::PlainObjectBase<DerivedP>& bc,
  78. const std::function<bool(const Eigen::PlainObjectBase<DerivedP>&, const Eigen::PlainObjectBase<DerivedSC>&, const Eigen::PlainObjectBase<DerivedS>&, Eigen::PlainObjectBase<DerivedP>&)>& local_projection,
  79. const Eigen::PlainObjectBase<DerivedP>& P0,
  80. const bool quiet,
  81. Eigen::PlainObjectBase<DerivedP>& P);
  82. }
  83. #ifndef IGL_STATIC_LIBRARY
  84. #include "shapeup.cpp"
  85. #endif
  86. #endif