AnimatLab  2
Test
Sensor.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 "Structure.h"
24 #include "Organism.h"
25 #include "ActivatedItem.h"
26 #include "ActivatedItemMgr.h"
27 #include "DataChartMgr.h"
28 #include "ExternalStimuliMgr.h"
29 #include "KeyFrame.h"
30 #include "SimulationRecorder.h"
31 #include "OdorType.h"
32 #include "Odor.h"
33 #include "Light.h"
34 #include "LightManager.h"
35 #include "Simulator.h"
36 
37 namespace AnimatSim
38 {
39  namespace Environment
40  {
41  namespace Bodies
42  {
50 {
51  m_fltDensity = 0;
52  m_bUsesJoint = false;
53  m_lpJointToParent = NULL;
54  m_fltRadius = 1;
57 }
58 
66 {
67 
68 }
69 
70 float Sensor::Radius() {return m_fltRadius;}
71 
72 void Sensor::Radius(float fltVal, bool bUseScaling)
73 {
74  Std_IsAboveMin((float) 0, fltVal, true, "Sensor.Radius");
75  if(bUseScaling)
77  else
78  m_fltRadius = fltVal;
79 
80  Resize();
81 }
82 
83 void Sensor::LatitudeSegments(int iVal)
84 {
85  Std_IsAboveMin((int) 10, iVal, true, "Sensor.LatitudeSegments", true);
86  m_iLatitudeSegments = iVal;
87  Resize();
88 }
89 
90 int Sensor::LatitudeSegments() {return m_iLatitudeSegments;}
91 
92 void Sensor::LongtitudeSegments(int iVal)
93 {
94  Std_IsAboveMin((int) 10, iVal, true, "Sensor.LongtitudeSegments", true);
95  m_iLongtitudeSegments = iVal;
96  Resize();
97 }
98 
99 int Sensor::LongtitudeSegments() {return m_iLongtitudeSegments;}
100 
101 bool Sensor::AllowRotateDragX() {return false;}
102 
103 bool Sensor::AllowRotateDragY() {return false;}
104 
105 bool Sensor::AllowRotateDragZ() {return false;}
106 
107 bool Sensor::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
108 {
109  std::string strType = Std_CheckString(strDataType);
110 
111  if(RigidBody::SetData(strType, strValue, false))
112  return true;
113 
114  if(strType == "RADIUS")
115  {
116  Radius((float) atof(strValue.c_str()));
117  return true;
118  }
119 
120  if(strType == "LATITUDESEGMENTS")
121  {
122  LatitudeSegments(atoi(strValue.c_str()));
123  return true;
124  }
125 
126  if(strType == "LONGTITUDESEGMENTS")
127  {
128  LongtitudeSegments(atoi(strValue.c_str()));
129  return true;
130  }
131 
132  //If it was not one of those above then we have a problem.
133  if(bThrowError)
134  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
135 
136  return false;
137 }
138 
139 void Sensor::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
140 {
141  RigidBody::QueryProperties(aryProperties);
142 
143  aryProperties.Add(new TypeProperty("Radius", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
144  aryProperties.Add(new TypeProperty("LatitudeSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
145  aryProperties.Add(new TypeProperty("LongtitudeSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
146 }
147 
149 {}
150 
151 // There are no parts or joints to create for muscle attachment points.
153 {}
154 
156 {}
157 
158 void Sensor::Load(CStdXml &oXml)
159 {
160  RigidBody::Load(oXml);
161 
162  oXml.IntoElem(); //Into RigidBody Element
163  Radius(oXml.GetChildFloat("Radius", m_fltRadius));
164  LatitudeSegments(oXml.GetChildInt("LatitudeSegments", m_iLatitudeSegments));
165  LongtitudeSegments(oXml.GetChildInt("LongtitudeSegments", m_iLongtitudeSegments));
166  oXml.OutOfElem(); //OutOf RigidBody Element
167 
168  //Reset the rotation to 0 for sensors
169  m_oRotation.Set(0, 0, 0);
170 }
171 
172  } //Bodies
173  } //Environment
174 } //AnimatSim
Sensor()
Default constructor.
Definition: Sensor.cpp:49
virtual bool AllowRotateDragX()
Gets whether this body part can be rotated along the x-axis by the user with the drag handlers...
Definition: Sensor.cpp:101
Base class file for all Animat simulation objects.
virtual void CreateParts()
Allows the rigid body to create its parts using the chosen physics engine.
Definition: Sensor.cpp:152
Declares the simulation recorder class.
Root namespace for the base simulation library for AnimatLab.
virtual bool AllowRotateDragY()
Gets whether this body part can be rotated along the y-axis by the user with the drag handlers...
Definition: Sensor.cpp:103
virtual bool AllowRotateDragZ()
Gets whether this body part can be rotated along the z-axis by the user with the drag handlers...
Definition: Sensor.cpp:105
Declares the body part class.
virtual float Radius()
Gets the radius.
Definition: Sensor.cpp:70
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
int m_iLongtitudeSegments
Number of segments along the longtitude direction that are used to build the sphere.
Definition: Sensor.h:35
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
virtual void Initialize()
Initializes this object.
Definition: Sensor.cpp:148
Declares the joint class.
Declares the organism class.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
Definition: StdXml.cpp:456
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.
virtual void Resize()
Called when this object has been resized.
Definition: BodyPart.cpp:141
Declares the activated item class.
Declares a light manager object.
float m_fltDensity
Uniform density for the rigid body.
Definition: RigidBody.h:79
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
Declares the node class.
virtual void CreateJoints()
Allows the rigid body to create its joints using the chosen physics engine.
Definition: Sensor.cpp:155
int m_iLatitudeSegments
Number of segments along the latitude direction that are used to build the sphere.
Definition: Sensor.h:32
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
Declares the sensor class.
Declares the data chart manager class.
Declares the rigid body class.
virtual ~Sensor()
Destructor.
Definition: Sensor.cpp:65
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 float InverseDistanceUnits()
Gets the inverse distance units.
Definition: Simulator.cpp:1742
Declares the odor class.
Declares the simulator class.
float m_fltRadius
The radius of the sensor part. It is shown as a sphere object.
Definition: Sensor.h:29
Declares the activated item manager class.
Declares the contact sensor class.
Declares the external stimuli manager class.
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