knn_octree.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_OCTREE
  9. #define IGL_KNN_OCTREE
  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::build_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. // children a vector of vectors, where the ith entry is a vector of
  28. // the ith octree cell's of octree children
  29. // centers a vector where the ith entry is a 3d row vector
  30. // representing the position of the ith cell's center
  31. // widths a vector where the ith entry is the width of the ith
  32. // 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 CentersType, typename WidthsType, typename DerivedI>
  37. IGL_INLINE void knn_octree(const Eigen::MatrixBase<DerivedP>& P,
  38. const KType & k,
  39. const std::vector<std::vector<IndexType> > & point_indices,
  40. const std::vector<Eigen::Matrix<IndexType,8,1>, Eigen::aligned_allocator<Eigen::Matrix<IndexType,8,1> > > & children,
  41. const std::vector<Eigen::Matrix<CentersType,1,3>, Eigen::aligned_allocator<Eigen::Matrix<CentersType,1,3> > > & centers,
  42. const std::vector<WidthsType> & widths,
  43. Eigen::PlainObjectBase<DerivedI> & I);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "knn_octree.cpp"
  47. #endif
  48. #endif