Menge Plugin Examples
A Collection of Example Plugins for the Menge Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
FreeFormation.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 __FREE_FORMATION_H__
48 #define __FREE_FORMATION_H__
49 
50 #include <map>
51 #include <vector>
52 #include "FSM.h"
53 #include "BaseAgent.h"
54 #include "resources/Resource.h"
55 #include "mengeCommon.h"
56 #include "PrefVelocity.h"
57 
58 using namespace Menge;
59 
60 
72 namespace Formations {
73 
77  struct FormationPoint {
78  size_t _id;
79  Vector2 _pos;
80  float _dist;
81  Vector2 _dir;
82  bool _border;
83  float _weight;
84  };
85 
89  class FreeFormation : public Resource{
90  public:
96  FreeFormation(const std::string & name);
97 
101  ~FreeFormation();
102 
108  virtual const std::string & getLabel() const { return LABEL; }
109 
122  static Resource * load( const std::string & fileName );
123 
128  static const std::string LABEL;
129 
138  void addAgent( const Agents::BaseAgent * agt );
139 
145  void removeAgent(const Agents::BaseAgent *agt);
146 
153  void mapAgentsToFormation(const BFSM::FSM * fsm);
154 
166  bool getGoalForAgent(const Agents::BaseAgent * agt, Agents::PrefVelocity &pVel, Vector2 &target);
167 
168  protected:
169 
176  void mapAgentToPoint(const Agents::BaseAgent *agt);
177 
184  void mapPointToAgent(FormationPoint *pt);
185 
193  void addFormationPoint(Vector2 pt, bool borderPoint, float weight );
194 
200  void addAgentPoint(const Agents::BaseAgent *agt);
201 
209  void normalizeFormation();
210 
219  float formationDistance( FormationPoint *pt1, FormationPoint *pt2 );
220 
225  std::map< size_t, size_t > _agent_formationPoint;
226 
231  std::map< size_t, size_t > _formationPoint_agent;
232 
239  std::map< size_t, FormationPoint * > _agentPoints;
240 
244  std::vector< FormationPoint * > _formationPoints;
245 
249  std::vector< FormationPoint * > _borderPoints;
250 
254  Vector2 _direction;
255 
259  float _speed;
260 
264  Vector2 _pos;
265 
271 
276  std::map< size_t, Vector2 > _agentPrefDirs;
277 
282  std::map< size_t, Vector2 > _agentPrefVels;
283 
291  std::map< size_t, float > _agentWeights;
292 
297  std::map< size_t, const Agents::BaseAgent * > _agents;
298  };
299 
304 
311  FormationPtr loadFormation( const std::string & fileName ) throw ( ResourceException );
312 };
313 
314 #endif
std::map< size_t, size_t > _agent_formationPoint
Maps formation point identifiers to agent identifiers. Why identifiers?
Definition: FreeFormation.h:225
bool _border
Flag indicating if this is a border point (true) or not (false).
Definition: FreeFormation.h:82
std::map< size_t, size_t > _formationPoint_agent
Maps agent identifiers to formation point identifiers. Why identifiers?
Definition: FreeFormation.h:231
float _weight
The weight of the sentinel point.
Definition: FreeFormation.h:83
Vector2 _dir
The direction of the sentinel point to the formation center.
Definition: FreeFormation.h:81
std::map< size_t, const Agents::BaseAgent * > _agents
A cache of previoius agent preferred directions. Maps agent identifiers to agents.
Definition: FreeFormation.h:297
std::map< size_t, FormationPoint * > _agentPoints
Maps agent identifiers to formation points. This lets me seach over a space instead of doing a lot of...
Definition: FreeFormation.h:239
float _dist
The distance of the sentinel point to the formation center.
Definition: FreeFormation.h:80
std::map< size_t, Vector2 > _agentPrefDirs
A cache of previoius agent preferred directions. Maps agent identifiers to directions.
Definition: FreeFormation.h:276
The name space for the Formation Model.
Definition: FormationsModifier.cpp:45
std::vector< FormationPoint * > _borderPoints
A separate cache of border points – this is a subset of _formationPoints.
Definition: FreeFormation.h:249
std::map< size_t, float > _agentWeights
A cache of previoius agent preferred weights. Maps agent identifiers to weights.
Definition: FreeFormation.h:291
std::vector< FormationPoint * > _formationPoints
The formation points defining the formation.
Definition: FreeFormation.h:244
float _agentRadius
The instantaneous max distance from the center of the formation to normalized agent positions ...
Definition: FreeFormation.h:270
Vector2 _pos
The position of the sentinel point (in formation space)
Definition: FreeFormation.h:79
Vector2 _direction
The formation's direction of travel.
Definition: FreeFormation.h:254
static const std::string LABEL
The unique label for this data type to be used with resource management.
Definition: FreeFormation.h:128
float _speed
The preferred speed of the formation.
Definition: FreeFormation.h:259
ResourcePtr< FreeFormation > FormationPtr
The definition of the managed pointer for formation data.
Definition: FreeFormation.h:303
Vector2 _pos
The location of the formation center in world space (0,0).
Definition: FreeFormation.h:264
The class for modeling a freestyle formation.
Definition: FreeFormation.h:89
virtual const std::string & getLabel() const
Reports the message label for this resource.
Definition: FreeFormation.h:108
FormationPtr loadFormation(const std::string &fileName)
load a formation
Definition: FreeFormation.cpp:417
size_t _id
The id of the sentinel point.
Definition: FreeFormation.h:78
The data structure representing a point in the formation.
Definition: FreeFormation.h:77
std::map< size_t, Vector2 > _agentPrefVels
A cache of previoius agent preferred velocities. Maps agent identifiers to velocities.
Definition: FreeFormation.h:282