knn_octree.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. namespace igl
  13. {
  14. // Given a 3D set of points P, an whole number k, and an octree
  15. // find the indicies of the k nearest neighbors for each point in P.
  16. // Note that each point is its own neighbor.
  17. //
  18. // The octree data structures used in this function are intended to be the
  19. // same ones output from igl::build_octree
  20. //
  21. // Inputs:
  22. // P #P by 3 list of point locations
  23. // k number of neighbors to find
  24. // point_indices a vector of vectors, where the ith entry is a vector of
  25. // the indices into P that are the ith octree cell's points
  26. // children a vector of vectors, where the ith entry is a vector of
  27. // the ith octree cell's of octree children
  28. // centers a vector where the ith entry is a 3d row vector
  29. // representing the position of the ith cell's center
  30. // widths a vector where the ith entry is the width of the ith
  31. // octree cell
  32. // Outputs:
  33. // I #P by k list of k-nearest-neighbor indices into P
  34. template <typename DerivedP, typename KType, typename IndexType,
  35. typename CentersType, typename WidthsType, typename DerivedI>
  36. IGL_INLINE void knn_octree(const Eigen::MatrixBase<DerivedP>& P,
  37. const KType & k,
  38. const std::vector<std::vector<IndexType> > & point_indices,
  39. const std::vector<Eigen::Matrix<IndexType,8,1>, Eigen::aligned_allocator<Eigen::Matrix<IndexType,8,1> > > & children,
  40. const std::vector<Eigen::Matrix<CentersType,1,3>, Eigen::aligned_allocator<Eigen::Matrix<CentersType,1,3> > > & centers,
  41. const std::vector<WidthsType> & widths,
  42. Eigen::PlainObjectBase<DerivedI> & I);
  43. }
  44. #ifndef IGL_STATIC_LIBRARY
  45. # include "knn_octree.cpp"
  46. #endif
  47. #endif