SphereMeshWedge.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2025 Alec Jacobson <[email protected]>
  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_SPHERE_MESH_WEDGE_H
  9. #define IGL_SPHERE_MESH_WEDGE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// A class to compute the signed distance to a "Sphere-Mesh Wedge" as seen in
  15. /// variable radius offset surfaces or Sphere-Meshes. Each wedge is defined
  16. /// by three vertices and three radii, one at each vertex. The wedge is
  17. /// the union of all spheres at points on the triangle with radius linearly
  18. /// interpolated. See, e.g., "Sphere-Meshes for Real-Time Hand Modeling and
  19. /// Tracking" or "A Multilinear Model for Bidirectional Craniofacial
  20. /// Reconstruction" or "Sphere-Meshes: Shape Approximation using Spherical
  21. /// Quadric Error Metrics" or "Variable-Radius Offset Surface Approximation on
  22. /// the GPU".
  23. ///
  24. template <typename Scalar>
  25. class SphereMeshWedge
  26. {
  27. public:
  28. using RowVector3S = Eigen::Matrix<Scalar, 1, 3>;
  29. // Fields
  30. enum
  31. {
  32. BIG_VERTEX = 0,
  33. BIG_EDGE = 1,
  34. NO_TRIANGLE = 2,
  35. FULL = 3
  36. } flavor;
  37. Eigen::Matrix<Scalar,3,3,Eigen::RowMajor> V;
  38. Eigen::Matrix<Scalar,3,1> r;
  39. Eigen::Matrix<Scalar,3,3,Eigen::RowMajor> EV;
  40. Eigen::Matrix<Scalar,3,1> l,l2,rr,a2,il2;
  41. int max_i;
  42. Eigen::Matrix<Scalar,5,4,Eigen::RowMajor> planes;
  43. Eigen::Matrix<Scalar,3,3,Eigen::RowMajor> T;
  44. Eigen::Matrix<Scalar,3,3,Eigen::RowMajor> C;
  45. SphereMeshWedge(){}
  46. /// Constructor that takes three vertices and three radii
  47. ///
  48. /// @param V0 first vertex position
  49. /// @param V1 second vertex position
  50. /// @param V2 third vertex position
  51. /// @param r0 radius at first vertex
  52. /// @param r1 radius at second vertex
  53. /// @param r2 radius at third vertex
  54. IGL_INLINE SphereMeshWedge(
  55. const RowVector3S & V0,
  56. const RowVector3S & V1,
  57. const RowVector3S & V2,
  58. const Scalar r0,
  59. const Scalar r1,
  60. const Scalar r2);
  61. /// @param[in] p 3-vector query point
  62. /// @return signed distance to the wedge at point p
  63. IGL_INLINE Scalar operator()(const RowVector3S & p) const;
  64. private:
  65. /// Precompute planes used for determining bounded signed to the skewed
  66. /// triangular slab portion.
  67. ///
  68. /// @return true if planes are well defined (false implies this slab has
  69. /// no contribution).
  70. IGL_INLINE bool compute_planes();
  71. /// Compute the signed distance to the wedge at a point p for the edge
  72. /// (i,j)
  73. ///
  74. /// @param[in] p 3-vector query point
  75. /// @param[in] i index of first vertex (0,1,2)
  76. /// @param[in] j index of second vertex (0,1,2)
  77. IGL_INLINE Scalar round_cone_signed_distance(const RowVector3S & p, const int i, const int j) const;
  78. };
  79. }
  80. #ifndef IGL_STATIC_LIBRARY
  81. #include "SphereMeshWedge.cpp"
  82. #endif
  83. #endif