signed_distance.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <alecjacobson@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_SIGNED_DISTANCE_H
  9. #define IGL_SIGNED_DISTANCE_H
  10. #include "igl_inline.h"
  11. #include "AABB.h"
  12. #include "WindingNumberAABB.h"
  13. #include <Eigen/Core>
  14. #include <vector>
  15. namespace igl
  16. {
  17. enum SignedDistanceType
  18. {
  19. // Use fast pseudo-normal test [Bærentzen & Aanæs 2005]
  20. SIGNED_DISTANCE_TYPE_PSEUDONORMAL = 0,
  21. SIGNED_DISTANCE_TYPE_WINDING_NUMBER = 1,
  22. SIGNED_DISTANCE_TYPE_DEFAULT = 2,
  23. SIGNED_DISTANCE_TYPE_UNSIGNED = 3,
  24. NUM_SIGNED_DISTANCE_TYPE = 4
  25. };
  26. // Computes signed distance to a mesh
  27. //
  28. // Inputs:
  29. // P #P by 3 list of query point positions
  30. // V #V by 3 list of vertex positions
  31. // F #F by ss list of triangle indices, ss should be 3 unless sign_type ==
  32. // SIGNED_DISTANCE_TYPE_UNSIGNED
  33. // sign_type method for computing distance _sign_ S
  34. // Outputs:
  35. // S #P list of smallest signed distances
  36. // I #P list of facet indices corresponding to smallest distances
  37. // C #P by 3 list of closest points
  38. // N #P by 3 list of closest normals (only set if
  39. // sign_type=SIGNED_DISTANCE_TYPE_PSEUDONORMAL)
  40. //
  41. // Known bugs: This only computes distances to triangles. So unreferenced
  42. // vertices and degenerate triangles are ignored.
  43. IGL_INLINE void signed_distance(
  44. const Eigen::MatrixXd & P,
  45. const Eigen::MatrixXd & V,
  46. const Eigen::MatrixXi & F,
  47. const SignedDistanceType sign_type,
  48. Eigen::VectorXd & S,
  49. Eigen::VectorXi & I,
  50. Eigen::MatrixXd & C,
  51. Eigen::MatrixXd & N);
  52. // Computes signed distance to mesh
  53. //
  54. // Inputs:
  55. // tree AABB acceleration tree (see AABB.h)
  56. // F #F by 3 list of triangle indices
  57. // FN #F by 3 list of triangle normals
  58. // VN #V by 3 list of vertex normals (ANGLE WEIGHTING)
  59. // EN #E by 3 list of edge normals (UNIFORM WEIGHTING)
  60. // EMAP #F*3 mapping edges in F to E
  61. // q Query point
  62. // Returns signed distance to mesh
  63. //
  64. IGL_INLINE double signed_distance_pseudonormal(
  65. const AABB<Eigen::MatrixXd,3> & tree,
  66. const Eigen::MatrixXd & V,
  67. const Eigen::MatrixXi & F,
  68. const Eigen::MatrixXd & FN,
  69. const Eigen::MatrixXd & VN,
  70. const Eigen::MatrixXd & EN,
  71. const Eigen::VectorXi & EMAP,
  72. const Eigen::RowVector3d & q);
  73. // Outputs:
  74. // s sign
  75. // sqrd squared distance
  76. // i closest primitive
  77. // c closest point
  78. // n normal
  79. IGL_INLINE void signed_distance_pseudonormal(
  80. const AABB<Eigen::MatrixXd,3> & tree,
  81. const Eigen::MatrixXd & V,
  82. const Eigen::MatrixXi & F,
  83. const Eigen::MatrixXd & FN,
  84. const Eigen::MatrixXd & VN,
  85. const Eigen::MatrixXd & EN,
  86. const Eigen::VectorXi & EMAP,
  87. const Eigen::RowVector3d & q,
  88. double & s,
  89. double & sqrd,
  90. int & i,
  91. Eigen::RowVector3d & c,
  92. Eigen::RowVector3d & n);
  93. IGL_INLINE void signed_distance_pseudonormal(
  94. const Eigen::MatrixXd & P,
  95. const Eigen::MatrixXd & V,
  96. const Eigen::MatrixXi & F,
  97. const AABB<Eigen::MatrixXd,3> & tree,
  98. const Eigen::MatrixXd & FN,
  99. const Eigen::MatrixXd & VN,
  100. const Eigen::MatrixXd & EN,
  101. const Eigen::VectorXi & EMAP,
  102. Eigen::VectorXd & S,
  103. Eigen::VectorXi & I,
  104. Eigen::MatrixXd & C,
  105. Eigen::MatrixXd & N);
  106. // Inputs:
  107. // tree AABB acceleration tree (see cgal/point_mesh_squared_distance.h)
  108. // hier Winding number evaluation hierarchy
  109. // q Query point
  110. // Returns signed distance to mesh
  111. IGL_INLINE double signed_distance_winding_number(
  112. const AABB<Eigen::MatrixXd,3> & tree,
  113. const Eigen::MatrixXd & V,
  114. const Eigen::MatrixXi & F,
  115. const igl::WindingNumberAABB<Eigen::Vector3d> & hier,
  116. const Eigen::RowVector3d & q);
  117. // Outputs:
  118. // s sign
  119. // sqrd squared distance
  120. // pp closest point and primitve
  121. IGL_INLINE void signed_distance_winding_number(
  122. const AABB<Eigen::MatrixXd,3> & tree,
  123. const Eigen::MatrixXd & V,
  124. const Eigen::MatrixXi & F,
  125. const igl::WindingNumberAABB<Eigen::Vector3d> & hier,
  126. const Eigen::RowVector3d & q,
  127. double & s,
  128. double & sqrd,
  129. int & i,
  130. Eigen::RowVector3d & c);
  131. }
  132. #ifndef IGL_STATIC_LIBRARY
  133. # include "signed_distance.cpp"
  134. #endif
  135. #endif