AnimatLab  2
Test
Light.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 "Light.h"
18 #include "BodyPart.h"
19 #include "Joint.h"
20 #include "ReceptiveField.h"
21 #include "ContactSensor.h"
22 #include "RigidBody.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  {
48 {
49  m_fltRadius = 1;
52  m_iLightNum = 0;
56  m_bEnabled = true;
57 }
58 
66 {
67 }
68 
69 #pragma region AccessorMutators
70 
78 bool Light::Enabled() {return m_bEnabled;}
79 
90 void Light::Enabled(bool bValue)
91 {
92  m_bEnabled = bValue;
93 }
94 
102 {
104  m_lpPhysicsMovableItem->Physics_CollectData();
105 }
106 
117 {
119  m_lpPhysicsMovableItem->Physics_Resize();
120 }
121 
122 float Light::Radius() {return m_fltRadius;}
123 
124 void Light::Radius(float fltVal, bool bUseScaling)
125 {
126  Std_IsAboveMin((float) 0, fltVal, true, "Light.Radius");
127  if(bUseScaling)
129  else
130  m_fltRadius = fltVal;
131 
132  Resize();
133 }
134 
143 void Light::LatitudeSegments(int iVal)
144 {
145  Std_IsAboveMin((int) 10, iVal, true, "Light.LatitudeSegments", true);
146  m_iLatitudeSegments = iVal;
147  Resize();
148 }
149 
159 
169 {
170  Std_IsAboveMin((int) 10, iVal, true, "Light.LongtitudeSegments", true);
171  m_iLongtitudeSegments = iVal;
172  Resize();
173 }
174 
184 
185 #pragma endregion
186 
187 void Light::Selected(bool bValue, bool bSelectMultiple)
188 {
189  AnimatBase::Selected(bValue, bSelectMultiple);
190  MovableItem::Selected(bValue, bSelectMultiple);
191 }
192 
201 void Light::LightNumber(int iVal)
202 {
203  Std_IsAboveMin((int) 0, iVal, true, "Light.LightNumber", true);
204  m_iLightNum = iVal;
205 }
206 
216 
217 void Light::ConstantAttenRatio(float fltVal)
218 {
219  Std_InValidRange((float) 0, (float) 1, fltVal, true, "Receptive Field Index");
220  m_fltConstantAttenRatio = fltVal;
221  Resize();
222 }
223 
224 float Light::ConstantAttenRatio() {return m_fltConstantAttenRatio;}
225 
226 void Light::LinearAttenDistance(float fltVal, bool bUseScaling)
227 {
228  Std_IsAboveMin((float) 0, fltVal, true, "Light.LinearAttenDistance", true);
229  if(bUseScaling)
231  else
232  m_fltLinearAttenDistance = fltVal;
233 
234  Resize();
235 }
236 
237 float Light::LinearAttenDistance() {return m_fltLinearAttenDistance;}
238 
239 void Light::QuadraticAttenDistance(float fltVal, bool bUseScaling)
240 {
241  Std_IsAboveMin((float) 0, fltVal, true, "Light.QuadraticAttenDistance", true);
242  if(bUseScaling)
244  else
246 
247  Resize();
248 }
249 
250 float Light::QuadraticAttenDistance() {return m_fltQuadraticAttenDistance;}
251 
265 {
267 }
268 
269 
270 #pragma region DataAccesMethods
271 
272 void Light::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
273 {
274  AnimatBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
275  m_lpMovableSim = lpSim;
276 }
277 
278 bool Light::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
279 {
280  std::string strType = Std_CheckString(strDataType);
281 
282  if(AnimatBase::SetData(strType, strValue, false))
283  return true;
284 
285  if(MovableItem::SetData(strType, strValue, false))
286  return true;
287 
288  if(strType == "ENABLED")
289  {
290  Enabled(Std_ToBool(strValue));
291  return true;
292  }
293 
294  if(strType == "RADIUS")
295  {
296  Radius((float) atof(strValue.c_str()));
297  return true;
298  }
299 
300  if(strType == "LATITUDESEGMENTS")
301  {
302  LatitudeSegments(atoi(strValue.c_str()));
303  return true;
304  }
305 
306  if(strType == "LONGTITUDESEGMENTS")
307  {
308  LongtitudeSegments(atoi(strValue.c_str()));
309  return true;
310  }
311 
312  if(strType == "CONSTANTATTENUATION")
313  {
314  ConstantAttenRatio((float) atof(strValue.c_str()));
315  return true;
316  }
317 
318  if(strType == "LINEARATTENUATIONDISTANCE")
319  {
320  LinearAttenDistance((float) atof(strValue.c_str()));
321  return true;
322  }
323 
324  if(strType == "QUADRATICATTENUATIONDISTANCE")
325  {
326  QuadraticAttenDistance((float) atof(strValue.c_str()));
327  return true;
328  }
329 
330  //If it was not one of those above then we have a problem.
331  if(bThrowError)
332  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
333 
334  return false;
335 }
336 
337 void Light::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
338 {
339  AnimatBase::QueryProperties(aryProperties);
340  MovableItem::QueryProperties(aryProperties);
341 
342  aryProperties.Add(new TypeProperty("Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Both));
343  aryProperties.Add(new TypeProperty("Radius", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
344  aryProperties.Add(new TypeProperty("LatitudeSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
345  aryProperties.Add(new TypeProperty("LongtitudeSegments", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
346  aryProperties.Add(new TypeProperty("ConstantAttenuation", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
347  aryProperties.Add(new TypeProperty("LinearAttenuationDistance", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
348  aryProperties.Add(new TypeProperty("QuadraticAttenuationDistance", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
349 }
350 
351 #pragma endregion
352 
353 void Light::Create()
354 {
355 }
356 
357 void Light::Load(CStdXml &oXml)
358 {
359  AnimatBase::Load(oXml);
360  MovableItem::Load(oXml);
361 
362  oXml.IntoElem(); //Into RigidBody Element
363  Enabled(oXml.GetChildBool("Enabled", m_bEnabled));
364  Radius(oXml.GetChildFloat("Radius", m_fltRadius));
365  LatitudeSegments(oXml.GetChildInt("LatitudeSegments", m_iLatitudeSegments));
366  LongtitudeSegments(oXml.GetChildInt("LongtitudeSegments", m_iLongtitudeSegments));
367  ConstantAttenRatio(oXml.GetChildFloat("ConstantAttenuation", m_fltConstantAttenRatio));
368  LinearAttenDistance(oXml.GetChildFloat("LinearAttenuationDistance", m_fltLinearAttenDistance));
369  QuadraticAttenDistance(oXml.GetChildFloat("QuadraticAttenuationDistance", m_fltQuadraticAttenDistance));
370  oXml.OutOfElem(); //OutOf RigidBody Element
371 }
372 
373  } //Environment
374 } //AnimatSim
virtual bool Enabled()
Tells whether this light is enabled.
Definition: Light.cpp:78
Base class file for all Animat simulation objects.
Declares the simulation recorder class.
virtual void SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
Sets the system pointers.
Simulates the entire environment.
Definition: Simulator.h:31
Simulator * m_lpMovableSim
The pointer to a Simulation.
Definition: MovableItem.h:23
Root namespace for the base simulation library for AnimatLab.
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: Light.cpp:278
Declares the body part class.
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
float m_fltQuadraticAttenDistance
The quadratic attenuation distance.
Definition: Light.h:45
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
float m_fltLinearAttenDistance
The linear attenuation distance.
Definition: Light.h:42
Class that stores information about types for QueryProperty information.
Definition: TypeProperty.h:35
Declares the key frame class.
bool Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
virtual int LightNumber()
Gets the light number.
Definition: Light.cpp:215
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.
Declares the activated item class.
virtual void VisualSelectionModeChanged(int iNewMode)
Called when the visual selection mode changed in GUI.
Definition: Light.cpp:264
Declares a light manager object.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: Light.cpp:337
IPhysicsMovableItem * m_lpPhysicsMovableItem
Definition: MovableItem.h:103
int m_iLightNum
Zero-based index of the light number. OSG only allows 8 lights.
Definition: Light.h:36
Declares the bounding box class.
virtual ~Light(void)
Destructor.
Definition: Light.cpp:65
virtual float Radius()
Gets the radius.
Definition: Light.cpp:122
A standard xml manipulation class.
Definition: StdXml.h:19
virtual int LongtitudeSegments()
Gets the longtitude segments.
Definition: Light.cpp:183
virtual bool Selected()
Tells if this items is selected or not.
Definition: AnimatBase.cpp:248
A "static" structure in the simulation.
Definition: Structure.h:84
Declares the node class.
float m_fltRadius
The radius of the sphere.
Definition: Light.h:27
virtual void UpdateData()
Called to collect any body data for this part.
Definition: Light.cpp:101
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Definition: AnimatBase.cpp:447
float m_fltConstantAttenRatio
The constant attenuation ratio.
Definition: Light.h:39
bool Std_ToBool(int iVal)
Converts a value toa bool.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
virtual bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
Definition: StdXml.cpp:699
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
int m_iLatitudeSegments
Number of segments along the latitude direction that are used to build the sphere.
Definition: Light.h:30
virtual void VisualSelectionModeChanged(int iNewMode)
Called when the visual selection mode changed in GUI.
virtual int LatitudeSegments()
Gets the latitude segments.
Definition: Light.cpp:158
Base class for body parts and neural network nodes.
Definition: Node.h:25
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
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.
virtual void Resize()
Called when this object has been resized.
Definition: Light.cpp:116
Declares the structure class.
Light(void)
Default constructor.
Definition: Light.cpp:47
Declares the odor type class.
int m_iLongtitudeSegments
Number of segments along the longtitude direction that are used to build the sphere.
Definition: Light.h:33
virtual float InverseDistanceUnits()
Gets the inverse distance units.
Definition: Simulator.cpp:1742
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
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