Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Menge::Agents::AgentInitializer Class Reference

Class which determines the agent properties for each new agent. More...

#include <AgentInitializer.h>

Inheritance diagram for Menge::Agents::AgentInitializer:
ORCA::AgentInitializer PedVO::AgentInitializer

Public Types

enum  ParseResult { FAILURE = 0, IGNORED, ACCEPTED }
 Return type for parsing efforts. Helps the various derived classes coordinate their work. More...
 

Public Member Functions

 AgentInitializer ()
 Constructor. More...
 
 AgentInitializer (const AgentInitializer &init)
 Copy Constructor. More...
 
virtual ~AgentInitializer ()
 Destructor.
 
bool parseProperties (TiXmlElement *node, const std::string &sceneFldr)
 Parses an AgentSet property tag, setting agent values as appropriate. More...
 
virtual bool setProperties (BaseAgent *agent)
 Sets the properties of the given agent based on the initializer's values. More...
 
virtual void setDefaults ()
 Sets all generators to default values. More...
 
virtual AgentInitializercopy () const
 Creates a copy of this AgentInitializer instance. More...
 

Static Public Attributes

static bool VERBOSE = false
 Determines if the agent properties parsing process will be verbose.
 

Protected Member Functions

virtual bool isRelevant (const ::std::string &tagName)
 Reports if this AgentInitializer cares about the given AgentSet property XML tag. More...
 
virtual ParseResult setFromXMLAttribute (const ::std::string &paramName, const ::std::string &value)
 Defines a constant value for an agent property as specified by the attribute of an agent property tag. More...
 
bool parsePropertySpec (TiXmlElement *node)
 Parses the Property tag that is the child of an AgentSet Parameter tag. More...
 
virtual ParseResult processProperty (::std::string propName, TiXmlElement *node)
 Process the given <Property .../> tag. More...
 
ParseResult constFloatGenerator (FloatGenerator *&gen, const ::std::string &valueStr, float scale=1.f)
 Helper function for setting a property from an xml attribute. More...
 
ParseResult constFloat (float &numValue, const ::std::string &valueStr, float scale=1.f)
 Helper function for setting a property from an xml attribute. More...
 
ParseResult constIntGenerator (IntGenerator *&gen, const ::std::string &valueStr)
 Helper function for setting a property from an xml attribute. More...
 
ParseResult constSizet (size_t &numValue, const ::std::string &valueStr)
 Helper function for setting a property from an xml attribute. More...
 
ParseResult getFloatGenerator (FloatGenerator *&gen, TiXmlElement *node, float scale=1.f)
 Helper function for setting a property from an xml Property node. More...
 
ParseResult getIntGenerator (IntGenerator *&gen, TiXmlElement *node)
 Helper function for setting a property from an xml Property node. More...
 

Protected Attributes

FloatGenerator_maxSpeed
 The maximum speed the agent can take.
 
FloatGenerator_maxAccel
 The maximum acceleration the agent can experience (interpreted isotropically).
 
FloatGenerator_prefSpeed
 The preferred speed of the agent.
 
IntGenerator_maxNeighbors
 The number of nearby agents used to plan dynamic respones.
 
FloatGenerator_neighborDist
 The maximum distance at which another agent will be considered for a response.
 
FloatGenerator_radius
 The agent's radius. See Agents::BaseAgent::_radius for details.
 
FloatGenerator_maxAngVel
 The agent's maximum angular velocity (in radians/sec) – used for controlling the changes in agent orientation.
 
size_t _obstacleSet
 A mask indicating which obstacles affect the agent. See Agents::BaseAgent::_obstacleSet for details.
 
float _priority
 The priority of each agent. See Agents::BaseAgent::_priority for details.
 
size_t _class
 The population class for this agent. See Agents::BaseAgent::_class for details.
 
std::vector< BFSM::VelModifier * > _velModifiers
 Velocity Modifiers to be applied to this class.
 

Detailed Description

Class which determines the agent properties for each new agent.

This base agent intializer class facilitates setting all BaseAgent properties. The property values are set using number generators (see RandGenerator.h).

Member Enumeration Documentation

Return type for parsing efforts. Helps the various derived classes coordinate their work.

Enumerator
FAILURE 

The parsing ended in failure.

IGNORED 

The XML data was ignored by the function.

ACCEPTED 

