1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
/*
* RVOSimulator3d.h
* RVO2-3D Library
*
* SPDX-FileCopyrightText: 2008 University of North Carolina at Chapel Hill
* SPDX-License-Identifier: Apache-2.0
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* 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
*
* <https://gamma.cs.unc.edu/RVO2/>
*/
#ifndef RVO3D_RVO_SIMULATOR_H_
#define RVO3D_RVO_SIMULATOR_H_
/**
* @file RVOSimulator3d.h
* @brief Contains the RVOSimulator3D class.
*/
#include <cstddef>
#include <limits>
#include <vector>
#include "Vector3.h"
namespace RVO3D {
class Agent3D;
class KdTree3D;
class Plane;
/**
* @brief Error value. A value equal to the largest unsigned integer, which is
* returned in case of an error by functions in RVO::RVOSimulator.
*/
const std::size_t RVO3D_ERROR = std::numeric_limits<std::size_t>::max();
/**
* @brief Defines the simulation. The main class of the library that contains
* all simulation functionality.
*/
class RVOSimulator3D {
public:
/**
* @brief Constructs a simulator instance.
*/
RVOSimulator3D();
/**
* @brief Constructs a simulator instance and sets the default properties
* for any new agent that is added.
* @param[in] timeStep The time step of the simulation. Must be positive.
* @param[in] neighborDist The default maximum distance (center point to
* center point) to other agents a new agent takes
* into account in the navigation. The larger this
* number, the longer the running time of the
* simulation. If the number is too low, the
* simulation will not be safe. Must be non-negative.
* @param[in] maxNeighbors The default maximum number of other agents a new
* agent takes into account in the navigation. The
* larger this number, the longer the running time of
* the simulation. If the number is too low, the
* simulation will not be safe.
* @param[in] timeHorizon The default minimum amount of time for which a new
* agent's velocities that are computed by the
* simulation are safe with respect to other agents.
* The larger this number, the sooner an agent will
* respond to the presence of other agents, but the
* less freedom the agent has in choosing its
* velocities. Must be positive.
* @param[in] radius The default radius of a new agent. Must be
* non-negative.
* @param[in] maxSpeed The default maximum speed of a new agent. Must be
* non-negative.
* @param[in] velocity The default initial three-dimensional linear
* velocity of a new agent (optional).
*/
RVOSimulator3D(float timeStep, float neighborDist, std::size_t maxNeighbors,
float timeHorizon, float radius, float maxSpeed,
const Vector3 &velocity = Vector3());
/**
* @brief Destroys this simulator instance.
*/
~RVOSimulator3D();
/**
* @brief Adds a new agent with default properties to the simulation.
* @param[in] position The three-dimensional starting position of this agent.
* @return The number of the agent or RVO::RVO3D_ERROR when the agent
* defaults have not been set.
*/
std::size_t addAgent(const Vector3 &position);
/**
* @brief Adds a new agent to the simulation.
* @param[in] position The three-dimensional starting position of this
* agent.
* @param[in] neighborDist The maximum distance (center point to center
* point) to other agents this agent takes into
* account in the navigation. The larger this number,
* the longer the running time of the simulation. If
* the number is too low, the simulation will not be
* safe. Must be non-negative.
* @param[in] maxNeighbors The maximum number of other agents this agent takes
* into account in the navigation. The larger this
* number, the longer the running time of the
* simulation. If the number is too low, the
* simulation will not be safe.
* @param[in] timeHorizon The minimum amount of time for which this agent's
* velocities that are computed by the simulation are
* safe with respect to other agents. The larger this
* number, the sooner this agent will respond to the
* presence of other agents, but the less freedom this
* agent has in choosing its velocities. Must be
* positive.
* @param[in] radius The radius of this agent. Must be non-negative.
* @param[in] maxSpeed The maximum speed of this agent. Must be
* non-negative.
* @param[in] velocity The initial three-dimensional linear velocity of
* this agent (optional).
* @return The number of the agent.
*/
std::size_t addAgent(const Vector3 &position, float neighborDist,
std::size_t maxNeighbors, float timeHorizon,
float radius, float maxSpeed,
const Vector3 &velocity = Vector3());
/**
* @brief Lets the simulator perform a simulation step and updates the
* three-dimensional position and three-dimensional velocity of each
* agent.
*/
void doStep();
/**
* @brief Returns the specified agent neighbor of the specified agent.
* @param[in] agentNo The number of the agent whose agent neighbor is to
* be retrieved.
* @param[in] neighborNo The number of the agent neighbor to be retrieved.
* @return The number of the neighboring agent.
*/
std::size_t getAgentAgentNeighbor(std::size_t agentNo,
std::size_t neighborNo) const;
/**
* @brief Returns the maximum neighbor count of a specified agent.
* @param[in] agentNo The number of the agent whose maximum neighbor count is
* to be retrieved.
* @return The present maximum neighbor count of the agent.
*/
std::size_t getAgentMaxNeighbors(std::size_t agentNo) const;
/**
* @brief Returns the maximum speed of a specified agent.
* @param[in] agentNo The number of the agent whose maximum speed is to be
* retrieved.
* @return The present maximum speed of the agent.
*/
float getAgentMaxSpeed(std::size_t agentNo) const;
/**
* @brief Returns the maximum neighbor distance of a specified agent.
* @param[in] agentNo The number of the agent whose maximum neighbor distance
* is to be retrieved.
* @return The present maximum neighbor distance of the agent.
*/
float getAgentNeighborDist(std::size_t agentNo) const;
/**
* @brief Returns the count of agent neighbors taken into account to
* compute the current velocity for the specified agent.
* @param[in] agentNo The number of the agent whose count of agent neighbors
* is to be retrieved.
* @return The count of agent neighbors taken into account to compute the
* current velocity for the specified agent.
*/
std::size_t getAgentNumAgentNeighbors(std::size_t agentNo) const;
/**
* @brief Returns the count of ORCA constraints used to compute the
* current velocity for the specified agent.
* @param[in] agentNo The number of the agent whose count of ORCA constraints
* i to be retrieved.
* @return The count of ORCA constraints used to compute the current
* velocity for the specified agent.
*/
std::size_t getAgentNumORCAPlanes(std::size_t agentNo) const;
/**
* @brief Returns the specified ORCA constraint of the specified agent.
* @param[in] agentNo The number of the agent whose ORCA constraint is to be
* retrieved.
* @param[in] planeNo The number of the ORCA constraint to be retrieved.
* @return A plane representing the specified ORCA constraint.
* @note The halfspace to which the normal of the plane points is the
* region of permissible velocities with respect to the specified
* ORCA constraint.
*/
const Plane &getAgentORCAPlane(std::size_t agentNo,
std::size_t planeNo) const;
/**
* @brief Returns the three-dimensional position of a specified agent.
* @param[in] agentNo The number of the agent whose three-dimensional position
* is to be retrieved.
* @return The present three-dimensional position of the (center of the)
* agent.
*/
const Vector3 &getAgentPosition(std::size_t agentNo) const;
/**
* @brief Returns the three-dimensional preferred velocity of a specified
* agent.
* @param[in] agentNo The number of the agent whose three-dimensional
* preferred velocity is to be retrieved.
* @return The present three-dimensional preferred velocity of the agent.
*/
const Vector3 &getAgentPrefVelocity(std::size_t agentNo) const;
/**
* @brief Returns the radius of a specified agent.
* @param[in] agentNo The number of the agent whose radius is to be retrieved.
* @return The present radius of the agent.
*/
float getAgentRadius(std::size_t agentNo) const;
/**
* @brief Returns the time horizon of a specified agent.
* @param[in] agentNo The number of the agent whose time horizon is to be
* retrieved.
* @return The present time horizon of the agent.
*/
float getAgentTimeHorizon(std::size_t agentNo) const;
/**
* @brief Returns the three-dimensional linear velocity of a specified
* agent.
* @param[in] agentNo The number of the agent whose three-dimensional linear
* velocity is to be retrieved.
* @return The present three-dimensional linear velocity of the agent.
*/
const Vector3 &getAgentVelocity(std::size_t agentNo) const;
/**
* @brief Returns the global time of the simulation.
* @return The present global time of the simulation (zero initially).
*/
float getGlobalTime() const { return globalTime_; }
/**
* @brief Returns the count of agents in the simulation.
* @return The count of agents in the simulation.
*/
std::size_t getNumAgents() const { return agents_.size(); }
/**
* @brief Returns the time step of the simulation.
* @return The present time step of the simulation.
*/
float getTimeStep() const { return timeStep_; }
/**
* @brief Removes an agent from the simulation.
* @param[in] agentNo The number of the agent that is to be removed.
* @note After the removal of the agent, the agent that previously had
* number getNumAgents() - 1 will now have number agentNo.
*/
void removeAgent(std::size_t agentNo);
/**
* @brief Sets the default properties for any new agent that is added.
* @param[in] neighborDist The default maximum distance (center point to
* center point) to other agents a new agent takes
* into account in the navigation. The larger this
* number, the longer he running time of the
* simulation. If the number is too low, the
* simulation will not be safe. Must be non-negative.
* @param[in] maxNeighbors The default maximum number of other agents a new
* agent takes into account in the navigation. The
* larger this number, the longer the running time of
* the simulation. If the number is too low, the
* simulation will not be safe.
* @param[in] timeHorizon The default minimum amount of time for which a new
* agent's velocities that are computed by the
* simulation are safe with respect to other agents.
* The larger this number, the sooner an agent will
* respond to the presence of other agents, but the
* less freedom the agent has in choosing its
* velocities. Must be positive.
* @param[in] radius The default radius of a new agent. Must be
* non-negative.
* @param[in] maxSpeed The default maximum speed of a new agent. Must be
* non-negative.
* @param[in] velocity The default initial three-dimensional linear
* velocity of a new agent (optional).
*/
void setAgentDefaults(float neighborDist, std::size_t maxNeighbors,
float timeHorizon, float radius, float maxSpeed,
const Vector3 &velocity = Vector3());
/**
* @brief Sets the maximum neighbor count of a specified agent.
* @param[in] agentNo The number of the agent whose maximum neighbor
* count is to be modified.
* @param[in] maxNeighbors The replacement maximum neighbor count.
*/
void setAgentMaxNeighbors(std::size_t agentNo, std::size_t maxNeighbors);
/**
* @brief Sets the maximum speed of a specified agent.
* @param[in] agentNo The number of the agent whose maximum speed is to be
* modified.
* @param[in] maxSpeed The replacement maximum speed. Must be non-negative.
*/
void setAgentMaxSpeed(std::size_t agentNo, float maxSpeed);
/**
* @brief Sets the maximum neighbor distance of a specified agent.
* @param[in] agentNo The number of the agent whose maximum neighbor
* distance is to be modified.
* @param[in] neighborDist The replacement maximum neighbor distance. Must be
* non-negative.
*/
void setAgentNeighborDist(std::size_t agentNo, float neighborDist);
/**
* @brief Sets the three-dimensional position of a specified agent.
* @param[in] agentNo The number of the agent whose three-dimensional
* position is to be modified.
* @param[in] position The replacement of the three-dimensional position.
*/
void setAgentPosition(std::size_t agentNo, const Vector3 &position);
/**
* @brief Sets the three-dimensional preferred velocity of a specified
* agent.
* @param[in] agentNo The number of the agent whose three-dimensional
* preferred velocity is to be modified.
* @param[in] prefVelocity The replacement of the three-dimensional preferred
* velocity.
*/
void setAgentPrefVelocity(std::size_t agentNo, const Vector3 &prefVelocity);
/**
* @brief Sets the radius of a specified agent.
* @param[in] agentNo The number of the agent whose radius is to be modified.
* @param[in] radius The replacement radius. Must be non-negative.
*/
void setAgentRadius(std::size_t agentNo, float radius);
/**
* @brief Sets the time horizon of a specified agent with respect to other
* agents.
* @param[in] agentNo The number of the agent whose time horizon is to be
* modified.
* @param[in] timeHorizon The replacement time horizon with respect to other
* agents. Must be positive.
*/
void setAgentTimeHorizon(std::size_t agentNo, float timeHorizon);
/**
* @brief Sets the three-dimensional linear velocity of a specified agent.
* @param[in] agentNo The number of the agent whose three-dimensional linear
* velocity is to be modified.
* @param[in] velocity The replacement three-dimensional linear velocity.
*/
void setAgentVelocity(std::size_t agentNo, const Vector3 &velocity);
/**
* @brief Sets the time step of the simulation.
* @param[in] timeStep The time step of the simulation. Must be positive.
*/
void setTimeStep(float timeStep) { timeStep_ = timeStep; }
public:
/* Not implemented. */
RVOSimulator3D(const RVOSimulator3D &other);
/* Not implemented. */
RVOSimulator3D &operator=(const RVOSimulator3D &other);
Agent3D *defaultAgent_;
KdTree3D *kdTree_;
float globalTime_;
float timeStep_;
std::vector<Agent3D *> agents_;
friend class Agent3D;
friend class KdTree3D;
};
} /* namespace RVO3D */
#endif /* RVO3D_RVO_SIMULATOR_H_ */
|