collapse_edge.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_COLLAPSE_EDGE_H
  9. #define IGL_COLLAPSE_EDGE_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include <set>
  14. namespace igl
  15. {
  16. // Assumes (V,F) is a closed manifold mesh (except for previouslly collapsed
  17. // faces which should be set to:
  18. // [IGL_COLLAPSE_EDGE_NULL IGL_COLLAPSE_EDGE_NULL IGL_COLLAPSE_EDGE_NULL].
  19. // Collapses exactly two faces and exactly 3 edges from E (e and one side of
  20. // each face gets collapsed to the other). This is implemented in a way that
  21. // it can be repeatedly called until satisfaction and then the garbage in F
  22. // can be collected by removing NULL faces.
  23. //
  24. // Inputs:
  25. // e index into E of edge to try to collapse. E(e,:) = [s d] or [d s] so
  26. // that s<d, then d is collapsed to s.
  27. /// p dim list of vertex position where to place merged vertex
  28. // Inputs/Outputs:
  29. // V #V by dim list of vertex positions, lesser index of E(e,:) will be set
  30. // to midpoint of edge.
  31. // F #F by 3 list of face indices into V.
  32. // E #E by 2 list of edge indices into V.
  33. // EMAP #F*3 list of indices into E, mapping each directed edge to unique
  34. // unique edge in E
  35. // EF #E by 2 list of edge flaps, EF(e,0)=f means e=(i-->j) is the edge of
  36. // F(f,:) opposite the vth corner, where EI(e,0)=v. Similarly EF(e,1) "
  37. // e=(j->i)
  38. // EI #E by 2 list of edge flap corners (see above).
  39. // e1 index into E of edge collpased on left
  40. // e2 index into E of edge collpased on left
  41. // f1 index into E of edge collpased on left
  42. // f2 index into E of edge collpased on left
  43. // Returns true if edge was collapsed
  44. #define IGL_COLLAPSE_EDGE_NULL 0
  45. IGL_INLINE bool collapse_edge(
  46. const int e,
  47. const Eigen::RowVectorXd & p,
  48. Eigen::MatrixXd & V,
  49. Eigen::MatrixXi & F,
  50. Eigen::MatrixXi & E,
  51. Eigen::VectorXi & EMAP,
  52. Eigen::MatrixXi & EF,
  53. Eigen::MatrixXi & EI,
  54. int & e1,
  55. int & e2,
  56. int & f1,
  57. int & f2);
  58. IGL_INLINE bool collapse_edge(
  59. const int e,
  60. const Eigen::RowVectorXd & p,
  61. Eigen::MatrixXd & V,
  62. Eigen::MatrixXi & F,
  63. Eigen::MatrixXi & E,
  64. Eigen::VectorXi & EMAP,
  65. Eigen::MatrixXi & EF,
  66. Eigen::MatrixXi & EI);
  67. // Collapse least-cost edge from a priority queue and update queue
  68. //
  69. // Inputs/Outputs:
  70. // cost_and_placement function computing cost of collapsing an edge and 3d
  71. // position where it should be placed:
  72. // cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  73. // Q queue containing pairs of costs and edge indices
  74. // Qit list of iterators so that Qit[e] --> iterator of edge e in Q
  75. // C #E by dim list of stored placements
  76. IGL_INLINE bool collapse_edge(
  77. const std::function<void(
  78. const int,
  79. const Eigen::MatrixXd &,
  80. const Eigen::MatrixXi &,
  81. const Eigen::MatrixXi &,
  82. const Eigen::VectorXi &,
  83. const Eigen::MatrixXi &,
  84. const Eigen::MatrixXi &,
  85. double &,
  86. Eigen::RowVectorXd &)> & cost_and_placement,
  87. Eigen::MatrixXd & V,
  88. Eigen::MatrixXi & F,
  89. Eigen::MatrixXi & E,
  90. Eigen::VectorXi & EMAP,
  91. Eigen::MatrixXi & EF,
  92. Eigen::MatrixXi & EI,
  93. std::set<std::pair<double,int> > & Q,
  94. std::vector<std::set<std::pair<double,int> >::iterator > & Qit,
  95. Eigen::MatrixXd & C);
  96. IGL_INLINE bool collapse_edge(
  97. const std::function<void(
  98. const int,
  99. const Eigen::MatrixXd &,
  100. const Eigen::MatrixXi &,
  101. const Eigen::MatrixXi &,
  102. const Eigen::VectorXi &,
  103. const Eigen::MatrixXi &,
  104. const Eigen::MatrixXi &,
  105. double &,
  106. Eigen::RowVectorXd &)> & cost_and_placement,
  107. Eigen::MatrixXd & V,
  108. Eigen::MatrixXi & F,
  109. Eigen::MatrixXi & E,
  110. Eigen::VectorXi & EMAP,
  111. Eigen::MatrixXi & EF,
  112. Eigen::MatrixXi & EI,
  113. std::set<std::pair<double,int> > & Q,
  114. std::vector<std::set<std::pair<double,int> >::iterator > & Qit,
  115. Eigen::MatrixXd & C,
  116. int & e,
  117. int & e1,
  118. int & e2,
  119. int & f1,
  120. int & f2);
  121. }
  122. #ifndef IGL_STATIC_LIBRARY
  123. # include "collapse_edge.cpp"
  124. #endif
  125. #endif