The XML data was accepted by the function.

Constructor & Destructor Documentation

Menge::Agents::AgentInitializer::AgentInitializer ( )

Constructor.

The values for each agent take a hard-coded default values.

Menge::Agents::AgentInitializer::AgentInitializer ( const AgentInitializer init)

Copy Constructor.

Parameters
initThe AgentInitializer to copy all values from.

Member Function Documentation

AgentInitializer::ParseResult Menge::Agents::AgentInitializer::constFloat ( float &  numValue,
const ::std::string &  valueStr,
float  scale = 1.f 
)
protected

Helper function for setting a property from an xml attribute.

This is used to parse and create a value generator in the case where the attribute is defined on the main property tag: e.g.,

    <Common property="value.../>
Parameters
numValueThe new float will be put into this variable.
valueStrThe string representing the attribute value to convert to a const float generator.
scaleOptional argument for changing the units of the input value. (e.g., specification commonly describes angles as degrees, but internal representation is in radians).
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
AgentInitializer::ParseResult Menge::Agents::AgentInitializer::constFloatGenerator ( FloatGenerator *&  gen,
const ::std::string &  valueStr,
float  scale = 1.f 
)
protected

Helper function for setting a property from an xml attribute.

This is used to parse and create a value generator in the case where the attribute is defined on the main property tag: e.g.,

    <Common property="value.../>
Parameters
genA reference to a pointer to a valid FloatGenerator. The new float generator will be put into this variable.
valueStrThe string representing the attribute value to convert to a const float generator.
scaleOptional argument for changing the units of the input value. (e.g., specification commonly describes angles as degrees, but internal representation is in radians).
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
AgentInitializer::ParseResult Menge::Agents::AgentInitializer::constIntGenerator ( IntGenerator *&  gen,
const ::std::string &  valueStr 
)
protected

Helper function for setting a property from an xml attribute.

This is used to parse and create a value generator in the case where the attribute is defined on the main property tag: e.g.,

    <Common property="value.../>
Parameters
genA reference to a pointer to a valid IntGenerator. The new int generator will be put into this variable.
valueStrThe string representing the attribute value to convert to a const float generator.
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
AgentInitializer::ParseResult Menge::Agents::AgentInitializer::constSizet ( size_t &  numValue,
const ::std::string &  valueStr 
)
protected

Helper function for setting a property from an xml attribute.

This is used to parse and create a value generator in the case where the attribute is defined on the main property tag: e.g.,

    <Common property="value.../>
Parameters
numValueThe new size_t will be put into this variable.
valueStrThe string representing the attribute value to convert to a const float generator.
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
virtual AgentInitializer* Menge::Agents::AgentInitializer::copy ( ) const
inlinevirtual

Creates a copy of this AgentInitializer instance.

Returns
A pointer to a new AgentInitializer with all of the same values as this. The caller is responsible for freeing up the new instance.

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.

AgentInitializer::ParseResult Menge::Agents::AgentInitializer::getFloatGenerator ( FloatGenerator *&  gen,
TiXmlElement *  node,
float  scale = 1.f 
)
protected

Helper function for setting a property from an xml Property node.

This is used to parse and create a value generator in the case where the attribute is defined explicitly as a distribution on a Property tag, e.g.,

    <Property name="property" dist="x".../>
Parameters
genA reference to a pointer to a valid FloatGenerator. The new float generator will be put into this variable.
nodeThe xml node containing attributes for the distribution specification.
scaleOptional argument for changing the units of the input value. (e.g., specification commonly describes angles as degrees, but internal representation is in radians).
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
AgentInitializer::ParseResult Menge::Agents::AgentInitializer::getIntGenerator ( IntGenerator *&  gen,
TiXmlElement *  node 
)
protected

Helper function for setting a property from an xml Property node.

This is used to parse and create a value generator in the case where the attribute is defined on the main property tag: e.g.,

    <Common property="value.../>
Parameters
genA reference to a pointer to a valid IntGenerator. The new int generator will be put into this variable.
nodeThe xml node containing attributes for the distribution specification.
Returns
A parse result indicating either ACCEPTED or FAILURE. IGNORED should never be a result, because it should only be called on expected parameters, so it must either succed or fail.
bool Menge::Agents::AgentInitializer::isRelevant ( const ::std::string &  tagName)
protectedvirtual

