octree.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Gavin Barill <[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_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. /// @param[in] P #P by 3 list of point locations
  31. /// @param[out] point_indices a vector of vectors, where the ith entry is a
  32. /// vector of the indices into P that are the ith octree cell's points
  33. /// @param[out] CH #OctreeCells by 8, where the ith row is the indices of the
  34. /// ith octree cell's children
  35. /// @param[out] CN #OctreeCells by 3, where the ith row is a 3d row vector
  36. /// representing the position of the ith cell's center
  37. /// @param[out] W #OctreeCells, a vector where the ith entry is the width of
  38. /// the ith octree cell
  39. template <typename DerivedP, typename IndexType, typename DerivedCH,
  40. typename DerivedCN, typename DerivedW>
  41. IGL_INLINE void octree(const Eigen::MatrixBase<DerivedP>& P,
  42. std::vector<std::vector<IndexType> > & point_indices,
  43. Eigen::PlainObjectBase<DerivedCH>& CH,
  44. Eigen::PlainObjectBase<DerivedCN>& CN,
  45. Eigen::PlainObjectBase<DerivedW>& W);
  46. }
  47. #ifndef IGL_STATIC_LIBRARY
  48. # include "octree.cpp"
  49. #endif
  50. #endif