From 0e7e299bf67b8a748c3377001bc2ded3499db0c4 Mon Sep 17 00:00:00 2001 From: Nimrod Gileadi Date: Thu, 23 Mar 2023 07:21:46 -0700 Subject: [PATCH] Declare loop variables inside for loop in C++ files. PiperOrigin-RevId: 518852339 Change-Id: I0174d873d89e48f11b816d337728f213c2798248 --- simulate/simulate.cc | 86 +++---- src/user/user_composite.cc | 30 +-- src/user/user_mesh.cc | 130 +++++------ src/user/user_model.cc | 318 ++++++++++++-------------- src/user/user_objects.cc | 149 ++++++------ src/user/user_util.cc | 5 +- src/xml/xml_native_reader.cc | 38 ++- src/xml/xml_native_writer.cc | 38 ++- src/xml/xml_urdf.cc | 4 +- src/xml/xml_util.cc | 21 +- test/engine/engine_util_solve_test.cc | 3 +- 11 files changed, 375 insertions(+), 447 deletions(-) diff --git a/simulate/simulate.cc b/simulate/simulate.cc index 63431bb2..b6992a85 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -139,8 +139,6 @@ const char help_title[] = // init profiler figures void profilerinit(mj::Simulate* sim) { - int i, n; - // set figures to default mjv_defaultFigure(&sim->figconstraint); mjv_defaultFigure(&sim->figcost); @@ -225,8 +223,8 @@ void profilerinit(mj::Simulate* sim) { sim->figtimer.range[1][1] = 0.4f; // init x axis on history figures (do not show yet) - for (n=0; n<6; n++) - for (i=0; ifigtimer.linedata[n][2*i] = -i; sim->figsize.linedata[n][2*i] = -i; } @@ -234,11 +232,9 @@ void profilerinit(mj::Simulate* sim) { // update profiler figures void profilerupdate(mj::Simulate* sim) { - int i, n; - // update constraint figure sim->figconstraint.linepnt[0] = mjMIN(mjMIN(sim->d->solver_iter, mjNSOLVER), mjMAXLINEPNT); - for (i=1; i<5; i++) { + for (int i=1; i<5; i++) { sim->figconstraint.linepnt[i] = sim->figconstraint.linepnt[0]; } if (sim->m->opt.solver==mjSOL_PGS) { @@ -248,7 +244,7 @@ void profilerupdate(mj::Simulate* sim) { if (sim->m->opt.solver==mjSOL_CG) { sim->figconstraint.linepnt[4] = 0; } - for (i=0; ifigconstraint.linepnt[0]; i++) { + for (int i=0; ifigconstraint.linepnt[0]; i++) { // x sim->figconstraint.linedata[0][2*i] = i; sim->figconstraint.linedata[1][2*i] = i; @@ -266,7 +262,7 @@ void profilerupdate(mj::Simulate* sim) { // update cost figure sim->figcost.linepnt[0] = mjMIN(mjMIN(sim->d->solver_iter, mjNSOLVER), mjMAXLINEPNT); - for (i=1; i<3; i++) { + for (int i=1; i<3; i++) { sim->figcost.linepnt[i] = sim->figcost.linepnt[0]; } if (sim->m->opt.solver==mjSOL_PGS) { @@ -274,7 +270,7 @@ void profilerupdate(mj::Simulate* sim) { sim->figcost.linepnt[2] = 0; } - for (i=0; ifigcost.linepnt[0]; i++) { + for (int i=0; ifigcost.linepnt[0]; i++) { // x sim->figcost.linedata[0][2*i] = i; sim->figcost.linedata[1][2*i] = i; @@ -306,9 +302,9 @@ void profilerupdate(mj::Simulate* sim) { // update figtimer int pnt = mjMIN(201, sim->figtimer.linepnt[0]+1); - for (n=0; n<5; n++) { + for (int n=0; n<5; n++) { // shift data - for (i=pnt-1; i>0; i--) { + for (int i=pnt-1; i>0; i--) { sim->figtimer.linedata[n][2*i+1] = sim->figtimer.linedata[n][2*i-1]; } @@ -329,9 +325,9 @@ void profilerupdate(mj::Simulate* sim) { // update figsize pnt = mjMIN(201, sim->figsize.linepnt[0]+1); - for (n=0; n<6; n++) { + for (int n=0; n<6; n++) { // shift data - for (i=pnt-1; i>0; i--) { + for (int i=pnt-1; i>0; i--) { sim->figsize.linedata[n][2*i+1] = sim->figsize.linedata[n][2*i-1]; } @@ -542,7 +538,6 @@ void watch(mj::Simulate* sim) { // make physics section of UI void makephysics(mj::Simulate* sim, int oldstate) { - int i; mjOption& opt = sim->m->opt; mjuiDef defPhysics[] = { @@ -591,13 +586,13 @@ void makephysics(mj::Simulate* sim, int oldstate) { {mjITEM_CHECKINT, "", 2, nullptr, ""}, {mjITEM_END} }; - for (i=0; idisable + i; mjui_add(&sim->ui0, defFlag); } mjui_add(&sim->ui0, defEnableFlags); - for (i=0; ienable + i; mjui_add(&sim->ui0, defFlag); @@ -611,8 +606,6 @@ void makephysics(mj::Simulate* sim, int oldstate) { // make rendering section of UI void makerendering(mj::Simulate* sim, int oldstate) { - int i, j; - mjuiDef defRendering[] = { { mjITEM_SECTION, @@ -665,7 +658,7 @@ void makerendering(mj::Simulate* sim, int oldstate) { }; // add model cameras, up to UI limit - for (i=0; im->ncam, mjMAXUIMULTI-2); i++) { + for (int i=0; im->ncam, mjMAXUIMULTI-2); i++) { // prepare name char camname[mjMAXUITEXT] = "\n"; if (sim->m->names[sim->m->name_camadr[i]]) { @@ -691,10 +684,10 @@ void makerendering(mj::Simulate* sim, int oldstate) { {mjITEM_CHECKBYTE, "", 2, nullptr, ""}, {mjITEM_END} }; - for (i=0; iui0, defTree); mjui_add(&sim->ui0, defOpenGL); - for (i=0; im->njnt && itemcntm->njnt && itemcntm->jnt_type[i]==mjJNT_HINGE || sim->m->jnt_type[i]==mjJNT_SLIDE)) { // skip if joint group is disabled if (!sim->vopt.jointgroup[mjMAX(0, mjMIN(mjNGROUP-1, sim->m->jnt_group[i]))]) { @@ -838,8 +830,6 @@ void makejoint(mj::Simulate* sim, int oldstate) { // make control section of UI void makecontrol(mj::Simulate* sim, int oldstate) { - int i; - mjuiDef defControl[] = { {mjITEM_SECTION, "Control", oldstate, nullptr, "AC"}, {mjITEM_BUTTON, "Clear all", 2}, @@ -856,7 +846,7 @@ void makecontrol(mj::Simulate* sim, int oldstate) { // add controls, exit if UI limit reached (Clear button already added) int itemcnt = 1; - for (i=0; im->nu && itemcntm->nu && itemcntvopt.actuatorgroup[mjMAX(0, mjMIN(mjNGROUP-1, sim->m->actuator_group[i]))]) { continue; @@ -886,11 +876,9 @@ void makecontrol(mj::Simulate* sim, int oldstate) { // make model-dependent UI sections void makesections(mj::Simulate* sim) { - int i; - // get section open-close state, UI 0 int oldstate0[NSECT0]; - for (i=0; iui0.nsect>i) { oldstate0[i] = sim->ui0.sect[i].state; @@ -899,7 +887,7 @@ void makesections(mj::Simulate* sim) { // get section open-close state, UI 1 int oldstate1[NSECT1]; - for (i=0; iui1.nsect>i) { oldstate1[i] = sim->ui1.sect[i].state; @@ -985,13 +973,11 @@ void copycamera(mj::Simulate* sim) { // update UI 0 when MuJoCo structures change (except for joint sliders) void updatesettings(mj::Simulate* sim) { - int i; - // physics flags - for (i=0; idisable[i] = ((sim->m->opt.disableflags & (1<enable[i] = ((sim->m->opt.enableflags & (1<(state->userdata); mjModel* m = sim->m; mjData* d = sim->d; - int i; char err[200]; // call UI 0 if event is directed to it @@ -1202,22 +1187,25 @@ void uiEvent(mjuiState* state) { case 5: // Adjust key case 6: // Load key - i = sim->key; + { + int i = sim->key; d->time = m->key_time[i]; - mju_copy(d->qpos, m->key_qpos+i*m->nq, m->nq); - mju_copy(d->qvel, m->key_qvel+i*m->nv, m->nv); - mju_copy(d->act, m->key_act+i*m->na, m->na); - mju_copy(d->mocap_pos, m->key_mpos+i*3*m->nmocap, 3*m->nmocap); - mju_copy(d->mocap_quat, m->key_mquat+i*4*m->nmocap, 4*m->nmocap); - mju_copy(d->ctrl, m->key_ctrl+i*m->nu, m->nu); + mju_copy(d->qpos, m->key_qpos + i * m->nq, m->nq); + mju_copy(d->qvel, m->key_qvel + i * m->nv, m->nv); + mju_copy(d->act, m->key_act + i * m->na, m->na); + mju_copy(d->mocap_pos, m->key_mpos + i * 3 * m->nmocap, 3 * m->nmocap); + mju_copy(d->mocap_quat, m->key_mquat + i * 4 * m->nmocap, + 4 * m->nmocap); + mju_copy(d->ctrl, m->key_ctrl + i * m->nu, m->nu); mj_forward(m, d); profilerupdate(sim); sensorupdate(sim); updatesettings(sim); - break; + } break; case 7: // Save key - i = sim->key; + { + int i = sim->key; m->key_time[i] = d->time; mju_copy(m->key_qpos+i*m->nq, d->qpos, m->nq); mju_copy(m->key_qvel+i*m->nv, d->qvel, m->nv); @@ -1225,7 +1213,7 @@ void uiEvent(mjuiState* state) { mju_copy(m->key_mpos+i*3*m->nmocap, d->mocap_pos, 3*m->nmocap); mju_copy(m->key_mquat+i*4*m->nmocap, d->mocap_quat, 4*m->nmocap); mju_copy(m->key_ctrl+i*m->nu, d->ctrl, m->nu); - break; + } break; } } @@ -1233,14 +1221,14 @@ void uiEvent(mjuiState* state) { else if (it && it->sectionid==SECT_PHYSICS) { // update disable flags in mjOption m->opt.disableflags = 0; - for (i=0; idisable[i]) { m->opt.disableflags |= (1<opt.enableflags = 0; - for (i=0; ienable[i]) { m->opt.enableflags |= (1<1) { tmpdim++; } @@ -149,7 +147,7 @@ void mjCComposite::SetDefault(void) { type==mjCOMPTYPE_LOOP || type==mjCOMPTYPE_CABLE || (type==mjCOMPTYPE_GRID && tmpdim==1)) { - for (i=0; iname = txt; // create bodies, geoms and joints: outside shell only - for (ix=0; ixvert.push_back(0); skin->vert.push_back(0); @@ -2248,12 +2243,11 @@ void mjCComposite::MakeSkin3Box(mjCSkin* skin, int c0, int c1, int side, // make one face of 3D skin, smooth void mjCComposite::MakeSkin3Smooth(mjCSkin* skin, int c0, int c1, int side, const std::map& vmap, const char* format) { - int i0, i1; char txt00[100], txt01[100], txt10[100], txt11[100]; // loop over bodies/vertices of specified face - for (i0=0; i0typeinertia), 3); @@ -438,7 +436,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { case mjGEOM_SPHERE: // find maximum distance geom->size[0] = 0; - for (i=0; isize[0] = mjMAX(geom->size[0], dst); @@ -450,7 +448,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { // find maximum distance in XY, separately in Z geom->size[0] = 0; geom->size[1] = 0; - for (i=0; itype==mjGEOM_CAPSULE) { geom->size[1] = 0; - for (i=0; i(new int[nvert]); auto redirect = std::unique_ptr(new int[nvert]); - for (i=0; i < nvert; i++) { + for (int i=0; i < nvert; i++) { index[i] = redirect[i] = i; } @@ -529,7 +526,7 @@ void mjCMesh::RemoveRepeated() { mjQUICKSORT(index.get(), nvert, sizeof(int), vertcompare, vert); // find repeated vertices, set redirect - for (i=1; i < nvert; i++) { + for (int i=1; i < nvert; i++) { if (vert[3*index[i]] == vert[3*index[i-1]] && vert[3*index[i]+1] == vert[3*index[i-1]+1] && vert[3*index[i]+2] == vert[3*index[i-1]+2]) { @@ -541,8 +538,8 @@ void mjCMesh::RemoveRepeated() { // compress vertices, change face data if (repeated) { // track redirections until non-redirected vertex, set - for (i=0; i=nvert) { throw mjCError(this, "vertex index out of range in %s (index = %d)", name.c_str(), i); } @@ -1023,7 +1018,7 @@ void mjCMesh::Process() { double a = _triangle(nrm, cen, vert+3*face[3*i], vert+3*face[3*i+1], vert+3*face[3*i+2]); // accumulate - for (j=0; j<3; j++) { + for (int j=0; j<3; j++) { facecen[j] += a*cen[j]; } area += a; @@ -1036,14 +1031,14 @@ void mjCMesh::Process() { } // finalize centroid of faces - for (j=0; j<3; j++) { + for (int j=0; j<3; j++) { facecen[j] /= area; } } // compute CoM and volume from pyramid volumes GetVolumeRef(type) = 0; - for (i=0; igeom.density*vol / (type==mjSHELL_MESH ? 12 : 20) * ( 2*(D[k[j][0]] * D[k[j][1]] + @@ -1153,7 +1148,7 @@ void mjCMesh::Process() { boxsz[2] = sqrt(6*(eigval[0]+eigval[1]-eigval[2])/mass)/2; // copy quat - for (j=0; j<4; j++) { + for (int j=0; j<4; j++) { GetQuatPtr(type)[j] = type == mjVOLUME_MESH ? quattmp[j] : GetQuatPtr(mjVOLUME_MESH)[j]; } @@ -1162,12 +1157,12 @@ void mjCMesh::Process() { double neg[4] = {quattmp[0], -quattmp[1], -quattmp[2], -quattmp[3]}; double mat[9]; mjuu_quat2mat(mat, neg); - for (i=0; i=0) { // search vert_globalid for match + int adr; for (adr=0; adrmjMINVAL) - for (j=0; j<3; j++) { + for (int j=0; j<3; j++) { normal[3*i+j] /= len; } else { normal[3*i] = normal[3*i+1] = 0; @@ -1608,7 +1601,6 @@ mjCSkin::~mjCSkin() { // compiler void mjCSkin::Compile(const mjVFS* vfs) { - size_t i, j; // load file if (!file.empty()) { @@ -1678,7 +1670,7 @@ void mjCSkin::Compile(const mjVFS* vfs) { // resolve body names bodyid.resize(nbone); - for (i=0; iFindObject(mjOBJ_BODY, bodyname[i]); if (!pbody) { throw mjCError(this, "unknown body '%s' in skin", bodyname[i].c_str()); @@ -1701,7 +1693,7 @@ void mjCSkin::Compile(const mjVFS* vfs) { fill(vw.begin(), vw.end(), 0.0f); // accumulate vertex weights from all bones - for (i=0; i=nvert) { @@ -1722,21 +1714,21 @@ void mjCSkin::Compile(const mjVFS* vfs) { } // check coverage - for (i=0; igeoms.size(); i++) geoms.push_back(body->geoms[i]); - for (i=0; ijoints.size(); i++) joints.push_back(body->joints[i]); - for (i=0; isites.size(); i++) sites.push_back(body->sites[i]); - for (i=0; icameras.size(); i++) cameras.push_back(body->cameras[i]); - for (i=0; ilights.size(); i++) lights.push_back(body->lights[i]); + for (int i=0; igeoms.size(); i++) geoms.push_back(body->geoms[i]); + for (int i=0; ijoints.size(); i++) joints.push_back(body->joints[i]); + for (int i=0; isites.size(); i++) sites.push_back(body->sites[i]); + for (int i=0; icameras.size(); i++) cameras.push_back(body->cameras[i]); + for (int i=0; ilights.size(); i++) lights.push_back(body->lights[i]); // recursive call to all child bodies - for (i=0; ibodies.size(); i++) MakeLists(body->bodies[i]); + for (int i=0; ibodies.size(); i++) MakeLists(body->bodies[i]); } // index assets void mjCModel::IndexAssets(void) { - unsigned int i; - // assets referenced in geoms - for (i=0; iname.empty()) { stripped = mjuu_strippath(meshes[i]->file); meshes[i]->name = mjuu_stripext(stripped); @@ -846,7 +839,7 @@ void mjCModel::SetDefaultNames(void) { } // skins - for (i=0; iname.empty()) { stripped = mjuu_strippath(skins[i]->file); skins[i]->name = mjuu_stripext(stripped); @@ -854,7 +847,7 @@ void mjCModel::SetDefaultNames(void) { } // hfields - for (i=0; iname.empty()) { stripped = mjuu_strippath(hfields[i]->file); hfields[i]->name = mjuu_stripext(stripped); @@ -867,7 +860,7 @@ void mjCModel::SetDefaultNames(void) { } // textures - for (i=0; iname.empty()) { stripped = mjuu_strippath(textures[i]->file); textures[i]->name = mjuu_stripext(stripped); @@ -880,7 +873,7 @@ void mjCModel::SetDefaultNames(void) { } // materials: name check only - for (i=0; iname.empty()) { throw mjCError(materials[i], "empty name in material"); } @@ -895,8 +888,6 @@ const int nVEL[4] = {6, 3, 1, 1}; // set array sizes void mjCModel::SetSizes(void) { - int i, j; - // set from object list sizes nbody = (int)bodies.size(); njnt = (int)joints.size(); @@ -921,13 +912,13 @@ void mjCModel::SetSizes(void) { nplugin = (int)plugins.size(); // nq, nv - for (i=0; itype]; nv += nVEL[joints[i]->type]; } // nu, na - for (i=0; i<(int)actuators.size(); i++) { + for (int i=0; i<(int)actuators.size(); i++) { if (actuators[i]->dyntype == mjDYN_NONE) { nu++; } else { @@ -937,12 +928,12 @@ void mjCModel::SetSizes(void) { } // nbvh - for (i=0; inbvh; } // nmeshvert, nmeshface, nmeshtexcoord, nmeshgraph - for (i=0; invert; nmeshnormal += meshes[i]->nnormal; nmeshface += meshes[i]->nface; @@ -951,67 +942,67 @@ void mjCModel::SetSizes(void) { } // nskinvert, nskintexvert, nskinface, nskinbone, nskinbonevert - for (i=0; ivert.size()/3; nskintexvert += skins[i]->texcoord.size()/2; nskinface += skins[i]->face.size()/3; nskinbone += skins[i]->bodyid.size(); - for (j=0; jbodyid.size(); j++) { + for (int j=0; jbodyid.size(); j++) { nskinbonevert += skins[i]->vertid[j].size(); } } // nhfielddata - for (i=0; inrow * hfields[i]->ncol; + for (int i=0; inrow * hfields[i]->ncol; // ntexdata - for (i=0; iwidth * textures[i]->height; + for (int i=0; iwidth * textures[i]->height; // nwrap - for (i=0; ipath.size(); + for (int i=0; ipath.size(); // nsensordata - for (i=0; idim; + for (int i=0; idim; // nnumericdata - for (i=0; isize; + for (int i=0; isize; // ntextdata - for (i=0; idata.size() + 1; + for (int i=0; idata.size() + 1; // ntupledata - for (i=0; iobjtype.size(); + for (int i=0; iobjtype.size(); // npluginattr - for (i=0; iflattened_attributes.size(); + for (int i=0; iflattened_attributes.size(); // nnames nnames = (int)modelname.size() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; - for (i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; + for (int i=0; iname.length() + 1; // nemax - for (i=0; itype==mjEQ_CONNECT) { nemax += 3; } else if (equalities[i]->type==mjEQ_WELD) { @@ -1092,8 +1083,6 @@ void* LRfunc(void* arg) { // compute actuator lengthrange void mjCModel::LengthRange(mjModel* m, mjData* data) { - int i; - // save options and modify mjOption saveopt = m->opt; m->opt.disableflags = mjDSBL_FRICTIONLOSS | mjDSBL_CONTACT | mjDSBL_PASSIVE | @@ -1107,7 +1096,7 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { // count actuators that need computation int cnt = 0; - for (i=0; inu; i++) { + for (int i=0; inu; i++) { // skip depending on mode and type int ismuscle = (m->actuator_gaintype[i]==mjGAIN_MUSCLE || m->actuator_biastype[i]==mjBIAS_MUSCLE); @@ -1132,7 +1121,7 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { // single thread if (!usethread || cnt<2 || nthread<2) { char err[200]; - for (i=0; inu; i++) { + for (int i=0; inu; i++) { if (!mj_setLengthRange(m, data, i, &LRopt, err, 200)) { throw mjCError(0, err); } @@ -1144,7 +1133,7 @@ void mjCModel::LengthRange(mjModel* m, mjData* data) { // allocate mjData for each thread char err[16][200]; mjData* pdata[16] = {data}; - for (i=1; iparentid]; @@ -1370,7 +1358,7 @@ void mjCModel::CopyTree(mjModel* m) { // count free joints int cntfree = 0; - for (j=0; j<(int)pb->joints.size(); j++) { + for (int j=0; j<(int)pb->joints.size(); j++) { cntfree += (pb->joints[j]->type == mjJNT_FREE); } @@ -1396,7 +1384,7 @@ void mjCModel::CopyTree(mjModel* m) { m->body_sameframe[i] = IsNullPose(m->body_ipos+3*i, m->body_iquat+4*i); // init simple: sameframe, and (self-root, or parent is fixed child of world) - j = m->body_parentid[i]; + int j = m->body_parentid[i]; m->body_simple[i] = (m->body_sameframe[i] && (m->body_rootid[i]==i || (m->body_parentid[j]==0 && @@ -1409,7 +1397,7 @@ void mjCModel::CopyTree(mjModel* m) { // loop over joints for this body int rotfound = 0; - for (j=0; j<(int)pb->joints.size(); j++) { + for (int j=0; j<(int)pb->joints.size(); j++) { // get pointer and id mjCJoint* pj = pb->joints[j]; int jid = pj->id; @@ -1470,7 +1458,7 @@ void mjCModel::CopyTree(mjModel* m) { } // set dof fields for this joint - for (j1=0; j1type]; j1++) { + for (int j1=0; j1type]; j1++) { // set attributes m->dof_bodyid[dofadr] = pb->id; m->dof_jntid[dofadr] = jid; @@ -1494,7 +1482,7 @@ void mjCModel::CopyTree(mjModel* m) { } // loop over geoms for this body - for (j=0; j<(int)pb->geoms.size(); j++) { + for (int j=0; j<(int)pb->geoms.size(); j++) { // get pointer and id mjCGeom* pg = pb->geoms[j]; int gid = pg->id; @@ -1549,7 +1537,7 @@ void mjCModel::CopyTree(mjModel* m) { } // loop over sites for this body - for (j=0; j<(int)pb->sites.size(); j++) { + for (int j=0; j<(int)pb->sites.size(); j++) { // get pointer and id mjCSite* ps = pb->sites[j]; int sid = ps->id; @@ -1582,7 +1570,7 @@ void mjCModel::CopyTree(mjModel* m) { } // loop over cameras for this body - for (j=0; j<(int)pb->cameras.size(); j++) { + for (int j=0; j<(int)pb->cameras.size(); j++) { // get pointer and id mjCCamera* pc = pb->cameras[j]; int cid = pc->id; @@ -1599,7 +1587,7 @@ void mjCModel::CopyTree(mjModel* m) { } // loop over lights for this body - for (j=0; j<(int)pb->lights.size(); j++) { + for (int j=0; j<(int)pb->lights.size(); j++) { // get pointer and id mjCLight* pl = pb->lights[j]; int lid = pl->id; @@ -1629,12 +1617,12 @@ void mjCModel::CopyTree(mjModel* m) { // compute nM and dof_Madr nM = 0; - for (i=0; idof_Madr[i] = nM; // count ancestor dofs including self - j = i; + int j = i; while (j>=0) { nM++; j = m->dof_parentid[j]; @@ -1647,7 +1635,7 @@ void mjCModel::CopyTree(mjModel* m) { m->nD = nD; // compute subtreedofs in backward pass over bodies - for (i = nbody - 1; i > 0; i--) { + for (int i = nbody - 1; i > 0; i--) { // add body dofs to self count bodies[i]->subtreedofs += bodies[i]->dofnum; @@ -1662,12 +1650,12 @@ void mjCModel::CopyTree(mjModel* m) { // compute nB nB = 0; - for (i = 0; i < nbody; i++) { + for (int i = 0; i < nbody; i++) { // add subtree dofs (including self) nB += bodies[i]->subtreedofs; // add dofs in ancestor bodies - j = bodies[i]->parentid; + int j = bodies[i]->parentid; while (j > 0) { nB += bodies[j]->dofnum; j = bodies[j]->parentid; @@ -1677,7 +1665,7 @@ void mjCModel::CopyTree(mjModel* m) { // set dof_simplenum int scnt = 0; - for (i=nv-1; i>=0; i--) { + for (int i=nv-1; i>=0; i--) { // dof in simple body if (m->body_simple[m->dof_bodyid[i]]) { scnt++; @@ -1696,7 +1684,7 @@ void mjCModel::CopyTree(mjModel* m) { // copy objects outside kinematic tree void mjCModel::CopyObjects(mjModel* m) { - int i, j, adr, bone_adr, vert_adr, normal_adr, face_adr, texcoord_adr; + int adr, bone_adr, vert_adr, normal_adr, face_adr, texcoord_adr; int bonevert_adr, graph_adr, data_adr; // sizes outside call to mj_makeModel @@ -1712,7 +1700,7 @@ void mjCModel::CopyObjects(mjModel* m) { texcoord_adr = 0; face_adr = 0; graph_adr = 0; - for (i=0; ibodyid.size()*sizeof(int)); // copy per-bone vertex data, advance vertex counter - for (j=0; jskin_bonenum[i]; j++) { + for (int j=0; jskin_bonenum[i]; j++) { // set fields m->skin_bonevertadr[bone_adr+j] = bonevert_adr; m->skin_bonevertnum[bone_adr+j] = (int)psk->vertid[j].size(); @@ -1813,7 +1801,7 @@ void mjCModel::CopyObjects(mjModel* m) { // hfields data_adr = 0; - for (i=0; ipair_dim[i] = pairs[i]->condim; m->pair_geom1[i] = pairs[i]->geom1; m->pair_geom2[i] = pairs[i]->geom2; @@ -1879,12 +1867,12 @@ void mjCModel::CopyObjects(mjModel* m) { } // body pairs to exclude - for (i=0; iexclude_signature[i] = excludes[i]->signature; } // equality constraints - for (i=0; itendon_rgba+4*i, pte->rgba, 4); // set wraps - for (j=0; j<(int)pte->path.size(); j++) { + for (int j=0; j<(int)pte->path.size(); j++) { m->wrap_type[adr+j] = pte->path[j]->type; m->wrap_objid[adr+j] = pte->path[j]->objid; m->wrap_prm[adr+j] = (mjtNum)pte->path[j]->prm; @@ -1942,7 +1930,7 @@ void mjCModel::CopyObjects(mjModel* m) { // actuators adr = 0; - for (i=0; inumeric_adr[i] = adr; m->numeric_size[i] = pcu->size; - for (j=0; j<(int)pcu->data.size(); j++) { + for (int j=0; j<(int)pcu->data.size(); j++) { m->numeric_data[adr+j] = (mjtNum)pcu->data[j]; } - for (j=(int)pcu->data.size(); j<(int)pcu->size; j++) { + for (int j=(int)pcu->data.size(); j<(int)pcu->size; j++) { m->numeric_data[adr+j] = 0; } @@ -2018,7 +2006,7 @@ void mjCModel::CopyObjects(mjModel* m) { // text fields adr = 0; - for (i=0; ituple_adr[i] = adr; m->tuple_size[i] = (int)ptu->objtype.size(); - for (j=0; jtuple_size[i]; j++) { + for (int j=0; jtuple_size[i]; j++) { m->tuple_objtype[adr+j] = (int)ptu->objtype[j]; m->tuple_objid[adr+j] = ptu->objid[j]; m->tuple_objprm[adr+j] = (mjtNum)ptu->objprm[j]; @@ -2051,7 +2039,7 @@ void mjCModel::CopyObjects(mjModel* m) { } // copy keyframe data - for (i=0; ikey_time[i] = (mjtNum)keys[i]->time; copyvec(m->key_qpos+i*nq, keys[i]->qpos.data(), nq); @@ -2065,14 +2053,14 @@ void mjCModel::CopyObjects(mjModel* m) { } // normalize quaternions in m->key_qpos - for (j=0; jnjnt; j++) { + for (int j=0; jnjnt; j++) { if (m->jnt_type[j]==mjJNT_BALL || m->jnt_type[j]==mjJNT_FREE) { mju_normalize4(m->key_qpos+i*nq+m->jnt_qposadr[j]+3*(m->jnt_type[j]==mjJNT_FREE)); } } // normalize quaternions in m->key_mquat - for (j=0; jkey_mquat+i*4*nmocap+4*j); } @@ -2103,35 +2091,33 @@ static void changeframe(double childpos[3], double childquat[4], // reindex elements during fuse void mjCModel::FuseReindex(mjCBody* body) { - size_t i; - // set parentid and weldid of children - for (i=0; ibodies.size(); i++) { + for (int i=0; ibodies.size(); i++) { body->bodies[i]->parentid = body->id; body->bodies[i]->weldid = (!body->bodies[i]->joints.empty() ? body->bodies[i]->id : body->weldid); } // joints - for (i=0; ijoints.size(); i++) { + for (int i=0; ijoints.size(); i++) { body->joints[i]->id = (int)joints.size(); joints.push_back(body->joints[i]); } // geoms - for (i=0; igeoms.size(); i++) { + for (int i=0; igeoms.size(); i++) { body->geoms[i]->id = (int)geoms.size(); geoms.push_back(body->geoms[i]); } // sites - for (i=0; isites.size(); i++) { + for (int i=0; isites.size(); i++) { body->sites[i]->id = (int)sites.size(); sites.push_back(body->sites[i]); } // process children recursively - for (i=0; ibodies.size(); i++) { + for (int i=0; ibodies.size(); i++) { FuseReindex(body->bodies[i]); } } @@ -2140,8 +2126,6 @@ void mjCModel::FuseReindex(mjCBody* body) { // fuse static bodies with their parent void mjCModel::FuseStatic(void) { - int i, j, k; - // skip if model has potential to reference elements with changed ids if (!skins.empty() || !pairs.empty() || @@ -2157,7 +2141,7 @@ void mjCModel::FuseStatic(void) { } // process fusable bodies - for (i=1; iparentid]; @@ -2195,7 +2179,7 @@ void mjCModel::FuseStatic(void) { // compute total mass par->mass = 0; mjuu_setvec(par->locipos, 0, 0, 0); - for (j=0; j<2; j++) { + for (int j=0; j<2; j++) { par->mass += mass[j]; par->locipos[0] += mass[j]*ipos[j][0]; par->locipos[1] += mass[j]*ipos[j][1]; @@ -2219,7 +2203,7 @@ void mjCModel::FuseStatic(void) { // add inertias double toti[6] = {0, 0, 0, 0, 0, 0}; - for (j=0; j<2; j++) { + for (int j=0; j<2; j++) { double inertA[6], inertB[6]; double dpos[3] = { ipos[j][0] - par->locipos[0], @@ -2229,7 +2213,7 @@ void mjCModel::FuseStatic(void) { mjuu_globalinertia(inertA, inertia[j], iquat[j]); mjuu_offcenter(inertB, mass[j], dpos); - for (k=0; k<6; k++) { + for (int k=0; k<6; k++) { toti[k] += inertA[k] + inertB[k]; } } @@ -2247,7 +2231,7 @@ void mjCModel::FuseStatic(void) { //------------- replace body with its children in parent body list // change frames of child bodies - for (j=0; jbodies.size(); j++) + for (int j=0; jbodies.size(); j++) changeframe(body->bodies[j]->locpos, body->bodies[j]->locquat, body->locpos, body->locquat); @@ -2280,7 +2264,7 @@ void mjCModel::FuseStatic(void) { //------------- assign geoms and sites to parent, change frames // geoms - for (j=0; jgeoms.size(); j++) { + for (int j=0; jgeoms.size(); j++) { // assign body->geoms[j]->body = par; par->geoms.push_back(body->geoms[j]); @@ -2290,7 +2274,7 @@ void mjCModel::FuseStatic(void) { } // sites - for (j=0; jsites.size(); j++) { + for (int j=0; jsites.size(); j++) { // assign body->sites[j]->body = par; par->sites.push_back(body->sites[j]); @@ -2321,7 +2305,7 @@ void mjCModel::FuseStatic(void) { //------------- re-index bodies, joints, geoms, sites // body ids - for (j=0; jid = j; } @@ -2872,8 +2856,6 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { // get numeric data back from mjModel bool mjCModel::CopyBack(const mjModel* m) { - int i, j; - // check for null pointer if (!m) { errInfo = mjCError(0, "mjModel pointer is null in CopyBack"); @@ -2905,7 +2887,7 @@ bool mjCModel::CopyBack(const mjModel* m) { visual = m->vis; // qpos0, qpos_spring - for (i=0; itype) { case mjJNT_FREE: copyvec(bodies[m->jnt_bodyid[i]]->pos, m->qpos0+m->jnt_qposadr[i], 3); @@ -2927,7 +2909,7 @@ bool mjCModel::CopyBack(const mjModel* m) { // body mjCBody* pb; - for (i=0; ilocpos, m->body_pos+3*i, 3); @@ -2944,7 +2926,7 @@ bool mjCModel::CopyBack(const mjModel* m) { // joint and dof mjCJoint* pj; - for (i=0; ijnt_dofadr[i]; + int j = m->jnt_dofadr[i]; copyvec(pj->solref_friction, m->dof_solref+mjNREF*j, mjNREF); copyvec(pj->solimp_friction, m->dof_solimp+mjNIMP*j, mjNIMP); pj->armature = (double)m->dof_armature[j]; @@ -2971,7 +2953,7 @@ bool mjCModel::CopyBack(const mjModel* m) { // geom mjCGeom* pg; - for (i=0; isize, m->geom_size+3*i, 3); @@ -2991,7 +2973,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // sites - for (i=0; isize, m->site_size + 3 * i, 3); copyvec(sites[i]->locpos, m->site_pos+3*i, 3); copyvec(sites[i]->locquat, m->site_quat+4*i, 4); @@ -3003,7 +2985,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // cameras - for (i=0; ipos, m->cam_pos+3*i, 3); copyvec(cameras[i]->quat, m->cam_quat+4*i, 4); cameras[i]->fovy = (double)m->cam_fovy[i]; @@ -3015,7 +2997,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // lights - for (i=0; ipos, m->light_pos+3*i, 3); copyvec(lights[i]->dir, m->light_dir+3*i, 3); copyvec(lights[i]->attenuation, m->light_attenuation+3*i, 3); @@ -3027,7 +3009,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // materials - for (i=0; itexrepeat, m->mat_texrepeat+2*i, 2); materials[i]->emission = m->mat_emission[i]; materials[i]->specular = m->mat_specular[i]; @@ -3037,7 +3019,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // pairs - for (i=0; isolref, m->pair_solref+mjNREF*i, mjNREF); copyvec(pairs[i]->solimp, m->pair_solimp+mjNIMP*i, mjNIMP); pairs[i]->margin = (double)m->pair_margin[i]; @@ -3046,14 +3028,14 @@ bool mjCModel::CopyBack(const mjModel* m) { } // equality constraints - for (i=0; idata, m->eq_data+mjNEQDATA*i, mjNEQDATA); copyvec(equalities[i]->solref, m->eq_solref+mjNREF*i, mjNREF); copyvec(equalities[i]->solimp, m->eq_solimp+mjNIMP*i, mjNIMP); } // tendons - for (i=0; irange, m->tendon_range+2*i, 2); copyvec(tendons[i]->solref_limit, m->tendon_solref_lim+mjNREF*i, mjNREF); copyvec(tendons[i]->solimp_limit, m->tendon_solimp_lim+mjNIMP*i, mjNIMP); @@ -3073,7 +3055,7 @@ bool mjCModel::CopyBack(const mjModel* m) { // actuators mjCActuator* pa; - for (i=0; idynprm, m->actuator_dynprm+i*mjNDYN, mjNDYN); @@ -3092,7 +3074,7 @@ bool mjCModel::CopyBack(const mjModel* m) { } // sensors - for (i=0; icutoff = (double)m->sensor_cutoff[i]; sensors[i]->noise = (double)m->sensor_noise[i]; @@ -3102,21 +3084,21 @@ bool mjCModel::CopyBack(const mjModel* m) { } // numeric data - for (i=0; inumeric_size[i]; j++) { + for (int i=0; inumeric_size[i]; j++) { numerics[i]->data[j] = (double)m->numeric_data[m->numeric_adr[i]+j]; } } // tuple data - for (i=0; ituple_size[i]; j++) { + for (int i=0; ituple_size[i]; j++) { tuples[i]->objprm[j] = (double)m->tuple_objprm[m->tuple_adr[i]+j]; } } // keyframes - for (i=0; inkey; i++) { + for (int i=0; inkey; i++) { mjCKey* pk = keys[i]; pk->time = (double)m->key_time[i]; diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index f05cf443..1bd47445 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -356,15 +356,13 @@ mjCBody::mjCBody(mjCModel* _model) { // destructor mjCBody::~mjCBody() { - unsigned int i; - // delete objects allocated here - for (i=0; i sel; // select geoms based on group sel.clear(); - for (i=0; igroup>=model->inertiagrouprange[0] && geoms[i]->group<=model->inertiagrouprange[1]) { sel.push_back(geoms[i]); @@ -603,7 +601,7 @@ void mjCBody::GeomFrame(void) { else if (sz>1) { // compute total mass and center of mass mass = 0; - for (i=0; imass; com[0] += sel[i]->mass * sel[i]->pos[0]; com[1] += sel[i]->mass * sel[i]->pos[1]; @@ -621,7 +619,7 @@ void mjCBody::GeomFrame(void) { ipos[2] = com[2]/mass; // add geom inertias - for (i=0; ipos[0] - ipos[0], @@ -820,8 +818,6 @@ int mjCBody::MakeBVH(std::vector& elements, int lev) { // compiler void mjCBody::Compile(void) { - unsigned int i; - // resize userdata if (userdata.size() > model->nuser_body) { throw mjCError(this, "user has more values than nuser_body in body '%s' (id = %d)", @@ -839,7 +835,7 @@ void mjCBody::Compile(void) { mjuu_normvec(iquat, 4); // set parentid and weldid of children - for (i=0; iparentid = id; bodies[i]->weldid = (!bodies[i]->joints.empty() ? bodies[i]->id : weldid); } @@ -857,7 +853,7 @@ void mjCBody::Compile(void) { } // compile all geoms, phase 1 - for (i=0; iinferinertia = id>0 && (!explicitinertial || model->inertiafromgeom == mjINERTIAFROMGEOM_TRUE) && geoms[i]->group >= model->inertiagrouprange[0] && @@ -924,7 +920,7 @@ void mjCBody::Compile(void) { } // make local frames of geoms - for (i=0; ilocpos, geoms[i]->locquat, geoms[i]->pos, geoms[i]->quat); } @@ -935,7 +931,7 @@ void mjCBody::Compile(void) { // compile all joints, count dofs dofnum = 0; - for (i=0; iCompile(); } @@ -946,7 +942,7 @@ void mjCBody::Compile(void) { // check for rotation dof after ball joint bool hasball = false; - for (i=0; itype==mjJNT_BALL || joints[i]->type==mjJNT_HINGE) && hasball) { throw mjCError(this, "ball followed by rotation in body '%s'", name.c_str()); } @@ -962,13 +958,13 @@ void mjCBody::Compile(void) { } // compile all sites - for (i=0; iCompile(); + for (int i=0; iCompile(); // compile all cameras - for (i=0; iCompile(); + for (int i=0; iCompile(); // compile all lights - for (i=0; iCompile(); + for (int i=0; iCompile(); // plugin if (is_plugin) { @@ -2217,11 +2213,10 @@ mjCTexture::~mjCTexture() { // insert random dots static void randomdot(unsigned char* rgb, const double* markrgb, int width, int height, double probability) { - int r, c, j; - for (r=0; r12) { throw mjCError(this, @@ -2685,9 +2673,9 @@ void mjCTexture::LoadCubeSingle(string filename, const mjVFS* vfs) { int loaded[6] = {0, 0, 0, 0, 0, 0}; // process grid - for (k=0; kstrippath) { @@ -2796,11 +2782,11 @@ void mjCTexture::LoadCubeSeparate(const mjVFS* vfs) { } // set undefined faces to rgb1 - for (i=0; i<6; i++) { + for (int i=0; i<6; i++) { if (!loaded[i]) { - for (k=0; knq); - for (i=0; inq; i++) { + for (int i=0; inq; i++) { qpos[i] = (double)m->qpos0[i]; } } else if (qpos.size()!=m->nq) { @@ -4434,7 +4419,7 @@ void mjCKey::Compile(const mjModel* m) { // qvel: allocate or check size if (qvel.empty()) { qvel.resize(m->nv); - for (i=0; inv; i++) { + for (int i=0; inv; i++) { qvel[i] = 0; } } else if (qvel.size()!=m->nv) { @@ -4444,7 +4429,7 @@ void mjCKey::Compile(const mjModel* m) { // act: allocate or check size if (act.empty()) { act.resize(m->na); - for (i=0; ina; i++) { + for (int i=0; ina; i++) { act[i] = 0; } } else if (act.size()!=m->na) { @@ -4455,7 +4440,7 @@ void mjCKey::Compile(const mjModel* m) { if (mpos.empty()) { mpos.resize(3*m->nmocap); if (m->nmocap) { - for (i=0; inbody; i++) { + for (int i=0; inbody; i++) { if (m->body_mocapid[i]>=0) { int mocapid = m->body_mocapid[i]; mpos[3*mocapid] = m->body_pos[3*i]; @@ -4472,7 +4457,7 @@ void mjCKey::Compile(const mjModel* m) { if (mquat.empty()) { mquat.resize(4*m->nmocap); if (m->nmocap) { - for (i=0; inbody; i++) { + for (int i=0; inbody; i++) { if (m->body_mocapid[i]>=0) { int mocapid = m->body_mocapid[i]; mquat[4*mocapid] = m->body_quat[4*i]; @@ -4489,7 +4474,7 @@ void mjCKey::Compile(const mjModel* m) { // ctrl: allocate or check size if (ctrl.empty()) { ctrl.resize(m->nu); - for (i=0; inu; i++) { + for (int i=0; inu; i++) { ctrl[i] = 0; } } else if (ctrl.size()!=m->nu) { diff --git a/src/user/user_util.cc b/src/user/user_util.cc index 7ffec0c1..a239094f 100644 --- a/src/user/user_util.cc +++ b/src/user/user_util.cc @@ -141,9 +141,8 @@ double mjuu_L1(const double* a, const double* b, int n) { // normalize vector to unit length, return previous length double mjuu_normvec(double* vec, const int n) { double nrm = 0; - int i; - for (i=0; iFirstChildElement("compiler"); section; + for (XMLElement* section = root->FirstChildElement("compiler"); section; section = section->NextSiblingElement("compiler")) { Compiler(section, model); } - for (section = root->FirstChildElement("option"); section; + for (XMLElement* section = root->FirstChildElement("option"); section; section = section->NextSiblingElement("option")) { Option(section, &model->option); } - for (section = root->FirstChildElement("size"); section; + for (XMLElement* section = root->FirstChildElement("size"); section; section = section->NextSiblingElement("size")) { Size(section, model); } //------------------ parse MJCF-specific sections - for (section = root->FirstChildElement("visual"); section; + for (XMLElement* section = root->FirstChildElement("visual"); section; section = section->NextSiblingElement("visual")) { Visual(section); } - for (section = root->FirstChildElement("statistic"); section; + for (XMLElement* section = root->FirstChildElement("statistic"); section; section = section->NextSiblingElement("statistic")) { Statistic(section); } readingdefaults = true; - for (section = root->FirstChildElement("default"); section; + for (XMLElement* section = root->FirstChildElement("default"); section; section = section->NextSiblingElement("default")) { Default(section, -1); } readingdefaults = false; - for (section = root->FirstChildElement("extension"); section; + for (XMLElement* section = root->FirstChildElement("extension"); section; section = section->NextSiblingElement("extension")) { Extension(section); } - for (section = root->FirstChildElement("custom"); section; + for (XMLElement* section = root->FirstChildElement("custom"); section; section = section->NextSiblingElement("custom")) { Custom(section); } - for (section = root->FirstChildElement("asset"); section; + for (XMLElement* section = root->FirstChildElement("asset"); section; section = section->NextSiblingElement("asset")) { Asset(section); } - for (section = root->FirstChildElement("worldbody"); section; + for (XMLElement* section = root->FirstChildElement("worldbody"); section; section = section->NextSiblingElement("worldbody")) { Body(section, model->GetWorld()); } - for (section = root->FirstChildElement("contact"); section; + for (XMLElement* section = root->FirstChildElement("contact"); section; section = section->NextSiblingElement("contact")) { Contact(section); } - for (section = root->FirstChildElement("equality"); section; + for (XMLElement* section = root->FirstChildElement("equality"); section; section = section->NextSiblingElement("equality")) { Equality(section); } - for (section = root->FirstChildElement("tendon"); section; + for (XMLElement* section = root->FirstChildElement("tendon"); section; section = section->NextSiblingElement("tendon")) { Tendon(section); } - for (section = root->FirstChildElement("actuator"); section; + for (XMLElement* section = root->FirstChildElement("actuator"); section; section = section->NextSiblingElement("actuator")) { Actuator(section); } - for (section = root->FirstChildElement("sensor"); section; + for (XMLElement* section = root->FirstChildElement("sensor"); section; section = section->NextSiblingElement("sensor")) { Sensor(section); } - for (section = root->FirstChildElement("keyframe"); section; + for (XMLElement* section = root->FirstChildElement("keyframe"); section; section = section->NextSiblingElement("keyframe")) { Keyframe(section); } @@ -1605,7 +1603,6 @@ void mjXReader::OneTendon(XMLElement* elem, mjCTendon* pten) { // actuator element parser void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) { - int n; string text, type; double diameter; @@ -1672,6 +1669,7 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) { // explicit attributes if (type=="general") { // explicit attributes + int n; if (MapValue(elem, "dyntype", &n, dyn_map, dyn_sz)) { pact->dyntype = (mjtDyn)n; } @@ -1811,7 +1809,7 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) { ReadAttr(elem, "fvmax", 1, pact->gainprm+8, text); // biasprm = gainprm - for (n=0; n<9; n++) { + for (int n=0; n<9; n++) { pact->biasprm[n] = pact->gainprm[n]; } diff --git a/src/xml/xml_native_writer.cc b/src/xml/xml_native_writer.cc index 15d7c0af..f32bd9d6 100644 --- a/src/xml/xml_native_writer.cc +++ b/src/xml/xml_native_writer.cc @@ -1135,7 +1135,6 @@ void mjXWriter::Extension(XMLElement* root) { // custom section void mjXWriter::Custom(XMLElement* root) { XMLElement* elem; - int i, j; // get sizes, skip section if empty int nnum = model->NumObjects(mjOBJ_NUMERIC); @@ -1151,7 +1150,7 @@ void mjXWriter::Custom(XMLElement* root) { XMLElement* section = InsertEnd(root, "custom"); // write all numerics - for (i=0; iGetObject(mjOBJ_NUMERIC, i); elem = InsertEnd(section, "numeric"); WriteAttrTxt(elem, "name", ptr->name); @@ -1160,7 +1159,7 @@ void mjXWriter::Custom(XMLElement* root) { } // write all texts - for (i=0; iGetObject(mjOBJ_TEXT, i); elem = InsertEnd(section, "text"); WriteAttrTxt(elem, "name", ptr->name); @@ -1168,13 +1167,13 @@ void mjXWriter::Custom(XMLElement* root) { } // write all tuples - for (i=0; iGetObject(mjOBJ_TUPLE, i); elem = InsertEnd(section, "tuple"); WriteAttrTxt(elem, "name", ptr->name); // write objects in tuple - for (j=0; j<(int)ptr->objtype.size(); j++) { + for (int j=0; j<(int)ptr->objtype.size(); j++) { XMLElement* obj = InsertEnd(elem, "element"); WriteAttrTxt(obj, "objtype", mju_type2Str((int)ptr->objtype[j])); WriteAttrTxt(obj, "objname", ptr->objname[j].c_str()); @@ -1191,7 +1190,6 @@ void mjXWriter::Custom(XMLElement* root) { // asset section void mjXWriter::Asset(XMLElement* root) { XMLElement* elem; - int i; // get sizes int ntex = model->NumObjects(mjOBJ_TEXTURE); @@ -1210,7 +1208,7 @@ void mjXWriter::Asset(XMLElement* root) { // write textures mjCTexture deftex(0); - for (i=0; iGetObject(mjOBJ_TEXTURE, i); elem = InsertEnd(section, "texture"); @@ -1260,7 +1258,7 @@ void mjXWriter::Asset(XMLElement* root) { } // write materials - for (i=0; iGetObject(mjOBJ_MATERIAL, i); elem = InsertEnd(section, "material"); @@ -1268,7 +1266,7 @@ void mjXWriter::Asset(XMLElement* root) { } // write meshes - for (i=0; iGetObject(mjOBJ_MESH, i); elem = InsertEnd(section, "mesh"); @@ -1276,7 +1274,7 @@ void mjXWriter::Asset(XMLElement* root) { } // write skins - for (i=0; iGetObject(mjOBJ_SKIN, i); elem = InsertEnd(section, "skin"); @@ -1284,7 +1282,7 @@ void mjXWriter::Asset(XMLElement* root) { } // write hfields - for (i=0; iGetObject(mjOBJ_HFIELD, i); elem = InsertEnd(section, "hfield"); @@ -1306,7 +1304,6 @@ void mjXWriter::Asset(XMLElement* root) { // recursive body writer void mjXWriter::Body(XMLElement* elem, mjCBody* body) { double unitq[4] = {1, 0, 0, 0}; - unsigned int i; if (!body) { throw mjXError(0, "missing body in XML write"); // SHOULD NOT OCCUR @@ -1340,27 +1337,27 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) { } // write joints - for (i=0; ijoints.size(); i++) { + for (int i=0; ijoints.size(); i++) { OneJoint(InsertEnd(elem, "joint"), body->joints[i], body->joints[i]->def); } // write geoms - for (i=0; igeoms.size(); i++) { + for (int i=0; igeoms.size(); i++) { OneGeom(InsertEnd(elem, "geom"), body->geoms[i], body->geoms[i]->def); } // write sites - for (i=0; isites.size(); i++) { + for (int i=0; isites.size(); i++) { OneSite(InsertEnd(elem, "site"), body->sites[i], body->sites[i]->def); } // write cameras - for (i=0; icameras.size(); i++) { + for (int i=0; icameras.size(); i++) { OneCamera(InsertEnd(elem, "camera"), body->cameras[i], body->cameras[i]->def); } // write lights - for (i=0; ilights.size(); i++) { + for (int i=0; ilights.size(); i++) { OneLight(InsertEnd(elem, "light"), body->lights[i], body->lights[i]->def); } @@ -1387,7 +1384,7 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) { } // write child bodies recursively - for (i=0; ibodies.size(); i++) { + for (int i=0; ibodies.size(); i++) { Body(InsertEnd(elem, "body"), body->bodies[i]); } } @@ -1397,7 +1394,6 @@ void mjXWriter::Body(XMLElement* elem, mjCBody* body) { // collision section void mjXWriter::Contact(XMLElement* root) { XMLElement* elem; - int i; // get number of pairs of each type int npair = model->NumObjects(mjOBJ_PAIR); @@ -1412,7 +1408,7 @@ void mjXWriter::Contact(XMLElement* root) { XMLElement* section = InsertEnd(root, "contact"); // write all geom pairs - for (i=0; iGetObject(mjOBJ_PAIR, i); elem = InsertEnd(section, "pair"); @@ -1420,7 +1416,7 @@ void mjXWriter::Contact(XMLElement* root) { } // write all exclude pairs - for (i=0; iGetObject(mjOBJ_EXCLUDE, i); elem = InsertEnd(section, "exclude"); diff --git a/src/xml/xml_urdf.cc b/src/xml/xml_urdf.cc index 1bde0bb3..b9969097 100644 --- a/src/xml/xml_urdf.cc +++ b/src/xml/xml_urdf.cc @@ -74,7 +74,7 @@ void mjXURDF::Clear(void) { void mjXURDF::Parse(XMLElement* root) { std::string name, text; XMLElement *elem, *temp; - int id_parent, id_child, i; + int id_parent, id_child; // set compiler defaults suitable for URDF model->strippath = true; @@ -158,7 +158,7 @@ void mjXURDF::Parse(XMLElement* root) { } // find all top-level bodies, call recursive tree constructor - for (i=0; i<(int)urName.size(); i++) { + for (int i=0; i<(int)urName.size(); i++) { if (urParent[i] < 0) { AddToTree(i); } diff --git a/src/xml/xml_util.cc b/src/xml/xml_util.cc index b2ea7e07..32fe7dd3 100644 --- a/src/xml/xml_util.cc +++ b/src/xml/xml_util.cc @@ -282,8 +282,6 @@ static int _max(int a, int b) { // print schema as text void mjXSchema::Print(std::stringstream& str, int level) { - int i; - // replace body with (world)body string name1 = (name=="body" ? "(world)body" : name); @@ -297,7 +295,7 @@ void mjXSchema::Print(std::stringstream& str, int level) { // attributes int cnt = _max(baselen, 30); - for (i=0; i<(int)attr.size(); i++) { + for (int i=0; i<(int)attr.size(); i++) { if (cnt>60) { str << "\n"; printspace(str, (cnt = _max(30, baselen)), " "); @@ -310,7 +308,7 @@ void mjXSchema::Print(std::stringstream& str, int level) { str << "\n"; // children - for (i=0; i<(int)child.size(); i++) { + for (int i=0; i<(int)child.size(); i++) { child[i]->Print(str, level+1); } } @@ -319,8 +317,6 @@ void mjXSchema::Print(std::stringstream& str, int level) { // print schema as HTML table void mjXSchema::PrintHTML(std::stringstream& str, int level, bool pad) { - int i; - // replace body with (world)body string name1 = (name=="body" ? "(world)body" : name); @@ -350,7 +346,7 @@ void mjXSchema::PrintHTML(std::stringstream& str, int level, bool pad) { // attributes str << "\t"; if (!attr.empty()) { - for (i=0; i<(int)attr.size(); i++) { + for (int i=0; i<(int)attr.size(); i++) { str << attr[i] << " "; } } else { @@ -359,7 +355,7 @@ void mjXSchema::PrintHTML(std::stringstream& str, int level, bool pad) { str << "\n\n"; // children - for (i=0; i<(int)child.size(); i++) { + for (int i=0; i<(int)child.size(); i++) { child[i]->PrintHTML(str, level+1, pad); } @@ -394,7 +390,6 @@ bool mjXSchema::NameMatch(XMLElement* elem, int level) { // validator XMLElement* mjXSchema::Check(XMLElement* elem, int level) { - int i; bool missing; char msg[100]; XMLElement *bad, *sub; @@ -414,7 +409,7 @@ XMLElement* mjXSchema::Check(XMLElement* elem, int level) { const XMLAttribute* attribute = elem->FirstAttribute(); while (attribute) { missing = true; - for (i=0; i<(int)attr.size(); i++) { + for (int i=0; i<(int)attr.size(); i++) { if (attr[i]==attribute->Name()) { missing = false; break; @@ -445,7 +440,7 @@ XMLElement* mjXSchema::Check(XMLElement* elem, int level) { } // clear reference counts - for (i=0; i<(int)child.size(); i++) { + for (int i=0; i<(int)child.size(); i++) { child[i]->refcnt = 0; } @@ -454,7 +449,7 @@ XMLElement* mjXSchema::Check(XMLElement* elem, int level) { while (sub) { // find in child array, update refcnt missing = true; - for (i=0; i<(int)child.size(); i++) { + for (int i=0; i<(int)child.size(); i++) { if (child[i]->NameMatch(sub, level+1)) { // check sub-tree if ((bad = child[i]->Check(sub, level+1))) { @@ -481,7 +476,7 @@ XMLElement* mjXSchema::Check(XMLElement* elem, int level) { // enforce sub-element types msg[0] = 0; - for (i=0; i<(int)child.size(); i++) { + for (int i=0; i<(int)child.size(); i++) { switch (child[i]->type) { case '!': if (child[i]->refcnt != 1) diff --git a/test/engine/engine_util_solve_test.cc b/test/engine/engine_util_solve_test.cc index dd649f26..0448e39a 100644 --- a/test/engine/engine_util_solve_test.cc +++ b/test/engine/engine_util_solve_test.cc @@ -92,8 +92,7 @@ bool isQPminimum(const mjtNum* res, const mjtNum* H, const mjtNum* g, int n, // compare to nudged solution mju_copy(res_nudge, res, n); - int i; - for (i=0; i < n; i++) { + for (int i=0; i < n; i++) { // nudge down res_nudge[i] = res[i] - eps; if (lower) {