14 #include <xercesc/util/OutOfMemoryException.hpp>
15 #include <xercesc/dom/DOMImplementation.hpp>
16 #include <xercesc/dom/DOMElement.hpp>
17 #include <xercesc/dom/DOMNodeList.hpp>
18 #include <xercesc/dom/DOMNamedNodeMap.hpp>
19 #include <xercesc/sax/SAXParseException.hpp>
24 using namespace XERCES_CPP_NAMESPACE;
32 Source jointSource(scene);
35 if(ParseFile(fileName))
37 LoadAnimation(jointSource);
50 Source jointSource(sNode);
53 if(ParseFile(fileName))
55 LoadAnimation(jointSource);
76 string dofIdentifier, jName, itplName;
78 DOMNodeList* actionList;
79 DOMNamedNodeMap* attrAc;
83 xmlStr = XMLString::transcode(
"action");
84 actionList = documentPtr->getElementsByTagName(xmlStr);
85 XMLString::release(&xmlStr);
87 attrAc = documentPtr->getDocumentElement()->getAttributes();
90 xmlStr = XMLString::transcode(
"speed");
91 charAux = XMLString::transcode(attrAc->getNamedItem(xmlStr)->getNodeValue());
95 XMLString::release(&xmlStr);
96 XMLString::release(&charAux);
99 xmlStr = XMLString::transcode(
"cycle");
100 charAux = XMLString::transcode(attrAc->getNamedItem(xmlStr)->getNodeValue());
101 cycle = (strcmp(charAux,
"true") == 0);
102 XMLString::release(&xmlStr);
103 XMLString::release(&charAux);
106 Set(speed, 1, cycle);
109 for (i = 0; i<actionList->getLength(); i++)
111 DOMNodeList* jointsL = actionList->item(i)->getChildNodes();
114 for (j = 0; j<jointsL->getLength(); j++)
116 bool isJointMovement;
118 charAux = XMLString::transcode(jointsL->item(j)->getNodeName());
119 isJointMovement = (strcmp(charAux,
"joint_movement") == 0);
120 XMLString::release(&charAux);
125 DOMNamedNodeMap* attrLt = jointsL->item(j)->getAttributes();
128 xmlStr = XMLString::transcode(
"duration");
129 charAux = XMLString::transcode(attrLt->getNamedItem(xmlStr)->getNodeValue());
133 XMLString::release(&xmlStr);
134 XMLString::release(&charAux);
137 xmlStr = XMLString::transcode(
"joint_name");
138 charAux = XMLString::transcode(attrLt->getNamedItem(xmlStr)->getNodeValue());
140 XMLString::release(&xmlStr);
141 XMLString::release(&charAux);
146 DOMNodeList* dofsL = jointsL->item(j)->getChildNodes();
151 jointMPtr = AddJointMover(jointPtr, dur, sineInterpolator);
155 for(k = 0; k<dofsL->getLength(); k++)
157 bool isInterpolation;
159 charAux = XMLString::transcode(dofsL->item(k)->getNodeName());
160 isInterpolation = (strcmp(charAux,
"interpolation") == 0);
161 XMLString::release(&charAux);
164 DOMNamedNodeMap* attrInterpLt = dofsL->item(k)->getAttributes();
167 xmlStr = XMLString::transcode(
"type");
168 charAux = XMLString::transcode(attrInterpLt->getNamedItem(xmlStr)->getNodeValue());
170 XMLString::release(&xmlStr);
171 XMLString::release(&charAux);
174 if (itplName !=
"ease-in_ease-out")
176 if (itplName ==
"linear")
178 else if (itplName ==
"range_sine")
184 cerr <<
"Error: Unknown interpolator: '" << itplName
185 <<
"'. Using: 'ease-in_ease-out'." << endl;
190 charAux = XMLString::transcode(dofsL->item(k)->getNodeName());
191 if(strcmp(charAux,
"dof_movement") == 0)
192 ParseDofMovement(jointMPtr, dofsL->item(k));
193 XMLString::release(&charAux);
199 cerr <<
"Error: Joint mover targeting at '" << jName
200 <<
"': No such scene node!" << endl;
211 DOMNodeList* dofMovElements;
212 DOMNamedNodeMap* attrPt;
217 float noiseAmplitude;
218 float noiseWaveLenght;
224 istringstream stream;
227 bool foundPositionalError =
false;
228 bool foundNoise =
false;
230 attrPt = dofMovItemPtr->getAttributes();
232 xmlStr = XMLString::transcode(
"initialTime");
233 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
236 XMLString::release(&xmlStr);
237 XMLString::release(&charAux);
239 xmlStr = XMLString::transcode(
"finalTime");
240 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
244 XMLString::release(&xmlStr);
245 XMLString::release(&charAux);
247 xmlStr = XMLString::transcode(
"finalPosition");
248 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
252 XMLString::release(&xmlStr);
253 XMLString::release(&charAux);
256 xmlStr = XMLString::transcode(
"dofID");
257 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
258 if ((strcmp(charAux,
"FLEX") == 0) || (strcmp(charAux,
"FLEXION") == 0))
262 if ((strcmp(charAux,
"ADDUCT") == 0) || (strcmp(charAux,
"ADDUCTION") == 0))
265 if (strcmp(charAux,
"TWIST") == 0)
269 cerr <<
"XmlAction::ParseDofMovement: Unknown DOF ID" << endl;
273 XMLString::release(&xmlStr);
274 XMLString::release(&charAux);
276 dofMovElements = dofMovItemPtr->getChildNodes();
279 for (count = 0; count < dofMovElements->getLength(); ++count)
281 cstr_nodeName = XMLString::transcode(dofMovElements->item(count)->getNodeName());
282 if (strcmp(cstr_nodeName,
"noise") == 0)
284 attrPt = dofMovElements->item(count)->getAttributes();
286 xmlStr = XMLString::transcode(
"amplitude");
287 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
290 stream >> noiseAmplitude;
291 XMLString::release(&xmlStr);
292 XMLString::release(&charAux);
294 xmlStr = XMLString::transcode(
"length");
295 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
298 stream >> noiseWaveLenght;
299 XMLString::release(&xmlStr);
300 XMLString::release(&charAux);
304 else if (strcmp(cstr_nodeName,
"error") == 0)
306 attrPt = dofMovElements->item(count)->getAttributes();
308 xmlStr = XMLString::transcode(
"overshoot");
309 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
313 XMLString::release(&xmlStr);
314 XMLString::release(&charAux);
315 NoisyDofMover::SetDefaultOvershoot(overshoot);
317 xmlStr = XMLString::transcode(
"offset");
318 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
322 XMLString::release(&xmlStr);
323 XMLString::release(&charAux);
324 NoisyDofMover::SetDefaultOffset(offset);
326 xmlStr = XMLString::transcode(
"peak_time");
327 charAux = XMLString::transcode(attrPt->getNamedItem(xmlStr)->getNodeValue());
331 XMLString::release(&xmlStr);
332 XMLString::release(&charAux);
333 NoisyDofMover::SetDefaultPeakTime(peakTime);
335 foundPositionalError =
true;
337 delete[] cstr_nodeName;
341 if (foundPositionalError || foundNoise)
347 noisyDofMoverPtr->
SetNoise(noiseAmplitude, noiseWaveLenght);
355 jointMPtr->
AddDofMover(dofID, inTime, fTime, fPos);
364 list<JointMover*>::const_iterator iter = action.
jointMoverList.begin();
366 output <<
"<?xml version=\"1.0\"?>\n"
367 <<
"<!DOCTYPE action SYSTEM \"vartAnimation.dtd\">\n"
368 <<
"<action action_name=\"" << action.
description <<
"\" speed=\"" << action.
speed
369 <<
"\" cycle=\"" << boolalpha << action.
cycle <<
"\">\n";
376 output <<
"</action>\n";
397 sceneNodePtr = &sNode;
404 return dynamic_cast<Joint*
>(scenePtr->GetObjectRec(name));
408 return dynamic_cast<Joint*
>(sceneNodePtr->FindChildByName(name));
Base class for objects that compose a scene graph.
Representation of joints.
Source(const Scene &scene)
Smooth (sine function) interpolator.
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
Header file for V-ART class "Scene".
std::string description
Textual description.
Header file for V-ART class "SineInterpolator".
Joint * GetJointByName(const std::string &name) const
Header file for V-ART class "JointMover".
void SetNoise(float newNoiseAmplitude, float newNoiseWaveLenght)
Sets the noise attributes.
Smooth (sine function) interpolator with range.
A set of objects, lights and cameras.
Header file for V-ART class "Joint".
void LoadAnimation(const Source &jointSource)
Interpolator representation.
Controllers for joint movement.
Noisy Controller for DOF movement.
std::list< JointMover * > jointMoverList
Parser and loader for xml files that describe an Action.
Header file for V-ART class "XmlAction".
Header file for V-ART class "NoisyDofMover".
Header file for V-ART class "LinearInterpolator".
Header file for V-ART class "SineInterpolator".
void SetInterpolator(const Interpolator &interp)
Changes the associated interpolator.
void AddDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a DofMover.
bool LoadFromFile(const std::string &fileName, const Scene &scene)
Loads action from a XML file.
NoisyDofMover * AddNoisyDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a noisy DofMover.
void ParseDofMovement(JointMover *jointMPtr, XERCES_CPP_NAMESPACE::DOMNode *dofMovItemPtr)