Encapsulate mjCModel internal lists.

PiperOrigin-RevId: 631760335
Change-Id: I9b67f6ed2e65a01877de15a92a04a1b31a6b3ff4
This commit is contained in:
Kyle Bayes
2024-05-08 05:01:13 -07:00
committed by Copybara-Service
parent 96844db926
commit 13bf9ae6bd
9 changed files with 809 additions and 821 deletions
+5 -5
View File
@@ -429,8 +429,8 @@ mjsPlugin* mjs_addPlugin(mjSpec* s) {
// add default to model
mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, int parentid, int* id) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
*id = (int)modelC->defaults.size();
mjCDef* def = modelC->AddDef(classname, parentid);
*id = (int)modelC->Defaults().size();
mjCDef* def = modelC->AddDefault(classname, parentid);
if (def) {
return &def->spec;
} else {
@@ -457,7 +457,7 @@ mjsDefault* mjs_getDefault(mjElement* element) {
// Find default with given name in model.
mjsDefault* mjs_findDefault(mjSpec* s, const char* classname) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjCDef* cdef = modelC->FindDef(classname);
mjCDef* cdef = modelC->FindDefault(classname);
if (!cdef) {
return nullptr;
}
@@ -469,7 +469,7 @@ mjsDefault* mjs_findDefault(mjSpec* s, const char* classname) {
// get default[0] from model
mjsDefault* mjs_getSpecDefault(mjSpec* s) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjCDef* def = modelC->defaults[0];
mjCDef* def = modelC->Defaults()[0];
if (!def) {
return nullptr;
}
@@ -677,7 +677,7 @@ void mjs_setActivePlugins(mjSpec* s, void* activeplugins) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
std::vector<std::pair<const mjpPlugin*, int>>* active_plugins =
reinterpret_cast<std::vector<std::pair<const mjpPlugin*, int>>*>(activeplugins);
modelC->active_plugins = std::move(*active_plugins);
modelC->SetActivePlugins(std::move(*active_plugins));
}
+11 -11
View File
@@ -561,7 +561,7 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjsBody* body, char* error, int
// create tendon
mjsTendon* ten = mjs_addTendon(&model->spec, &def[mjCOMPKIND_TENDON].spec);
mjs_setDefault(ten->element, &model->defaults[0]->spec);
mjs_setDefault(ten->element, &model->Defaults()[0]->spec);
mjs_setString(ten->name, txt0);
ten->group = 4;
mjs_wrapSite(ten, txt1);
@@ -569,7 +569,7 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjsBody* body, char* error, int
// add equality constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_TENDON].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_TENDON;
mjs_setString(eq->name1, mjs_getString(ten->name));
}
@@ -675,7 +675,7 @@ bool mjCComposite::MakeGrid(mjCModel* model, mjsBody* body, char* error, int err
// create tendon
mjCTendon* ten = model->AddTendon(def + mjCOMPKIND_TENDON);
ten->def = model->defaults[0];
ten->def = model->Defaults()[0];
mju::sprintf_arr(txt, "%sT%d_%d_%d", prefix.c_str(), i, ix, iy);
ten->name = txt;
ten->WrapSite(txt1);
@@ -683,7 +683,7 @@ bool mjCComposite::MakeGrid(mjCModel* model, mjsBody* body, char* error, int err
// add equality constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_TENDON].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_TENDON;
mjs_setString(eq->name1, ten->name.c_str());
}
@@ -1045,7 +1045,7 @@ mjsBody* mjCComposite::AddRopeBody(mjCModel* model, mjsBody* body, int ix, int i
// add constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_TWIST].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_JOINT;
mjs_setString(eq->name1, mjs_getString(jnt->name));
}
@@ -1063,7 +1063,7 @@ mjsBody* mjCComposite::AddRopeBody(mjCModel* model, mjsBody* body, int ix, int i
// add constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_STRETCH].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_JOINT;
mjs_setString(eq->name1, mjs_getString(jnt->name));
}
@@ -1131,7 +1131,7 @@ bool mjCComposite::MakeBox(mjCModel* model, mjsBody* body, char* error, int erro
// fixed tendon for all joints
mjCTendon* ten = model->AddTendon(def + mjCOMPKIND_TENDON);
ten->def = model->defaults[0];
ten->def = model->Defaults()[0];
mju::sprintf_arr(txt, "%sT", prefix.c_str());
ten->name = txt;
@@ -1184,7 +1184,7 @@ bool mjCComposite::MakeBox(mjCModel* model, mjsBody* body, char* error, int erro
// add fix constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_JOINT].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_JOINT;
mjs_setString(eq->name1, mjs_getString(jnt->name));
@@ -1218,7 +1218,7 @@ bool mjCComposite::MakeBox(mjCModel* model, mjsBody* body, char* error, int erro
// finalize fixed tendon
mjsEquality* eqt = mjs_addEquality(&model->spec, &def[mjCOMPKIND_TENDON].spec);
mjs_setDefault(eqt->element, &model->defaults[0]->spec);
mjs_setDefault(eqt->element, &model->Defaults()[0]->spec);
eqt->type = mjEQ_TENDON;
mjs_setString(eqt->name1, ten->name.c_str());
@@ -1244,7 +1244,7 @@ void mjCComposite::MakeShear(mjCModel* model) {
// create tendon
mjCTendon* ten = model->AddTendon(def + mjCOMPKIND_SHEAR);
ten->def = model->defaults[0];
ten->def = model->Defaults()[0];
ten->WrapSite(txt1);
ten->WrapSite(txt2);
@@ -1254,7 +1254,7 @@ void mjCComposite::MakeShear(mjCModel* model) {
// equality constraint
mjsEquality* eq = mjs_addEquality(&model->spec, &def[mjCOMPKIND_SHEAR].spec);
mjs_setDefault(eq->element, &model->defaults[0]->spec);
mjs_setDefault(eq->element, &model->Defaults()[0]->spec);
eq->type = mjEQ_TENDON;
mjs_setString(eq->name1, txt);
}
+1 -1
View File
@@ -521,7 +521,7 @@ bool mjCFlexcomp::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) {
// create edge equality constraint
if (equality) {
mjsEquality* pe = mjs_addEquality(&model->spec, &def.spec);
mjs_setDefault(pe->element, &model->defaults[0]->spec);
mjs_setDefault(pe->element, &model->Defaults()[0]->spec);
pe->type = mjEQ_FLEX;
pe->active = true;
mjs_setString(pe->name1, name.c_str());
+5 -5
View File
@@ -151,7 +151,7 @@ mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// in case this body is not compiled
CopyFromSpec();
@@ -2560,12 +2560,12 @@ void mjCFlex::Compile(const mjVFS* vfs) {
for (int i=0; i < nvert; i++) {
// get body id, set vertxpos = body.xpos0
int b = rigid ? vertbodyid[0] : vertbodyid[i];
mju_copy3(vertxpos.data()+3*i, model->bodies[b]->xpos0);
mju_copy3(vertxpos.data()+3*i, model->Bodies()[b]->xpos0);
// add vertex offset within body if not centered
if (!centered) {
mjtNum offset[3];
mju_rotVecQuat(offset, vert_.data()+3*i, model->bodies[b]->xquat0);
mju_rotVecQuat(offset, vert_.data()+3*i, model->Bodies()[b]->xquat0);
mju_addTo3(vertxpos.data()+3*i, offset);
}
}
@@ -2631,9 +2631,9 @@ void mjCFlex::Compile(const mjVFS* vfs) {
mjXUtil::Vector2String(useredge, edgeidx);
for (const auto& vbodyid : vertbodyid) {
if (model->bodies[vbodyid]->plugin.instance) {
if (model->Bodies()[vbodyid]->plugin.instance) {
mjCPlugin* plugin_instance =
static_cast<mjCPlugin*>(model->bodies[vbodyid]->plugin.instance);
static_cast<mjCPlugin*>(model->Bodies()[vbodyid]->plugin.instance);
plugin_instance->config_attribs["face"] = userface;
plugin_instance->config_attribs["edge"] = useredge;
}
+576 -618
View File
File diff suppressed because it is too large Load Diff
+85 -55
View File
@@ -192,14 +192,6 @@ class mjCModel : public mjCModel_, private mjSpec {
mjCKey* AddKey();
mjCPlugin* AddPlugin();
// copy vector of elements to this model
template <class T> void CopyList(std::vector<T*>& dest,
const std::vector<T*>& source,
std::map<mjCDef*, int>& def_map,
const std::vector<mjCDef*>& defaults);
// delete from list the elements that are compatible with other but not this model
template <class T> void RemoveFromList(std::vector<T*>& list, const mjCModel& other);
// delete elements marked as discard=true
template <class T> void Delete(std::vector<T*>& elements,
@@ -214,43 +206,58 @@ class mjCModel : public mjCModel_, private mjSpec {
// API for access to other variables
bool IsCompiled() const; // is model already compiled
const mjCError& GetError(void) const; // get reference of error object
mjCBody* GetWorld() const; // pointer to world body
mjCDef* FindDef(std::string name) const; // find default class name
mjCDef* AddDef(std::string name, int parentid); // add default class to array
const mjCError& GetError() const; // get reference of error object
mjCBody* GetWorld(); // pointer to world body
mjCDef* FindDefault(std::string name); // find defaults class name
mjCDef* AddDefault(std::string name, int parentid); // add defaults class to array
mjCBase* FindObject(mjtObj type, std::string name) const; // find object given type and name
mjCBody* FindBody(mjCBody* body, std::string name) const; // find body given name
mjCBody* FindBody(mjCBody* body, std::string name); // find body given name
mjCFrame* FindFrame(mjCBody* body, std::string name) const; // find frame given name
bool IsNullPose(const mjtNum* pos, const mjtNum* quat) const; // detect null pose
void SetActivePlugins(const std::vector<std::pair<const mjpPlugin*, int>>&& active_plugins) {
active_plugins_ = std::move(active_plugins);
}
// accessors
std::string get_meshdir(void) const { return meshdir_; }
std::string get_texturedir(void) const { return texturedir_; }
std::string get_meshdir() const { return meshdir_; }
std::string get_texturedir() const { return texturedir_; }
const std::vector<mjCDef*>& Defaults() const { return defaults_; }
const std::vector<std::pair<const mjpPlugin*, int>>& ActivePlugins() const {
return active_plugins_;
};
const std::vector<mjCFlex*>& Flexes() const { return flexes_; }
const std::vector<mjCMesh*>& Meshes() const {return meshes_; }
const std::vector<mjCSkin*>& Skins() const { return skins_; }
const std::vector<mjCHField*>& HFields() const { return hfields_; }
const std::vector<mjCTexture*>& Textures() const { return textures_; }
const std::vector<mjCMaterial*>& Materials() const { return materials_; }
const std::vector<mjCPair*>& Pairs() const { return pairs_; }
const std::vector<mjCBodyPair*>& Excludes() const { return excludes_; }
const std::vector<mjCEquality*>& Equalities() const { return equalities_; }
const std::vector<mjCTendon*>& Tendons() const { return tendons_; }
const std::vector<mjCActuator*>& Actuators() const { return actuators_; }
const std::vector<mjCSensor*>& Sensors() const { return sensors_; }
const std::vector<mjCNumeric*>& Numerics() const { return numerics_; }
const std::vector<mjCText*>& Texts() const { return texts_; }
const std::vector<mjCTuple*>& Tuples() const { return tuples_; }
const std::vector<mjCKey*>& Keys() const { return keys_; }
const std::vector<mjCPlugin*>& Plugins() const { return plugins_; }
const std::vector<mjCBody*>& Bodies() const { return bodies_; }
const std::vector<mjCGeom*>& Geoms() const { return geoms_; }
// resolve plugin instance, create a new one if needed
void ResolvePlugin(mjCBase* obj, const std::string& plugin_name,
const std::string& plugin_instance_name,
mjCPlugin** plugin_instance);
// settings for each defaults class
std::vector<mjCDef*> defaults;
// list of active plugins
std::vector<std::pair<const mjpPlugin*, int>> active_plugins;
private:
void TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs);
mjModel* _Compile(const mjVFS* vfs);
// clear objects allocated by Compile
void Clear(void);
// add object of any type
template <class T> T* AddObject(std::vector<T*>& list, std::string type);
// add object of any type, with def parameter
template <class T> T* AddObjectDef(std::vector<T*>& list, std::string type,
mjCDef* def);
void Clear();
// if asset name is missing, set to filename
template<class T> void SetDefaultNames(std::vector<T*>& assets);
@@ -259,6 +266,13 @@ class mjCModel : public mjCModel_, private mjSpec {
template <class T> void DeleteMaterial(std::vector<T*>& list,
std::string_view name = "");
private:
// settings for each defaults class
std::vector<mjCDef*> defaults_;
// list of active plugins
std::vector<std::pair<const mjpPlugin*, int>> active_plugins_;
// compile phases
void MakeLists(mjCBody* body); // make lists of bodies, geoms, joints, sites
void SetNuser(); // set nuser fields
@@ -273,35 +287,51 @@ class mjCModel : public mjCModel_, private mjSpec {
void CopyTree(mjModel*); // copy objects inside kinematic tree
// objects created here
std::vector<mjCFlex*> flexes; // list of flexes
std::vector<mjCMesh*> meshes; // list of meshes
std::vector<mjCSkin*> skins; // list of skins
std::vector<mjCHField*> hfields; // list of height fields
std::vector<mjCTexture*> textures; // list of textures
std::vector<mjCMaterial*> materials; // list of materials
std::vector<mjCPair*> pairs; // list of geom pairs to include
std::vector<mjCBodyPair*> excludes; // list of body pairs to exclude
std::vector<mjCEquality*> equalities; // list of equality constraints
std::vector<mjCTendon*> tendons; // list of tendons
std::vector<mjCActuator*> actuators; // list of actuators
std::vector<mjCSensor*> sensors; // list of sensors
std::vector<mjCNumeric*> numerics; // list of numeric fields
std::vector<mjCText*> texts; // list of text fields
std::vector<mjCTuple*> tuples; // list of tuple fields
std::vector<mjCKey*> keys; // list of keyframe fields
std::vector<mjCPlugin*> plugins; // list of plugin instances
std::vector<mjCFlex*> flexes_; // list of flexes
std::vector<mjCMesh*> meshes_; // list of meshes
std::vector<mjCSkin*> skins_; // list of skins
std::vector<mjCHField*> hfields_; // list of height fields
std::vector<mjCTexture*> textures_; // list of textures
std::vector<mjCMaterial*> materials_; // list of materials
std::vector<mjCPair*> pairs_; // list of geom pairs to include
std::vector<mjCBodyPair*> excludes_; // list of body pairs to exclude
std::vector<mjCEquality*> equalities_; // list of equality constraints
std::vector<mjCTendon*> tendons_; // list of tendons
std::vector<mjCActuator*> actuators_; // list of actuators
std::vector<mjCSensor*> sensors_; // list of sensors
std::vector<mjCNumeric*> numerics_; // list of numeric fields
std::vector<mjCText*> texts_; // list of text fields
std::vector<mjCTuple*> tuples_; // list of tuple fields
std::vector<mjCKey*> keys_; // list of keyframe fields
std::vector<mjCPlugin*> plugins_; // list of plugin instances
// pointers to objects created inside kinematic tree
std::vector<mjCBody*> bodies; // list of bodies
std::vector<mjCJoint*> joints; // list of joints allowing motion relative to parent
std::vector<mjCGeom*> geoms; // list of geoms attached to this body
std::vector<mjCSite*> sites; // list of sites attached to this body
std::vector<mjCCamera*> cameras; // list of cameras
std::vector<mjCLight*> lights; // list of lights
std::vector<mjCFrame*> frames; // list of frames
std::vector<mjCBody*> bodies_; // list of bodies
std::vector<mjCJoint*> joints_; // list of joints allowing motion relative to parent
std::vector<mjCGeom*> geoms_; // list of geoms attached to this body
std::vector<mjCSite*> sites_; // list of sites attached to this body
std::vector<mjCCamera*> cameras_; // list of cameras
std::vector<mjCLight*> lights_; // list of lights
std::vector<mjCFrame*> frames_; // list of frames
// array of pointers to each object list (enumerated by type)
std::array<std::vector<mjCBase*>*, mjNOBJECT> object_lists;
std::array<std::vector<mjCBase*>*, mjNOBJECT> object_lists_;
// add object of any type
template <class T> T* AddObject(std::vector<T*>& list, std::string type);
// add object of any type, with defaults parameter
template <class T> T* AddObjectDefault(std::vector<T*>& list, std::string type,
mjCDef* def);
// copy vector of elements to this model
template <class T> void CopyList(std::vector<T*>& dest,
const std::vector<T*>& sources,
std::map<mjCDef*, int>& def_map,
const std::vector<mjCDef*>& defaults);
// delete from list the elements that are compatible with other but not this model
template <class T> void RemoveFromList(std::vector<T*>& list, const mjCModel& other);
// create mjCBase lists from children lists
void CreateObjectLists();
+15 -15
View File
@@ -1497,7 +1497,7 @@ void mjCBody::Compile(void) {
// compute body global pose (no joint transformations in qpos0)
if (id>0) {
mjCBody* par = model->bodies[parentid];
mjCBody* par = model->Bodies()[parentid];
mju_rotVecQuat(xpos0, pos, par->xquat0);
mju_addTo3(xpos0, par->xpos0);
mju_mulQuat(xquat0, par->xquat0, quat);
@@ -1679,7 +1679,7 @@ mjCJoint::mjCJoint(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -1883,7 +1883,7 @@ mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -1969,7 +1969,7 @@ double mjCGeom::GetVolume(void) {
// get from mesh
if (type==mjGEOM_MESH || type==mjGEOM_SDF) {
if (mesh->id<0 || !((std::size_t) mesh->id <= model->meshes.size())) {
if (mesh->id<0 || !((std::size_t) mesh->id <= model->Meshes().size())) {
throw mjCError(this, "invalid mesh id in mesh geom");
}
@@ -2022,7 +2022,7 @@ void mjCGeom::SetInertia(void) {
// get from mesh
if (type==mjGEOM_MESH || type==mjGEOM_SDF) {
if (mesh->id<0 || !((std::size_t) mesh->id <= model->meshes.size())) {
if (mesh->id<0 || !((std::size_t) mesh->id <= model->Meshes().size())) {
throw mjCError(this, "invalid mesh id in mesh geom");
}
@@ -2523,7 +2523,7 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
}
@@ -2669,7 +2669,7 @@ mjCCamera::mjCCamera(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -2823,7 +2823,7 @@ mjCLight::mjCLight(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
PointToLocal();
CopyFromSpec();
@@ -3860,7 +3860,7 @@ mjCMaterial::mjCMaterial(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -3948,7 +3948,7 @@ mjCPair::mjCPair(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -4309,7 +4309,7 @@ mjCEquality::mjCEquality(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -4444,7 +4444,7 @@ void mjCEquality::Compile(void) {
ResolveReferences(model);
// make sure flex is not rigid
if (type==mjEQ_FLEX && model->flexes[obj1id]->rigid) {
if (type==mjEQ_FLEX && model->Flexes()[obj1id]->rigid) {
throw mjCError(this, "rigid flex '%s' in equality constraint %d", name1_.c_str(), id);
}
}
@@ -4471,7 +4471,7 @@ mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// point to local
PointToLocal();
@@ -4763,7 +4763,7 @@ void mjCTendon::Compile(void) {
}
// mark geoms as non visual
model->geoms[path[i]->obj->id]->SetNotVisual();
model->Geoms()[path[i]->obj->id]->SetNotVisual();
break;
case mjWRAP_JOINT:
@@ -4950,7 +4950,7 @@ mjCActuator::mjCActuator(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
def = (_def ? _def : (_model ? _model->defaults[0] : 0));
def = (_def ? _def : (_model ? _model->Defaults()[0] : 0));
// in case this actuator is not compiled
CopyFromSpec();
+99 -99
View File
@@ -107,8 +107,8 @@ class mjCBoundingVolume {
void SetId(int val) { idval_ = val; }
private:
int idval_; // local id copy for nodes not storing their id's (e.g. faces)
const int* id_; // pointer to object id
int idval_; // local id copy for nodes not storing their id's (e.g. faces)
const int* id_; // pointer to object id
};
@@ -354,6 +354,10 @@ class mjCFrame : public mjCFrame_, private mjsFrame {
friend class mjCModel;
public:
mjCFrame(mjCModel* = 0, mjCFrame* = 0);
mjCFrame(const mjCFrame& other);
mjCFrame& operator=(const mjCFrame& other);
mjsFrame spec;
using mjCBase::name;
using mjCBase::classname;
@@ -368,9 +372,6 @@ class mjCFrame : public mjCFrame_, private mjsFrame {
bool IsAncestor(const mjCFrame* child) const; // true if child is contained in this frame
private:
mjCFrame(mjCModel* = 0, mjCFrame* = 0); // constructor
mjCFrame(const mjCFrame& other); // copy constructor
mjCFrame& operator=(const mjCFrame& other); // copy assignment
void Compile(void); // compiler
mjCBody* body; // body that owns the frame
@@ -400,6 +401,10 @@ class mjCJoint : public mjCJoint_, private mjsJoint {
friend class mjXURDF;
public:
mjCJoint(mjCModel* = nullptr, mjCDef* = nullptr);
mjCJoint(const mjCJoint& other);
mjCJoint& operator=(const mjCJoint& other);
mjsJoint spec;
using mjCBase::name;
using mjCBase::classname;
@@ -416,10 +421,6 @@ class mjCJoint : public mjCJoint_, private mjsJoint {
private:
mjCJoint(mjCModel* = 0, mjCDef* = 0);
mjCJoint(const mjCJoint& other); // copy constructor
mjCJoint& operator=(const mjCJoint& other); // copy assignment
int Compile(void); // compiler; return dofnum
void PointToLocal(void);
};
@@ -468,6 +469,10 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
friend class mjXURDF;
public:
mjCGeom(mjCModel* = nullptr, mjCDef* = nullptr);
mjCGeom(const mjCGeom& other);
mjCGeom& operator=(const mjCGeom& other);
using mjCBase::name;
mjsGeom spec; // variables set by user
double GetVolume(void); // compute geom volume
@@ -491,10 +496,6 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
void del_material() { spec_material_.clear(); }
private:
mjCGeom(mjCModel* = 0, mjCDef* = 0);
mjCGeom(const mjCGeom& other); // copy constructor
mjCGeom& operator=(const mjCGeom& other); // copy assignment
void Compile(void); // compiler
double GetRBound(void); // compute bounding sphere radius
void ComputeAABB(void); // compute axis-aligned bounding box
@@ -533,6 +534,10 @@ class mjCSite : public mjCSite_, private mjsSite {
friend class mjXURDF;
public:
mjCSite(mjCModel* = nullptr, mjCDef* = nullptr);
mjCSite(const mjCSite& other);
mjCSite& operator=(const mjCSite& other);
mjsSite spec; // variables set by user
// use strings from mjCBase rather than mjStrings from mjsSite
@@ -546,10 +551,6 @@ class mjCSite : public mjCSite_, private mjsSite {
void del_material() { material_.clear(); }
private:
mjCSite(mjCModel* = 0, mjCDef* = 0); // constructor
mjCSite(const mjCSite& other); // copy constructor
mjCSite& operator=(const mjCSite& other); // copy assignment
void Compile(void); // compiler
void CopyFromSpec(); // copy spec into attributes
void PointToLocal(void);
@@ -578,6 +579,10 @@ class mjCCamera : public mjCCamera_, private mjsCamera {
friend class mjXWriter;
public:
mjCCamera(mjCModel* = nullptr, mjCDef* = nullptr);
mjCCamera(const mjCCamera& other);
mjCCamera& operator=(const mjCCamera& other);
mjsCamera spec;
using mjCBase::name;
using mjCBase::classname;
@@ -588,10 +593,6 @@ class mjCCamera : public mjCCamera_, private mjsCamera {
const std::vector<double>& get_userdata() { return userdata_; }
private:
mjCCamera(mjCModel* = 0, mjCDef* = 0); // constructor
mjCCamera(const mjCCamera& other); // copy constructor
mjCCamera& operator=(const mjCCamera& other); // copy assignment
void Compile(void); // compiler
void CopyFromSpec(void);
void PointToLocal(void);
@@ -618,6 +619,10 @@ class mjCLight : public mjCLight_, private mjsLight {
friend class mjXWriter;
public:
mjCLight(mjCModel* = nullptr, mjCDef* = nullptr);
mjCLight(const mjCLight& other);
mjCLight& operator=(const mjCLight& other);
mjsLight spec;
using mjCBase::name;
using mjCBase::classname;
@@ -627,10 +632,6 @@ class mjCLight : public mjCLight_, private mjsLight {
const std::string& get_targetbody() { return targetbody_; }
private:
mjCLight(mjCModel* = 0, mjCDef* = 0); // constructor
mjCLight(const mjCLight& other); // copy constructor
mjCLight& operator=(const mjCLight& other); // copy assignment
void Compile(void); // compiler
void CopyFromSpec(void);
void PointToLocal(void);
@@ -681,6 +682,10 @@ class mjCFlex: public mjCFlex_, private mjsFlex {
friend class mjXWriter;
public:
mjCFlex(mjCModel* = nullptr);
mjCFlex(const mjCFlex& other);
mjCFlex& operator=(const mjCFlex& other);
mjsFlex spec;
using mjCBase::name;
using mjCBase::classname;
@@ -703,10 +708,6 @@ class mjCFlex: public mjCFlex_, private mjsFlex {
void DelTexcoord(); // delete texcoord
private:
mjCFlex(mjCModel* = 0);
mjCFlex(const mjCFlex& other); // copy constructor
mjCFlex& operator=(const mjCFlex& other); // copy assignment
void Compile(const mjVFS* vfs); // compiler
void CreateBVH(void); // create flex BVH
void CreateShellPair(void); // create shells and evpairs
@@ -779,9 +780,9 @@ class mjCMesh: public mjCMesh_, private mjsMesh {
friend class mjCFlexcomp;
friend class mjXWriter;
public:
mjCMesh(mjCModel* = 0, mjCDef* = 0);
mjCMesh(const mjCMesh& other); // copy constructor
mjCMesh& operator=(const mjCMesh& other); // copy assignment
mjCMesh(mjCModel* = nullptr, mjCDef* = nullptr);
mjCMesh(const mjCMesh& other);
mjCMesh& operator=(const mjCMesh& other);
~mjCMesh();
mjsMesh spec;
@@ -910,6 +911,11 @@ class mjCSkin: public mjCSkin_, private mjsSkin {
friend class mjXWriter;
public:
mjCSkin(mjCModel* = nullptr);
mjCSkin(const mjCSkin& other);
mjCSkin& operator=(const mjCSkin& other);
~mjCSkin();
mjsSkin spec;
using mjCBase::name;
using mjCBase::classname;
@@ -931,11 +937,6 @@ class mjCSkin: public mjCSkin_, private mjsSkin {
void PointToLocal();
private:
mjCSkin(mjCModel* = 0); // constructor
mjCSkin(const mjCSkin& other); // copy constructor
mjCSkin& operator=(const mjCSkin& other); // copy assignment
~mjCSkin(); // destructor
void ResolveReferences(const mjCModel* m);
void NameSpace(const mjCModel* m);
void Compile(const mjVFS* vfs); // compiler
@@ -965,6 +966,11 @@ class mjCHField : public mjCHField_, private mjsHField {
friend class mjXWriter;
public:
mjCHField(mjCModel* model);
mjCHField(const mjCHField& other);
mjCHField& operator=(const mjCHField& other);
~mjCHField();
mjsHField spec;
using mjCBase::name;
using mjCBase::info;
@@ -978,11 +984,6 @@ class mjCHField : public mjCHField_, private mjsHField {
std::vector<float>& get_userdata() { return userdata_; }
private:
mjCHField(mjCModel* model); // constructor
mjCHField(const mjCHField& other); // copy constructor
mjCHField& operator=(const mjCHField& other); // copy assignment
~mjCHField(); // destructor
void Compile(const mjVFS* vfs); // compiler
void LoadCustom(mjResource* resource); // load from custom format
@@ -1012,7 +1013,10 @@ class mjCTexture : public mjCTexture_, private mjsTexture {
friend class mjXWriter;
public:
~mjCTexture(); // destructor
mjCTexture(mjCModel*);
mjCTexture(const mjCTexture& other);
mjCTexture& operator=(const mjCTexture& other);
~mjCTexture();
mjsTexture spec;
using mjCBase::name;
@@ -1027,10 +1031,6 @@ class mjCTexture : public mjCTexture_, private mjsTexture {
std::vector<std::string> get_cubefiles() const { return cubefiles_; }
private:
mjCTexture(mjCModel*); // constructor
mjCTexture(const mjCTexture& other); // copy constructor
mjCTexture& operator=(const mjCTexture& other); // copy assignment
void Compile(const mjVFS* vfs); // compiler
void Builtin2D(void); // make builtin 2D
@@ -1069,6 +1069,10 @@ class mjCMaterial : public mjCMaterial_, private mjsMaterial {
friend class mjXWriter;
public:
mjCMaterial(mjCModel* = nullptr, mjCDef* = nullptr);
mjCMaterial(const mjCMaterial& other);
mjCMaterial& operator=(const mjCMaterial& other);
mjsMaterial spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1082,10 +1086,6 @@ class mjCMaterial : public mjCMaterial_, private mjsMaterial {
void del_texture() { texture_.clear(); }
private:
mjCMaterial(mjCModel* = 0, mjCDef* = 0); // constructor
mjCMaterial(const mjCMaterial& other); // copy constructor
mjCMaterial& operator=(const mjCMaterial& other); // copy assignment
void Compile(void); // compiler
};
@@ -1110,6 +1110,10 @@ class mjCPair : public mjCPair_, private mjsPair {
friend class mjXWriter;
public:
mjCPair(mjCModel* = nullptr, mjCDef* = nullptr);
mjCPair(const mjCPair& other);
mjCPair& operator=(const mjCPair& other);
mjsPair spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1128,10 +1132,6 @@ class mjCPair : public mjCPair_, private mjsPair {
}
private:
mjCPair(mjCModel* = 0, mjCDef* = 0); // constructor
mjCPair(const mjCPair& other); // copy constructor
mjCPair& operator=(const mjCPair& other); // copy assignment
void Compile(void); // compiler
mjCGeom* geom1; // geom1
@@ -1160,6 +1160,10 @@ class mjCBodyPair : public mjCBodyPair_, private mjsExclude {
friend class mjCModel;
public:
mjCBodyPair(mjCModel*);
mjCBodyPair(const mjCBodyPair& other);
mjCBodyPair& operator=(const mjCBodyPair& other);
mjsExclude spec;
using mjCBase::name;
using mjCBase::info;
@@ -1177,9 +1181,6 @@ class mjCBodyPair : public mjCBodyPair_, private mjsExclude {
}
private:
mjCBodyPair(mjCModel*); // constructor
mjCBodyPair(const mjCBodyPair& other); // copy constructor
mjCBodyPair& operator=(const mjCBodyPair& other); // copy assignment
void Compile(void); // compiler
};
@@ -1206,6 +1207,10 @@ class mjCEquality : public mjCEquality_, private mjsEquality {
friend class mjXWriter;
public:
mjCEquality(mjCModel* = 0, mjCDef* = 0);
mjCEquality(const mjCEquality& other);
mjCEquality& operator=(const mjCEquality& other);
mjsEquality spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1217,10 +1222,6 @@ class mjCEquality : public mjCEquality_, private mjsEquality {
void NameSpace(const mjCModel* m);
private:
mjCEquality(mjCModel* = 0, mjCDef* = 0); // constructor
mjCEquality(const mjCEquality& other); // copy constructor
mjCEquality& operator=(const mjCEquality& other); // copy assignment
void Compile(void); // compiler
};
@@ -1246,6 +1247,11 @@ class mjCTendon : public mjCTendon_, private mjsTendon {
friend class mjXWriter;
public:
mjCTendon(mjCModel* = nullptr, mjCDef* = nullptr);
mjCTendon(const mjCTendon& other);
mjCTendon& operator=(const mjCTendon& other);
~mjCTendon();
mjsTendon spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1279,11 +1285,6 @@ class mjCTendon : public mjCTendon_, private mjsTendon {
bool is_limited() const;
private:
mjCTendon(mjCModel* = 0, mjCDef* = 0); // constructor
mjCTendon(const mjCTendon& other); // copy constructor
mjCTendon& operator=(const mjCTendon& other); // copy assignment
~mjCTendon(); // destructor
void Compile(void); // compiler
};
@@ -1342,14 +1343,13 @@ class mjCPlugin : public mjCPlugin_ {
friend class mjXWriter;
public:
mjCPlugin(mjCModel*);
mjCPlugin(const mjCPlugin& other);
mjCPlugin& operator=(const mjCPlugin& other);
mjsPlugin spec;
mjCBase* parent; // parent object (only used when generating error message)
mjCPlugin(const mjCPlugin& other); // copy constructor
private:
mjCPlugin(mjCModel*); // constructor
mjCPlugin& operator=(const mjCPlugin& other); // copy assignment
void Compile(void); // compiler
};
@@ -1381,6 +1381,10 @@ class mjCActuator : public mjCActuator_, private mjsActuator {
friend class mjXWriter;
public:
mjCActuator(mjCModel* = nullptr, mjCDef* = nullptr);
mjCActuator(const mjCActuator& other);
mjCActuator& operator=(const mjCActuator& other);
mjsActuator spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1397,10 +1401,6 @@ class mjCActuator : public mjCActuator_, private mjsActuator {
bool is_actlimited() const;
private:
mjCActuator(mjCModel* = 0, mjCDef* = 0); // constructor
mjCActuator(const mjCActuator& other); // copy constructor
mjCActuator& operator=(const mjCActuator& other); // copy assignment
void Compile(void); // compiler
void CopyFromSpec();
void PointToLocal();
@@ -1436,6 +1436,10 @@ class mjCSensor : public mjCSensor_, private mjsSensor {
friend class mjXWriter;
public:
mjCSensor(mjCModel*);
mjCSensor(const mjCSensor& other);
mjCSensor& operator=(const mjCSensor& other);
mjsSensor spec;
using mjCBase::name;
using mjCBase::classname;
@@ -1447,10 +1451,6 @@ class mjCSensor : public mjCSensor_, private mjsSensor {
const std::string& get_refname() { return spec_refname_; }
private:
mjCSensor(mjCModel*); // constructor
mjCSensor(const mjCSensor& other); // copy constructor
mjCSensor& operator=(const mjCSensor& other); // copy assignment
void Compile(void); // compiler
void CopyFromSpec();
void PointToLocal();
@@ -1477,6 +1477,11 @@ class mjCNumeric : public mjCNumeric_, private mjsNumeric {
friend class mjXWriter;
public:
mjCNumeric(mjCModel*);
mjCNumeric(const mjCNumeric& other);
mjCNumeric& operator=(const mjCNumeric& other);
~mjCNumeric();
mjsNumeric spec;
using mjCBase::name;
using mjCBase::info;
@@ -1485,11 +1490,6 @@ class mjCNumeric : public mjCNumeric_, private mjsNumeric {
void CopyFromSpec();
private:
mjCNumeric(mjCModel*); // constructor
mjCNumeric(const mjCNumeric& other); // copy constructor
mjCNumeric& operator=(const mjCNumeric& other); // copy assignment
~mjCNumeric(); // destructor
void Compile(void); // compiler
};
@@ -1509,6 +1509,11 @@ class mjCText : public mjCText_, private mjsText {
friend class mjXWriter;
public:
mjCText(mjCModel*);
mjCText(const mjCText& other);
mjCText& operator=(const mjCText& other);
~mjCText();
mjsText spec;
using mjCBase::name;
using mjCBase::info;
@@ -1517,11 +1522,6 @@ class mjCText : public mjCText_, private mjsText {
void CopyFromSpec();
private:
mjCText(mjCModel*); // constructor
mjCText(const mjCText& other); // copy constructor
mjCText& operator=(const mjCText& other); // copy assignment
~mjCText(); // destructor
void Compile(void); // compiler
};
@@ -1546,6 +1546,11 @@ class mjCTuple : public mjCTuple_, private mjsTuple {
friend class mjXWriter;
public:
mjCTuple(mjCModel*);
mjCTuple(const mjCTuple& other);
mjCTuple& operator=(const mjCTuple& other);
~mjCTuple();
mjsTuple spec;
using mjCBase::name;
using mjCBase::info;
@@ -1556,11 +1561,6 @@ class mjCTuple : public mjCTuple_, private mjsTuple {
void NameSpace(const mjCModel* m);
private:
mjCTuple(mjCModel*); // constructor
mjCTuple(const mjCTuple& other); // copy constructor
mjCTuple& operator=(const mjCTuple& other); // copy assignment
~mjCTuple(); // destructor
void Compile(void); // compiler
};
@@ -1590,6 +1590,11 @@ class mjCKey : public mjCKey_, private mjsKey {
friend class mjXWriter;
public:
mjCKey(mjCModel*);
mjCKey(const mjCKey& other);
mjCKey& operator=(const mjCKey& other);
~mjCKey();
mjsKey spec;
using mjCBase::name;
using mjCBase::info;
@@ -1598,11 +1603,6 @@ class mjCKey : public mjCKey_, private mjsKey {
void CopyFromSpec();
private:
mjCKey(mjCModel*); // constructor
mjCKey(const mjCKey& other); // copy constructor
mjCKey& operator=(const mjCKey& other); // copy assignment
~mjCKey(); // destructor
void Compile(const mjModel* m); // compiler
};
+12 -12
View File
@@ -806,7 +806,7 @@ string mjXWriter::Write(char *error, size_t error_sz) {
Visual(root);
Statistic(root);
writingdefaults = true;
Default(root, model->defaults[0]);
Default(root, model->Defaults()[0]);
writingdefaults = false;
Extension(root);
Custom(root);
@@ -1136,7 +1136,7 @@ void mjXWriter::Default(XMLElement* root, mjCDef* def) {
// pointer to parent defaults
mjCDef* par;
if (def->parentid>=0) {
par = model->defaults[def->parentid];
par = model->Defaults()[def->parentid];
} else {
par = new mjCDef;
}
@@ -1209,7 +1209,7 @@ void mjXWriter::Default(XMLElement* root, mjCDef* def) {
// add children recursively
for (int i=0; i<(int)def->childid.size(); i++) {
Default(section, model->defaults[def->childid[i]]);
Default(section, model->Defaults()[def->childid[i]]);
}
// delete parent defaults if allocated here
@@ -1223,7 +1223,7 @@ void mjXWriter::Default(XMLElement* root, mjCDef* def) {
// extension section
void mjXWriter::Extension(XMLElement* root) {
// skip section if there is no required plugin
if (model->active_plugins.empty()) {
if (model->ActivePlugins().empty()) {
return;
}
@@ -1236,7 +1236,7 @@ void mjXWriter::Extension(XMLElement* root) {
// write all plugins
const mjpPlugin* last_plugin = nullptr;
XMLElement* plugin_elem = nullptr;
for (int i = 0; i < model->plugins.size(); ++i) {
for (int i = 0; i < model->Plugins().size(); ++i) {
mjCPlugin* pp = static_cast<mjCPlugin*>(model->GetObject(mjOBJ_PLUGIN, i));
if (pp->name.empty()) {
@@ -1273,7 +1273,7 @@ void mjXWriter::Extension(XMLElement* root) {
}
// write <plugin> elements for plugins without explicit instances
for (const auto& [plugin, slot] : model->active_plugins) {
for (const auto& [plugin, slot] : model->ActivePlugins()) {
if (seen_plugins.find(plugin) == seen_plugins.end()) {
plugin_elem = InsertEnd(section, "plugin");
WriteAttrTxt(plugin_elem, "plugin", plugin->name);
@@ -1755,7 +1755,7 @@ void mjXWriter::Sensor(XMLElement* root) {
// write all sensors
for (int i=0; i<num; i++) {
XMLElement* elem = 0;
mjCSensor* psen = model->sensors[i];
mjCSensor* psen = model->Sensors()[i];
std::string instance_name = "";
std::string plugin_name = "";
@@ -1994,7 +1994,7 @@ void mjXWriter::Keyframe(XMLElement* root) {
XMLElement* elem = InsertEnd(section, "key");
bool change = false;
mjCKey* pk = model->keys[i];
mjCKey* pk = model->Keys()[i];
// check name and write
if (!pk->name.empty()) {
@@ -2038,8 +2038,8 @@ void mjXWriter::Keyframe(XMLElement* root) {
// check mpos and write
if (model->nmocap) {
for (int j=0; j<model->nbody; j++) {
if (model->bodies[j]->mocap) {
mjCBody* pb = model->bodies[j];
if (model->Bodies()[j]->mocap) {
mjCBody* pb = model->Bodies()[j];
int id = pb->mocapid;
if (pb->pos[0] != pk->mpos_[3*id] ||
pb->pos[1] != pk->mpos_[3*id+1] ||
@@ -2055,8 +2055,8 @@ void mjXWriter::Keyframe(XMLElement* root) {
// check mquat and write
if (model->nmocap) {
for (int j=0; j<model->nbody; j++) {
if (model->bodies[j]->mocap) {
mjCBody* pb = model->bodies[j];
if (model->Bodies()[j]->mocap) {
mjCBody* pb = model->Bodies()[j];
int id = pb->mocapid;
if (pb->quat[0] != pk->mquat_[4*id] ||
pb->quat[1] != pk->mquat_[4*id+1] ||