Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KNearestQuery.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 
43 #ifndef __K_NEAREST_QUERY_H__
44 #define __K_NEAREST_QUERY_H__
45 
46 // UTILS
47 #include "ProximityQuery.h"
48 #include "SpatialQueryStructs.h"
49 #include <vector>
50 
51 namespace Menge {
52 
53  namespace Agents {
54 
63  class KNearestQuery : public ProximityQuery {
64  public:
69 
70 
77  void filterAgent(const BaseAgent * agent, float distSq);
78 
85  void filterObstacle(const Obstacle * obstacle, float distSq);
86 
92  void setMaxAgentResults(size_t results){_maxAgentResults = results;}
93 
99  void setMaxObstacleResults(size_t results){_maxObstacleResults = results;}
100 
101 
107  void setQueryPoint(Vector2 point){_queryPoint = point;}
108 
114  void setQueryRangeSq(float range){_initialRange = range;}
115 
116 
123 
130 
136  size_t agentResultCount(){ return _agentResults.size();}
137 
143  size_t obstacleResultCount(){ return _obstacleResults.size();}
144 
145 
149  void startQuery();
150 
156  virtual Vector2 getQueryPoint() { return _queryPoint;};
157 
164  NearAgent getAgentResult(size_t i) { return _agentResults[i];};
165 
173 
180  virtual float getMaxAgentRange();
181 
188  virtual float getMaxObstacleRange() { return _initialRange; };
189 
190  protected:
194  size_t _maxAgentResults;
195 
200 
206 
212 
213 
217  std::vector<NearAgent> _agentResults;
218 
222  std::vector<NearObstacle> _obstacleResults;
223 
228 
233  };
234  } // namespace Agents
235 } // namespace Menge
236 #endif
size_t agentResultCount()
gets the number of agent results stored currently
Definition: KNearestQuery.h:136
size_t _maxObstacleResults
the max number of obstacle results to store
Definition: KNearestQuery.h:199
virtual float getMaxAgentRange()
updates the max agent query range if conditions inside the query are met typically, we don't shrink the query range until the result set is full
Definition: KNearestQuery.cpp:114
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
void setQueryPoint(Vector2 point)
sets the query point
Definition: KNearestQuery.h:107
float _initialRange
the base max range of queries
Definition: KNearestQuery.h:232
void filterObstacle(const Obstacle *obstacle, float distSq)
filters an obstacle and determines if it is within the set of k-nearest neighbors ...
Definition: KNearestQuery.cpp:80
struct to store obstacle proximity query results.
Definition: SpatialQueryStructs.h:87
void setMaxObstacleResults(size_t results)
sets the max number of obstacle results for this query to store
Definition: KNearestQuery.h:99
struct to store agent proximity query results.
Definition: SpatialQueryStructs.h:64
void setQueryRangeSq(float range)
sets the query point
Definition: KNearestQuery.h:114
void setMaxAgentResults(size_t results)
sets the max number of agent results for this query to store
Definition: KNearestQuery.h:92
std::vector< NearObstacle > _obstacleResults
vector of pairs. Each pair contains a distance to an obstacle, and the obstacle
Definition: KNearestQuery.h:222
virtual float getMaxObstacleRange()
updates the max query obstacle range if conditions inside the query are met typically, we don't shrink the query range until the result set is full
Definition: KNearestQuery.h:188
void filterAgent(const BaseAgent *agent, float distSq)
filters an agent and determines if it is within the set of k-nearest neighbors
Definition: KNearestQuery.cpp:51
float _maxAgentResultDistance
the max distance to an agent result. Useful for informing the spatial query to stop searching further...
Definition: KNearestQuery.h:205
The base class for filtering spatial queries according to proximity.
Definition: ProximityQuery.h:72
size_t obstacleResultCount()
gets the number of obstacle results stored currently
Definition: KNearestQuery.h:143
Vector2 _queryPoint
the start point for the query
Definition: KNearestQuery.h:227
NearAgent getAgentResult(size_t i)
gets the ith agent result
Definition: KNearestQuery.h:164
KNearestQuery()
default Constructor.
Definition: KNearestQuery.h:68
Defines static obstacles in the simulation.
Definition: Obstacle.h:56
size_t _maxAgentResults
the max number of agent results to store
Definition: KNearestQuery.h:188
size_t maxObstacleResults()
gets the max number of obstacle results for this query to store
Definition: KNearestQuery.h:129
virtual Vector2 getQueryPoint()
gets the start point for the query
Definition: KNearestQuery.h:156
Structs for storing results from spatial queries.
The base class for all objects which actually perform filtering and store results from spatial querie...
std::vector< NearAgent > _agentResults
vector of pairs. Each pair contains a distance to an agent, and the agent
Definition: KNearestQuery.h:217
Defines the basic agent properties and functionality that all simulation agents share.
Definition: BaseAgent.h:123
The K-Nearest query class.
Definition: KNearestQuery.h:63
float _maxObstacleResultDistance
the max distance to an obstacle result. Useful for informing the spatial query to stop searching furt...
Definition: KNearestQuery.h:211
The namespace that contains the basic simulation mechanisms.
void startQuery()
clears the result vectors. Resets the query
Definition: KNearestQuery.cpp:104
NearObstacle getObstacleResult(size_t i)
gets the ith obstacle result
Definition: KNearestQuery.h:172
size_t maxAgentResults()
gets the max number of agent results for this query to store
Definition: KNearestQuery.h:122