histc.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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_HISTC_H
  9. #define IGL_HISTC_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. // Like matlab's histc. Count occurances of values in X between consecutive
  15. // entries in E
  16. //
  17. // Inputs:
  18. // X m-long Vector of values
  19. // E n-long Monotonically increasing vector of edges
  20. // Outputs:
  21. // N n-long vector where N(k) reveals how many values in X fall between
  22. // E(k) <= X < E(k+1)
  23. // B m-long vector of bin ids so that B(j) = k if E(k) <= X(j) < E(k+1).
  24. // B(j) = -1 if X(j) is outside of E.
  25. //
  26. // O(n+m*log(n))
  27. template <typename DerivedX, typename DerivedE, typename DerivedN, typename DerivedB>
  28. IGL_INLINE void histc(
  29. const Eigen::PlainObjectBase<DerivedX > & X,
  30. const Eigen::PlainObjectBase<DerivedE > & E,
  31. Eigen::PlainObjectBase<DerivedN > & N,
  32. Eigen::PlainObjectBase<DerivedB > & B);
  33. // Truly O(m*log(n))
  34. template <typename DerivedX, typename DerivedE, typename DerivedB>
  35. IGL_INLINE void histc(
  36. const Eigen::PlainObjectBase<DerivedX > & X,
  37. const Eigen::PlainObjectBase<DerivedE > & E,
  38. Eigen::PlainObjectBase<DerivedB > & B);
  39. // Scalar search wrapper
  40. template <typename DerivedE>
  41. IGL_INLINE void histc(
  42. const typename DerivedE::Scalar & x,
  43. const Eigen::PlainObjectBase<DerivedE > & E,
  44. typename DerivedE::Index & b);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "histc.cpp"
  48. #endif
  49. #endif