shapeup.h 4.6 KB

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