2020-01-10 12:22:34 +01: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 14:53:52 +02:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2020-01-10 12:22:34 +01: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 14:53:52 +02:00
|
|
|
* <https://gamma.cs.unc.edu/RVO2/>
|
2020-01-10 12:22:34 +01:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file KdTree.h
|
|
|
|
* \brief Contains the KdTree class.
|
|
|
|
*/
|
2022-05-18 14:53:52 +02:00
|
|
|
#ifndef RVO3D_KD_TREE_H_
|
|
|
|
#define RVO3D_KD_TREE_H_
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Vector3.h"
|
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
namespace RVO3D {
|
|
|
|
class Agent3D;
|
|
|
|
class RVOSimulator3D;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief Defines <i>k</i>d-trees for agents in the simulation.
|
|
|
|
*/
|
2023-01-10 07:14:16 +01:00
|
|
|
class KdTree3D {
|
2022-05-18 14:21:02 +02:00
|
|
|
public:
|
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief Defines an agent <i>k</i>d-tree node.
|
|
|
|
*/
|
2023-01-10 07:14:16 +01:00
|
|
|
class AgentTreeNode3D {
|
2022-05-18 14:21:02 +02:00
|
|
|
public:
|
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The beginning node number.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
size_t begin;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The ending node number.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
size_t end;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The left node number.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
size_t left;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The right node number.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
size_t right;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The maximum coordinates.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
Vector3 maxCoord;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief The minimum coordinates.
|
|
|
|
*/
|
2022-05-18 14:21:02 +02:00
|
|
|
Vector3 minCoord;
|
|
|
|
};
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief Constructs a <i>k</i>d-tree instance.
|
|
|
|
* \param sim The simulator instance.
|
|
|
|
*/
|
2023-01-10 07:14:16 +01:00
|
|
|
explicit KdTree3D(RVOSimulator3D *sim);
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01:00
|
|
|
* \brief Builds an agent <i>k</i>d-tree.
|
|
|
|
*/
|
2023-01-10 07:14:16 +01:00
|
|
|
void buildAgentTree(std::vector<Agent3D *> agents);
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
void buildAgentTreeRecursive(size_t begin, size_t end, size_t node);
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:21:02 +02:00
|
|
|
/**
|
2020-01-10 12:22:34 +01: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.
|
|
|
|
*/
|
2023-01-10 07:14:16 +01:00
|
|
|
void computeAgentNeighbors(Agent3D *agent, float rangeSq) const;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
void queryAgentTreeRecursive(Agent3D *agent, float &rangeSq, size_t node) const;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
std::vector<Agent3D *> agents_;
|
|
|
|
std::vector<AgentTreeNode3D> agentTree_;
|
|
|
|
RVOSimulator3D *sim_;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2023-01-10 07:14:16 +01:00
|
|
|
friend class Agent3D;
|
|
|
|
friend class RVOSimulator3D;
|
2022-05-18 14:21:02 +02:00
|
|
|
};
|
|
|
|
}
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-05-18 14:53:52 +02:00
|
|
|
#endif /* RVO3D_KD_TREE_H_ */
|