From: Markus R. <rol...@us...> - 2006-02-22 19:42:16
|
Update of /cvsroot/simspark/simspark/spark/plugin/rosimporter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24229 Modified Files: roselements.cpp roselements.h rosimporter.cpp rosimporter.h Log Message: - implemented parsing of graphical representation within complex shapes, still needs translation into our own TrimMesh class Index: roselements.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/roselements.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** roselements.h 19 Feb 2006 14:16:58 -0000 1.3 --- roselements.h 22 Feb 2006 19:42:07 -0000 1.4 *************** *** 66,69 **** --- 66,72 ---- #define RA_INSTANCENAME "instanceName" + // ComplexShape + #define RA_VERTEXLIST "vertexList" + class RosElements { *************** *** 92,95 **** --- 95,100 ---- RE_VERTEXLIST, RE_VERTEX, + RE_GRAPHICALREPRESENTATION, + RE_POLYGON, RE_MACRO, Index: roselements.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/roselements.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** roselements.cpp 19 Feb 2006 14:16:58 -0000 1.3 --- roselements.cpp 22 Feb 2006 19:42:07 -0000 1.4 *************** *** 66,69 **** --- 66,71 ---- ROS_DEFINE_ELEMENT(RE_VERTEXLIST,"VertexList"); ROS_DEFINE_ELEMENT(RE_VERTEX,"Vertex"); + ROS_DEFINE_ELEMENT(RE_GRAPHICALREPRESENTATION, "GraphicalRepresentation"); + ROS_DEFINE_ELEMENT(RE_POLYGON,"Polygon"); ROS_DEFINE_ELEMENT(RE_MACRO, "Macro"); Index: rosimporter.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** rosimporter.cpp 19 Feb 2006 15:04:01 -0000 1.7 --- rosimporter.cpp 22 Feb 2006 19:42:07 -0000 1.8 *************** *** 32,35 **** --- 32,36 ---- #include <oxygen/physicsserver/body.h> #include <oxygen/physicsserver/hingejoint.h> + #include <oxygen/geometryserver/trimesh.h> #include <kerosin/openglserver/glbase.h> #include <kerosin/materialserver/materialserver.h> *************** *** 87,91 **** } ! bool RosImporter::ImportScene(const std::string& fileName, shared_ptr<BaseNode> parent, shared_ptr<ParameterList> parameter) --- 88,92 ---- } ! bool RosImporter::ImportScene(const string& fileName, shared_ptr<BaseNode> parent, shared_ptr<ParameterList> parameter) *************** *** 111,115 **** } ! bool RosImporter::ParseScene(const std::string& scene, shared_ptr<BaseNode> parent, shared_ptr<ParameterList> parameter) --- 112,116 ---- } ! bool RosImporter::ParseScene(const string& scene, shared_ptr<BaseNode> parent, shared_ptr<ParameterList> parameter) *************** *** 226,231 **** } ! bool RosImporter::ReadAttribute(TiXmlElement* element, const std::string& attribute, ! std::string& value, bool succeedIfMissing) { if (element == 0) --- 227,232 ---- } ! bool RosImporter::ReadAttribute(TiXmlElement* element, const string& attribute, ! string& value, bool succeedIfMissing) { if (element == 0) *************** *** 250,254 **** } ! bool RosImporter::ReadAttribute(TiXmlElement* element, const std::string& attribute, double& value, bool succeedIfMissing) { --- 251,255 ---- } ! bool RosImporter::ReadAttribute(TiXmlElement* element, const string& attribute, double& value, bool succeedIfMissing) { *************** *** 1185,1190 **** --- 1186,1314 ---- transform->SetName(name); + // TODO: read <Appearance> tag, does ist always 'ref' to the + // surrounding compley shape? + + TriMesh mesh; + if (! ReadGraphicalRep(parent, element, mesh)) + { + return false; + } + GetLog()->Debug() << "(RosImporter) read complex shape " << name << "\n"; return true; } + + bool RosImporter::ReadGraphicalRep(shared_ptr<BaseNode> parent, TiXmlElement* element, TriMesh& mesh) + { + TiXmlElement* graphRepElem = GetFirstChild(element, RosElements::RE_GRAPHICALREPRESENTATION); + if (graphRepElem == 0) + { + string name = S_UNNAMED; + ReadAttribute(element, RA_NAME, name, true); + + GetLog()->Error() << "(RosImporter) ERROR: missing graphical representation in " + << GetXMLPath(element) << " name " << name << " \n"; + + return false; + } + + string vertexListName; + if (! ReadAttribute(graphRepElem, RA_VERTEXLIST, vertexListName)) + { + return false; + } + + TVertexListMap::const_iterator iter = mVertexListMap.find(vertexListName); + if (iter == mVertexListMap.end()) + { + string name; + ReadAttribute(element, RA_NAME, name, true); + + GetLog()->Error() << "(RosImporter) ERROR: undefined vertex list " << vertexListName << " in " + << GetXMLPath(element) << " name " << name << " \n"; + + return false; + } + + const TVertexList& vertexList = (*iter).second; + + TComplexGeomList geomList; + if (! ReadComplexElements(graphRepElem, geomList)) + { + return false; + } + + return true; + } + + bool RosImporter::ReadComplexElements(TiXmlElement* element, TComplexGeomList& geomList) + { + // TODO: read TriangleStrips + + for ( + TiXmlNode* node = GetFirstChild(element, RosElements::RE_POLYGON); + node != 0; + node = element->IterateChildren(node) + ) + { + TiXmlElement* element = static_cast<TiXmlElement*>(node); + + RosElements::ERosElement type = GetType(element); + switch (type) + { + default: + GetLog()->Error() << "(RosImporter::ReadComplexElements) ERROR: skipping unknown element " + << GetXMLPath(element) << "\n"; + break; + + case RosElements::RE_POLYGON: + ComplexGeom geom(CG_Polygon); + if (! ReadComplexGeom(element, geom)) + { + return false; + } + + GetLog()->Debug() << "(RosImporter) read polygon with " << geom.vertices.size() << " vertices\n"; + geomList.push_back(geom); + break; + } + } + + return true; + } + + bool RosImporter::ReadComplexGeom(TiXmlElement* element, ComplexGeom& geom) + { + for ( + TiXmlNode* node = GetFirstChild(element, RosElements::RE_VERTEX); + node != 0; + node = element->IterateChildren(node) + ) + { + TiXmlElement* element = static_cast<TiXmlElement*>(node); + + RosElements::ERosElement type = GetType(element); + switch (type) + { + default: + GetLog()->Error() << "(RosImporter::ReadComplexGeom) ERROR: skipping unknown element " + << GetXMLPath(element) << "\n"; + break; + + case RosElements::RE_VERTEX: + { + string ref; + if (! ReadAttribute(element, RA_REF, ref)) + { + return false; + } + + geom.vertices.push_back(ref); + break; + } + } + } + + return true; + } Index: rosimporter.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** rosimporter.h 19 Feb 2006 15:04:01 -0000 1.6 --- rosimporter.h 22 Feb 2006 19:42:07 -0000 1.7 *************** *** 34,37 **** --- 34,38 ---- class ContactJointHandler; class Body; + class TriMesh; } *************** *** 100,103 **** --- 101,130 ---- typedef std::map<std::string, TVertexList> TVertexListMap; + /** define a list of string references into a vertex list */ + typedef std::list<std::string> TVertexRefList; + + /** the possible types of complex geoms that make up a + ComplexShape + */ + enum EComplexGeom + { + CG_None = 0, + CG_Polygon, + CG_TriangleStrip + }; + + struct ComplexGeom + { + public: + EComplexGeom type; + TVertexRefList vertices; + + public: + ComplexGeom(EComplexGeom t = CG_None) : type(t) {} + }; + + /** defines a list of complex geoms */ + typedef std::list<ComplexGeom> TComplexGeomList; + public: RosImporter(); *************** *** 174,178 **** bool ReadVertexList(TiXmlElement* element); bool ReadComplexShape(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); ! protected: --- 201,207 ---- bool ReadVertexList(TiXmlElement* element); bool ReadComplexShape(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, ENodeContext context); ! bool ReadGraphicalRep(boost::shared_ptr<oxygen::BaseNode> parent, TiXmlElement* element, oxygen::TriMesh& mesh); ! bool ReadComplexElements(TiXmlElement* element, TComplexGeomList& geomList); ! bool ReadComplexGeom(TiXmlElement* element, ComplexGeom& geom); protected: |