From: Markus R. <rol...@us...> - 2006-02-19 14:17:07
|
Update of /cvsroot/simspark/simspark/spark/plugin/rosimporter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20791 Modified Files: roselements.cpp roselements.h rosimporter.cpp rosimporter.h Log Message: - implemented parsing of compound node - initial parsing of comples shapes - implemented registry of vertex lists - presence of name attribute is not required - made some error messages more descriptive Index: roselements.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/roselements.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** roselements.h 19 Feb 2006 13:16:18 -0000 1.2 --- roselements.h 19 Feb 2006 14:16:58 -0000 1.3 *************** *** 87,90 **** --- 87,96 ---- RE_CAPPEDCYLINDER, + RE_COMPOUND, + + RE_COMPLEXSHAPE, + RE_VERTEXLIST, + RE_VERTEX, + RE_MACRO, RE_USE, Index: roselements.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/roselements.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** roselements.cpp 19 Feb 2006 13:19:18 -0000 1.2 --- roselements.cpp 19 Feb 2006 14:16:58 -0000 1.3 *************** *** 53,56 **** --- 53,57 ---- ROS_DEFINE_ELEMENT(RE_ELEMENTS,"Elements"); ROS_DEFINE_ELEMENT(RE_MOVABLE,"Movable"); + ROS_DEFINE_ELEMENT(RE_COMPOUND,"Compound"); ROS_DEFINE_ELEMENT(RE_TRANSLATION, "Translation"); *************** *** 62,65 **** --- 63,70 ---- ROS_DEFINE_ELEMENT(RE_CAPPEDCYLINDER,"CappedCylinder"); + ROS_DEFINE_ELEMENT(RE_COMPLEXSHAPE,"ComplexShape"); + ROS_DEFINE_ELEMENT(RE_VERTEXLIST,"VertexList"); + ROS_DEFINE_ELEMENT(RE_VERTEX,"Vertex"); + ROS_DEFINE_ELEMENT(RE_MACRO, "Macro"); ROS_DEFINE_ELEMENT(RE_USE, "Use"); Index: rosimporter.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** rosimporter.cpp 19 Feb 2006 13:19:18 -0000 1.5 --- rosimporter.cpp 19 Feb 2006 14:16:58 -0000 1.6 *************** *** 53,56 **** --- 53,57 ---- static const string S_VISUAL("visual_"); static const string S_MACRO("macro_"); + static const string S_UNNAMED("<unnamed>"); RosImporter::TMacroMap RosImporter::mMacroMap; *************** *** 118,121 **** --- 119,142 ---- } + bool RosImporter::IgnoreNode(const TiXmlNode* node) const + { + if (node == 0) + { + return true; + } + + switch(node->Type()) + { + case TiXmlNode::ELEMENT: + return false; + + default: + /** ignore declarations, comments and other + unknown node types + */ + return true; + } + } + bool RosImporter::ParseScene(const char* scene, int size, shared_ptr<BaseNode> parent, *************** *** 154,174 **** ) { ! if (node == 0) { continue; } - switch(node->Type()) - { - case TiXmlNode::ELEMENT: - break; - - default: - /** ignore declarations, comments and other - unknown node types - */ - continue; - } - TiXmlElement* element = static_cast<TiXmlElement*>(node); bool ok = true; --- 175,183 ---- ) { ! if (IgnoreNode(node)) { continue; } TiXmlElement* element = static_cast<TiXmlElement*>(node); bool ok = true; *************** *** 193,196 **** --- 202,209 ---- ok = ReadMacro(parent, element); break; + + case RosElements::RE_VERTEXLIST: + ok = ReadVertexList(element); + break; } *************** *** 217,222 **** if (! succeedIfMissing) { GetLog()->Error() << "(RosImporter) ERROR: missing string attribute " << attribute << " in " ! << GetXMLPath(element) << "\n"; return false; } --- 230,238 ---- if (! succeedIfMissing) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: missing string attribute " << attribute << " in " ! << GetXMLPath(element) << " name " << name << " \n"; return false; } *************** *** 238,243 **** if (! succeedIfMissing) { GetLog()->Error() << "(RosImporter) ERROR: missing float attribute " << attribute << " in " ! << GetXMLPath(element) << "\n"; return false; } --- 254,262 ---- if (! succeedIfMissing) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: missing float attribute " << attribute << " in " ! << GetXMLPath(element) << " name " << name << "\n"; return false; } *************** *** 257,262 **** ) { GetLog()->Error() << "(RosImporter) ERROR: missing color attributes in " ! << GetXMLPath(element) << "\n"; return false; } --- 276,284 ---- ) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: missing color attributes in " ! << GetXMLPath(element) << " name " << name << "\n"; return false; } *************** *** 282,287 **** if (! succeedIfMissing) { GetLog()->Error() << "(RosImporter) ERROR: invalid or missing vector attributes in " ! << GetXMLPath(element) << "\n"; return false; } --- 304,312 ---- if (! succeedIfMissing) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: invalid or missing vector attributes in " ! << GetXMLPath(element) << " name " << name << "\n"; return false; } *************** *** 396,416 **** ) { ! if (node == 0) { continue; } - switch(node->Type()) - { - case TiXmlNode::ELEMENT: - break; - - default: - /** ignore declarations, comments and other - unknown node types - */ - continue; - } - TiXmlElement* childElement = static_cast<TiXmlElement*>(node); if (! ReadElements(parent, childElement, context)) --- 421,429 ---- ) { ! if (IgnoreNode(node)) { continue; } TiXmlElement* childElement = static_cast<TiXmlElement*>(node); if (! ReadElements(parent, childElement, context)) *************** *** 423,426 **** --- 436,461 ---- } + bool RosImporter::ReadCompound(shared_ptr<BaseNode> parent, TiXmlElement* element, ENodeContext context) + { + string name; + Trans trans; + + if ( + (! ReadAttribute(element, RA_NAME, name, true)) || + (! ReadTrans(element, trans)) + ) + { + return false; + } + + // transform + shared_ptr<Transform> transform = CreateTransform(parent, trans); + transform->SetName(name); + + GetLog()->Debug() << "(RosImporter) read compound node " << name << "\n"; + + return ReadChildElements(parent, element, context); + } + bool RosImporter::ReadElements(shared_ptr<BaseNode> parent, TiXmlElement* element, ENodeContext context) { *************** *** 455,458 **** --- 490,497 ---- break; + case RosElements::RE_COMPOUND: + ok = ReadCompound(parent,element,context); + break; + case RosElements::RE_MOVABLE: ok = ReadMovable(parent,element,context); *************** *** 482,485 **** --- 521,528 ---- ok = ReadUse(parent,element,context); break; + + case RosElements::RE_COMPLEXSHAPE: + ok = ReadComplexShape(parent,element,context); + break; } *************** *** 641,656 **** if (physElem == 0) { GetLog()->Error() << "(RosImporter) ERROR: missing physical attributes in " ! << GetXMLPath(element) << "\n"; return false; } - // we must have a mass TiXmlElement* massElem = GetFirstChild(physElem, RosElements::RE_MASS); if (massElem == 0) { GetLog()->Error() << "(RosImporter) ERROR: missing mass element in physical attributes in " ! << GetXMLPath(element) << "\n"; return false; } --- 684,704 ---- if (physElem == 0) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: missing physical attributes in " ! << GetXMLPath(element) << " name " << name << "\n"; return false; } // we must have a mass TiXmlElement* massElem = GetFirstChild(physElem, RosElements::RE_MASS); if (massElem == 0) { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + GetLog()->Error() << "(RosImporter) ERROR: missing mass element in physical attributes in " ! << GetXMLPath(element) << "name " << name << " \n"; return false; } *************** *** 689,693 **** if ( ! (! ReadAttribute(element, RA_NAME, name)) || (! ReadAttribute(element, RA_RADIUS, radius)) || (! ReadAttribute(element, RA_HEIGHT, height)) || --- 737,741 ---- if ( ! (! ReadAttribute(element, RA_NAME, name, true)) || (! ReadAttribute(element, RA_RADIUS, radius)) || (! ReadAttribute(element, RA_HEIGHT, height)) || *************** *** 759,763 **** if ( ! (! ReadAttribute(element, RA_NAME, name)) || (! ReadAttribute(element, RA_RADIUS, radius)) || (! ReadTrans(element, trans)) || --- 807,811 ---- if ( ! (! ReadAttribute(element, RA_NAME, name, true)) || (! ReadAttribute(element, RA_RADIUS, radius)) || (! ReadTrans(element, trans)) || *************** *** 829,833 **** if ( ! (! ReadAttribute(element, RA_NAME, name)) || (! ReadAttribute(element, RA_LENGTH, length)) || (! ReadAttribute(element, RA_WIDTH, width)) || --- 877,881 ---- if ( ! (! ReadAttribute(element, RA_NAME, name, true)) || (! ReadAttribute(element, RA_LENGTH, length)) || (! ReadAttribute(element, RA_WIDTH, width)) || *************** *** 954,958 **** if ( ! (! ReadAttribute(element, RA_NAME, name)) || (! ReadAnchorPoint(element, anchor)) || (! ReadAxis(element, axis)) --- 1002,1006 ---- if ( ! (! ReadAttribute(element, RA_NAME, name, true)) || (! ReadAnchorPoint(element, anchor)) || (! ReadAxis(element, axis)) *************** *** 1053,1054 **** --- 1101,1197 ---- return ok; } + + bool RosImporter::ReadVertexList(TiXmlElement* element) + { + string listName; + if (! ReadAttribute(element, RA_NAME, listName)) + { + return false; + } + + mVertexListMap[listName] = TVertexList(); + + // work with a reference in to the map to avoid an expensive copy + TVertexList& vertices = mVertexListMap[listName]; + + for ( + TiXmlNode* node = GetFirstChild(element, RosElements::RE_VERTEX); + node != 0; + node = element->IterateChildren(node) + ) + { + if (IgnoreNode(node)) + { + continue; + } + + TiXmlElement* element = static_cast<TiXmlElement*>(node); + + RosElements::ERosElement type = GetType(element); + switch (type) + { + default: + GetLog()->Error() << "(RosImporter::ReadVertices) ERROR: skipping unknown element " + << GetXMLPath(element) << "\n"; + break; + + case RosElements::RE_VERTEX: + { + Vector3f vec; + string name; + + if ( + (! ReadAttribute(element, RA_NAME, name)) || + (! ReadVector(element, vec)) + ) + { + return false; + } + + vertices[name] = vec; + break; + } + } + } + + GetLog()->Debug() << "(RosImporter) read vertex list " << listName << "\n"; + return true; + } + + bool RosImporter::ReadComplexShape(shared_ptr<BaseNode> parent, TiXmlElement* element, ENodeContext context) + { + string name; + Trans trans; + Appearance appear; + Physical physical; + TVertexList vertices; + + if ( + (! ReadAttribute(element, RA_NAME, name, true)) || + (! ReadTrans(element, trans)) || + (! ReadAppearance(element, appear)) || + (! ReadPhysical(element, physical, context)) + ) + { + return false; + } + + // look for an inlined vertex list and parse it + TiXmlElement* vertListElem = + GetFirstChild(element, RosElements::RE_VERTEXLIST); + + if ( + (vertListElem != 0) && + (! ReadVertexList(vertListElem)) + ) + { + return false; + } + + shared_ptr<Transform> transform = CreateTransform(parent, trans); + transform->SetName(name); + + GetLog()->Debug() << "(RosImporter) read complex shape " << name << "\n"; + + return true; + } Index: rosimporter.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rosimporter.h 19 Feb 2006 13:19:18 -0000 1.4 --- rosimporter.h 19 Feb 2006 14:16:58 -0000 1.5 *************** *** 91,94 **** --- 91,102 ---- typedef std::map<std::string, boost::shared_ptr<TiXmlElement> > TMacroMap; + /** define a mapping from name to vertex name as defined within a + VertexList element + */ + typedef std::map<std::string, salt::Vector3f> TVertexList; + + /** define a mapping from name to vertex list name */ + typedef std::map<std::string, TVertexList> TVertexListMap; + public: RosImporter(); *************** *** 111,114 **** --- 119,123 ---- TiXmlElement* GetFirstChild(TiXmlNode* node, RosElements::ERosElement type); TiXmlElement* IterateChildren(TiXmlNode* node, RosElements::ERosElement type); + bool IgnoreNode(const TiXmlNode* node) const; RosElements::ERosElement GetType(const TiXmlElement* element) const; *************** *** 137,140 **** --- 146,150 ---- bool ReadElements(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); + bool ReadCompound(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); bool ReadMovable(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); *************** *** 159,162 **** --- 169,176 ---- bool ReadHinge(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); + bool ReadVertexList(TiXmlElement* element); + bool ReadComplexShape(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); + + protected: /** the last supplied fileName */ *************** *** 172,175 **** --- 186,192 ---- double mGlobalCFM; + /** the registry of vertex lists */ + TVertexListMap mVertexListMap; + /** the static macro registry is shared across RosImporter instances |