AnimatLab
2
Test
|
Nervous system for an organism. More...
#include <NervousSystem.h>
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 NeuralModule * | FindNeuralModule (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 NeuralModule * | GetNeuralModule () |
Gets the neural module. More... | |
virtual Node * | GetNode () |
Gets the node. More... | |
virtual Simulator * | GetSimulator () |
Gets the simulator pointer. More... | |
virtual Structure * | GetStructure () |
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 NervousSystem * | CastToDerived (AnimatBase *lpBase) |
Protected Member Functions | |
void | AddNeuralModule (NeuralModule *lpModule) |
Adds a neural module to the nervous system. More... | |
NeuralModule * | LoadNeuralModule (CStdXml &oXml) |
Creates and loads a neural module. More... | |
virtual void | StepAdapters () |
virtual void | StepSim () |
Protected Attributes | |
CStdPtrMap< std::string, NeuralModule > | m_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::NeuralModule * | m_lpModule |
The pointer to this items parentNeuralModule. If this is not relevant for this object then this is NULL. | |
Node * | m_lpNode |
The pointer to this items parent Node. If this is not relevant for this object then this is NULL. | |
Simulator * | m_lpSim |
The pointer to a Simulation. | |
AnimatSim::Environment::Structure * | m_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.. | |
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.
Definition at line 28 of file NervousSystem.h.
AnimatSim::Behavior::NervousSystem::NervousSystem | ( | ) |
Default constructor.
Definition at line 52 of file NervousSystem.cpp.
References m_lpOrganism.
|
virtual |
Destructor.
Definition at line 65 of file NervousSystem.cpp.
References m_aryNeuralModules, and StdUtils::Std_TraceMsg().
|
protected |
Adds a neural module to the nervous system.
[in,out] | lpModule | If non-null, the pointer to a module. |
If | module 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().
|
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.
strXml | The 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().
|
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.
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().
|
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.
strModuleName | Name of the DLL module file to find. |
bThrowError | true to throw error, else it just return NULL if not found. |
If | bThrowError is true and nothing is found. |
Definition at line 166 of file NervousSystem.cpp.
References m_aryNeuralModules, and StdUtils::Std_CheckString().
|
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.
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().
|
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.
bState | true 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().
|
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.
[in,out] | aryBytes | The array of bytes where the data is being stored. |
[in,out] | lIndex | Current 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().
|
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.
[in,out] | oXml | The xml data packet that will be loaded. |
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().
|
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.
strID | Unique 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().
|
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.
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().
|
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.
[in,out] | aryBytes | The array of bytes where the data is being stored. |
[in,out] | lIndex | Current 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().
|
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.
[in,out] | lpSim | The pointer to a simulation. |
[in,out] | lpStructure | The pointer to the parent structure. |
[in,out] | lpModule | The pointer to the parent module module. |
[in,out] | lpNode | The pointer to the parent node. |
bVerify | true to call VerifySystemPointers. |
|
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.
Reimplemented from AnimatSim::AnimatBase.
Definition at line 252 of file NervousSystem.cpp.
Referenced by AnimatSim::Environment::Organism::StepNeuralEngine().
|
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.
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().