Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NavMeshEdge.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 
47 #ifndef __NAV_MESH_EDGE_H__
48 #define __NAV_MESH_EDGE_H__
49 
50 #include <fstream>
51 #include "mengeCommon.h"
52 
53  namespace Menge {
54 
55  // Forward declarations
56  class NavMesh;
57  class NavMeshNode;
58  namespace Agents {
59  class PrefVelocity;
60  }
61 
72  class NavMeshEdge {
73  public:
77  NavMeshEdge();
78 
82  ~NavMeshEdge();
83 
89  inline Vector2 getP0() const { return _point; }
90 
97  inline Vector2 getP0( float dist ) const { return _point + _dir * dist; }
98 
104  inline Vector2 getP1() const { return _point + _dir * _width; }
105 
112  inline Vector2 getP1( float dist ) const { return _point + _dir * (_width - dist); }
113 
119  inline Vector2 getDirection() const { return _dir; }
120 
126  NavMeshNode * getFirstNode() const { return _node0; }
127 
138  NavMeshNode * getOtherByID( unsigned int id ) const;
139 
150  NavMeshNode * getOtherByPtr( const NavMeshNode * node );
151 
162  const NavMeshNode * getOtherByPtr( const NavMeshNode * node ) const;
163 
164 
165 
167  // Getters/setters
169 
175  inline void setPoint( const Vector2 & p ) { _point.set( p ); }
176 
183  inline void setDirection( const Vector2 & d ) { _dir.set( d ); }
184 
190  inline void setWidth( float w ) { _width = w; }
191 
197  inline float getWidth() const { return _width; }
198 
205  inline void setNodes( NavMeshNode * n0, NavMeshNode * n1 ) { _node0 = n0; _node1 = n1; }
206 
208  // Geometric queries
210 
217  inline Vector2 getPoint( float t ) const { return _point + t * _dir; }
218 
232  bool pointClear( const Vector2 & pos, float radius, float param ) const;
233 
246  Vector2 targetPoint( const Vector2 & pos, float radius ) const;
247 
261  Vector2 getClearDirection( const Vector2 & pos, float radius, const Vector2 & dir ) const;
262 
280  void setClearDirections( const Vector2 & pos, float radius, const Vector2 & dir, Agents::PrefVelocity & pVel ) const;
281 
288  float getSqDist( const Vector2 & pt ) const;
289 
299  float getSqDist( const Vector2 & pt, Vector2 & nearPt ) const;
300 
307  float getDist( const Vector2 & pt ) const { return sqr( getSqDist( pt ) ); }
308 
319  float getNodeDistance( float minWidth );
320 
327  inline float getNodeDistance() const { return _distance; }
328 
339  bool loadFromAscii( std::ifstream & f, Vector2 * vertices );
340 
350  bool pointOnLeft( unsigned int id ) const;
351 
361  bool pointOnLeft( const NavMeshNode * node ) const;
362 
363  friend class NavMesh;
364 
365  protected:
366  // Geometry of the edge's portal
372 
378 
382  float _width;
383 
384  // Logical connectivity data
389  float _distance;
390 
391  // TODO: Does lower-indexed/upper-indexed really matter?
398 
405  };
406 } // namespace Menge
407 
408 #endif // __NAV_MESH_EDGE_H__
Vector2 getPoint(float t) const
Selects a point along the edge.
Definition: NavMeshEdge.h:217
void setPoint(const Vector2 &p)
Sets the edge's point value.
Definition: NavMeshEdge.h:175
Vector2 getP1() const
Returns the second edge point.
Definition: NavMeshEdge.h:104
NavMeshNode * getFirstNode() const
Returns the first attached NavMeshNode.
Definition: NavMeshEdge.h:126
Vector2 _point
The point that defines the portal geometry. The portal is defined as p(t) = _point + t * _dir...
Definition: NavMeshEdge.h:371
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Vector2 getP1(float dist) const
Returns a point inset from the second end point.
Definition: NavMeshEdge.h:112
NavMeshNode * _node0
A pointer to the first nav mesh node connected by this edge. When standing in this node...
Definition: NavMeshEdge.h:397
NavMeshEdge()
Constructor.
Definition: NavMeshEdge.cpp:57
bool loadFromAscii(std::ifstream &f, Vector2 *vertices)
Sets the edge properties from an edge definition in the given ascii file stream.
Definition: NavMeshEdge.cpp:143
void setWidth(float w)
Sets the edge's width value.
Definition: NavMeshEdge.h:190
The navigation mesh adjacency graph node. It corresponds to a convex polygon in the navigation mesh...
Definition: NavMeshNode.h:64
float getWidth() const
Reports the width of the edge.
Definition: NavMeshEdge.h:197
NavMeshNode * getOtherByPtr(const NavMeshNode *node)
Returns a pointer to the node on the opposite end of the edge from the given node (by pointer)...
Definition: NavMeshEdge.cpp:78
NavMeshNode * _node1
A pointer to the second nav mesh node connected by this edge. When standing in this node...
Definition: NavMeshEdge.h:404
float getNodeDistance() const
Return the Euclidian distance between the two nodes this edge connects.
Definition: NavMeshEdge.h:327
void set(Type x, Type y)
Set the x- and y-values from scalar values.
Definition: Vector2.h:121
The navigation mesh adjacency graph edge.
Definition: NavMeshEdge.h:72
float _width
The width of the portal.
Definition: NavMeshEdge.h:382
void setNodes(NavMeshNode *n0, NavMeshNode *n1)
Sets the connected node pointers.
Definition: NavMeshEdge.h:205
float getDist(const Vector2 &pt) const
Reports the distance to the edge from the given point.
Definition: NavMeshEdge.h:307
NavMeshNode * getOtherByID(unsigned int id) const
Returns a pointer to the node on the opposite end of the edge from the given node (by id)...
Definition: NavMeshEdge.cpp:67
float getSqDist(const Vector2 &pt) const
Reports the squared distance to the edge from the given point.
Definition: NavMeshEdge.cpp:100
bool pointOnLeft(unsigned int id) const
Reports if _point in this edge is on the left for the node with the given id.
Definition: NavMeshEdge.cpp:513
Vector2 targetPoint(const Vector2 &pos, float radius) const
Computes a target point with respect to this edge. The target point is a point along the line of the ...
Definition: NavMeshEdge.cpp:181
The class for defining a navigation mesh. A decomposition of the free space into a connected mesh of ...
Definition: NavMesh.h:120
void setDirection(const Vector2 &d)
Sets the edge's direction value.
Definition: NavMeshEdge.h:183
Vector2 getClearDirection(const Vector2 &pos, float radius, const Vector2 &dir) const
Computes the collision-free velocity towards the portal based on the agent radius and the preferred d...
Definition: NavMeshEdge.cpp:244
The definition of a preferred velocity.
Definition: PrefVelocity.h:68
bool pointClear(const Vector2 &pos, float radius, float param) const
Reports if the point q = _point + param * _dir is clear for an agent with the given radius positioned...
Definition: NavMeshEdge.cpp:166
The namespace that contains the basic simulation mechanisms.
~NavMeshEdge()
Destructor.
Definition: NavMeshEdge.cpp:62
Vector2 _dir
The unit-length direction of the portal. See _point for how the portal is defined w...
Definition: NavMeshEdge.h:377
Vector2 getP0() const
Returns the first edge point.
Definition: NavMeshEdge.h:89
void setClearDirections(const Vector2 &pos, float radius, const Vector2 &dir, Agents::PrefVelocity &pVel) const
Sets the directions of a preferred velocity that passes through the edge biased towards the indicated...
Definition: NavMeshEdge.cpp:385
float _distance
The "distance" between the two nodes connected by this edge. Used to estimate the cost of a path (the...
Definition: NavMeshEdge.h:389
Vector2 getDirection() const
Returns the direction of the edge.
Definition: NavMeshEdge.h:119
Vector2 getP0(float dist) const
Returns a point inset from the first end point.
Definition: NavMeshEdge.h:97