From e76f3ce1e3ec5dec289375371faf48a19abb8e1c Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Fri, 12 Jul 2024 08:21:52 -0700 Subject: [PATCH] Rename model to spec in xml_native_reader.cc. PiperOrigin-RevId: 651780148 Change-Id: I476c79af4b47bf763f1f3cb166d3f0897554a207 --- src/xml/xml_base.cc | 4 +- src/xml/xml_base.h | 2 +- src/xml/xml_native_reader.cc | 126 +++++++++++++++++------------------ src/xml/xml_urdf.cc | 34 +++++----- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/xml/xml_base.cc b/src/xml/xml_base.cc index 4d809581..0563d248 100644 --- a/src/xml/xml_base.cc +++ b/src/xml/xml_base.cc @@ -37,14 +37,14 @@ using tinyxml2::XMLElement; // base constructor mjXBase::mjXBase() { - model = NULL; + spec = NULL; } // set model field void mjXBase::SetModel(const mjSpec* _model) { - model = (mjSpec*)_model; + spec = (mjSpec*)_model; } diff --git a/src/xml/xml_base.h b/src/xml/xml_base.h index c9afec77..40df63b5 100644 --- a/src/xml/xml_base.h +++ b/src/xml/xml_base.h @@ -94,7 +94,7 @@ class mjXBase : public mjXUtil { static int ReadAlternative(tinyxml2::XMLElement* elem, mjsOrientation& alt); protected: - mjSpec* model; // internally-allocated model + mjSpec* spec; // internally-allocated model }; #endif // MUJOCO_SRC_XML_XML_BASE_H_ diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index fe89c151..bd7f2ca3 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -826,31 +826,31 @@ void mjXReader::Parse(XMLElement* root, const mjVFS* vfs) { // get model name string modelname; if (ReadAttrTxt(root, "model", modelname)) { - mjs_setString(model->modelname, modelname.c_str()); + mjs_setString(spec->modelname, modelname.c_str()); } // get comment if (root->FirstChild() && root->FirstChild()->ToComment()) { - mjs_setString(model->comment, root->FirstChild()->Value()); + mjs_setString(spec->comment, root->FirstChild()->Value()); } else { - mjs_setString(model->comment, ""); + mjs_setString(spec->comment, ""); } //------------------- parse MuJoCo sections embedded in all XML formats for (XMLElement* section = FirstChildElement(root, "compiler"); section; section = NextSiblingElement(section, "compiler")) { - Compiler(section, model); + Compiler(section, spec); } for (XMLElement* section = FirstChildElement(root, "option"); section; section = NextSiblingElement(section, "option")) { - Option(section, &model->option); + Option(section, &spec->option); } for (XMLElement* section = FirstChildElement(root, "size"); section; section = NextSiblingElement(section, "size")) { - Size(section, model); + Size(section, spec); } //------------------ parse MJCF-specific sections @@ -924,7 +924,7 @@ void mjXReader::Parse(XMLElement* root, const mjVFS* vfs) { for (XMLElement* section = FirstChildElement(root, "worldbody"); section; section = NextSiblingElement(section, "worldbody")) { - Body(section, mjs_findBody(model, "world"), nullptr); + Body(section, mjs_findBody(spec, "world"), nullptr); } } @@ -1278,14 +1278,14 @@ void mjXReader::Statistic(XMLElement* section) { string text; // read statistics - ReadAttr(section, "meaninertia", 1, &model->stat.meaninertia, text); - ReadAttr(section, "meanmass", 1, &model->stat.meanmass, text); - ReadAttr(section, "meansize", 1, &model->stat.meansize, text); - ReadAttr(section, "extent", 1, &model->stat.extent, text); - if (mjuu_defined(model->stat.extent) && model->stat.extent<=0) { + ReadAttr(section, "meaninertia", 1, &spec->stat.meaninertia, text); + ReadAttr(section, "meanmass", 1, &spec->stat.meanmass, text); + ReadAttr(section, "meansize", 1, &spec->stat.meansize, text); + ReadAttr(section, "extent", 1, &spec->stat.extent, text); + if (mjuu_defined(spec->stat.extent) && spec->stat.extent<=0) { throw mjXError(section, "extent must be strictly positive"); } - ReadAttr(section, "center", 3, model->stat.center, text); + ReadAttr(section, "center", 3, spec->stat.center, text); } @@ -1370,10 +1370,10 @@ void mjXReader::OneMesh(XMLElement* elem, mjsMesh* pmesh) { // read attributes if (ReadAttrTxt(elem, "name", name)) { - mjs_setString(pmesh->name, name.c_str()); + *pmesh->name = name; } if (ReadAttrTxt(elem, "content_type", content_type)) { - mjs_setString(pmesh->content_type, content_type.c_str()); + *pmesh->content_type = content_type; } auto file = ReadAttrFile(elem, "file", MeshDir()); if (file) { @@ -2480,7 +2480,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjsBody* pbody, mjsDefault* def) // make composite char error[200]; - bool res = comp.Make(model, pbody, error, 200); + bool res = comp.Make(spec, pbody, error, 200); // throw error if (!res) { @@ -2606,7 +2606,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* pbody) { // make flexcomp char error[200]; - bool res = fcomp.Make(model, pbody, error, 200); + bool res = fcomp.Make(spec, pbody, error, 200); // throw error if (!res) { @@ -2626,10 +2626,10 @@ void mjXReader::OnePlugin(XMLElement* elem, mjsPlugin* plugin) { mjs_setString(plugin->name, name.c_str()); mjs_setString(plugin->instance_name, instance_name.c_str()); if (instance_name.empty()) { - plugin->instance = mjs_addPlugin(model)->instance; + plugin->instance = mjs_addPlugin(spec)->instance; ReadPluginConfigs(elem, plugin); } else { - model->hasImplicitPluginElem = true; + spec->hasImplicitPluginElem = true; } } @@ -2651,12 +2651,12 @@ void mjXReader::Default(XMLElement* section, const mjsDefault* def) { } } if (def) { - def = mjs_addDefault(model, text.c_str(), def); + def = mjs_addDefault(spec, text.c_str(), def); if (!def) { throw mjXError(section, "repeated default class name"); } } else { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); if (!text.empty() && text != "main") { throw mjXError(section, "top-level default class 'main' cannot be renamed"); } @@ -2765,12 +2765,12 @@ void mjXReader::Extension(XMLElement* section) { XMLElement* child = FirstChildElement(elem); while (child) { if (std::string(child->Value())=="instance") { - if (model->hasImplicitPluginElem) { + if (spec->hasImplicitPluginElem) { throw mjXError( child, "explicit plugin instance must appear before implicit plugin elements"); } string name; - mjsPlugin* p = mjs_addPlugin(model); + mjsPlugin* p = mjs_addPlugin(spec); mjs_setString(p->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); ReadAttrTxt(child, "name", name, /* required = */ true); mjs_setString(p->name, name.c_str()); @@ -2788,7 +2788,7 @@ void mjXReader::Extension(XMLElement* section) { elem = NextSiblingElement(elem); } - mjs_setActivePlugins(model, &active_plugins); + mjs_setActivePlugins(spec, &active_plugins); } @@ -2809,7 +2809,7 @@ void mjXReader::Custom(XMLElement* section) { // numeric if (name=="numeric") { // create custom - mjsNumeric* pnum = mjs_addNumeric(model); + mjsNumeric* pnum = mjs_addNumeric(spec); // write error info mjs_setString(pnum->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); @@ -2840,7 +2840,7 @@ void mjXReader::Custom(XMLElement* section) { // text else if (name=="text") { // create custom - mjsText* pte = mjs_addText(model); + mjsText* pte = mjs_addText(spec); // write error info mjs_setString(pte->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); @@ -2860,7 +2860,7 @@ void mjXReader::Custom(XMLElement* section) { // tuple else if (name=="tuple") { // create custom - mjsTuple* ptu = mjs_addTuple(model); + mjsTuple* ptu = mjs_addTuple(spec); // write error info mjs_setString(ptu->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); @@ -2919,7 +2919,7 @@ void mjXReader::Custom(XMLElement* section) { void mjXReader::Visual(XMLElement* section) { string text, name; XMLElement* elem; - mjVisual* vis = &model->visual; + mjVisual* vis = &spec->visual; int n; // iterate over child elements @@ -3063,13 +3063,13 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // texture sub-element if (name=="texture") { // create texture - mjsTexture* ptex = mjs_addTexture(model); + mjsTexture* ptex = mjs_addTexture(spec); // write error info mjs_setString(ptex->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); @@ -3137,28 +3137,28 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) { // material sub-element else if (name=="material") { // create material and parse - mjsMaterial* pmat = mjs_addMaterial(model, def); + mjsMaterial* pmat = mjs_addMaterial(spec, def); OneMaterial(elem, pmat); } // mesh sub-element else if (name=="mesh") { // create mesh and parse - mjsMesh* pmesh = mjs_addMesh(model, def); + mjsMesh* pmesh = mjs_addMesh(spec, def); OneMesh(elem, pmesh); } // skin sub-element... deprecate ??? else if (name=="skin") { // create skin and parse - mjsSkin* pskin = mjs_addSkin(model); + mjsSkin* pskin = mjs_addSkin(spec); OneSkin(elem, pskin); } // hfield sub-element else if (name=="hfield") { // create hfield - mjsHField* phf = mjs_addHField(model); + mjsHField* phf = mjs_addHField(spec); // write error info mjs_setString(phf->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); @@ -3231,7 +3231,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) { } // store child spec in model - mjs_addSpec(model, child); + mjs_addSpec(spec, child); } // advance to next element @@ -3376,8 +3376,8 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { // read childdef mjsDefault* childdef = 0; if (ReadAttrTxt(elem, "childclass", text)) { - childdef = mjs_findDefault(model, text.c_str()); - mjs_findDefault(model, text.c_str()); + childdef = mjs_findDefault(spec, text.c_str()); + mjs_findDefault(spec, text.c_str()); if (!childdef) { throw mjXError(elem, "unknown default childclass"); } @@ -3420,13 +3420,13 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { alt.type = mjORIENTATION_EULER; mjuu_copyvec(alt.euler, euler, 3); double rotation[4] = {1, 0, 0, 0}; - mjs_resolveOrientation(rotation, model->degree, model->eulerseq, &alt); + mjs_resolveOrientation(rotation, spec->degree, spec->eulerseq, &alt); // read childdef mjsDefault* childdef = 0; if (ReadAttrTxt(elem, "childclass", text)) { - childdef = mjs_findDefault(model, text.c_str()); - mjs_findDefault(model, text.c_str()); + childdef = mjs_findDefault(spec, text.c_str()); + mjs_findDefault(spec, text.c_str()); if (!childdef) { throw mjXError(elem, "unknown default childclass"); } @@ -3451,7 +3451,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { alt.euler[0] = i*euler[0]; alt.euler[1] = i*euler[1]; alt.euler[2] = i*euler[2]; - mjs_resolveOrientation(quat, model->degree, model->eulerseq, &alt); + mjs_resolveOrientation(quat, spec->degree, spec->eulerseq, &alt); mjuu_setvec(pframe->quat, quat[0], quat[1], quat[2], quat[3]); // process suffix @@ -3463,12 +3463,12 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { // attach to parent if (mjs_attachFrame(pbody, pframe, /*prefix=*/"", suffix.c_str()) != 0) { - throw mjXError(elem, mjs_getError(model)); + throw mjXError(elem, mjs_getError(spec)); } } // delete subtree - mjs_detachBody(model, subtree); + mjs_detachBody(spec, subtree); } // body sub-element @@ -3476,8 +3476,8 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { // read childdef mjsDefault* childdef = 0; if (ReadAttrTxt(elem, "childclass", text)) { - childdef = mjs_findDefault(model, text.c_str()); - mjs_findDefault(model, text.c_str()); + childdef = mjs_findDefault(spec, text.c_str()); + mjs_findDefault(spec, text.c_str()); if (!childdef) { throw mjXError(elem, "unknown default childclass"); } @@ -3528,11 +3528,11 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { ReadAttrTxt(elem, "body", body_name); ReadAttrTxt(elem, "prefix", prefix); - mjsBody* child = mjs_findBody(model, (prefix+body_name).c_str()); + mjsBody* child = mjs_findBody(spec, (prefix+body_name).c_str()); mjsFrame* pframe = frame ? frame : mjs_addFrame(pbody, nullptr); if (!child) { - mjSpec* asset = mjs_findSpec(model, model_name.c_str()); + mjSpec* asset = mjs_findSpec(spec, model_name.c_str()); if (!asset) { throw mjXError(0, "could not find model '%s'", model_name.c_str()); } @@ -3542,7 +3542,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { } if (mjs_attachBody(pframe, child, prefix.c_str(), "") != 0) { mj_deleteSpec(asset); - throw mjXError(elem, mjs_getError(model)); + throw mjXError(elem, mjs_getError(spec)); } } else { // only set frame to existing body @@ -3576,19 +3576,19 @@ void mjXReader::Contact(XMLElement* section) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // geom pair to include if (name=="pair") { // create pair and parse - mjsPair* ppair = mjs_addPair(model, def); + mjsPair* ppair = mjs_addPair(spec, def); OnePair(elem, ppair); } // body pair to exclude else if (name=="exclude") { - mjsExclude* pexclude = mjs_addExclude(model); + mjsExclude* pexclude = mjs_addExclude(spec); string exname, exbody1, exbody2; // write error info @@ -3621,11 +3621,11 @@ void mjXReader::Equality(XMLElement* section) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // create equality constraint and parse - mjsEquality* pequality = mjs_addEquality(model, def); + mjsEquality* pequality = mjs_addEquality(spec, def); OneEquality(elem, pequality); // advance to next element @@ -3649,20 +3649,20 @@ void mjXReader::Deformable(XMLElement* section) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // flex sub-element if (name=="flex") { // create flex and parse - mjsFlex* pflex = mjs_addFlex(model); + mjsFlex* pflex = mjs_addFlex(spec); OneFlex(elem, pflex); } // skin sub-element else if (name=="skin") { // create skin and parse - mjsSkin* pskin = mjs_addSkin(model); + mjsSkin* pskin = mjs_addSkin(spec); OneSkin(elem, pskin); } @@ -3685,11 +3685,11 @@ void mjXReader::Tendon(XMLElement* section) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // create equality constraint and parse - mjsTendon* pten = mjs_addTendon(model, def); + mjsTendon* pten = mjs_addTendon(spec, def); OneTendon(elem, pten); // process wrap sub-elements @@ -3751,11 +3751,11 @@ void mjXReader::Actuator(XMLElement* section) { // get class if specified, otherwise use default0 mjsDefault* def = GetClass(elem); if (!def) { - def = mjs_getSpecDefault(model); + def = mjs_getSpecDefault(spec); } // create actuator and parse - mjsActuator* pact = mjs_addActuator(model, def); + mjsActuator* pact = mjs_addActuator(spec, def); OneActuator(elem, pact); // advance to next element @@ -3771,7 +3771,7 @@ void mjXReader::Sensor(XMLElement* section) { XMLElement* elem = FirstChildElement(section); while (elem) { // create sensor, get string type - mjsSensor* psen = mjs_addSensor(model); + mjsSensor* psen = mjs_addSensor(spec); string type = elem->Value(); string text, name, objname, refname; std::vector userdata; @@ -4111,7 +4111,7 @@ void mjXReader::Keyframe(XMLElement* section) { string text, name = ""; // add keyframe - mjsKey* pk = mjs_addKey(model); + mjsKey* pk = mjs_addKey(spec); // read name, time ReadAttrTxt(elem, "name", name); @@ -4167,7 +4167,7 @@ mjsDefault* mjXReader::GetClass(XMLElement* section) { mjsDefault* def = nullptr; if (ReadAttrTxt(section, "class", text)) { - def = mjs_findDefault(model, text.c_str()); + def = mjs_findDefault(spec, text.c_str()); if (!def) { throw mjXError( section, diff --git a/src/xml/xml_urdf.cc b/src/xml/xml_urdf.cc index 4b2317c1..b623f79c 100644 --- a/src/xml/xml_urdf.cc +++ b/src/xml/xml_urdf.cc @@ -62,7 +62,7 @@ mjXURDF::~mjXURDF() { // clear internal variables void mjXURDF::Clear(void) { - model = 0; + spec = 0; urName.clear(); urParent.clear(); @@ -96,25 +96,25 @@ void mjXURDF::Parse( if (mjc) { XMLElement *section; if ((section = FindSubElem(mjc, "compiler"))) { - mjXReader::Compiler(section, model); + mjXReader::Compiler(section, spec); } if ((section = FindSubElem(mjc, "option"))) { - mjXReader::Option(section, &model->option); + mjXReader::Option(section, &spec->option); } if ((section = FindSubElem(mjc, "size"))) { - mjXReader::Size(section, model); + mjXReader::Size(section, spec); } } // enforce required compiler defaults for URDF - model->degree = false; + spec->degree = false; // get model name std::string modelname; if (ReadAttrTxt(root, "name", modelname)) { - mjs_setString(model->modelname, modelname.c_str()); + mjs_setString(spec->modelname, modelname.c_str()); } // find and register all materials @@ -208,7 +208,7 @@ void mjXURDF::Parse( // override the pose for the base link and add a free joint for (int i = 0; i < (int)urName.size(); i++) { if (urParent[i] < 0) { - mjsBody* world = mjs_findBody(model, "world"); + mjsBody* world = mjs_findBody(spec, "world"); mjsBody* pbody = mjs_findChild(world, urName[i].c_str()); mjuu_copyvec(pbody->pos, pos, 3); mjuu_copyvec(pbody->quat, quat, 4); @@ -234,7 +234,7 @@ void mjXURDF::Body(XMLElement* body_elem) { // get body name and pointer to mjsBody ReadAttrTxt(body_elem, "name", name, true); name = GetPrefixedName(name); - world = mjs_findBody(model, "world"); + world = mjs_findBody(spec, "world"); pbody = mjs_findChild(world, name.c_str()); if (!pbody) { throw mjXError(body_elem, "URDF body not found"); // SHOULD NOT OCCUR @@ -316,7 +316,7 @@ void mjXURDF::Body(XMLElement* body_elem) { } } // create geom if not discarded - if (!model->discardvisual) { + if (!spec->discardvisual) { pgeom = Geom(elem, pbody, false); // save color @@ -392,7 +392,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) { elem = FindSubElem(joint_elem, "parent", true); ReadAttrTxt(elem, "link", name, true); name = GetPrefixedName(name); - world = mjs_findBody(model, "world"); + world = mjs_findBody(spec, "world"); parent = mjs_findChild(world, name.c_str()); if (!parent) { // SHOULD NOT OCCUR throw mjXError(elem, "invalid parent name in URDF joint definition"); @@ -402,7 +402,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) { elem = FindSubElem(joint_elem, "child", true); ReadAttrTxt(elem, "link", name, true); name = GetPrefixedName(name); - world = mjs_findBody(model, "world"); + world = mjs_findBody(spec, "world"); pbody = mjs_findChild(world, name.c_str()); if (!pbody) { // SHOULD NOT OCCUR throw mjXError(elem, "invalid child name in URDF joint definition"); @@ -583,7 +583,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) { .value_or(default_meshscale); // strip file name if necessary - if (model->strippath) { + if (spec->strippath) { meshfile = mjuu_strippath(meshfile); } @@ -592,19 +592,19 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) { meshname = mjuu_stripext(meshname); // look for existing mesh - mjsMesh* mesh = mjs_findMesh(model, meshname.c_str()); + mjsMesh* mesh = mjs_findMesh(spec, meshname.c_str()); mjsMesh* pmesh = 0; // does not exist: create if (!mesh) { - pmesh = mjs_addMesh(model, 0); + pmesh = mjs_addMesh(spec, 0); } // exists with different scale: append name with '1', create else if (mesh->scale[0]!=meshscale[0] || mesh->scale[1]!=meshscale[1] || mesh->scale[2]!=meshscale[2]) { - pmesh = mjs_addMesh(model, 0); + pmesh = mjs_addMesh(spec, 0); meshname = meshname + "1"; } @@ -703,14 +703,14 @@ void mjXURDF::AddToTree(int n) { // get pointer to parent in mjCModel tree mjsBody *parent = 0, *child = 0, *world = 0; if (urParent[n]>=0) { - world = mjs_findBody(model, "world"); + world = mjs_findBody(spec, "world"); parent = mjs_findChild(world, urName[urParent[n]].c_str()); if (!parent) throw mjXError(0, "URDF body parent should already be in tree: %s", urName[urParent[n]].c_str()); // SHOULD NOT OCCUR } else { - parent = mjs_findBody(model, "world"); + parent = mjs_findBody(spec, "world"); } // add this body