AnimatLab  2
Test
AnimatSim::Behavior::NervousSystem Class Reference

Nervous system for an organism. More...

#include <NervousSystem.h>

+ Inheritance diagram for AnimatSim::Behavior::NervousSystem:
+ Collaboration diagram for AnimatSim::Behavior::NervousSystem:

Public Member Functions

 NervousSystem ()
 Default constructor. More...
 
virtual ~NervousSystem ()
 Destructor. More...
 
virtual void AddNeuralModule (std::string strXml)
 Creates and adds a new neural module from an XML definition. More...
 
virtual long CalculateSnapshotByteSize ()
 Calculates the snapshot byte size. More...
 
virtual NeuralModuleFindNeuralModule (std::string strModuleName, bool bThrowError=true)
 Searches for a neural module with a matching module name. More...
 
virtual void Initialize ()
 Initializes this object. More...
 
virtual void Kill (bool bState=true)
 Kills. More...
 
virtual void Load (CStdXml &oXml)
 
virtual void LoadKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Loads a key frame snapshot. More...
 
virtual void MinTimeStep (float &fltMin)
 
virtual void RemoveNeuralModule (std::string strID)
 Removes the neural module based on its ID. More...
 
virtual void ResetSimulation ()
 Resets the simulation back to time 0. More...
 
virtual void SaveKeyFrameSnapshot (byte *aryBytes, long &lIndex)
 Saves a key frame snapshot. More...
 
