signed_distance.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. SIGNED_DISTANCE_TYPE_PSEUDONORMAL = 0,
  20. SIGNED_DISTANCE_TYPE_WINDING_NUMBER = 1,
  21. SIGNED_DISTANCE_TYPE_DEFAULT = 2,
  22. SIGNED_DISTANCE_TYPE_IGNORE = 3,
  23. NUM_SIGNED_DISTANCE_TYPE = 4
  24. };
  25. // Computes signed distance to a mesh
  26. //
  27. // Inputs:
  28. // P #P by 3 list of query point positions
  29. // V #V by 3 list of vertex positions
  30. // F #F by 3 list of triangle indices
  31. // sign_type method for computing distance _sign_ (see signed_distance.h)
  32. // Outputs:
  33. // S #P list of smallest signed distances
  34. // I #P list of facet indices corresponding to smallest distances
  35. // C #P by 3 list of closest points
  36. // N #P by 3 list of closest normals (only set if
  37. // sign_type=SIGNED_DISTANCE_TYPE_PSEUDONORMAL)
  38. //
  39. // Known bugs: This only computes distances to triangles. So unreferenced
  40. // vertices and degenerate triangles are ignored.
  41. IGL_INLINE void signed_distance(
  42. const Eigen::MatrixXd & P,
  43. const Eigen::MatrixXd & V,
  44. const Eigen::MatrixXi & F,
  45. const SignedDistanceType sign_type,
  46. Eigen::VectorXd & S,
  47. Eigen::VectorXi & I,
  48. Eigen::MatrixXd & C,
  49. Eigen::MatrixXd & N);
  50. // Computes signed distance to mesh
  51. //
  52. // Inputs:
  53. // tree AABB acceleration tree (see AABB.h)
  54. // F #F by 3 list of triangle indices
  55. // FN #F by 3 list of triangle normals
  56. // VN #V by 3 list of vertex normals (ANGLE WEIGHTING)
  57. // EN #E by 3 list of edge normals (UNIFORM WEIGHTING)
  58. // EMAP #F*3 mapping edges in F to E
  59. // q Query point
  60. // Returns signed distance to mesh
  61. //
  62. IGL_INLINE double signed_distance_pseudonormal(
  63. const AABB<Eigen::MatrixXd,3> & tree,
  64. const Eigen::MatrixXd & V,
  65. const Eigen::MatrixXi & F,
  66. const Eigen::MatrixXd & FN,
  67. const Eigen::MatrixXd & VN,
  68. const Eigen::MatrixXd & EN,
  69. const Eigen::VectorXi & EMAP,
  70. const Eigen::RowVector3d & q);
  71. // Outputs:
  72. // s sign
  73. // sqrd squared distance
  74. // i closest primitive
  75. // c closest point
  76. // n normal
  77. IGL_INLINE void signed_distance_pseudonormal(
  78. const AABB<Eigen::MatrixXd,3> & tree,
  79. const Eigen::MatrixXd & V,
  80. const Eigen::MatrixXi & F,
  81. const Eigen::MatrixXd & FN,
  82. const Eigen::MatrixXd & VN,
  83. const Eigen::MatrixXd & EN,
  84. const Eigen::VectorXi & EMAP,
  85. const Eigen::RowVector3d & q,
  86. double & s,
  87. double & sqrd,
  88. int & i,
  89. Eigen::RowVector3d & c,
  90. Eigen::RowVector3d & n);
  91. // Inputs:
  92. // tree AABB acceleration tree (see cgal/point_mesh_squared_distance.h)
  93. // hier Winding number evaluation hierarchy
  94. // q Query point
  95. // Returns signed distance to mesh
  96. IGL_INLINE double signed_distance_winding_number(
  97. const AABB<Eigen::MatrixXd,3> & tree,
  98. const Eigen::MatrixXd & V,
  99. const Eigen::MatrixXi & F,
  100. const igl::WindingNumberAABB<Eigen::Vector3d> & hier,
  101. const Eigen::RowVector3d & q);
  102. // Outputs:
  103. // s sign
  104. // sqrd squared distance
  105. // pp closest point and primitve
  106. IGL_INLINE void signed_distance_winding_number(
  107. const AABB<Eigen::MatrixXd,3> & tree,
  108. const Eigen::MatrixXd & V,
  109. const Eigen::MatrixXi & F,
  110. const igl::WindingNumberAABB<Eigen::Vector3d> & hier,
  111. const Eigen::RowVector3d & q,
  112. double & s,
  113. double & sqrd,
  114. int & i,
  115. Eigen::RowVector3d & c);
  116. }
  117. #ifndef IGL_STATIC_LIBRARY
  118. # include "signed_distance.cpp"
  119. #endif
  120. #endif