kelvinlets.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef IGL_KELVINLETS_H
  2. #define IGL_KELVINLETS_H
  3. #include <Eigen/Core>
  4. #include <array>
  5. #include "igl_inline.h"
  6. namespace igl {
  7. /// Kelvinlets brush type
  8. enum class BrushType : int
  9. {
  10. GRAB,
  11. SCALE,
  12. TWIST,
  13. PINCH,
  14. };
  15. /// Parameters for controling kelvinlets
  16. template<typename Scalar>
  17. struct KelvinletParams
  18. {
  19. const Scalar epsilon;
  20. const int scale;
  21. const BrushType brushType;
  22. std::array<Scalar, 3> ep{}, w{};
  23. KelvinletParams(const Scalar& epsilon,
  24. const int falloff,
  25. const BrushType& type)
  26. : epsilon(epsilon)
  27. , scale(falloff)
  28. , brushType(type)
  29. {
  30. static constexpr std::array<Scalar, 3> brush_scaling_params{ 1.0f,
  31. 1.1f,
  32. 1.21f };
  33. for (int i = 0; i < 3; i++) {
  34. ep[i] = epsilon * brush_scaling_params[i];
  35. }
  36. w[0] = 1;
  37. w[1] = -((ep[2] * ep[2] - ep[0] * ep[0]) / (ep[2] * ep[2] - ep[1] * ep[1]));
  38. w[2] = (ep[1] * ep[1] - ep[0] * ep[0]) / (ep[2] * ep[2] - ep[1] * ep[1]);
  39. }
  40. };
  41. /// Implements Pixar's Regularized Kelvinlets (Pixar Technical Memo #17-03):
  42. /// Sculpting Brushes based on Fundamental Solutions of Elasticity, a technique
  43. /// for real-time physically based volume sculpting of virtual elastic materials
  44. ///
  45. /// @param[in] V #V by dim list of input points in space
  46. /// @param[in] x0 dim-vector of brush tip
  47. /// @param[in] f dim-vector of brush force (translation)
  48. /// @param[in] F dim by dim matrix of brush force matrix (linear)
  49. /// @param[in] params parameters for the kelvinlet brush like brush radius, scale etc
  50. /// @param[out] X #V by dim list of output points in space
  51. template<typename DerivedV,
  52. typename Derivedx0,
  53. typename Derivedf,
  54. typename DerivedF,
  55. typename DerivedU>
  56. IGL_INLINE void kelvinlets(
  57. const Eigen::MatrixBase<DerivedV>& V,
  58. const Eigen::MatrixBase<Derivedx0>& x0,
  59. const Eigen::MatrixBase<Derivedf>& f,
  60. const Eigen::MatrixBase<DerivedF>& F,
  61. const KelvinletParams<typename DerivedV::Scalar>& params,
  62. Eigen::PlainObjectBase<DerivedU>& U);
  63. }
  64. #ifndef IGL_STATIC_LIBRARY
  65. #include "kelvinlets.cpp"
  66. #endif
  67. #endif