Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NavMeshNode.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 
45 #ifndef __NAV_MESH_NODE_H__
46 #define __NAV_MESH_NODE_H__
47 
48 #include <fstream>
49 #include "fsmCommon.h"
50 #include "NavMeshPoly.h"
51 
52 namespace Menge {
53 
54  // Forward declarations
55  class NavMesh;
56  class NavMeshEdge;
57  class PathPlanner;
58  class NavMeshObstacle;
59 
64  class NavMeshNode {
65  public:
69  NavMeshNode();
70 
74  ~NavMeshNode();
75 
79  NavMeshNode & operator=( const NavMeshNode & n );
80 
86  void setID( unsigned int id ) { _id = id; }
87 
91  unsigned int getID() const { return _id; }
92 
98  inline void setCenter( const Vector2 & c ) { _center.set( c ); }
99 
105  Vector2 getCenter() const { return _center; }
106 
113 
119  size_t getVertexCount() const { return _poly._vertCount; }
120 
129  void setVertices( const Vector2 * vertices ) { _poly._vertices = vertices; }
130 
138  unsigned int getVertexID( size_t i ) const { return _poly._vertIDs[ i ]; }
139 
145  size_t getObstacleCount() const { return _obstCount; }
146 
153  const NavMeshObstacle * getObstacle( size_t i ) const { return _obstacles[ i ]; }
154 
161  NavMeshObstacle * getObstacle( size_t i ) { return _obstacles[ i ]; }
162 
166  size_t getNeighborCount() const { return _edgeCount; }
167 
176  const NavMeshNode * getNeighbor( size_t i ) const;
177 
183  size_t getEdgeCount() const { return _edgeCount; }
184 
191  NavMeshEdge * getEdge( size_t i ) { return _edges[ i ]; }
192 
199  const NavMeshEdge * getEdge( size_t i ) const { return _edges[ i ]; }
200 
209  NavMeshEdge * getConnection( unsigned nodeID );
210 
219  bool containsPoint( const Vector2 & point ) const { return _poly.containsPoint( point ); }
220 
229  bool loadFromAscii( std::ifstream & f );
230 
234  inline float getElevation( const Vector2 & p ) const { return _poly.getElevation( p ); }
235 
239  inline Vector2 getGradient() const { return _poly.getGradient(); }
240 
241  friend class NavMesh;
242  friend class NavMeshEdge;
243  friend class PathPlanner;
244 
245  protected:
250 
254  size_t _edgeCount;
255 
260 
264  size_t _obstCount;
265 
271 
276 
280  unsigned int _id;
281  };
282 } // namespace Menge
283 
284 #endif // __NAV_MESH_NODE_H__
unsigned int * _vertIDs
An array of indices into the vertex list defining the polygon. The indices must be ordered such that ...
Definition: NavMeshPoly.h:155
const NavMeshEdge * getEdge(size_t i) const
Retrieves a const pointer to the ith edge connected to this node.
Definition: NavMeshNode.h:199
NavMeshEdge ** _edges
An array of edges connecting to other nodes.
Definition: NavMeshNode.h:249
bool loadFromAscii(std::ifstream &f)
Sets the node properties from a node definition in the given ascii file stream.
Definition: NavMeshNode.cpp:128
NavMeshNode()
Constructor.
Definition: NavMeshNode.cpp:52
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
float getElevation(const Vector2 &point) const
Computes the elevation of the polygon at the given point.
Definition: NavMeshPoly.cpp:161
const NavMeshObstacle * getObstacle(size_t i) const
Returns a const pointer to the ith obstacle in the node.
Definition: NavMeshNode.h:153
NavMeshPoly _poly
The polygon associated with this node.
Definition: NavMeshNode.h:275
const NavMeshNode * getNeighbor(size_t i) const
Returns a pointer to the ith neighbor.
Definition: NavMeshNode.cpp:99
size_t _vertCount
The number of vertices in the polygon.
Definition: NavMeshPoly.h:160
unsigned int _id
The identifier of this node.
Definition: NavMeshNode.h:280
size_t getObstacleCount() const
Returns the number of obstacles connected to this node.
Definition: NavMeshNode.h:145
The navigation mesh adjacency graph node. It corresponds to a convex polygon in the navigation mesh...
Definition: NavMeshNode.h:64
NavMeshNode & operator=(const NavMeshNode &n)
Assignment operator.
Definition: NavMeshNode.cpp:68
NavMeshEdge * getConnection(unsigned nodeID)
Returns the pointer to the edge connecting this node with the node whose identifier is given...
Definition: NavMeshNode.cpp:106
The polygon used in each node of a navigation mesh graph.
Definition: NavMeshPoly.h:61
Vector2 getGradient() const
Computes the gradient based on this node's polygon.
Definition: NavMeshNode.h:239
void setID(unsigned int id)
Sets the node identifier.
Definition: NavMeshNode.h:86
void setVertices(const Vector2 *vertices)
Sets this node's polygon to the given vertex array. The polygon can then evaluate its indices with re...
Definition: NavMeshNode.h:129
bool containsPoint(const Vector2 &point) const
Reports if the given point is inside the polygon.
Definition: NavMeshNode.h:219
void set(Type x, Type y)
Set the x- and y-values from scalar values.
Definition: Vector2.h:121
Vector2 getCenter() const
Reports the center (centroid) of the node's polygon.
Definition: NavMeshNode.h:105
The navigation mesh adjacency graph edge.
Definition: NavMeshEdge.h:72
~NavMeshNode()
Destructor.
Definition: NavMeshNode.cpp:57
Defines the geometric, convex polygon for each navigation mesh node.
Class for computing paths through a navigation mesh.
Definition: PathPlanner.h:133
Vector2 getGradient() const
Reports the gradient of the polygon. Because it is a plane, the gradient is constant at all positions...
Definition: NavMeshPoly.h:106
Vector3 getCenter3D() const
Reports the center (centroid) of the node's polygon.
Definition: NavMeshNode.h:112
const Vector2 * _vertices
A pointer to the mesh vertex information for performing geometric tests.
Definition: NavMeshPoly.h:166
Vector2 _center
The "position" of the node - used to compute distance between node and goal (A* heuristic) ...
Definition: NavMeshNode.h:270
NavMeshObstacle ** _obstacles
An array of obstacles connected to this node.
Definition: NavMeshNode.h:259
float getElevation(const Vector2 &p) const
Computes the height based on this node's polygon.
Definition: NavMeshNode.h:234
size_t getEdgeCount() const
Reports the number of edges on the node.
Definition: NavMeshNode.h:183
unsigned int getID() const
Retrive the identifier for this node.
Definition: NavMeshNode.h:91
size_t _obstCount
The number of obstacles connecting to this node.
Definition: NavMeshNode.h:264
unsigned int getVertexID(size_t i) const
Gets the index of the ith vertex in this node's polygon.
Definition: NavMeshNode.h:138
Specification of an obstacle. It is the same as a pedModel specification but includes a pointer to a ...
Definition: NavMeshObstacle.h:61
Collection of convenient pre-compiler information for fsm definitions.
The class for defining a navigation mesh. A decomposition of the free space into a connected mesh of ...
Definition: NavMesh.h:120
size_t getVertexCount() const
Returns the number of vertices in the node's polygon.
Definition: NavMeshNode.h:119
size_t getNeighborCount() const
Reports the number of nodes adjacent to this node.
Definition: NavMeshNode.h:166
void setCenter(const Vector2 &c)
Sets the node's center value.
Definition: NavMeshNode.h:98
bool containsPoint(const Vector2 &point) const
Reports if the point lies inside the polygon. NOTE: This is limited to 2D polygons.
Definition: NavMeshPoly.cpp:75
NavMeshObstacle * getObstacle(size_t i)
Returns a const pointer to the ith obstacle in the node.
Definition: NavMeshNode.h:161
Type x() const
Get the x-value.
Definition: Vector2.h:106
size_t _edgeCount
The number of edges connecting to this node.
Definition: NavMeshNode.h:254
NavMeshEdge * getEdge(size_t i)
Retrieves the ith edge connected to this node.
Definition: NavMeshNode.h:191
Type y() const
Get the y-value.
Definition: Vector2.h:113