Reports if this AgentInitializer cares about the given AgentSet property XML tag.

This is the mechanism by which new sub-classes can extend the parameter space. Each pedestrian model which introduces new per-agent properties that must override this function. However, the overriden function must, in turn, call the parent class if it doesn't consider the tag relevant, giving the parent class a chance to determine if the tag is relevant. This is the mechanism by which derived classes will also benefit from the <Common> parameter set.

Parameters
tagNameThe name of the tag to test.
Returns
True if the tag is relevant, false otherwise.

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.

bool Menge::Agents::AgentInitializer::parseProperties ( TiXmlElement *  node,
const std::string &  sceneFldr 
)

Parses an AgentSet property tag, setting agent values as appropriate.

This function can be called on all AgentSet property tags. The function is responsible for determining which tags have relevant information and which are to be ignored.

If a tag is deemed to be relevant, but the content of the tag is incorrect, such as a mal-formed property definition, then the parsing "fails". However, unexpected property attributes or specifications will be ignored. If the system is running in verbose mode, these unexpected attributes will be indicated on the console.

Such a tag could look like this:

    <Common r="0.1" class="2" ... />

or

    <Common r="0.1" class="2" ... >
        <Property type="radius" dist="u" min="0.18" max="0.2"/>
        <Property type="prefSpeed" dist="n" mean="1.34" stddev="0.2"/>
    </Common>
Parameters
nodeThe xml node containing agent properties for an AgentSet.
sceneFldrSince we now need access to resources at this stage, we pass the base folder for resource loading
Returns
True if parsing was "successful", false otherwise.
bool Menge::Agents::AgentInitializer::parsePropertySpec ( TiXmlElement *  node)
protected

Parses the Property tag that is the child of an AgentSet Parameter tag.

As with the other parsing code, success is defined by finding an expected, correct field or an unexpected tag (which is just ignored). Failure occurs when the tags are as expected, but the values are invalid.

Parameters
nodeThe xml node containing agent properties for an AgentSet.
Returns
True if parsing was "successful", false otherwise.
AgentInitializer::ParseResult Menge::Agents::AgentInitializer::processProperty ( ::std::string  propName,
TiXmlElement *  node 
)
protectedvirtual

Process the given <Property .../> tag.

As a pre-condition to this function, the XML node contains a <Property.../> tag and has been confirmed to have, at least, a name attribute. Nothing else about the tag has been validated.

If the property name is unexpected, it will be ignored. If it is expected, this function will attempt to interpret the XML tag as a number distribution for a valid agent attribute. If it can do so, it is successful, if it can't, it fails.

Parameters
propNameThe extracted "name" attribute from the Property tag.
nodeThe XML node for the Property tag.
Returns
The ParseResult indicating if the property was successful (IGNORED or ACCEPTED) or if it was a malformed tag (FAILURE).

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.

void Menge::Agents::AgentInitializer::setDefaults ( )
virtual

Sets all generators to default values.

Resets all number generators to default const values. This assumes that all required number generators already exist and will delete them appropriately. Do not call this in the constructor.

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.

AgentInitializer::ParseResult Menge::Agents::AgentInitializer::setFromXMLAttribute ( const ::std::string &  paramName,
const ::std::string &  value 
)
protectedvirtual

Defines a constant value for an agent property as specified by the attribute of an agent property tag.

Derived classes should override this function, but possibly call the parent class's implementation. First, it should test to see if the paramName is expected by the derived class. If so, the derived class can determine fail or accept. If it is not expected, it should call the parent class's implementation and returns its value.

Parameters
paramNameA string containing the parameter name.
valueA string containing the value for the parameter.
Returns
The result of the parse: failure, ignored, or accepted.

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.

bool Menge::Agents::AgentInitializer::setProperties ( BaseAgent agent)
virtual

Sets the properties of the given agent based on the initializer's values.

This needs to be overridden by sub-classes. The first thing the sub-class should do is dynamic_cast the argument to its expected type to make sure it is the proper agent type. If not, this should be considered failure. Then it should set its unique properties and then call the super class's setProperties function.

Parameters
agentThe agent whose properties are to be set.
Returns
True if the properties were set successfully, false otherwise.

Reimplemented in ORCA::AgentInitializer, and PedVO::AgentInitializer.


The documentation for this class was generated from the following files: