14 #include <xercesc/dom/DOMNodeList.hpp>
15 #include <xercesc/dom/DOMNamedNodeMap.hpp>
18 using XERCES_CPP_NAMESPACE::DOMNodeList;
19 using XERCES_CPP_NAMESPACE::DOMNode;
20 using XERCES_CPP_NAMESPACE::DOMNamedNodeMap;
29 meshMap::iterator iterMesh;
30 meshObjMap::iterator iterMeshObj;
32 if (ParseFile(fileName))
40 for(iterMesh = mapMesh.begin(); iterMesh != mapMesh.end(); ++iterMesh)
42 for(iterMeshObj = mapMeshObj.begin(); iterMeshObj != mapMeshObj.end(); ++iterMeshObj)
43 delete iterMeshObj->second;
62 DOMNodeList* sceneList = documentPtr->getElementsByTagName(
XercesString(
"scene"));
66 for (
unsigned int i = 0; i < sceneList->getLength(); i++)
68 DOMNodeList* nodesL = sceneList->item(i)->getChildNodes();
69 for(j = 0; j<nodesL->getLength(); j++)
71 if (
TempCString(nodesL->item(j)->getNodeName()) ==
"camera")
74 else if (
TempCString(nodesL->item(j)->getNodeName()) ==
"node")
77 nodePtr = LoadSceneNode(nodesL->item(j), basePath);
97 meshMap::iterator iterMesh;
98 meshObjMap::iterator iterMeshObj;
99 list<VART::MeshObject*> meshObjectList;
100 list<VART::MeshObject*>::iterator iter;
105 iterMesh = mapMesh.find(filen);
108 if(iterMesh != mapMesh.end())
110 iterMeshObj = mapMeshObj.find(meshName);
111 if(iterMeshObj != mapMeshObj.end())
114 finalMesh = iterMeshObj->second;
115 mapMeshObj.erase(iterMeshObj);
121 cerr<<
"Error! Mesh "<<meshName<<
" not found in file "<<filen<<endl;
131 meshObjectList.clear();
133 for (iter = meshObjectList.begin(); iter != meshObjectList.end(); ++iter)
135 if ((*iter)->GetDescription() == meshName)
145 mapMesh[filen] = mapMeshObj;
147 cerr <<
"Error: No mesh object named " << meshName <<
" was found!" << endl;
162 istringstream stream;
164 int currentChild = 1;
166 int rTemp, gTemp, bTemp, aTemp;
168 DOMNodeList* listNode = sceneList->getChildNodes();
169 numChildren = listNode->getLength();
173 if (
TempCString(listNode->item(1)->getNodeName()) ==
"bezier")
176 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"sphere")
181 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
182 DOMNamedNodeMap* attrAux;
186 for(i = 0; i<childNodes->getLength(); i++)
188 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"radius")
190 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
196 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"material")
198 unsigned char r, g, b;
199 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
205 r =
static_cast<unsigned char>(rTemp);
206 greenStr.GetValue(&gTemp);
207 g =
static_cast<unsigned char>(gTemp);
208 blueStr.GetValue(&bTemp);
209 b =
static_cast<unsigned char>(bTemp);
213 attrAux = listNode->item(1)->getAttributes();
219 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"cylinder")
226 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
227 DOMNamedNodeMap* attrAux;
231 for(i = 0; i<childNodes->getLength(); i++)
233 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"radius")
235 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
241 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"height")
243 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
249 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"material")
251 unsigned char r, g, b;
252 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
258 r =
static_cast<unsigned char>(rTemp);
259 greenStr.GetValue(&gTemp);
260 g =
static_cast<unsigned char>(gTemp);
261 blueStr.GetValue(&bTemp);
262 b =
static_cast<unsigned char>(bTemp);
266 attrAux = listNode->item(1)->getAttributes();
269 result = cylinderPtr;
272 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"meshobject")
276 list<VART::MeshObject*> meshObjectList;
277 list<VART::MeshObject*>::iterator iter;
283 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
284 DOMNamedNodeMap* attrAux = listNode->item(1)->getAttributes();
286 for (i = 0; i<childNodes->getLength(); i++)
288 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"material")
292 for (j = 0; j<attrAux->getLength(); j++)
294 if (
TempCString(attrAux->item(j)->getNodeName()) ==
"filename")
297 else if (
TempCString(attrAux->item(j)->getNodeName()) ==
"description")
302 else if (
TempCString(attrAux->item(j)->getNodeName()) ==
"type")
307 result = LoadMeshFromFile(basePath+file_name, typeName, obj_name);
310 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"directionallight")
317 float ambientIntensity;
326 istringstream stream;
327 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
328 DOMNamedNodeMap* attrTemp = listNode->item(1)->getAttributes();
334 for (i = 0; i<childNodes->getLength(); i++)
336 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"intensity")
338 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
345 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"ambientIntensity")
347 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
354 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"color")
356 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
363 r =
static_cast<unsigned char>(rTemp);
364 greenStr.GetValue(&gTemp);
365 g =
static_cast<unsigned char>(gTemp);
366 blueStr.GetValue(&bTemp);
367 b =
static_cast<unsigned char>(bTemp);
368 alphaStr.GetValue(&aTemp);
369 a =
static_cast<unsigned char>(aTemp);
374 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"enabled")
376 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
379 if (boolValue ==
"true")
380 directionallightPtr->
Turn(
true);
383 if (boolValue ==
"false")
384 directionallightPtr->
Turn(
false);
387 cerr <<
"XmlScene::LoadSceneNode: Error at 'directionallight' attribute: "
388 <<
"unknown value for 'enabled': '" << boolValue
389 <<
"'. Assuming 'true'.\n";
390 directionallightPtr->
Turn(
true);
395 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"position")
397 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
403 yStr.GetValue(&yPos);
404 zStr.GetValue(&zPos);
410 result = directionallightPtr;
413 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"spotlight")
424 float ambientIntensity;
431 istringstream stream;
433 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
434 DOMNamedNodeMap* attrTemp = listNode->item(1)->getAttributes();
436 for (i = 0; i<childNodes->getLength(); i++)
438 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"intensity")
440 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
446 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"ambientIntensity")
448 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
454 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"color")
456 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
462 r =
static_cast<unsigned char>(rTemp);
463 greenStr.GetValue(&gTemp);
464 g =
static_cast<unsigned char>(gTemp);
465 blueStr.GetValue(&bTemp);
466 b =
static_cast<unsigned char>(bTemp);
469 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"enabled")
471 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
474 if (boolValue ==
"true")
475 spotlightPtr->
Turn(
true);
478 if (boolValue ==
"false")
479 spotlightPtr->
Turn(
false);
482 cerr <<
"XmlScene::LoadSceneNode: Error at 'spotlight' attribute: "
483 <<
"unknown value for 'enabled': '" << boolValue
484 <<
"'. Assuming 'true'.\n";
485 spotlightPtr->
Turn(
true);
489 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"position")
491 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
497 yStr.GetValue(&yPos);
498 zStr.GetValue(&zPos);
504 result = spotlightPtr;
507 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"pointlight")
517 float ambientIntensity;
525 istringstream stream;
527 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
528 DOMNamedNodeMap* attrTemp = listNode->item(1)->getAttributes();
530 for (i = 0; i<childNodes->getLength(); i++)
532 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"intensity")
534 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
540 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"ambientIntensity")
542 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
548 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"color")
550 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
556 r =
static_cast<unsigned char>(rTemp);
557 greenStr.GetValue(&gTemp);
558 g =
static_cast<unsigned char>(gTemp);
559 blueStr.GetValue(&bTemp);
560 b =
static_cast<unsigned char>(bTemp);
563 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"enabled")
565 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
568 if (boolValue ==
"true")
569 pointlightPtr->
Turn(
true);
572 if (boolValue ==
"false")
573 pointlightPtr->
Turn(
false);
576 cerr <<
"XmlScene::LoadSceneNode: Error at 'pointlight' attribute: "
577 <<
"unknown value for 'enabled': '" << boolValue
578 <<
"'. Assuming 'true'.\n";
579 pointlightPtr->
Turn(
true);
583 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"position")
585 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
591 yStr.GetValue(&yPos);
592 zStr.GetValue(&zPos);
598 result = pointlightPtr;
601 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"transform")
606 list<VART::Transform>::const_iterator iter;
607 list<VART::Transform> listTrans;
608 istringstream stream;
618 DOMNodeList* childNodes = listNode->item(1)->getChildNodes();
619 DOMNamedNodeMap* attrTemp = listNode->item(1)->getAttributes();
621 for (i = 0; i<childNodes->getLength(); i++)
624 if (
TempCString(childNodes->item(i)->getNodeName()) ==
"matrix")
628 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
648 m01Str.GetValue(&tempFloat);
650 m02Str.GetValue(&tempFloat);
652 m03Str.GetValue(&tempFloat);
654 m10Str.GetValue(&tempFloat);
656 m11Str.GetValue(&tempFloat);
658 m12Str.GetValue(&tempFloat);
660 m13Str.GetValue(&tempFloat);
662 m20Str.GetValue(&tempFloat);
664 m21Str.GetValue(&tempFloat);
666 m22Str.GetValue(&tempFloat);
667 data[10] = tempFloat;
668 m23Str.GetValue(&tempFloat);
669 data[11] = tempFloat;
670 m30Str.GetValue(&tempFloat);
671 data[12] = tempFloat;
672 m31Str.GetValue(&tempFloat);
673 data[13] = tempFloat;
674 m32Str.GetValue(&tempFloat);
675 data[14] = tempFloat;
676 m33Str.GetValue(&tempFloat);
677 data[15] = tempFloat;
685 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"translation")
687 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
693 yStr.GetValue(&yPos);
694 zStr.GetValue(&zPos);
695 trans-> MakeTranslation(
Point4D(xPos, yPos, zPos, 0));
702 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"scale")
704 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
710 yStr.GetValue(&yPos);
711 zStr.GetValue(&zPos);
712 trans-> MakeScale(xPos, yPos, zPos);
719 else if (
TempCString(childNodes->item(i)->getNodeName()) ==
"rotation")
721 DOMNamedNodeMap* attrPt = childNodes->item(i)->getAttributes();
729 else if (axisStr ==
"y")
731 else if (axisStr ==
"z")
740 else if (
TempCString(listNode->item(1)->getNodeName()) ==
"joint")
742 list<VART::Dof*> listOfDofs;
743 list<VART::Dof*>::const_iterator iter;
744 DOMNamedNodeMap* attrNode = listNode->item(1)->getAttributes();
748 if (name ==
"biaxial")
751 DOMNamedNodeMap* attrAux;
755 loadDofs (listNode->item(1), &listOfDofs);
756 for (iter = listOfDofs.begin(); iter!= listOfDofs.end(); ++iter)
758 attrAux = listNode->item(1)->getAttributes();
764 else if (name ==
"polyaxial")
767 DOMNamedNodeMap* attrAux;
771 loadDofs (listNode->item(1), &listOfDofs);
772 for (iter = listOfDofs.begin(); iter!=listOfDofs.end(); ++iter)
774 attrAux = listNode->item(1)->getAttributes();
780 else if (name ==
"uniaxial")
783 DOMNamedNodeMap* attrAux;
787 attrAux = listNode->item(1)->getAttributes();
790 loadDofs (listNode->item(1), &listOfDofs);
791 for (iter = listOfDofs.begin(); iter!=listOfDofs.end(); ++iter)
801 while (currentChild < numChildren)
804 SceneNode* snPtr = LoadSceneNode(listNode->item(currentChild), basePath);
814 list<VART::Dof*>::iterator iter;
817 istringstream stream;
821 float minValue, maxValue, resValue;
824 DOMNodeList* dof = node->getChildNodes();
825 DOMNamedNodeMap* attrAux;
828 for (i = 0; i< dof->getLength(); i++)
830 if (
TempCString(dof->item(i)->getNodeName()) ==
"dof")
833 DOMNodeList* dofAux = dof->item(i)->getChildNodes();
837 for (j = 0; j <dofAux->getLength(); j++ )
839 if (
TempCString(dofAux->item(j)->getNodeName()) ==
"position")
841 DOMNamedNodeMap* attrPos = dofAux->item(j)->getAttributes();
847 yStr.GetValue(&yPos);
848 zStr.GetValue(&zPos);
849 position.
SetXYZW(xPos,yPos,zPos,1);
852 else if (
TempCString(dofAux->item(j)->getNodeName()) ==
"axis")
854 DOMNamedNodeMap* attrAxis = dofAux->item(j)->getAttributes();
860 yStr.GetValue(&yPos);
861 zStr.GetValue(&zPos);
862 axis.
SetXYZW(xPos, yPos, zPos, 0);
865 else if (
TempCString(dofAux->item(j)->getNodeName()) ==
"range")
867 DOMNamedNodeMap *attrRange = dofAux->item(j)->getAttributes();
873 maxStr.GetValue(&maxValue);
874 resStr.GetValue(&resValue);
877 d->
Set(axis, position, minValue, maxValue);
878 attrAux = dof->item(i)->getAttributes();
A joint with one rotational degrees of freedom.
Base class for objects that compose a scene graph.
Header file for V-ART class "Dof".
void SetColor(const Color &c)
Points and vectors using homogeneous coordinates.
MeshObject * LoadMeshFromFile(std::string filen, std::string type, std::string meshName)
Load MeshObjects from file.
void SetRadius(float r)
Sets the value of top and bottom radius.
void SetMaterial(const Material &mat)
Material assignment.
void Normalize()
Normalizes the point/vector.
const std::string & GetDescription() const
Returns a copy of the object's description.
bool LoadFromFile(const std::string &fileName)
Parses the xml file. If it doesn't have errors, load scene.
RGBA color representation.
void SetLocation(const Point4D &newLocation)
Sets the location of the light.
Header file for V-ART class "File".
void SetDescription(const std::string &desc)
void AddDof(Dof *dof)
Adds a Dof.
static std::string GetPathFromString(const std::string &fileName)
Header file for V-ART class "UniaxialJoint".
Header file for V-ART class "Sphere".
void loadDofs(XERCES_CPP_NAMESPACE::DOMNode *node, std::list< Dof * > *dofs)
Load the dofs of the joint.
Header file for V-ART class "BiaxialJoint".
void SetIntensity(float i)
Header file for V-ART class "PolyaxialJoint".
A joint with two rotational degrees of freedom.
Class for auto conversion from C strings to Xerces strings.
void SetAmbientIntensity(float ai)
void SetDescription(const std::string &desc)
Changes the object's description.
Material properties for graphical objects.
void Turn(bool on_off)
Turns a light on or off.
A joint with three rotational degrees of freedom.
SceneNode * LoadSceneNode(XERCES_CPP_NAMESPACE::DOMNode *sceneList, const std::string &basePath)
Load the nodes (transformations, geometry, etc.) of the scene.
bool GetValue(int *valuePtr) const
bool LoadScene(const std::string &basePath)
Load the scene based in xml archieve.
Class for auto conversion from Xerces strings to C strings.
void SetMaterial(const Material &mat)
Material assignment.
Header file for V-ART class "Cylinder".
void SetXYZW(double x, double y, double z, double w)
Header file for V-ART class "MeshObject".
virtual void AddDof(Dof *dof)
Add a DOF to the joint.
static bool ReadFromOBJ(const std::string &filename, std::list< MeshObject * > *resultPtr)
Read MeshObjects from a Wavefront OBJ file.
Degree Of Freedom - basic component of a Joint.
void Set(const Point4D &vec, const Point4D &pos, float min, float max)
Initializes a DOF previouly created with default constructor.
void AddDof(Dof *dof)
Add a DOF to the joint.
Header file for V-ART class "XmlScene".
Graphical object made of polygon meshes.
void AddChild(SceneNode &child)
Add a child at the end of child list.
Represents a light source.