signed_distance.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 Eigen::MatrixXd & P,
  81. const Eigen::MatrixXd & V,
  82. const Eigen::MatrixXi & F,
  83. const AABB<Eigen::MatrixXd,3> & tree,
  84. const Eigen::MatrixXd & FN,
  85. const Eigen::MatrixXd & VN,
  86. const Eigen::MatrixXd & EN,
  87. const Eigen::VectorXi & EMAP,
  88. Eigen::VectorXd & S,
  89. Eigen::VectorXi & I,
  90. Eigen::MatrixXd & C,
  91. Eigen::MatrixXd & N);
  92. IGL_INLINE void signed_distance_pseudonormal(
  93. const AABB<Eigen::MatrixXd,3> & tree,
  94. const Eigen::MatrixXd & V,
  95. const Eigen::MatrixXi & F,
  96. const Eigen::MatrixXd & FN,
  97. const Eigen::MatrixXd & VN,
  98. const Eigen::MatrixXd & EN,
  99. const Eigen::VectorXi & EMAP,
  100. const Eigen::RowVector3d & q,
  101. double & s,
  102. double & sqrd,
  103. int & i,
  104. Eigen::RowVector3d & c,
  105. Eigen::RowVector3d & n);
  106. IGL_INLINE void signed_distance_pseudonormal(
  107. const AABB<Eigen::MatrixXd,2> & tree,
  108. const Eigen::MatrixXd & V,
  109. const Eigen::MatrixXi & F,
  110. const Eigen::MatrixXd & FN,
  111. const Eigen::MatrixXd & VN,
  112. const Eigen::RowVector2d & q,
  113. double & s,
  114. double & sqrd,
  115. int & i,
  116. Eigen::RowVector2d & c,
  117. Eigen::RowVector2d & n);
  118. // Inputs:
  119. // tree AABB acceleration tree (see cgal/point_mesh_squared_distance.h)
  120. // hier Winding number evaluation hierarchy
  121. // q Query point
  122. // Returns signed distance to mesh
  123. IGL_INLINE double signed_distance_winding_number(
  124. const AABB<Eigen::MatrixXd,3> & tree,
  125. const Eigen::MatrixXd & V,
  126. const Eigen::MatrixXi & F,
  127. const igl::WindingNumberAABB<Eigen::Vector3d> & hier,
  128. const Eigen::RowVector3d & q);
  129. // Outputs:
  130. // s sign
  131. // sqrd squared distance
  132. // pp closest point and primitve
  133. IGL_INLINE void signed_distance_winding_number(
  134. const AABB<Eigen::MatrixXd,3> & tree,
  135. const Eigen::MatrixXd & V,
  136. const Eigen::MatrixXi & F,
  137. const igl::WindingNumberAABB<Eigen::Matrix<double,3,1> > & hier,
  138. const Eigen::Matrix<double,1,3> & q,
  139. double & s,
  140. double & sqrd,
  141. int & i,
  142. Eigen::Matrix<double,1,3> & c);
  143. IGL_INLINE void signed_distance_winding_number(
  144. const AABB<Eigen::MatrixXd,2> & tree,
  145. const Eigen::MatrixXd & V,
  146. const Eigen::MatrixXi & F,
  147. const Eigen::Matrix<double,1,2> & q,
  148. double & s,
  149. double & sqrd,
  150. int & i,
  151. Eigen::Matrix<double,1,2> & c);
  152. }
  153. #ifndef IGL_STATIC_LIBRARY
  154. # include "signed_distance.cpp"
  155. #endif
  156. #endif