ramer_douglas_peucker.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef IGL_RAMER_DOUGLAS_PEUCKER_H
  2. #define IGL_RAMER_DOUGLAS_PEUCKER_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. namespace igl
  6. {
  7. // Ramer-Douglas-Peucker piecewise-linear curve simplification.
  8. //
  9. // Inputs:
  10. // P #P by dim ordered list of vertices along the curve
  11. // tol tolerance (maximal euclidean distance allowed between the new line
  12. // and a vertex)
  13. // Outputs:
  14. // S #S by dim ordered list of points along the curve
  15. // J #S list of indices into P so that S = P(J,:)
  16. template <typename DerivedP, typename DerivedS, typename DerivedJ>
  17. IGL_INLINE void ramer_douglas_peucker(
  18. const Eigen::MatrixBase<DerivedP> & P,
  19. const typename DerivedP::Scalar tol,
  20. Eigen::PlainObjectBase<DerivedS> & S,
  21. Eigen::PlainObjectBase<DerivedJ> & J);
  22. // Run (Ramer-)Duglass-Peucker curve simplification but keep track of where
  23. // every point on the original curve maps to on the simplified curve.
  24. //
  25. // Inputs:
  26. // P #P by dim list of points, (use P([1:end 1],:) for loops)
  27. // tol DP tolerance
  28. // Outputs:
  29. // S #S by dim list of points along simplified curve
  30. // J #S indices into P of simplified points
  31. // Q #P by dim list of points mapping along simplified curve
  32. //
  33. template <
  34. typename DerivedP,
  35. typename DerivedS,
  36. typename DerivedJ,
  37. typename DerivedQ>
  38. IGL_INLINE void ramer_douglas_peucker(
  39. const Eigen::MatrixBase<DerivedP> & P,
  40. const typename DerivedP::Scalar tol,
  41. Eigen::PlainObjectBase<DerivedS> & S,
  42. Eigen::PlainObjectBase<DerivedJ> & J,
  43. Eigen::PlainObjectBase<DerivedQ> & Q);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "ramer_douglas_peucker.cpp"
  47. #endif
  48. #endif