collapse_edge.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_COLLAPSE_EDGE_H
  9. #define IGL_COLLAPSE_EDGE_H
  10. #include "igl_inline.h"
  11. #include "min_heap.h"
  12. #include "decimate_callback_types.h"
  13. #include <Eigen/Core>
  14. #include <vector>
  15. #include <set>
  16. namespace igl
  17. {
  18. #ifndef IGL_COLLAPSE_EDGE_NULL
  19. /// Special value for indicating a null vertex index as the result of a
  20. /// collapsed edge.
  21. #define IGL_COLLAPSE_EDGE_NULL 0
  22. #endif
  23. /// Attempt to collapse a given edge of a mesh. Assumes (V,F) is a closed
  24. /// manifold mesh (except for previously collapsed faces which should be set
  25. /// to: [IGL_COLLAPSE_EDGE_NULL IGL_COLLAPSE_EDGE_NULL
  26. /// IGL_COLLAPSE_EDGE_NULL]. Collapses exactly two faces and exactly 3 edges
  27. /// from E (e and one side of each face gets collapsed to the other). This is
  28. /// implemented in a way that it can be repeatedly called until satisfaction
  29. /// and then the garbage in F can be collected by removing NULL faces.
  30. ///
  31. /// @param[in] e index into E of edge to try to collapse. E(e,:) = [s d] or [d s] so
  32. /// that s<d, then d is collapsed to s.
  33. /// @param[in] p dim list of vertex position where to place merged vertex
  34. /// [mesh inputs]
  35. /// @param[in,out] V #V by dim list of vertex positions, lesser index of E(e,:) will be set
  36. /// to midpoint of edge.
  37. /// @param[in,out] F #F by 3 list of face indices into V.
  38. /// @param[in,out] E #E by 2 list of edge indices into V.
  39. /// @param[in,out] EMAP #F*3 list of indices into E, mapping each directed edge to unique
  40. /// unique edge in E
  41. /// @param[in,out] EF #E by 2 list of edge flaps, EF(e,0)=f means e=(i-->j) is the edge of
  42. /// F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1) "
  43. /// e=(j->i)
  44. /// @param[in,out] EI #E by 2 list of edge flap corners (see above).
  45. /// [mesh inputs]
  46. /// @param[out] e1 index into E of edge collpased on left
  47. /// @param[out] e2 index into E of edge collpased on right
  48. /// @param[out] f1 index into F of face collpased on left
  49. /// @param[out] f2 index into F of face collpased on right
  50. /// @return true if edge was collapsed
  51. IGL_INLINE bool collapse_edge(
  52. const int e,
  53. const Eigen::RowVectorXd & p,
  54. Eigen::MatrixXd & V,
  55. Eigen::MatrixXi & F,
  56. Eigen::MatrixXi & E,
  57. Eigen::VectorXi & EMAP,
  58. Eigen::MatrixXi & EF,
  59. Eigen::MatrixXi & EI,
  60. int & e1,
  61. int & e2,
  62. int & f1,
  63. int & f2);
  64. /// \overload
  65. ///
  66. /// @param[in] Nsv #Nsv vertex circulation around s (see circulation)
  67. /// @param[in] Nsf #Nsf face circulation around s
  68. /// @param[in] Ndv #Ndv vertex circulation around d
  69. /// @param[in] Ndf #Ndf face circulation around d
  70. IGL_INLINE bool collapse_edge(
  71. const int e,
  72. const Eigen::RowVectorXd & p,
  73. /*const*/ std::vector<int> & Nsv,
  74. const std::vector<int> & Nsf,
  75. /*const*/ std::vector<int> & Ndv,
  76. const std::vector<int> & Ndf,
  77. Eigen::MatrixXd & V,
  78. Eigen::MatrixXi & F,
  79. Eigen::MatrixXi & E,
  80. Eigen::VectorXi & EMAP,
  81. Eigen::MatrixXi & EF,
  82. Eigen::MatrixXi & EI,
  83. int & e1,
  84. int & e2,
  85. int & f1,
  86. int & f2);
  87. /// \overload
  88. IGL_INLINE bool collapse_edge(
  89. const int e,
  90. const Eigen::RowVectorXd & p,
  91. Eigen::MatrixXd & V,
  92. Eigen::MatrixXi & F,
  93. Eigen::MatrixXi & E,
  94. Eigen::VectorXi & EMAP,
  95. Eigen::MatrixXi & EF,
  96. Eigen::MatrixXi & EI);
  97. /// Collapse least-cost edge from a priority queue and update queue
  98. ///
  99. /// See decimate.h for more details.
  100. ///
  101. /// @param[in] cost_and_placement function computing cost of collapsing an edge and 3d
  102. /// position where it should be placed:
  103. /// cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  104. /// **If the edges is collapsed** then this function will be called on all
  105. /// edges of all faces previously incident on the endpoints of the
  106. /// collapsed edge.
  107. /// @param[in] pre_collapse callback called with index of edge whose collapse is about
  108. /// to be attempted. This function should return whether to **proceed**
  109. /// with the collapse: returning true means "yes, try to collapse",
  110. /// returning false means "No, consider this edge 'uncollapsable', behave
  111. /// as if collapse_edge(e) returned false.
  112. /// @param[in] post_collapse callback called with index of edge whose collapse was
  113. /// just attempted and a flag revealing whether this was successful.
  114. /// @param[in,out] V #V by dim list of vertex positions, lesser index of E(e,:) will be set
  115. /// to midpoint of edge.
  116. /// @param[in,out] F #F by 3 list of face indices into V.
  117. /// @param[in,out] E #E by 2 list of edge indices into V.
  118. /// @param[in,out] EMAP #F*3 list of indices into E, mapping each directed edge to unique
  119. /// unique edge in E
  120. /// @param[in,out] EF #E by 2 list of edge flaps, EF(e,0)=f means e=(i-->j) is the edge of
  121. /// F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1)
  122. /// e=(j->i)
  123. /// @param[in,out] EI #E by 2 list of edge flap corners (see above).
  124. /// @param[in] Q queue containing pairs of costs and edge indices and insertion "time"
  125. /// @param[in] EQ #E list of "time" of last time pushed into Q
  126. /// @param[in] C #E by dim list of stored placements
  127. /// @param[out] e index into E of attempted collapsed edge. Set to -1 if Q is empty or
  128. /// contains only infinite cost edges.
  129. /// @param[out] e1 index into E of edge collpased on left.
  130. /// @param[out] e2 index into E of edge collpased on right.
  131. /// @param[out] f1 index into F of face collpased on left.
  132. /// @param[out] f2 index into F of face collpased on right.
  133. IGL_INLINE bool collapse_edge(
  134. const decimate_cost_and_placement_callback & cost_and_placement,
  135. const decimate_pre_collapse_callback & pre_collapse,
  136. const decimate_post_collapse_callback & post_collapse,
  137. Eigen::MatrixXd & V,
  138. Eigen::MatrixXi & F,
  139. Eigen::MatrixXi & E,
  140. Eigen::VectorXi & EMAP,
  141. Eigen::MatrixXi & EF,
  142. Eigen::MatrixXi & EI,
  143. igl::min_heap< std::tuple<double,int,int> > & Q,
  144. Eigen::VectorXi & EQ,
  145. Eigen::MatrixXd & C,
  146. int & e,
  147. int & e1,
  148. int & e2,
  149. int & f1,
  150. int & f2);
  151. /// \overload
  152. IGL_INLINE bool collapse_edge(
  153. const decimate_cost_and_placement_callback & cost_and_placement,
  154. Eigen::MatrixXd & V,
  155. Eigen::MatrixXi & F,
  156. Eigen::MatrixXi & E,
  157. Eigen::VectorXi & EMAP,
  158. Eigen::MatrixXi & EF,
  159. Eigen::MatrixXi & EI,
  160. igl::min_heap< std::tuple<double,int,int> > & Q,
  161. Eigen::VectorXi & EQ,
  162. Eigen::MatrixXd & C);
  163. /// \overload
  164. IGL_INLINE bool collapse_edge(
  165. const decimate_cost_and_placement_callback & cost_and_placement,
  166. const decimate_pre_collapse_callback & pre_collapse,
  167. const decimate_post_collapse_callback & post_collapse,
  168. Eigen::MatrixXd & V,
  169. Eigen::MatrixXi & F,
  170. Eigen::MatrixXi & E,
  171. Eigen::VectorXi & EMAP,
  172. Eigen::MatrixXi & EF,
  173. Eigen::MatrixXi & EI,
  174. igl::min_heap< std::tuple<double,int,int> > & Q,
  175. Eigen::VectorXi & EQ,
  176. Eigen::MatrixXd & C);
  177. }
  178. #ifndef IGL_STATIC_LIBRARY
  179. # include "collapse_edge.cpp"
  180. #endif
  181. #endif