KdTree.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * KdTree.h
  3. * RVO2-3D Library
  4. *
  5. * Copyright 2008 University of North Carolina at Chapel Hill
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * https://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * Please send all bug reports to <geom@cs.unc.edu>.
  20. *
  21. * The authors may be contacted via:
  22. *
  23. * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
  24. * Dept. of Computer Science
  25. * 201 S. Columbia St.
  26. * Frederick P. Brooks, Jr. Computer Science Bldg.
  27. * Chapel Hill, N.C. 27599-3175
  28. * United States of America
  29. *
  30. * <https://gamma.cs.unc.edu/RVO2/>
  31. */
  32. /**
  33. * \file KdTree.h
  34. * \brief Contains the KdTree class.
  35. */
  36. #ifndef RVO3D_KD_TREE_H_
  37. #define RVO3D_KD_TREE_H_
  38. #include <cstddef>
  39. #include <vector>
  40. #include "Vector3.h"
  41. // Note: Slightly modified to work better with Godot.
  42. // - Removed `sim_`.
  43. // - KdTree things are public
  44. namespace RVO {
  45. class Agent;
  46. class RVOSimulator;
  47. /**
  48. * \brief Defines <i>k</i>d-trees for agents in the simulation.
  49. */
  50. class KdTree {
  51. public:
  52. /**
  53. * \brief Defines an agent <i>k</i>d-tree node.
  54. */
  55. class AgentTreeNode {
  56. public:
  57. /**
  58. * \brief The beginning node number.
  59. */
  60. size_t begin;
  61. /**
  62. * \brief The ending node number.
  63. */
  64. size_t end;
  65. /**
  66. * \brief The left node number.
  67. */
  68. size_t left;
  69. /**
  70. * \brief The right node number.
  71. */
  72. size_t right;
  73. /**
  74. * \brief The maximum coordinates.
  75. */
  76. Vector3 maxCoord;
  77. /**
  78. * \brief The minimum coordinates.
  79. */
  80. Vector3 minCoord;
  81. };
  82. /**
  83. * \brief Constructs a <i>k</i>d-tree instance.
  84. * \param sim The simulator instance.
  85. */
  86. explicit KdTree();
  87. /**
  88. * \brief Builds an agent <i>k</i>d-tree.
  89. */
  90. void buildAgentTree(std::vector<Agent *> agents);
  91. void buildAgentTreeRecursive(size_t begin, size_t end, size_t node);
  92. /**
  93. * \brief Computes the agent neighbors of the specified agent.
  94. * \param agent A pointer to the agent for which agent neighbors are to be computed.
  95. * \param rangeSq The squared range around the agent.
  96. */
  97. void computeAgentNeighbors(Agent *agent, float rangeSq) const;
  98. void queryAgentTreeRecursive(Agent *agent, float &rangeSq, size_t node) const;
  99. std::vector<Agent *> agents_;
  100. std::vector<AgentTreeNode> agentTree_;
  101. friend class Agent;
  102. friend class RVOSimulator;
  103. };
  104. }
  105. #endif /* RVO3D_KD_TREE_H_ */