histc.h 1.8 KB

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