AnimatLab  2
Test
OdorType.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
11 
12 #include "Node.h"
13 #include "IPhysicsMovableItem.h"
14 #include "IPhysicsBody.h"
15 #include "BoundingBox.h"
16 #include "MovableItem.h"
17 #include "BodyPart.h"
18 #include "Joint.h"
19 #include "ReceptiveField.h"
20 #include "ContactSensor.h"
21 #include "RigidBody.h"
22 #include "Structure.h"
23 #include "Organism.h"
24 #include "ActivatedItem.h"
25 #include "ActivatedItemMgr.h"
26 #include "DataChartMgr.h"
27 #include "ExternalStimuliMgr.h"
28 #include "KeyFrame.h"
29 #include "SimulationRecorder.h"
30 #include "OdorType.h"
31 #include "Odor.h"
32 #include "Light.h"
33 #include "LightManager.h"
34 #include "Simulator.h"
35 
36 
37 namespace AnimatSim
38 {
39  namespace Environment
40  {
48 {
50 }
51 
59 {
60 
61 try
62 {
63  m_aryOdorSources.RemoveAll();
64 }
65 catch(...)
66 {Std_TraceMsg(0, "Caught Error in desctructor of Odor\r\n", "", -1, false, true);}
67 }
68 
78 
88 void OdorType::DiffusionConstant(float fltVal, bool bUseScaling)
89 {
90  Std_IsAboveMin((float) 0, fltVal, true, "Diffusion Constant");
91 
92  if(bUseScaling)
93  fltVal = fltVal/(m_lpSim->DistanceUnits()*m_lpSim->DistanceUnits()); //Our diffusion constant is in m^2/s. We need to convert its distance units appropriately.
94 
95  m_fltDiffusionConstant = fltVal;
96 };
97 
109 Odor *OdorType::FindOdorSource(std::string strOdorID, bool bThrowError)
110 {
111  Odor *lpOdor = NULL;
112  CStdMap<std::string, Odor *>::iterator oPos;
113  oPos = m_aryOdorSources.find(Std_CheckString(strOdorID));
114 
115  if(oPos != m_aryOdorSources.end())
116  lpOdor = oPos->second;
117  else if(bThrowError)
118  THROW_PARAM_ERROR(Al_Err_lOdorIDNotFound, Al_Err_strOdorIDNotFound, "OdorID", strOdorID);
119 
120  return lpOdor;
121 }
122 
132 {
133  if(!FindOdorSource(lpOdor->ID(), false))
134  {
135  m_aryOdorSources.Add(lpOdor->ID(), lpOdor);
136  }
137 }
138 
153 float OdorType::CalculateOdorValue(CStdFPoint &oSensorPos)
154 {
155  //Loop through each of the associated odors and calculate the value for each one.
156  CStdMap<std::string, Odor *>::iterator oIterator;
157  Odor *lpOdor = NULL;
158  float fltVal = 0;
159 
160  for(oIterator=m_aryOdorSources.begin();
161  oIterator!=m_aryOdorSources.end();
162  ++oIterator)
163  {
164  lpOdor = oIterator->second;
165  fltVal += lpOdor->CalculateOdorValue(this, oSensorPos);
166  }
167 
168  return fltVal;
169 }
170 
171 bool OdorType::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
172 {
173  std::string strType = Std_CheckString(strDataType);
174 
175  if(AnimatBase::SetData(strType, strValue, false))
176  return true;
177 
178  if(strType == "DIFFUSIONCONSTANT")
179  {
180  DiffusionConstant((float) atof(strValue.c_str()));
181  return true;
182  }
183 
184  //If it was not one of those above then we have a problem.
185  if(bThrowError)
186  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
187 
188  return false;
189 }
190 
191 void OdorType::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
192 {
193  AnimatBase::QueryProperties(aryProperties);
194 
195  aryProperties.Add(new TypeProperty("DiffusionConstant", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
196 }
197 
198 void OdorType::Load(CStdXml &oXml)
199 {
200  AnimatBase::Load(oXml);
201 
202  oXml.IntoElem(); //Into Joint Element
203 
204  DiffusionConstant(oXml.GetChildFloat("DiffusionConstant", m_fltDiffusionConstant));
205 
206  oXml.OutOfElem(); //OutOf Joint Element
207 }
208 
209  } // Environment
210 } //AnimatSim
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
Declares the body part class.
virtual ~OdorType()
Destructor.
Definition: OdorType.cpp:58
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual std::string ID()
Gets the unique GUID ID of this object.
Definition: AnimatBase.cpp:167
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
virtual void DistanceUnits(std::string strUnits)
Sets the distance units.
Definition: Simulator.cpp:1717
Declares the key frame class.
Declares the joint class.
Declares the organism class.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
Declares a light object.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
float m_fltDiffusionConstant
The diffusion constant that defines how fast odors of this type move through the environment.
Definition: OdorType.h:31
virtual float CalculateOdorValue(OdorType *lpType, CStdFPoint &oSensorPos)
Calculates the odor value for this Odorant for a given odor sensor somewhere in the environment...
Definition: Odor.cpp:200
A standard xml manipulation class.
Definition: StdXml.h:19
virtual float DiffusionConstant()
Gets the diffusion constant.
Definition: OdorType.cpp:77
Declares the node class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: AnimatBase.cpp:447
CStdMap< std::string, Odor * > m_aryOdorSources
The array of odor sources of this type within the environment.
Definition: OdorType.h:34
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: OdorType.cpp:171
virtual void AddOdorSource(Odor *lpOdor)
Adds an odor source to the list of odors that are emitting this type of odor.
Definition: OdorType.cpp:131
OdorType()
Default constructor.
Definition: OdorType.cpp:47
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual float CalculateOdorValue(CStdFPoint &oSensorPos)
Calculates the odor value for this OdorType for a given sensor location.
Definition: OdorType.cpp:153
Declares the data chart manager class.
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the structure class.
Declares the odor type class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: OdorType.cpp:191
Declares the odor class.
Declares the simulator class.
virtual Odor * FindOdorSource(std::string strOdorID, bool bThrowError=true)
Finds the odor source with the specified GUID ID.
Definition: OdorType.cpp:109
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
Definition: AnimatBase.cpp:371
Declares the receptive field class.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617