AnimatLab  2
Test
OdorSensor.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 "Sensor.h"
23 #include "OdorType.h"
24 #include "Odor.h"
25 #include "OdorSensor.h"
26 #include "Structure.h"
27 #include "Organism.h"
28 #include "ActivatedItem.h"
29 #include "ActivatedItemMgr.h"
30 #include "DataChartMgr.h"
31 #include "ExternalStimuliMgr.h"
32 #include "KeyFrame.h"
33 #include "SimulationRecorder.h"
34 #include "Light.h"
35 #include "LightManager.h"
36 #include "Simulator.h"
37 
38 namespace AnimatSim
39 {
40  namespace Environment
41  {
42  namespace Bodies
43  {
51 {
52  m_fltOdorValue = 0;
53  m_lpOdorType = NULL;
54 }
55 
63 {
64  m_lpOdorType = NULL;
65 }
66 
75 void OdorSensor::OdorTypeID(std::string strID)
76 {
77  SetOdorTypePointer(strID);
78  m_strOdorTypeID = strID;
79 }
80 
89 std::string OdorSensor::OdorTypeID() {return m_strOdorTypeID;}
90 
99 void OdorSensor::SetOdorTypePointer(std::string strID)
100 {
101  if(Std_IsBlank(strID))
102  m_lpOdorType = NULL;
103  else
104  {
105  m_lpOdorType = dynamic_cast<OdorType *>(m_lpSim->FindByID(strID));
106  if(!m_lpOdorType)
107  THROW_PARAM_ERROR(Al_Err_lPartTypeNotOdorType, Al_Err_strPartTypeNotOdorType, "ID", strID);
108  }
109 }
110 
112 {
114  m_fltOdorValue = 0;
115 }
116 
117 bool OdorSensor::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
118 {
119  std::string strType = Std_CheckString(strDataType);
120 
121  if(Sensor::SetData(strType, strValue, false))
122  return true;
123 
124  if(strType == "ODORTYPEID")
125  {
126  OdorTypeID(strValue);
127  return true;
128  }
129 
130  //If it was not one of those above then we have a problem.
131  if(bThrowError)
132  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
133 
134  return false;
135 }
136 
137 void OdorSensor::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
138 {
139  Sensor::QueryProperties(aryProperties);
140 
141  aryProperties.Add(new TypeProperty("OdorValue", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
142 
143  aryProperties.Add(new TypeProperty("OdorTypeID", AnimatPropertyType::String, AnimatPropertyDirection::Set));
144 }
145 
146 float *OdorSensor::GetDataPointer(const std::string &strDataType)
147 {
148  std::string strType = Std_CheckString(strDataType);
149 
150  if(strType == "ODORVALUE")
151  return &m_fltOdorValue;
152 
153  return RigidBody::GetDataPointer(strDataType);
154 }
155 
157 {
159 
160  if(m_lpOdorType)
162 }
163 
164 void OdorSensor::Load(CStdXml &oXml)
165 {
166  Sensor::Load(oXml);
167 
168  oXml.IntoElem(); //Into RigidBody Element
169 
170  OdorTypeID(oXml.GetChildString("OdorTypeID", ""));
171 
172  oXml.OutOfElem(); //OutOf RigidBody Element
173 }
174 
175  } //Bodies
176  } //Environment
177 } //AnimatSim
178 
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.
Declares the odor sensor class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: RigidBody.cpp:1473
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
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
Declares the key frame class.
virtual std::string OdorTypeID()
Gets the odor type identifier.
Definition: OdorSensor.cpp:89
Declares the joint class.
Declares the organism class.
Declares a light object.
Declares the activated item class.
Declares a light manager object.
Declares the bounding box class.
OdorType * m_lpOdorType
Pointer to the type odor to detect.
Definition: OdorSensor.h:31
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
Declares the node class.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
Definition: StdXml.cpp:307
std::string m_strOdorTypeID
Identifier for the odor type.
Definition: OdorSensor.h:34
virtual AnimatBase * FindByID(std::string strID, bool bThrowError=true)
Searches for the object with the specified ID.
Definition: Simulator.cpp:4008
virtual void StepSimulation()
Step the simulation for this object.
Definition: OdorSensor.cpp:156
virtual void SetOdorTypePointer(std::string strID)
Sets the odor type pointer.
Definition: OdorSensor.cpp:99
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 sensor class.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
Declares the data chart manager class.
Declares the rigid body class.
virtual void StepSimulation()
Step the simulation for this object.
Definition: RigidBody.cpp:1630
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.
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.
Declares the receptive field class.
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: OdorSensor.cpp:111
float m_fltOdorValue
The odor concentration value.
Definition: OdorSensor.h:28