decimate.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // Returns true if m was reached (otherwise #G > m)
  29. IGL_INLINE bool decimate(
  30. const Eigen::MatrixXd & V,
  31. const Eigen::MatrixXi & F,
  32. const size_t max_m,
  33. Eigen::MatrixXd & U,
  34. Eigen::MatrixXi & G,
  35. Eigen::VectorXi & J);
  36. // Assumes a **closed** manifold mesh. See igl::connect_boundary_to_infinity
  37. // and igl::decimate in decimate.cpp
  38. // is handling meshes with boundary by connecting all boundary edges with
  39. // dummy facets to infinity **and** modifying the stopping criteria.
  40. //
  41. // Inputs:
  42. // cost_and_placement function computing cost of collapsing an edge and 3d
  43. // position where it should be placed:
  44. // cost_and_placement(V,F,E,EMAP,EF,EI,cost,placement);
  45. // stopping_condition function returning whether to stop collapsing edges
  46. // based on current state. Guaranteed to be called after _successfully_
  47. // collapsing edge e removing edges (e,e1,e2) and faces (f1,f2):
  48. // bool should_stop =
  49. // stopping_condition(V,F,E,EMAP,EF,EI,Q,Qit,C,e,e1,e2,f1,f2);
  50. IGL_INLINE bool decimate(
  51. const Eigen::MatrixXd & V,
  52. const Eigen::MatrixXi & F,
  53. const std::function<void(
  54. const int /*e*/,
  55. const Eigen::MatrixXd &/*V*/,
  56. const Eigen::MatrixXi &/*F*/,
  57. const Eigen::MatrixXi &/*E*/,
  58. const Eigen::VectorXi &/*EMAP*/,
  59. const Eigen::MatrixXi &/*EF*/,
  60. const Eigen::MatrixXi &/*EI*/,
  61. double & /*cost*/,
  62. Eigen::RowVectorXd & /*p*/
  63. )> & cost_and_placement,
  64. const std::function<bool(
  65. const Eigen::MatrixXd & ,/*V*/
  66. const Eigen::MatrixXi & ,/*F*/
  67. const Eigen::MatrixXi & ,/*E*/
  68. const Eigen::VectorXi & ,/*EMAP*/
  69. const Eigen::MatrixXi & ,/*EF*/
  70. const Eigen::MatrixXi & ,/*EI*/
  71. const std::set<std::pair<double,int> > & ,/*Q*/
  72. const std::vector<std::set<std::pair<double,int> >::iterator > &,/*Qit*/
  73. const Eigen::MatrixXd & ,/*C*/
  74. const int ,/*e*/
  75. const int ,/*e1*/
  76. const int ,/*e2*/
  77. const int ,/*f1*/
  78. const int /*f2*/
  79. )> & stopping_condition,
  80. Eigen::MatrixXd & U,
  81. Eigen::MatrixXi & G,
  82. Eigen::VectorXi & J);
  83. }
  84. #ifndef IGL_STATIC_LIBRARY
  85. # include "decimate.cpp"
  86. #endif
  87. #endif