Clean up mjCModel definition.
PiperOrigin-RevId: 611102699 Change-Id: I64a3927c30f16764742966f4c5e1e0e579af5f50
This commit is contained in:
committed by
Copybara-Service
parent
789188d51d
commit
b2bd377bad
+60
-65
@@ -15,6 +15,7 @@
|
||||
#ifndef MUJOCO_SRC_USER_USER_MODEL_H_
|
||||
#define MUJOCO_SRC_USER_USER_MODEL_H_
|
||||
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -32,16 +33,12 @@
|
||||
typedef std::map<std::string, int, std::less<> > mjKeyMap;
|
||||
typedef std::array<mjKeyMap, mjNOBJECT> mjListKeyMap;
|
||||
|
||||
|
||||
|
||||
//---------------------------------- class mjCModel ------------------------------------------------
|
||||
// mjCModel contains everything needed to generate the low-level model.
|
||||
// It can be constructed manually by calling 'Add' functions and setting
|
||||
// the public fields of the various objects. Alternatively it can constructed
|
||||
// by loading an XML file via mjCXML. Once an mjCModel object is
|
||||
// constructed, 'Compile' can be called to generate the corresponding mjModel object
|
||||
// (which is the low-level model). The mjCModel object can then be deleted.
|
||||
|
||||
class mjCModel : private mjmModel {
|
||||
friend class mjCBody;
|
||||
friend class mjCCamera;
|
||||
@@ -63,98 +60,99 @@ class mjCModel : private mjmModel {
|
||||
friend class mjXWriter;
|
||||
|
||||
public:
|
||||
mjCModel(); // constructor
|
||||
~mjCModel(); // destructor
|
||||
mjCModel();
|
||||
~mjCModel();
|
||||
void CopyFromSpec(); // copy spec to private attributes
|
||||
void PointToLocal();
|
||||
|
||||
mjmModel spec;
|
||||
|
||||
mjModel* Compile(const mjVFS* vfs = 0); // COMPILER: construct mjModel
|
||||
mjModel* Compile(const mjVFS* vfs = nullptr); // construct mjModel
|
||||
bool CopyBack(const mjModel*); // DECOMPILER: copy numeric back
|
||||
void FuseStatic(void); // fuse static bodies with parent
|
||||
void FuseStatic(); // fuse static bodies with parent
|
||||
void FuseReindex(mjCBody* body); // reindex elements during fuse
|
||||
|
||||
// API for adding model elements
|
||||
mjCFlex* AddFlex();
|
||||
mjCMesh* AddMesh(mjCDef* def = nullptr);
|
||||
mjCSkin* AddSkin();
|
||||
mjCHField* AddHField();
|
||||
mjCTexture* AddTexture();
|
||||
mjCMaterial* AddMaterial(mjCDef* def = nullptr);
|
||||
mjCPair* AddPair(mjCDef* def = nullptr); // geom pair for inclusion
|
||||
mjCBodyPair* AddExclude(); // body pair for exclusion
|
||||
mjCEquality* AddEquality(mjCDef* def = nullptr); // equality constraint
|
||||
mjCTendon* AddTendon(mjCDef* def = nullptr);
|
||||
mjCActuator* AddActuator(mjCDef* def = nullptr);
|
||||
mjCSensor* AddSensor();
|
||||
mjCNumeric* AddNumeric();
|
||||
mjCText* AddText();
|
||||
mjCTuple* AddTuple();
|
||||
mjCKey* AddKey();
|
||||
mjCPlugin* AddPlugin();
|
||||
|
||||
//------------------------ API for adding model elements
|
||||
mjCFlex* AddFlex(void); // flex
|
||||
mjCMesh* AddMesh(mjCDef* def = 0); // mesh
|
||||
mjCSkin* AddSkin(void); // skin
|
||||
mjCHField* AddHField(void); // heightfield
|
||||
mjCTexture* AddTexture(void); // texture
|
||||
mjCMaterial* AddMaterial(mjCDef* def = 0); // material
|
||||
mjCPair* AddPair(mjCDef* def = 0); // geom pair for inclusion
|
||||
mjCBodyPair* AddExclude(void); // body pair for exclusion
|
||||
mjCEquality* AddEquality(mjCDef* def = 0); // equality constraint
|
||||
mjCTendon* AddTendon(mjCDef* def = 0); // tendon
|
||||
mjCActuator* AddActuator(mjCDef* def = 0); // actuator
|
||||
mjCSensor* AddSensor(void); // sensor
|
||||
mjCNumeric* AddNumeric(void); // custom numeric
|
||||
mjCText* AddText(void); // custom text
|
||||
mjCTuple* AddTuple(void); // custom tuple
|
||||
mjCKey* AddKey(void); // keyframe
|
||||
mjCPlugin* AddPlugin(void); // plugin instance
|
||||
// delete elements marked as discard=true
|
||||
template <class T> void Delete(std::vector<T*>& elements,
|
||||
const std::vector<bool>& discard);
|
||||
|
||||
//------------------------ API for deleting model elements
|
||||
template <class T>
|
||||
void Delete(std::vector<T*>& elements,
|
||||
const std::vector<bool>& discard); // delete elements marked as discard=true
|
||||
// delete all elements
|
||||
template <class T> void DeleteAll(std::vector<T*>& elements);
|
||||
|
||||
template <class T>
|
||||
void DeleteAll(std::vector<T*>& elements); // delete all elements
|
||||
|
||||
//------------------------ API for access to model elements (outside tree)
|
||||
// API for access to model elements (outside tree)
|
||||
int NumObjects(mjtObj type); // number of objects in specified list
|
||||
mjCBase* GetObject(mjtObj type, int id); // pointer to specified object
|
||||
|
||||
//------------------------ API for access to other variables
|
||||
bool IsCompiled(void); // is model already compiled
|
||||
int GetFixed(void); // number of fixed massless bodies
|
||||
mjCError GetError(void); // copy of error object
|
||||
mjCBody* GetWorld(void); // pointer to world body
|
||||
// API for access to other variables
|
||||
bool IsCompiled(); // is model already compiled
|
||||
int GetFixed(); // number of fixed massless bodies
|
||||
mjCError GetError(); // copy of error object
|
||||
mjCBody* GetWorld(); // pointer to world body
|
||||
mjCDef* FindDef(std::string name); // find default class name
|
||||
mjCDef* AddDef(std::string name, int parentid); // add default class to array
|
||||
mjCBase* FindObject(mjtObj type, std::string name); // find object given type and name
|
||||
bool IsNullPose(const mjtNum* pos, const mjtNum* quat); // detect null pose
|
||||
|
||||
//------------------------ getters
|
||||
// accessors
|
||||
std::string get_meshdir(void) const { return meshdir_; }
|
||||
std::string get_texturedir(void) const { return texturedir_; }
|
||||
|
||||
//------------------------ API for plugins
|
||||
void ResolvePlugin(mjCBase* obj, // resolve plugin instance, create a new one if needed
|
||||
const std::string& plugin_name,
|
||||
// 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;
|
||||
|
||||
//------------------------ global data
|
||||
std::vector<mjCDef*> defaults; // settings for each defaults class
|
||||
std::vector<std::pair<const mjpPlugin*, int>> active_plugins; // list of active plugins
|
||||
// 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);
|
||||
|
||||
void Clear(void); // clear objects allocated by Compile
|
||||
// clear objects allocated by Compile
|
||||
void Clear(void);
|
||||
|
||||
template <class T> // add object of any type
|
||||
T* AddObject(std::vector<T*>& list, std::string type);
|
||||
// add object of any type
|
||||
template <class T> T* AddObject(std::vector<T*>& list, std::string type);
|
||||
|
||||
template <class T> // add object of any type, with def parameter
|
||||
T* AddObjectDef(std::vector<T*>& list, std::string type, mjCDef* def);
|
||||
// add object of any type, with def parameter
|
||||
template <class T> T* AddObjectDef(std::vector<T*>& list, std::string type,
|
||||
mjCDef* def);
|
||||
|
||||
template<class T> // if asset name is missing, set to filename
|
||||
void SetDefaultNames(std::vector<T*>& assets);
|
||||
// if asset name is missing, set to filename
|
||||
template<class T> void SetDefaultNames(std::vector<T*>& assets);
|
||||
|
||||
template <class T> // delete material from object
|
||||
void DeleteMaterial(std::vector<T*>& list, std::string_view name = "");
|
||||
// delete material from object
|
||||
template <class T> void DeleteMaterial(std::vector<T*>& list,
|
||||
std::string_view name = "");
|
||||
|
||||
//------------------------ compile phases
|
||||
// compile phases
|
||||
void MakeLists(mjCBody* body); // make lists of bodies, geoms, joints, sites
|
||||
void IndexAssets(bool discard); // convert asset names into indices
|
||||
void CheckEmptyNames(void); // check empty names
|
||||
void SetSizes(void); // compute sizes
|
||||
void CheckEmptyNames(); // check empty names
|
||||
void SetSizes(); // compute sizes
|
||||
void AutoSpringDamper(mjModel*); // automatic stiffness and damping computation
|
||||
void LengthRange(mjModel*, mjData*); // compute actuator lengthrange
|
||||
void CopyNames(mjModel*); // copy names, compute name addresses
|
||||
@@ -162,7 +160,6 @@ class mjCModel : private mjmModel {
|
||||
void CopyObjects(mjModel*); // copy objects outside kinematic tree
|
||||
void CopyTree(mjModel*); // copy objects inside kinematic tree
|
||||
|
||||
//------------------------ sizes
|
||||
// sizes set from object list lengths
|
||||
int nbody; // number of bodies
|
||||
int njnt; // number of joints
|
||||
@@ -226,7 +223,6 @@ class mjCModel : private mjmModel {
|
||||
int nD; // number of non-zeros in sparse dof-dof matrix
|
||||
int nB; // number of non-zeros in sparse body-dof matrix
|
||||
|
||||
//------------------------ object lists
|
||||
// objects created here
|
||||
std::vector<mjCFlex*> flexes; // list of flexes
|
||||
std::vector<mjCMesh*> meshes; // list of meshes
|
||||
@@ -254,8 +250,6 @@ class mjCModel : private mjmModel {
|
||||
std::vector<mjCCamera*> cameras; // list of cameras
|
||||
std::vector<mjCLight*> lights; // list of lights
|
||||
|
||||
//------------------------ internal variables
|
||||
|
||||
// array of pointers to each object list (enumerated by type)
|
||||
std::array<std::vector<mjCBase*>*, mjNOBJECT> object_lists;
|
||||
|
||||
@@ -266,13 +260,14 @@ class mjCModel : private mjmModel {
|
||||
double extent_auto; // spatial extent, as computed by mj_setConst
|
||||
double center_auto[3]; // center of model, as computed by mj_setConst
|
||||
|
||||
// map from object names to ids
|
||||
mjListKeyMap ids;
|
||||
|
||||
mjListKeyMap ids; // map from object names to ids
|
||||
bool compiled; // already compiled flag (cannot be compiled again)
|
||||
mjCError errInfo; // last error info
|
||||
int fixCount; // how many bodies have been fixed
|
||||
std::vector<mjtNum> qpos0; // save qpos0, to recognize changed key_qpos in write
|
||||
|
||||
// save qpos0, to recognize changed key_qpos in write
|
||||
std::vector<mjtNum> qpos0;
|
||||
|
||||
// variable-size attributes
|
||||
std::string comment_; // comment at top of XML
|
||||
|
||||
Reference in New Issue
Block a user