octree.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_OCTREE
  9. #define IGL_OCTREE
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. // Given a set of 3D points P, generate data structures for a pointerless
  16. // octree. Each cell stores its points, children, center location and width.
  17. // Our octree is not dense. We use the following rule: if the current cell
  18. // has any number of points, it will have all 8 children. A leaf cell will
  19. // have -1's as its list of child indices.
  20. //
  21. // We use a binary numbering of children. Treating the parent cell's center
  22. // as the origin, we number the octants in the following manner:
  23. // The first bit is 1 iff the octant's x coordinate is positive
  24. // The second bit is 1 iff the octant's y coordinate is positive
  25. // The third bit is 1 iff the octant's z coordinate is positive
  26. //
  27. // For example, the octant with negative x, positive y, positive z is:
  28. // 110 binary = 6 decimal
  29. //
  30. // Inputs:
  31. // P #P by 3 list of point locations
  32. //
  33. // Outputs:
  34. // point_indices a vector of vectors, where the ith entry is a vector of
  35. // the indices into P that are the ith octree cell's points
  36. // CH #OctreeCells by 8, where the ith row is the indices of
  37. // the ith octree cell's children
  38. // CN #OctreeCells by 3, where the ith row is a 3d row vector
  39. // representing the position of the ith cell's center
  40. // W #OctreeCells, a vector where the ith entry is the width
  41. // of the ith octree cell
  42. //
  43. template <typename DerivedP, typename IndexType, typename DerivedCH,
  44. typename DerivedCN, typename DerivedW>
  45. IGL_INLINE void octree(const Eigen::MatrixBase<DerivedP>& P,
  46. std::vector<std::vector<IndexType> > & point_indices,
  47. Eigen::PlainObjectBase<DerivedCH>& CH,
  48. Eigen::PlainObjectBase<DerivedCN>& CN,
  49. Eigen::PlainObjectBase<DerivedW>& W);
  50. }
  51. #ifndef IGL_STATIC_LIBRARY
  52. # include "octree.cpp"
  53. #endif
  54. #endif