Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpatialQueryKDTree.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright and trademark 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
49 #ifndef __SPATIAL_QUERY_KD_TREE_H__
50 #define __SPATIAL_QUERY_KD_TREE_H__
51 
52 // UTILS
57 
58 namespace Menge {
59 
60  namespace Agents {
61 
66  class MENGE_API BergKDTree : public SpatialQuery {
67  public:
71  explicit BergKDTree(): SpatialQuery() {
72  }
73 
74  // Agent operations
75 
81  virtual void setAgents( const std::vector< BaseAgent * > & agents ) {
82  _agentTree.setAgents( agents );
83  }
84 
89  virtual void updateAgents() {
90  _agentTree.buildTree();
91  };
92 
98  virtual void agentQuery( ProximityQuery *query) const {
99  _agentTree.agentQuery(query);
100  }
101 
102  // Obstacle operations
103 
108  virtual void processObstacles() {
109  _obstTree.buildTree( _obstacles );
110  }
111 
118  virtual void obstacleQuery( ProximityQuery *query) const {
119  _obstTree.obstacleQuery( query);
120  }
121 
135  virtual bool queryVisibility(const Vector2& q1, const Vector2& q2, float radius) const {
136  return _obstTree.queryVisibility( q1, q2, radius );
137  }
138 
139  protected:
144 
149 
150  };
151 
153 
157  class MENGE_API BergKDTreeFactory : public SpatialQueryFactory {
158  public:
168  virtual const char * name() const { return "kd-tree"; }
169 
177  virtual const char * description() const {
178  return "Performs spatial queries by creating a kd-tree on the agents and a bsp " \
179  "tree on the obstacles.";
180  };
181 
182  protected:
193  SpatialQuery * instance() const { return new BergKDTree(); }
194  };
195  } // namespace Agents
196 } // namespace Menge
197 #endif //__SPATIAL_QUERY_KD_TREE_H__
virtual void updateAgents()
Allows the spatial query structure to update its knowledge of the agent positions.
Definition: SpatialQueryKDTree.h:89
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
virtual void agentQuery(ProximityQuery *query) const
performs an agent based proximity query
Definition: SpatialQueryKDTree.h:98
Defines an obstacle kd-tree.
Definition: ObstacleKDTree.h:96
virtual const char * description() const
A description of the spatial query.
Definition: SpatialQueryKDTree.h:177
A class for parsing the xml description of a spatial query and instantiating particular instances...
Definition: SpatialQueryFactory.h:62
Spatial query object. Used to determine obstacles and agents near an agent – based on a kd-tree...
Definition: SpatialQueryKDTree.h:66
virtual void processObstacles()
Do the necessary pre-computation to support obstacle definitions.
Definition: SpatialQueryKDTree.h:108
virtual void obstacleQuery(ProximityQuery *query) const
perform an obstacle based proximity query
Definition: SpatialQueryKDTree.h:118
The base class for filtering spatial queries according to proximity.
Definition: ProximityQuery.h:72
The factory for parsing xml data and instantiating spaital query implementations. ...
virtual void setAgents(const std::vector< BaseAgent * > &agents)
Define the set of agents on which kd-tree will query.
Definition: SpatialQueryKDTree.h:81
AgentKDTree _agentTree
A kd-tree for the agent queries.
Definition: SpatialQueryKDTree.h:143
virtual bool queryVisibility(const Vector2 &q1, const Vector2 &q2, float radius) const
Queries the visibility between two points within a specified radius.
Definition: SpatialQueryKDTree.h:135
BergKDTree()
Constructor.
Definition: SpatialQueryKDTree.h:71
The base class for all objects which support agent spatial queries including: k-nearest agent neighbo...
The base class for performing spatial queries.
Definition: SpatialQuery.h:114
virtual const char * name() const
The name of the spatial query implemenation.
Definition: SpatialQueryKDTree.h:168
Contains the definition of the ObstacleKDTree class. Performs spatial queries for Obstacles...
SpatialQuery * instance() const
Create an instance of this class's spatial query implementation.
Definition: SpatialQueryKDTree.h:193
The namespace that contains the basic simulation mechanisms.
Contains the definition of the AgentKDTree class. Performs spatial queries for agents.
Factory for the BergKDTree.
Definition: SpatialQueryKDTree.h:157
A kd-tree for performing nearest-neighbor searches.
Definition: AgentKDTree.h:74
ObstacleKDTree _obstTree
A kd-tree for the obstacle queries.
Definition: SpatialQueryKDTree.h:148