AnimatLab  2
Go to the documentation of this file.
7 #include "StdAfx.h"
8 #include "IMovableItemCallback.h"
9 #include "ISimGUICallback.h"
10 #include "AnimatBase.h"
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"
37 namespace AnimatSim
38 {
39  namespace Environment
40  {
50 {
51  m_lpParent = lpParent;
52  m_lpOdorType = NULL;
53  m_fltQuantity = 100;
54  m_bUseFoodQuantity = false;
55  m_bEnabled = true;
56 }
65 {
67 try
68 {
69  m_lpParent = NULL;
70 }
71 catch(...)
72 {Std_TraceMsg(0, "Caught Error in desctructor of Odor\r\n", "", -1, false, true);}
73 }
86 {return m_bEnabled;}
98 void Odor::Enabled(bool bVal)
99 {
100  m_bEnabled = bVal;
101 }
113 void Odor::SetOdorType(std::string strType)
114 {
115  //Now lets find the odor type for this odor and add this one to it.
116  m_lpOdorType = m_lpSim->FindOdorType(strType);
118 }
140 void Odor::Quantity(float fltVal)
141 {
142  Std_IsAboveMin((float) 0, m_fltQuantity, true, "Quantity");
143  m_fltQuantity = fltVal;
144 }
158 {
160  return m_lpParent->FoodQuantity();
161  else
162  return m_fltQuantity;
163 };
183 void Odor::UseFoodQuantity(bool bVal) {m_bUseFoodQuantity = bVal;}
200 float Odor::CalculateOdorValue(OdorType *lpType, CStdFPoint &oSensorPos)
201 {
202  if(!m_lpParent || !m_bEnabled) return 0;
204  CStdFPoint oOdorPos = m_lpParent->GetCurrentPosition();
206  float fltDist = Std_CalculateDistance(oOdorPos, oSensorPos);
207  float fltVal = (this->Quantity() * lpType->DiffusionConstant()) / (fltDist * fltDist);
209  return fltVal;
210 }
212 bool Odor::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
213 {
214  std::string strType = Std_CheckString(strDataType);
216  if(AnimatBase::SetData(strType, strValue, false))
217  return true;
219  if(strType == "ENABLED")
220  {
221  Enabled(Std_ToBool(strValue));
222  return true;
223  }
225  if(strType == "QUANTITY")
226  {
227  Quantity(atof(strValue.c_str()));
228  return true;
229  }
231  if(strType == "USEFOODQUANTITY")
232  {
233  UseFoodQuantity(Std_ToBool(strValue));
234  return true;
235  }
237  //If it was not one of those above then we have a problem.
238  if(bThrowError)
239  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
241  return false;
242 }
244 void Odor::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
245 {
246  AnimatBase::QueryProperties(aryProperties);
248  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
249  aryProperties.Add(new TypeProperty("Quantity", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
250  aryProperties.Add(new TypeProperty("UseFoodQuantity", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
251 }
253 void Odor::Load(CStdXml &oXml)
254 {
255  AnimatBase::Load(oXml);
257  oXml.IntoElem(); //Into Odor Element
259  SetOdorType(oXml.GetChildString("OdorTypeID"));
260  Quantity(oXml.GetChildFloat("Quantity", m_fltQuantity));
261  UseFoodQuantity(oXml.GetChildBool("UseFoodQuantity", m_bUseFoodQuantity));
262  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
264  oXml.OutOfElem(); //OutOf Odor Element
265 }
267  } // Environment
268 } //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 float FoodQuantity()
Gets the food quantity.
Definition: RigidBody.cpp:676
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual ~Odor()
Definition: Odor.cpp:64
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
RigidBody * m_lpParent
Pointer to the parent RigidBody part that is emitting the odor.
Definition: Odor.h:23
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
OdorType * m_lpOdorType
Pointer to the type of odor the body part is emitting.
Definition: Odor.h:26
float m_fltQuantity
The quantity used to calculate the odor value.
Definition: Odor.h:29
Declares the key frame class.
Odor(RigidBody *lpParent)
Definition: Odor.cpp:49
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: Odor.cpp:212
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Odor.cpp:244
Declares the joint class.
Declares the organism class.
virtual bool Enabled()
Gets whether the odor is enabled or not.
Definition: Odor.cpp:85
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.
virtual CStdFPoint GetCurrentPosition()
Gets the current position of this part.
virtual bool UseFoodQuantity()
Tells whether we should use the FoodQuantity of the parent RigidBody when calculating the odor value...
Definition: Odor.cpp:173
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
Odor type that can be emitted from a RigidBody and sensed by an OdorSensor.
Definition: OdorType.h:27
virtual OdorType * FindOdorType(std::string strOdorID, bool bThrowError=true)
Searches for the first odor type with the specified ID.
Definition: Simulator.cpp:3891
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
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual float Quantity()
Gets the quantity that will be used when calculating the odor concentration.
Definition: Odor.cpp:157
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 GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
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
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
Definition: AnimatBase.h:40
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the data chart manager class.
virtual OdorType * GetOdorType()
Gets a pointer to the odor type.
Definition: Odor.cpp:128
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void SetOdorType(std::string strType)
Sets the odor type to emit for this odorant.
Definition: Odor.cpp:113
Declares the structure class.
Declares the odor type class.
Declares the odor class.
Declares the simulator class.
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
The base class for all of the basic rigid body type of objects.
Definition: RigidBody.h:66
Declares the receptive field class.
double Std_CalculateDistance(CStdIPoint &ptA, CStdIPoint &ptB)
Calculates the distance between two points.
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617