Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Obstacle.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 
44 #ifndef OBSTACLE_H
45 #define OBSTACLE_H
46 
47 #include "mengeCommon.h"
48 
49 namespace Menge {
50 
51  namespace Agents {
52 
56  class MENGE_API Obstacle {
57  public:
61  enum NearTypeEnum {
62  FIRST,
63  MIDDLE,
64  LAST
65  };
66 
70  Obstacle();
71 
75  ~Obstacle();
76 
81  inline Vector2 normal() const { return Vector2( _unitDir.y(), -_unitDir.x() ); }
82 
86  inline const Vector2 & getP0() const { return _point; }
87 
91  inline const Vector2 midPt() const { return _point + ( 0.5f * _length) * _unitDir; }
92 
96  Vector2 getP1() const;
97 
101  const Obstacle * next() const { return _nextObstacle; }
102 
114  NearTypeEnum distanceSqToPoint( const Vector2 & pt, Vector2 & nearPt, float & distSq ) const;
115 
126  float circleIntersection( const Vector2 & dir, const Vector2 & start, float radius ) const;
127 
133  inline float length() const { return _length; }
134 
141  bool pointOnObstacle( const Vector2 & pt ) const;
142 
152  // NOTE: This test is "safe" because if _doubleSided is true, the leftOf test doesn't
153  // get performed. If it is false, then _nextObstacle must point to a valid obstacle.
154  inline bool pointOutside( const Vector2 & point ) const { return _doubleSided || ( leftOf( _point, getP1(), point ) < 0.f ); }
155 
166  inline bool p0Convex( bool agtOnRight) const { return agtOnRight ? _isConvex : _doubleSided && !_isConvex; }
167 
178  // NOTE: The only way for _nextObstacle to be NULL is for this to be double sided.
179  // And end points of double-sided obstacles are always convex.
180  inline bool p1Convex( bool agtOnRight) const { return _nextObstacle == 0x0 ? true : ( agtOnRight ? _nextObstacle->_isConvex : _doubleSided && _nextObstacle->_isConvex ); }
181 
191  inline void setClosedState( bool closed ) { _doubleSided = !closed; }
192 
200 
205  bool _isConvex;
206 
212 
217 
223 
228 
232  float _length;
233 
237  size_t _id;
238 
242  size_t _class;
243  };
244 
255  inline MENGE_API float distSqPointLineSegment(const Vector2& a, const Vector2& b,
256  const Vector2& c)
257  {
258  const float r = ((c - a) * (b - a)) / absSq(b - a);
259 
260  if (r < 0.0f) {
261  return absSq(c - a);
262  } else if (r > 1.0f) {
263  return absSq(c - b);
264  } else {
265  return absSq(c - (a + r * (b - a)));
266  }
267  }
268  } // namespace Agents
269 } // namespace Menge
270 #endif
271 
size_t _id
A unique identifier for this obstacle.
Definition: Obstacle.h:237
size_t _class
The class of obstacle, used so agents can ignore/include obstacles.
Definition: Obstacle.h:242
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Vector2 normal() const
Retrieves the normal of the obstacle.
Definition: Obstacle.h:81
Obstacle * _prevObstacle
Pointer to the previous obstacle in the greater obstacle structure. If the obstacle is open...
Definition: Obstacle.h:222
void setClosedState(bool closed)
Sets the obstacle's closed state.
Definition: Obstacle.h:191
const Obstacle * next() const
Returns the next obstacle in sequence.
Definition: Obstacle.h:101
float length() const
Returns the length of the obstacle.
Definition: Obstacle.h:133
float _length
The distance in the direction the obstacle extends.
Definition: Obstacle.h:232
Obstacle * _nextObstacle
Pointer to the next obstacle in the greater obstacle structure. If the obstacle is open...
Definition: Obstacle.h:211
bool p0Convex(bool agtOnRight) const
Reports if the obstacle is convext at _point.
Definition: Obstacle.h:166
Vector2 _unitDir
The direction the obstacle extends from the originating point.
Definition: Obstacle.h:227
Vector2 _point
The point from which the obstacle is defined.
Definition: Obstacle.h:216
const Vector2 & getP0() const
Retrieve the first point on the obstacle.
Definition: Obstacle.h:86
Defines static obstacles in the simulation.
Definition: Obstacle.h:56
const Vector2 midPt() const
Retrieve the obstacle's mid-point.
Definition: Obstacle.h:91
bool p1Convex(bool agtOnRight) const
Reports if the obstacle is convext at _point + _length * _unitDir.
Definition: Obstacle.h:180
NearTypeEnum
An enumeration to define the type of nearest point - first, middle, last.
Definition: Obstacle.h:61
The namespace that contains the basic simulation mechanisms.
bool _doubleSided
Reports if the obstacle is double sided.
Definition: Obstacle.h:199
bool _isConvex
Reports if the obstacle is convex around the obstacle's point (_point).
Definition: Obstacle.h:205
bool pointOutside(const Vector2 &point) const
Reports if the given point is on the "outside" of the obstacle. This definition depends on whether th...
Definition: Obstacle.h:154