decimate.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_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 closed manifold mesh
  17. // Collapses edges until desired number of faces is achieved. This uses
  18. // default edge cost and merged vertex placement functions {edge length, edge
  19. // midpoint}.
  20. //
  21. // Inputs:
  22. // V #V by dim list of vertex positions
  23. // F #F by 3 list of face indices into V.
  24. // max_m desired number of output faces
  25. // Outputs:
  26. // U #U by dim list of output vertex posistions (can be same ref as V)
  27. // G #G by 3 list of output face indices into U (can be same ref as G)
  28. // J #G list of indices into F of birth face
  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. // Inputs:
  38. // cost_and_placement function computing cost of collapsing an edge and 3d
  39. // position where it should be placed:
  40. // cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  41. // stopping_condition function returning whether to stop collapsing edges
  42. // based on current state. Guaranteed to be called after _successfully_
  43. // collapsing edge e removing edges (e,e1,e2) and faces (f1,f2):
  44. // bool should_stop =
  45. // stopping_condition(V,F,E,EMAP,EF,EI,Q,Qit,C,e,e1,e2,f1,f2);
  46. IGL_INLINE bool decimate(
  47. const Eigen::MatrixXd & V,
  48. const Eigen::MatrixXi & F,
  49. const std::function<void(
  50. const int,
  51. const Eigen::MatrixXd &,
  52. const Eigen::MatrixXi &,
  53. const Eigen::MatrixXi &,
  54. const Eigen::VectorXi &,
  55. const Eigen::MatrixXi &,
  56. const Eigen::MatrixXi &,
  57. double &,
  58. Eigen::RowVectorXd &)> & cost_and_placement,
  59. const std::function<bool(
  60. const Eigen::MatrixXd &,
  61. const Eigen::MatrixXi &,
  62. const Eigen::MatrixXi &,
  63. const Eigen::VectorXi &,
  64. const Eigen::MatrixXi &,
  65. const Eigen::MatrixXi &,
  66. const std::set<std::pair<double,int> > &,
  67. const std::vector<std::set<std::pair<double,int> >::iterator > &,
  68. const Eigen::MatrixXd &,
  69. const int,
  70. const int,
  71. const int,
  72. const int,
  73. const int)> & stopping_condition,
  74. Eigen::MatrixXd & U,
  75. Eigen::MatrixXi & G,
  76. Eigen::VectorXi & J);
  77. }
  78. #ifndef IGL_STATIC_LIBRARY
  79. # include "decimate.cpp"
  80. #endif
  81. #endif