knn.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Gavin Barill <gavinpcb@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_KNN
  9. #define IGL_KNN
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. // Given a 3D set of points P, an whole number k, and an octree
  16. // find the indicies of the k nearest neighbors for each point in P.
  17. // Note that each point is its own neighbor.
  18. //
  19. // The octree data structures used in this function are intended to be the
  20. // same ones output from igl::octree
  21. //
  22. // Inputs:
  23. // P #P by 3 list of point locations
  24. // k number of neighbors to find
  25. // point_indices a vector of vectors, where the ith entry is a vector of
  26. // the indices into P that are the ith octree cell's points
  27. // CH #OctreeCells by 8, where the ith row is the indices of
  28. // the ith octree cell's children
  29. // CN #OctreeCells by 3, where the ith row is a 3d row vector
  30. // representing the position of the ith cell's center
  31. // W #OctreeCells, a vector where the ith entry is the width
  32. // of the ith octree cell
  33. // Outputs:
  34. // I #P by k list of k-nearest-neighbor indices into P
  35. template <typename DerivedP, typename KType, typename IndexType,
  36. typename DerivedCH, typename DerivedCN, typename DerivedW,
  37. typename DerivedI>
  38. IGL_INLINE void knn(const Eigen::MatrixBase<DerivedP>& P,
  39. const KType & k,
  40. const std::vector<std::vector<IndexType> > & point_indices,
  41. const Eigen::MatrixBase<DerivedCH>& CH,
  42. const Eigen::MatrixBase<DerivedCN>& CN,
  43. const Eigen::MatrixBase<DerivedW>& W,
  44. Eigen::PlainObjectBase<DerivedI> & I);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. # include "knn.cpp"
  48. #endif
  49. #endif