decimate.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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_DECIMATE_H
  9. #define IGL_DECIMATE_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 manifold mesh (possibly with boundary) Collapses edges
  17. // until desired number of faces is achieved. This uses default edge cost and
  18. // merged vertex placement functions {edge length, edge midpoint}.
  19. //
  20. // Inputs:
  21. // V #V by dim list of vertex positions
  22. // F #F by 3 list of face indices into V.
  23. // max_m desired number of output faces
  24. // Outputs:
  25. // U #U by dim list of output vertex posistions (can be same ref as V)
  26. // G #G by 3 list of output face indices into U (can be same ref as G)
  27. // J #G list of indices into F of birth face
  28. // I #U list of indices into V of birth vertices
  29. // Returns true if m was reached (otherwise #G > m)
  30. IGL_INLINE bool decimate(
  31. const Eigen::MatrixXd & V,
  32. const Eigen::MatrixXi & F,
  33. const size_t max_m,
  34. Eigen::MatrixXd & U,
  35. Eigen::MatrixXi & G,
  36. Eigen::VectorXi & J,
  37. Eigen::VectorXi & I);
  38. // Inputs:
  39. // V #V by dim list of vertex positions
  40. // F #F by 3 list of face indices into V.
  41. // max_m desired number of output faces
  42. // Outputs:
  43. // U #U by dim list of output vertex posistions (can be same ref as V)
  44. // G #G by 3 list of output face indices into U (can be same ref as G)
  45. // J #G list of indices into F of birth face
  46. // Returns true if m was reached (otherwise #G > m)
  47. IGL_INLINE bool decimate(
  48. const Eigen::MatrixXd & V,
  49. const Eigen::MatrixXi & F,
  50. const size_t max_m,
  51. Eigen::MatrixXd & U,
  52. Eigen::MatrixXi & G,
  53. Eigen::VectorXi & J);
  54. // Assumes a **closed** manifold mesh. See igl::connect_boundary_to_infinity
  55. // and igl::decimate in decimate.cpp
  56. // is handling meshes with boundary by connecting all boundary edges with
  57. // dummy facets to infinity **and** modifying the stopping criteria.
  58. //
  59. // Inputs:
  60. // cost_and_placement function computing cost of collapsing an edge and 3d
  61. // position where it should be placed:
  62. // cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  63. // stopping_condition function returning whether to stop collapsing edges
  64. // based on current state. Guaranteed to be called after _successfully_
  65. // collapsing edge e removing edges (e,e1,e2) and faces (f1,f2):
  66. // bool should_stop =
  67. // stopping_condition(V,F,E,EMAP,EF,EI,Q,Qit,C,e,e1,e2,f1,f2);
  68. IGL_INLINE bool decimate(
  69. const Eigen::MatrixXd & V,
  70. const Eigen::MatrixXi & F,
  71. const std::function<void(
  72. const int /*e*/,
  73. const Eigen::MatrixXd &/*V*/,
  74. const Eigen::MatrixXi &/*F*/,
  75. const Eigen::MatrixXi &/*E*/,
  76. const Eigen::VectorXi &/*EMAP*/,
  77. const Eigen::MatrixXi &/*EF*/,
  78. const Eigen::MatrixXi &/*EI*/,
  79. double & /*cost*/,
  80. Eigen::RowVectorXd & /*p*/
  81. )> & cost_and_placement,
  82. const std::function<bool(
  83. const Eigen::MatrixXd & ,/*V*/
  84. const Eigen::MatrixXi & ,/*F*/
  85. const Eigen::MatrixXi & ,/*E*/
  86. const Eigen::VectorXi & ,/*EMAP*/
  87. const Eigen::MatrixXi & ,/*EF*/
  88. const Eigen::MatrixXi & ,/*EI*/
  89. const std::set<std::pair<double,int> > & ,/*Q*/
  90. const std::vector<std::set<std::pair<double,int> >::iterator > &,/*Qit*/
  91. const Eigen::MatrixXd & ,/*C*/
  92. const int ,/*e*/
  93. const int ,/*e1*/
  94. const int ,/*e2*/
  95. const int ,/*f1*/
  96. const int /*f2*/
  97. )> & stopping_condition,
  98. Eigen::MatrixXd & U,
  99. Eigen::MatrixXi & G,
  100. Eigen::VectorXi & J,
  101. Eigen::VectorXi & I);
  102. }
  103. #ifndef IGL_STATIC_LIBRARY
  104. # include "decimate.cpp"
  105. #endif
  106. #endif