virtual void SetSystemPointers (Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
 Sets the system pointers. More...
 
virtual void StepSimulation ()
 Step the simulation for this object. More...
 
virtual void VerifySystemPointers ()
 Verify that system pointers have been set correctly. More...
 
- Public Member Functions inherited from AnimatSim::AnimatBase
 AnimatBase ()
 Constructs an AnimatBase object. More...
 
virtual ~AnimatBase ()
 Destroys the AnimatBase object.. More...
 
virtual bool AddItem (const std::string &strItemType, const std::string &strXml, bool bThrowError=true, bool bDoNotInit=false)
 Adds a new object to this parent. More...
 
virtual void AfterResetSimulation ()
 Called after a simulation reset for some objects. More...
 
virtual void Copy (CStdSerialize *lpSource)
 
virtual void Enabled (bool bVal)
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual bool Enabled ()
 Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications. More...
 
virtual float * GetDataPointer (const std::string &strDataType)
 Returns a float pointer to a data item of interest in this object. More...
 
virtual NeuralModuleGetNeuralModule ()
 Gets the neural module. More...
 
virtual NodeGetNode ()
 Gets the node. More...
 
virtual SimulatorGetSimulator ()
 Gets the simulator pointer. More...
 
virtual StructureGetStructure ()
 Gets the structure for this node. More...
 
virtual bool HasProperty (const std::string &strName)
 Queries this object if it has a property with the given name. More...
 
virtual std::string ID ()
 Gets the unique GUID ID of this object. More...
 
virtual void ID (std::string strValue)
 Sets the unique GUID ID of the object. More...
 
virtual void Load (StdUtils::CStdXml &oXml)
 Loads the item using an XML data packet. More...
 
virtual std::string Name ()
 Gets the name of this object. More...
 
virtual void Name (std::string strValue)
 Sets the name of the object. Blank is acceptable. More...
 
virtual AnimatPropertyType PropertyType (const std::string &strName)
 
virtual void QueryProperties (CStdPtrArray< TypeProperty > &aryProperties)
 Queries this object for a list of properties that can be changed using SetData. More...
 
virtual void ReInitialize ()
 Re-initialize this object. More...
 
virtual bool RemoveItem (const std::string &strItemType, const std::string &strID, bool bThrowError=true)
 Removes a child item from this parent. More...
 
virtual void Reset ()
 Resets this object. More...
 
virtual void RigidBodyAdded (std::string strID)
 
virtual void RigidBodyRemoved (std::string strID)
 
virtual bool Selected ()
 Tells if this items is selected or not. More...
 
virtual void Selected (bool bValue, bool bSelectMultiple)
 Selects this object. More...
 
virtual bool SetData (const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual bool SetData (const std::string &strDataType, const float fltValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual bool SetData (const std::string &strDataType, const long lValue, bool bThrowError=true)
 Set a variable based on a string data type name. More...
 
virtual void SetSystemPointers (Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
 Sets the system pointers. More...
 
virtual void SimPausing ()
 Called just before the simulation pauses. More...
 
virtual void SimStarting ()
 Called just before the simulation starts. More...
 
virtual void SimStopping ()
 Called just before the simulation stops. More...
 
virtual void TimeStepModified ()
 Notification method that the time step modified has been modified. Objects should recalculate any slice times as needed. More...
 
virtual std::string Type ()
 returns the string type name of this object. More...
 
virtual void Type (std::string strValue)
 Sets the class type for this object. More...
 
virtual void VisualSelectionModeChanged (int iNewMode)
 Visual selection mode changed. More...
 

Static Public Member Functions

static NervousSystemCastToDerived (AnimatBase *lpBase)
 

Protected Member Functions

void AddNeuralModule (NeuralModule *lpModule)
 Adds a neural module to the nervous system. More...
 
NeuralModuleLoadNeuralModule (CStdXml &oXml)
 Creates and loads a neural module. More...
 
virtual void StepAdapters ()
 
virtual void StepSim ()
 

Protected Attributes

CStdPtrMap< std::string, NeuralModulem_aryNeuralModules
 The array of neural modules used within this nervous system.
 
Organism * m_lpOrganism
 The pointer to this node's organism.
 
- Protected Attributes inherited from AnimatSim::AnimatBase
bool m_bEnabled
 Tells if this item is enabled or not. If it is not enabled then it is not run.
 
bool m_bSelected
 Tells whether the object is selected or not.
 
AnimatSim::Behavior::NeuralModulem_lpModule
 The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NULL.
 
Nodem_lpNode
 The pointer to this items parent Node. If this is not relevant for this object then this is NULL.
 
Simulatorm_lpSim
 The pointer to a Simulation.
 
AnimatSim::Environment::Structurem_lpStructure
 The pointer to this items parent Structure. If this is not relevant for this object then this is NULL.
 
std::string m_strID
 The unique Id for this object.
 
std::string m_strName
 The name for this object.
 
std::string m_strType
 The type for this object. Examples are Box, Plane, Neuron, etc..
 

Detailed Description

Nervous system for an organism.

An organism is a Structure that has a nervous system. The nervous system is made up of one or more NeuralModules, where each NeuralModule implements a given neural simulation method, firing rate vs. integrate and fire. Each of these neural modules is simulated independently with different integration time steps. You can connect elements in one module with elements in another by using an Adapter. This allow you to convert the firing rate, or other variable of interest, of one neuron into a current injected into a neuron in the other module.

Author
dcofer
Date
2/24/2011

Definition at line 28 of file NervousSystem.h.

Constructor & Destructor Documentation

AnimatSim::Behavior::NervousSystem::NervousSystem ( )

Default constructor.

Author
dcofer
Date
2/24/2011

Definition at line 52 of file NervousSystem.cpp.

References m_lpOrganism.

AnimatSim::Behavior::NervousSystem::~NervousSystem ( )
virtual

Destructor.

Author
dcofer
Date
2/24/2011

Definition at line 65 of file NervousSystem.cpp.

References m_aryNeuralModules, and StdUtils::Std_TraceMsg().

+ Here is the call graph for this function:

Member Function Documentation

void AnimatSim::Behavior::NervousSystem::AddNeuralModule ( NeuralModule lpModule)
protected

Adds a neural module to the nervous system.

Author
dcofer
Date
2/24/2011
Parameters
[in,out]lpModuleIf non-null, the pointer to a module.
Exceptions
Ifmodule is null, or duplicate module name.

Definition at line 88 of file NervousSystem.cpp.

References m_aryNeuralModules, StdUtils::CStdErrorInfo::m_strError, AnimatSim::Behavior::NeuralModule::ModuleName(), and StdUtils::Std_CheckString().

Referenced by AnimatSim::Environment::Organism::AddItem(), and LoadNeuralModule().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::AddNeuralModule ( std::string  strXml)
virtual

Creates and adds a new neural module from an XML definition.

This method is used to both create and add a new neural module to the nervous system by using a XML configuration data packet. This is primarily used by the AddItem method to create a new module when the user does so in the GUI.

Author
dcofer
Date
2/24/2011
Parameters
strXmlThe string xml for loading the new module.

Definition at line 119 of file NervousSystem.cpp.

References StdUtils::CStdXml::Deserialize(), StdUtils::CStdXml::FindChildElement(), StdUtils::CStdXml::FindElement(), AnimatSim::Behavior::NeuralModule::Initialize(), and LoadNeuralModule().

+ Here is the call graph for this function:

long AnimatSim::Behavior::NervousSystem::CalculateSnapshotByteSize ( )
virtual

Calculates the snapshot byte size.

Sometimes the user may want to capture a snapshot of the simulation at a given point in time, and then be able to go back to that specific point. To do this we grab a snapshot of all the data in the system, including the neural variables. We essentially serialize the data into a binary format for later re-use. This method calculates the number of bytes that will be required to store the entire object.

Author
dcofer
Date
2/24/2011
Returns
The calculated snapshot byte size.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 289 of file NervousSystem.cpp.

References AnimatSim::AnimatBase::CalculateSnapshotByteSize(), and m_aryNeuralModules.

Referenced by AnimatSim::Environment::Organism::CalculateSnapshotByteSize().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

NeuralModule * AnimatSim::Behavior::NervousSystem::FindNeuralModule ( std::string  strModuleName,
bool  bThrowError = true 
)
virtual

Searches for a neural module with a matching module name.

The module name is the name of the DLL to load. This must be unique and match the name of the DLL file.

Author
dcofer
Date
2/24/2011
Parameters
strModuleNameName of the DLL module file to find.
bThrowErrortrue to throw error, else it just return NULL if not found.
Returns
null if it fails, else the found neural module.
Exceptions
IfbThrowError is true and nothing is found.

Definition at line 166 of file NervousSystem.cpp.

References m_aryNeuralModules, and StdUtils::Std_CheckString().

+ Here is the call graph for this function:

void AnimatSim::Behavior::NervousSystem::Initialize ( )
virtual

Initializes this object.

After an object is loaded in it must be initialized before it can be used. This allows the object to retrieve any pointers or setup memory that it will need during execution. Each object is responsible for initializing any of its child objects, so you simply need to call this method on the containing class to init all child objects. It also calls VerifySystemPointers to make sure that the system pointers have been setup correctly.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 223 of file NervousSystem.cpp.

References AnimatSim::AnimatBase::Initialize(), AnimatSim::Behavior::NeuralModule::Initialize(), and m_aryNeuralModules.

Referenced by AnimatSim::Environment::Organism::Initialize().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::Kill ( bool  bState = true)
virtual

Kills.

Called to kill the organism, nervous system, neurons, and body parts. All neural items are disabled to prevent any further neural activity, and all joints are disabled to allow free rotation, and all biomechancical components are disabled so they can no longer produce forces. This method is only relevant to these types of objects, but I am putting the definition in the base class because a variety of different types of classes all need this method and I want it consolidated. Those classes that do not need it do not have to call it or do anything when it is called.

Author
dcofer
Date
3/3/2011
Parameters
bStatetrue to state.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 181 of file NervousSystem.cpp.

References AnimatSim::AnimatBase::Kill(), and m_aryNeuralModules.

Referenced by AnimatSim::Environment::Organism::Kill().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::LoadKeyFrameSnapshot ( byte *  aryBytes,
long &  lIndex 
)
virtual

Loads a key frame snapshot.

Sometimes the user may want to capture a snapshot of the simulation at a given point in time, and then be able to go back to that specific point. To do this we grab a snapshot of all the data in the system, including the neural variables. We essentially serialize the data into a binary format for later re-use. This method goes through each module and loads its data from the byte array.

Author
dcofer
Date
2/24/2011
Parameters
[in,out]aryBytesThe array of bytes where the data is being stored.
[in,out]lIndexCurrent zero-based index of the read position in the array.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 318 of file NervousSystem.cpp.

References AnimatSim::AnimatBase::LoadKeyFrameSnapshot(), and m_aryNeuralModules.

Referenced by AnimatSim::Environment::Organism::LoadKeyFrameSnapshot().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

NeuralModule * AnimatSim::Behavior::NervousSystem::LoadNeuralModule ( CStdXml oXml)
protected

Creates and loads a neural module.

This method uses the module name, module filename and module type to load a neural module DLL file and get its class factory (IStdClassFactory). It then uses the class factory to create a new neural module object and then loads it from the xml data.

Author
dcofer
Date
2/25/2011
Parameters
[in,out]oXmlThe xml data packet that will be loaded.
Returns
null if it fails, else the neural module.

Definition at line 364 of file NervousSystem.cpp.

References AddNeuralModule(), StdUtils::IStdClassFactory::CreateObject(), StdUtils::CStdXml::GetChildString(), StdUtils::CStdXml::IntoElem(), AnimatSim::AnimatBase::Load(), AnimatSim::Simulator::LoadClassFactory(), AnimatSim::AnimatBase::m_lpSim, AnimatSim::AnimatBase::m_lpStructure, StdUtils::CStdXml::OutOfElem(), and AnimatSim::Behavior::NeuralModule::SetSystemPointers().

Referenced by AddNeuralModule().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::RemoveNeuralModule ( std::string  strID)
virtual

Removes the neural module based on its ID.

This method is primarily used by the RemoveItem method to allow the GUI to remove a neural module when the user needs to do so.

Author
dcofer
Date
2/24/2011
Parameters
strIDUnique GUID ID string of the module to delete.

Definition at line 144 of file NervousSystem.cpp.

References m_aryNeuralModules.

Referenced by AnimatSim::Environment::Organism::RemoveItem().

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::ResetSimulation ( )
virtual

Resets the simulation back to time 0.

This method calls the ResetSimulation method on all subitems in order to reset the simulation back to the beginning.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 192 of file NervousSystem.cpp.

References m_aryNeuralModules, and AnimatSim::Behavior::NeuralModule::ResetSimulation().

Referenced by AnimatSim::Environment::Organism::ResetSimulation().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::SaveKeyFrameSnapshot ( byte *  aryBytes,
long &  lIndex 
)
virtual

Saves a key frame snapshot.

Sometimes the user may want to capture a snapshot of the simulation at a given point in time, and then be able to go back to that specific point. To do this we grab a snapshot of all the data in the system, including the neural variables. We essentially serialize the data into a binary format for later re-use. This method goes through each module and saves its data into the byte array.

Author
dcofer
Date
2/24/2011
Parameters
[in,out]aryBytesThe array of bytes where the data is being stored.
[in,out]lIndexCurrent zero-based index of the write position in the array.

Reimplemented from AnimatSim::AnimatBase.

Definition at line 305 of file NervousSystem.cpp.

References m_aryNeuralModules, and AnimatSim::AnimatBase::SaveKeyFrameSnapshot().

Referenced by AnimatSim::Environment::Organism::SaveKeyFrameSnapshot().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void AnimatSim::Behavior::NervousSystem::SetSystemPointers ( Simulator lpSim,
Structure *  lpStructure,
NeuralModule lpModule,
Node lpNode,
bool  bVerify 
)
virtual

Sets the system pointers.

There are a number of system pointers that are needed for use in the objects. The primariy one being a pointer to the simulation object itself so that you can get global parameters like the scale units and so on. However, each object may need other types of pointers as well, for example neurons need to have a pointer to their parent structure/organism, and to the NeuralModule they reside within. So different types of objects will need different sets of system pointers. We call this method to set the pointers just after creation and before Load is called. We then call VerifySystemPointers here, during Load and during Initialize in order to ensure that the correct pointers have been set for each type of objects. These pointers can then be safely used throughout the rest of the system.

Author
dcofer
Date
3/2/2011
Parameters
[in,out]lpSimThe pointer to a simulation.
[in,out]lpStructureThe pointer to the parent structure.
[in,out]lpModuleThe pointer to the parent module module.
[in,out]lpNodeThe pointer to the parent node.
bVerifytrue to call VerifySystemPointers.
void AnimatSim::Behavior::NervousSystem::StepSimulation ( )
virtual

Step the simulation for this object.

This is called on an object each time it is stepped in the simulation. this is where its simulation code is processed. However, StepSimulation is not necessarily called every single time that the simulation as a whole is stepped. A good example of this is that neural modules can have different integration time steps. So a firing rate module may have a DT of 0.5 ms, while an integrate and fire model may have one of 0.1 ms. So the firing rate module would only get its StepSimulation method called every 5th time that the other module was called. This is all handed in the StepSimulation method of the Simulator and NervousSystem.

Author
dcofer
Date
3/1/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 252 of file NervousSystem.cpp.

Referenced by AnimatSim::Environment::Organism::StepNeuralEngine().

+ Here is the caller graph for this function:

void AnimatSim::Behavior::NervousSystem::VerifySystemPointers ( )
virtual

Verify that system pointers have been set correctly.

The system pointers should be set just after an object is created. However, if for some reason it was not then this could cause read/write memory access errors later on because we would be using NULL pointers. This method is called during SetSystemPointers, Load, and Initialize to verify that the pointers for that type of object have been set correctly. We are calling three different places to ensure that it is checked before use. For example, if you are doing a Load call then you want to check it before attempting the load, but there may be an object that does not Load, but only does Initialize. So we need to check it there as well.

Author
dcofer
Date
3/4/2011

Reimplemented from AnimatSim::AnimatBase.

Definition at line 212 of file NervousSystem.cpp.

References m_lpOrganism, AnimatSim::AnimatBase::m_lpStructure, AnimatSim::AnimatBase::m_strID, and AnimatSim::AnimatBase::VerifySystemPointers().

+ Here is the call graph for this function:


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