13 #include <xercesc/dom/DOMNodeList.hpp>
14 #include <xercesc/dom/DOMElement.hpp>
22 cout <<
"XmlJointAction::XmlJointAction()" << endl;
26 XERCES_CPP_NAMESPACE::DOMNode* dofMovItemPtr)
29 using namespace XERCES_CPP_NAMESPACE;
31 DOMNamedNodeMap* dofAttrs = dofMovItemPtr->getAttributes();
34 GetAttributeValue(dofAttrs,
"initialTime", &inTime);
37 GetAttributeValue(dofAttrs,
"finalTime", &fTime);
40 GetAttributeValue(dofAttrs,
"finalPosition", &fPos);
43 GetAttributeValue(dofAttrs,
"dofID", &dofIDString);
45 if ((dofIDString ==
"FLEX") || (dofIDString ==
"FLEXION"))
49 if ((dofIDString ==
"ADDUCT") || (dofIDString ==
"ADDUCTION"))
53 if (dofIDString ==
"TWIST")
57 cerr <<
"XmlAction::ParseDofMovement: Unknown DOF ID (" << dofIDString <<
")."
65 DOMNodeList* dofMovElements = dofMovItemPtr->getChildNodes();
67 float noiseWaveLenght;
68 bool foundNoise =
false;
69 bool foundPositionalError =
false;
71 for (
unsigned int count = 0; count < dofMovElements->getLength(); ++count)
73 string nodeName(
TempCString(dofMovElements->item(count)->getNodeName()));
74 if (nodeName ==
"noise")
76 DOMNamedNodeMap* noiseAttrs = dofMovElements->item(count)->getAttributes();
77 GetAttributeValue(noiseAttrs,
"amplitude", &noiseAmplitude);
78 GetAttributeValue(noiseAttrs,
"length", &noiseWaveLenght);
82 if (nodeName ==
"error")
84 DOMNamedNodeMap* errorAttrs = dofMovElements->item(count)->getAttributes();
87 GetAttributeValue(errorAttrs,
"overshoot", &overshoot);
88 NoisyDofMover::SetDefaultOvershoot(overshoot);
91 GetAttributeValue(errorAttrs,
"offset", &offset);
92 NoisyDofMover::SetDefaultOffset(offset);
95 GetAttributeValue(errorAttrs,
"peak_time", &peakTime);
96 NoisyDofMover::SetDefaultPeakTime(peakTime);
98 foundPositionalError =
true;
103 if (foundPositionalError || foundNoise)
109 noisyDofMoverPtr->
SetNoise(noiseAmplitude, noiseWaveLenght);
112 jointMPtr->
AddDofMover(dofID, inTime, fTime, fPos);
116 XERCES_CPP_NAMESPACE::DOMNode* xmlNodePtr)
118 using namespace XERCES_CPP_NAMESPACE;
123 DOMNamedNodeMap* jmAttrs = xmlNodePtr->getAttributes();
126 GetAttributeValue(jmAttrs,
"duration", &moverDuration);
129 GetAttributeValue(jmAttrs,
"joint_name", &jointName);
136 JointMover* jointMoverPtr = AddJointMover(targetJointPtr, moverDuration, sineInterpolator);
137 DOMNodeList* childrenList = xmlNodePtr->getChildNodes();
139 for (
unsigned int i=0; i < childrenList->getLength(); ++i)
141 string name(
TempCString(childrenList->item(i)->getNodeName()));
142 if (name ==
"interpolation")
144 DOMNamedNodeMap* itpAttrs = childrenList->item(i)->getAttributes();
147 GetAttributeValue(itpAttrs,
"type", &itpType);
149 if (itpType !=
"ease-in_ease-out")
151 if (itpType ==
"linear")
155 if (itpType ==
"range_sine")
162 cerr <<
"Error: Unknown interpolator type: '" << itpType
163 <<
"'. Using: 'ease-in_ease-out'." << endl;
169 if (name ==
"dof_movement")
170 ParseDofMovement(jointMoverPtr, childrenList->item(i));
178 using namespace XERCES_CPP_NAMESPACE;
181 if(ParseFile(fileName))
184 DOMNamedNodeMap* actionAttrs = documentPtr->getDocumentElement()->getAttributes();
186 bool result = GetAttributeValue(actionAttrs,
"action_name", &description);
188 result |= GetAttributeValue(actionAttrs,
"speed", &speedModifier);
190 result |= GetAttributeValue(actionAttrs,
"cycle", &cyclic);
192 DOMNodeList* jmList = documentPtr->getDocumentElement()->getChildNodes();
194 for (
unsigned int jm = 0; jm < jmList->getLength(); ++jm)
196 string name(
TempCString(jmList->item(jm)->getNodeName()));
197 if (name ==
"joint_movement")
198 CreateJointMover(sNode, jmList->item(jm));
Locates a SceneNode by its description.
Base class for objects that compose a scene graph.
Representation of joints.
Smooth (sine function) interpolator.
Header file for V-ART class "SineInterpolator".
Header file for V-ART class "JointMover".
void SetNoise(float newNoiseAmplitude, float newNoiseWaveLenght)
Sets the noise attributes.
Smooth (sine function) interpolator with range.
virtual void LocateBreadthFirst(SNLocator *locatorPtr) const
Seaches for a particular scene node (breadth first)
Header file for V-ART class "Joint".
Header file for V-ART class "XmlJointAction".
Interpolator representation.
Controllers for joint movement.
void ParseDofMovement(JointMover *jointMPtr, XERCES_CPP_NAMESPACE::DOMNode *dofMovItemPtr)
Noisy Controller for DOF movement.
Header file for V-ART class "NoisyDofMover".
Class for auto conversion from Xerces strings to C strings.
void CreateJointMover(const VART::SceneNode &sNode, XERCES_CPP_NAMESPACE::DOMNode *xmlNodePtr)
Header file for V-ART class "LinearInterpolator".
Header file for V-ART class "SineInterpolator".
void SetInterpolator(const Interpolator &interp)
Changes the associated interpolator.
bool LoadFromFile(const std::string &fileName, const SceneNode &sNode)
Loads JointAction from a XML file.
void AddDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a DofMover.
NoisyDofMover * AddNoisyDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a noisy DofMover.
const SceneNode * LocatedNode() const
Returns the located node.