2021-12-16 05:15:23 +00:00
|
|
|
/*
|
|
|
|
* KdTree.h
|
|
|
|
* RVO2-3D Library
|
|
|
|
*
|
|
|
|
* Copyright 2008 University of North Carolina at Chapel Hill
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2022-05-18 12:53:52 +00:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2021-12-16 05:15:23 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Please send all bug reports to <geom@cs.unc.edu>.
|
|
|
|
*
|
|
|
|
* The authors may be contacted via:
|
|
|
|
*
|
|
|
|
* Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
|
|
|
|
* Dept. of Computer Science
|
|
|
|
* 201 S. Columbia St.
|
|
|
|
* Frederick P. Brooks, Jr. Computer Science Bldg.
|
|
|
|
* Chapel Hill, N.C. 27599-3175
|
|
|
|
* United States of America
|
|
|
|
*
|
2022-05-18 12:53:52 +00:00
|
|
|
* <https://gamma.cs.unc.edu/RVO2/>
|
2021-12-16 05:15:23 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file KdTree.h
|
|
|
|
* \brief Contains the KdTree class.
|
|
|
|
*/
|
2022-05-18 12:53:52 +00:00
|
|
|
#ifndef RVO3D_KD_TREE_H_
|
|
|
|
#define RVO3D_KD_TREE_H_
|
2021-12-16 05:15:23 +00:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Vector3.h"
|
|
|
|
|
|
|
|
// Note: Slightly modified to work better with Godot.
|
|
|
|
// - Removed `sim_`.
|
|
|
|
// - KdTree things are public
|
|
|
|
namespace RVO {
|
2022-05-18 12:21:02 +00:00
|
|
|
class Agent;
|
|
|
|
class RVOSimulator;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief Defines <i>k</i>d-trees for agents in the simulation.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
class KdTree {
|
|
|
|
public:
|
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief Defines an agent <i>k</i>d-tree node.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
class AgentTreeNode {
|
|
|
|
public:
|
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The beginning node number.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
size_t begin;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The ending node number.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
size_t end;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The left node number.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
size_t left;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The right node number.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
size_t right;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The maximum coordinates.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
Vector3 maxCoord;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief The minimum coordinates.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
Vector3 minCoord;
|
|
|
|
};
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief Constructs a <i>k</i>d-tree instance.
|
|
|
|
* \param sim The simulator instance.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
explicit KdTree();
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief Builds an agent <i>k</i>d-tree.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
void buildAgentTree(std::vector<Agent *> agents);
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
void buildAgentTreeRecursive(size_t begin, size_t end, size_t node);
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
/**
|
2021-12-16 05:15:23 +00:00
|
|
|
* \brief Computes the agent neighbors of the specified agent.
|
|
|
|
* \param agent A pointer to the agent for which agent neighbors are to be computed.
|
|
|
|
* \param rangeSq The squared range around the agent.
|
|
|
|
*/
|
2022-05-18 12:21:02 +00:00
|
|
|
void computeAgentNeighbors(Agent *agent, float rangeSq) const;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
void queryAgentTreeRecursive(Agent *agent, float &rangeSq, size_t node) const;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
std::vector<Agent *> agents_;
|
|
|
|
std::vector<AgentTreeNode> agentTree_;
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:21:02 +00:00
|
|
|
friend class Agent;
|
|
|
|
friend class RVOSimulator;
|
|
|
|
};
|
|
|
|
}
|
2021-12-16 05:15:23 +00:00
|
|
|
|
2022-05-18 12:53:52 +00:00
|
|
|
#endif /* RVO3D_KD_TREE_H_ */
|