AnimatLab  2
Test
ConstraintLimit.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "AnimatBase.h"
9 
10 #include "Node.h"
11 #include "IPhysicsMovableItem.h"
12 #include "IPhysicsBody.h"
13 #include "ISimGUICallback.h"
14 #include "BoundingBox.h"
15 #include "MovableItem.h"
16 #include "BodyPart.h"
17 #include "Joint.h"
18 #include "ReceptiveField.h"
19 #include "ContactSensor.h"
20 #include "RigidBody.h"
21 #include "ConstraintLimit.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 namespace AnimatSim
37 {
38  namespace Environment
39  {
47 {
48  m_lpSim = NULL;
49  m_lpStructure = NULL;
50  m_lpJoint = NULL;
51 
52  m_fltLimitPos = 0;
53  m_fltDamping = 0;
54  m_fltRestitution = 0;
55  m_fltStiffness = 0;
56  m_bIsLowerLimit = true;
57  m_bIsShowPosition = false;
58 }
59 
67 {
68 }
69 
71 
72 void ConstraintLimit::LimitPos(float fltVal, bool bUseScaling, bool bOverrideSameCheck)
73 {
74  //If the values are the same then skip setting this step to preven having to
75  //recalculate the matrix positions repeatedly. Only do this when the new position is
76  // different than the old one.
77  if(fabs(fltVal - m_fltLimitPos) < 1e-5 && !bOverrideSameCheck)
78  return;
79 
80  if(bUseScaling && m_lpSim && m_lpJoint && !m_lpJoint->UsesRadians())
82  else
83  m_fltLimitPos = fltVal;
84 
85  SetLimitPos();
86 }
87 
89 
90 void ConstraintLimit::Damping(float fltVal, bool bUseScaling)
91 {
92  Std_IsAboveMin((float) 0, fltVal, true, "Constraint::Damping", true);
93 
94  if(bUseScaling)
95  fltVal *= m_lpSim->InverseMassUnits();
96 
97  m_fltDamping = fltVal;
99 }
100 
102 
104 {
105  Std_IsAboveMin((float) 0, fltVal, true, "Constraint::Restitution", true);
106  m_fltRestitution = fltVal;
107  SetLimitValues();
108 }
109 
111 
112 void ConstraintLimit::Stiffness(float fltVal, bool bUseScaling)
113 {
114  Std_IsAboveMin((float) 0, fltVal, true, "Constraint::Stiffness", true);
115 
116  if(bUseScaling)
117  fltVal *= m_lpSim->InverseMassUnits();
118 
119  m_fltStiffness = fltVal;
120  SetLimitValues();
121 }
122 
136 void ConstraintLimit::Color(float fltR, float fltG, float fltB, float fltA)
137 {m_vColor.Set(fltR, fltG, fltB, fltA);}
138 
148 
157 void ConstraintLimit::Color(std::string strXml)
158 {
159  m_vColor.Load(strXml, "Color");
160 }
161 
162 float ConstraintLimit::Alpha() {return m_vColor.a();}
163 
173 
183 
194 
205 
228 void ConstraintLimit::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, bool bVerify)
229 {
230  AnimatBase::SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, false);
231  m_lpJoint = dynamic_cast<Joint *>(lpNode);
232 
233  if(bVerify) VerifySystemPointers();
234 }
235 
249 void ConstraintLimit::SetSystemPointers(Simulator *lpSim, Structure *lpStructure, NeuralModule *lpModule, Node *lpNode, float fltPosition, bool bVerify)
250 {
251  SetSystemPointers(lpSim, lpStructure, lpModule, lpNode, bVerify);
252  LimitPos(fltPosition);
253 }
254 
256 {
258 
259  if(!m_lpStructure)
260  THROW_PARAM_ERROR(Al_Err_lStructureNotDefined, Al_Err_strStructureNotDefined, "ConstraintLimit: ", m_strName);
261 
262  if(!m_lpJoint)
263  THROW_PARAM_ERROR(Al_Err_lJointNotDefined, Al_Err_strJointNotDefined, "ConstraintLimit: ", m_strName);
264 }
265 
266 #pragma region DataAccesMethods
267 
268 float *ConstraintLimit::GetDataPointer(const std::string &strDataType)
269 {
270  std::string strType = Std_CheckString(strDataType);
271 
272  if(strType == "LIMITPOS")
273  return &m_fltLimitPos;
274  else
275  THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "JointID: " + STR(m_strName) + " DataType: " + strDataType);
276 
277  return NULL;
278 }
279 
280 bool ConstraintLimit::SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError)
281 {
282  std::string strType = Std_CheckString(strDataType);
283 
284  if(AnimatBase::SetData(strDataType, strValue, false))
285  return true;
286 
287  if(strType == "LIMITPOS")
288  {
289  LimitPos((float) atof(strValue.c_str()));
290  return true;
291  }
292  else if(strType == "DAMPING")
293  {
294  Damping((float) atof(strValue.c_str()));
295  return true;
296  }
297  else if(strType == "RESTITUTION")
298  {
299  Restitution((float) atof(strValue.c_str()));
300  return true;
301  }
302  else if(strType == "STIFFNESS")
303  {
304  Stiffness((float) atof(strValue.c_str()));
305  return true;
306  }
307  else if(strType == "COLOR")
308  {
309  Color(strValue);
310  return true;
311  }
312  else if(strType == "ALPHA")
313  {
314  Alpha((float) atof(strValue.c_str()));
315  return true;
316  }
317 
318  //If it was not one of those above then we have a problem.
319  if(bThrowError)
320  THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType, "Data Type", strDataType);
321 
322  return false;
323 }
324 
325 void ConstraintLimit::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
326 {
327  AnimatBase::QueryProperties(aryProperties);
328 
329  aryProperties.Add(new TypeProperty("LimitPos", AnimatPropertyType::Float, AnimatPropertyDirection::Both));
330  aryProperties.Add(new TypeProperty("Damping", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
331  aryProperties.Add(new TypeProperty("Restitution", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
332  aryProperties.Add(new TypeProperty("Stiffness", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
333  aryProperties.Add(new TypeProperty("Color", AnimatPropertyType::Xml, AnimatPropertyDirection::Set));
334  aryProperties.Add(new TypeProperty("Alpha", AnimatPropertyType::Float, AnimatPropertyDirection::Set));
335 }
336 
337 #pragma endregion
338 
348 void ConstraintLimit::Load(CStdXml &oXml, std::string strName)
349 {
350  oXml.FindChildElement(strName);
351 
352  AnimatBase::Load(oXml);
353 
354  oXml.IntoElem(); //Into ConstraintLimit Element
355 
356  LimitPos(oXml.GetChildFloat("LimitPos", m_fltLimitPos));
357  Damping(oXml.GetChildFloat("Damping", m_fltDamping));
358  Restitution(oXml.GetChildFloat("Restitution", m_fltRestitution));
359  Stiffness(oXml.GetChildFloat("Stiffness", m_fltStiffness));
360 
361  oXml.OutOfElem(); //OutOf ConstraintLimit Element
362 }
363 
364 
365  } //Environment
366 } //AnimatSim
The base class for all of the joint type of objects.
Definition: Joint.h:40
Base class file for all Animat simulation objects.
Standard color class.
Definition: StdColor.h:22
float m_fltLimitPos
The limit position for the constraint. This can be in radians or meters depending on the type of join...
virtual bool IsShowPosition()
Gets whether this contstraint is actually just being used to show the current position of the joint...
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
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
Root namespace for the base simulation library for AnimatLab.
void Set(float R, float G, float B, float A)
Sets the color values.
Definition: StdColor.cpp:153
virtual float InverseMassUnits()
Gets the inverse mass units.
Definition: Simulator.cpp:1797
virtual float LimitPos()
Gets the limit position.
Declares the body part class.
float m_fltRestitution
The restitution coefficient for the constraint.
virtual float Restitution()
Gets the restitution coefficient of the constraint.
void Load(CStdXml &oXml, std::string strParamName, bool bThrowError=true)
Loads the color.
Definition: StdColor.cpp:540
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual bool IsLowerLimit()
Query if this object is lower limit.
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 float Stiffness()
Gets the stiffness of the constraint.
Declares the key frame class.
virtual float Alpha()
Gets the alpha value.
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.
AnimatSim::Environment::Structure * m_lpStructure
The pointer to this items parent Structure. If this is not relevant for this object then this is NULL...
Definition: AnimatBase.h:46
Declares a light object.
Joint * m_lpJoint
Pointer to parent joint.
Declares the activated item class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
virtual float Damping()
Gets the damping value of the contraint.
Declares a light manager object.
float m_fltDamping
The damping for the constraint.
Declares the bounding box class.
A standard xml manipulation class.
Definition: StdXml.h:19
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
A "static" structure in the simulation.
Definition: Structure.h:84
Declares the node class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
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 void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Definition: AnimatBase.cpp:771
virtual void SetLimitValues()=0
Sets the limit values of the joint in the child object.
float m_fltStiffness
The stiffness of the constraint.
virtual void SetLimitPos()=0
Sets the limit position using the current value set within the object.
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
virtual CStdColor * Color()
Gets the color that is used when displaying this constraint.
Declares the data chart manager class.
bool m_bIsLowerLimit
If true then this is the lower limit of a pair of ConstraintLimits, else it is the upper limit...
Declares the rigid body class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the constraint limit class.
Declares the structure class.
virtual void QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
Declares the odor type class.
virtual void VerifySystemPointers()
Verify that system pointers have been set correctly.
Definition: AnimatBase.cpp:315
virtual bool UsesRadians()
Tells whether this joint uses radians or meters for its measurements.
Definition: Joint.cpp:97
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.
CStdColor m_vColor
The color used to display the limit.
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
void a(float fltA, bool bThrowError=true)
Sets the alpha value of the color.
Definition: StdColor.cpp:126
Declares the receptive field class.
std::string m_strName
The name for this object.
Definition: AnimatBase.h:61
virtual float GetChildFloat(std::string strElementName)
Gets a float value from the element with the specified name.
Definition: StdXml.cpp:617