collapse_least_cost_edge.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_LEAST_COST_EDGE_H
  9. #define IGL_COLLAPSE_LEAST_COST_EDGE_H
  10. #include "igl_inline.h"
  11. #include "min_heap.h"
  12. #include "decimate_callback_types.h"
  13. #include "COLLAPSE_EDGE_NULL.h"
  14. #include <Eigen/Core>
  15. #include <vector>
  16. namespace igl
  17. {
  18. /// Collapse least-cost edge from a priority queue and update queue
  19. ///
  20. /// See decimate.h for more details.
  21. ///
  22. /// @param[in] cost_and_placement function computing cost of collapsing an edge and 3d
  23. /// position where it should be placed:
  24. /// cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  25. /// **If the edges is collapsed** then this function will be called on all
  26. /// edges of all faces previously incident on the endpoints of the
  27. /// collapsed edge.
  28. /// @param[in] pre_collapse callback called with index of edge whose collapse is about
  29. /// to be attempted. This function should return whether to **proceed**
  30. /// with the collapse: returning true means "yes, try to collapse",
  31. /// returning false means "No, consider this edge 'uncollapsable', behave
  32. /// as if collapse_edge(e) returned false.
  33. /// @param[in] post_collapse callback called with index of edge whose collapse was
  34. /// just attempted and a flag revealing whether this was successful.
  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. /// @param[in] Q queue containing pairs of costs and edge indices and insertion "time"
  46. /// @param[in] EQ #E list of "time" of last time pushed into Q
  47. /// @param[in] C #E by dim list of stored placements
  48. /// @param[out] e index into E of attempted collapsed edge. Set to -1 if Q is empty or
  49. /// contains only infinite cost edges.
  50. /// @param[out] e1 index into E of edge collpased on left.
  51. /// @param[out] e2 index into E of edge collpased on right.
  52. /// @param[out] f1 index into F of face collpased on left.
  53. /// @param[out] f2 index into F of face collpased on right.
  54. ///
  55. /// \bug This function is not templated nicely and refactoring it and its
  56. /// dependencies to do so is non-trivial, see
  57. /// https://github.com/libigl/libigl/issues/2452
  58. IGL_INLINE bool collapse_least_cost_edge(
  59. const decimate_cost_and_placement_callback & cost_and_placement,
  60. const decimate_pre_collapse_callback & pre_collapse,
  61. const decimate_post_collapse_callback & post_collapse,
  62. Eigen::MatrixXd & V,
  63. Eigen::MatrixXi & F,
  64. Eigen::MatrixXi & E,
  65. Eigen::VectorXi & EMAP,
  66. Eigen::MatrixXi & EF,
  67. Eigen::MatrixXi & EI,
  68. igl::min_heap< std::tuple<double,int,int> > & Q,
  69. Eigen::VectorXi & EQ,
  70. Eigen::MatrixXd & C,
  71. int & e,
  72. int & e1,
  73. int & e2,
  74. int & f1,
  75. int & f2);
  76. }
  77. #ifndef IGL_STATIC_LIBRARY
  78. # include "collapse_least_cost_edge.cpp"
  79. #endif
  80. #endif