Migrate mjModel size fields from int to mjtSize.
This change updates all size-related members within the `mjModel` struct from `int` to `mjtSize`. This allows MuJoCo to handle models with a larger number of elements. Corresponding changes were made to macros, function signatures, and I/O routines to accommodate the new `mjtSize` type. PiperOrigin-RevId: 860144595 Change-Id: I701c6d607715d240766b6210a9773cd9e4258c59
This commit is contained in:
committed by
Copybara-Service
parent
4a64017a5f
commit
30b903b6c0
+34
-16
@@ -2218,28 +2218,45 @@ void mjCModel::SetSizes() {
|
||||
}
|
||||
|
||||
// nhfielddata
|
||||
for (int i=0; i < nhfield; i++)nhfielddata += hfields_[i]->nrow * hfields_[i]->ncol;
|
||||
for (int i=0; i < nhfield; i++) {
|
||||
nhfielddata += static_cast<mjtSize>(hfields_[i]->nrow) * hfields_[i]->ncol;
|
||||
}
|
||||
|
||||
// ntexdata
|
||||
for (int i=0; i < ntex; i++)ntexdata += textures_[i]->nchannel * textures_[i]->width * textures_[i]->height;
|
||||
for (int i=0; i < ntex; i++) {
|
||||
const mjCTexture* tex = textures_[i];
|
||||
ntexdata += static_cast<mjtSize>(tex->nchannel) * tex->width * tex->height;
|
||||
}
|
||||
|
||||
// nwrap
|
||||
for (int i=0; i < ntendon; i++)nwrap += (int)tendons_[i]->path.size();
|
||||
for (int i=0; i < ntendon; i++) {
|
||||
nwrap += (int)tendons_[i]->path.size();
|
||||
}
|
||||
|
||||
// nsensordata
|
||||
for (int i=0; i < nsensor; i++)nsensordata += sensors_[i]->dim;
|
||||
for (int i=0; i < nsensor; i++) {
|
||||
nsensordata += sensors_[i]->dim;
|
||||
}
|
||||
|
||||
// nnumericdata
|
||||
for (int i=0; i < nnumeric; i++)nnumericdata += numerics_[i]->size;
|
||||
for (int i=0; i < nnumeric; i++) {
|
||||
nnumericdata += numerics_[i]->size;
|
||||
}
|
||||
|
||||
// ntextdata
|
||||
for (int i=0; i < ntext; i++)ntextdata += (int)texts_[i]->data_.size() + 1;
|
||||
for (int i=0; i < ntext; i++) {
|
||||
ntextdata += (int)texts_[i]->data_.size() + 1;
|
||||
}
|
||||
|
||||
// ntupledata
|
||||
for (int i=0; i < ntuple; i++)ntupledata += (int)tuples_[i]->objtype_.size();
|
||||
for (int i=0; i < ntuple; i++) {
|
||||
ntupledata += (int)tuples_[i]->objtype_.size();
|
||||
}
|
||||
|
||||
// npluginattr
|
||||
for (int i=0; i < nplugin; i++)npluginattr += (int)plugins_[i]->flattened_attributes.size();
|
||||
for (int i=0; i < nplugin; i++) {
|
||||
npluginattr += (int)plugins_[i]->flattened_attributes.size();
|
||||
}
|
||||
|
||||
// nnames
|
||||
nnames = (int)modelname_.size() + 1;
|
||||
@@ -3185,10 +3202,10 @@ int mjCModel::CountNJmom(const mjModel* m) {
|
||||
|
||||
// copy objects outside kinematic tree
|
||||
void mjCModel::CopyObjects(mjModel* m) {
|
||||
int adr, bone_adr, vert_adr, node_adr, normal_adr, face_adr, texcoord_adr, oct_adr;
|
||||
int edge_adr, elem_adr, elemdata_adr, elemedge_adr, shelldata_adr, evpair_adr;
|
||||
int bonevert_adr, graph_adr, data_adr, bvh_adr;
|
||||
int poly_adr, polymap_adr, polyvert_adr;
|
||||
mjtSize adr, bone_adr, vert_adr, node_adr, normal_adr, face_adr, texcoord_adr, oct_adr;
|
||||
mjtSize edge_adr, elem_adr, elemdata_adr, elemedge_adr, shelldata_adr, evpair_adr;
|
||||
mjtSize bonevert_adr, graph_adr, data_adr, bvh_adr;
|
||||
mjtSize poly_adr, polymap_adr, polyvert_adr;
|
||||
|
||||
// sizes outside call to mj_makeModel
|
||||
m->nemax = nemax;
|
||||
@@ -3556,7 +3573,8 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
m->hfield_adr[i] = data_adr;
|
||||
|
||||
// copy elevation data
|
||||
memcpy(m->hfield_data + data_adr, phf->data.data(), phf->nrow*phf->ncol*sizeof(float));
|
||||
memcpy(m->hfield_data + data_adr, phf->data.data(),
|
||||
static_cast<mjtSize>(phf->nrow) * phf->ncol * sizeof(float));
|
||||
|
||||
// advance counter
|
||||
data_adr += phf->nrow*phf->ncol;
|
||||
@@ -3577,11 +3595,11 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
m->tex_adr[i] = data_adr;
|
||||
|
||||
// copy rgb data
|
||||
memcpy(m->tex_data + data_adr, ptex->data_.data(),
|
||||
ptex->nchannel * ptex->width * ptex->height);
|
||||
mjtSize nbytes = static_cast<mjtSize>(ptex->nchannel) * ptex->width * ptex->height;
|
||||
memcpy(m->tex_data + data_adr, ptex->data_.data(), nbytes);
|
||||
|
||||
// advance counter
|
||||
data_adr += ptex->nchannel * ptex->width * ptex->height;
|
||||
data_adr += nbytes;
|
||||
}
|
||||
|
||||
// materials
|
||||
|
||||
+71
-71
@@ -54,81 +54,81 @@ class mjCModel_ : public mjsElement {
|
||||
std::string suffix;
|
||||
|
||||
protected:
|
||||
bool compiled; // already compiled flag
|
||||
bool compiled; // already compiled flag
|
||||
|
||||
// sizes set from object list lengths
|
||||
int nbody; // number of bodies
|
||||
int njnt; // number of joints
|
||||
int ngeom; // number of geoms
|
||||
int nsite; // number of sites
|
||||
int ncam; // number of cameras
|
||||
int nlight; // number of lights
|
||||
int nflex; // number of flexes
|
||||
int nmesh; // number of meshes
|
||||
int nskin; // number of skins
|
||||
int nhfield; // number of height fields
|
||||
int ntex; // number of textures
|
||||
int nmat; // number of materials
|
||||
int npair; // number of geom pairs in pair array
|
||||
int nexclude; // number of excluded body pairs
|
||||
int neq; // number of equality constraints
|
||||
int ntendon; // number of tendons
|
||||
int nsensor; // number of sensors
|
||||
int nnumeric; // number of numeric fields
|
||||
int ntext; // number of text fields
|
||||
int ntuple; // number of tuple fields
|
||||
int nmocap; // number of mocap bodies
|
||||
int nplugin; // number of plugin instances
|
||||
mjtSize nbody; // number of bodies
|
||||
mjtSize njnt; // number of joints
|
||||
mjtSize ngeom; // number of geoms
|
||||
mjtSize nsite; // number of sites
|
||||
mjtSize ncam; // number of cameras
|
||||
mjtSize nlight; // number of lights
|
||||
mjtSize nflex; // number of flexes
|
||||
mjtSize nmesh; // number of meshes
|
||||
mjtSize nskin; // number of skins
|
||||
mjtSize nhfield; // number of height fields
|
||||
mjtSize ntex; // number of textures
|
||||
mjtSize nmat; // number of materials
|
||||
mjtSize npair; // number of geom pairs in pair array
|
||||
mjtSize nexclude; // number of excluded body pairs
|
||||
mjtSize neq; // number of equality constraints
|
||||
mjtSize ntendon; // number of tendons
|
||||
mjtSize nsensor; // number of sensors
|
||||
mjtSize nnumeric; // number of numeric fields
|
||||
mjtSize ntext; // number of text fields
|
||||
mjtSize ntuple; // number of tuple fields
|
||||
mjtSize nmocap; // number of mocap bodies
|
||||
mjtSize nplugin; // number of plugin instances
|
||||
|
||||
// sizes computed by Compile
|
||||
int nq; // number of generalized coordinates = dim(qpos)
|
||||
int nv; // number of degrees of freedom = dim(qvel)
|
||||
int nu; // number of actuators/controls
|
||||
int na; // number of activation variables
|
||||
int ntree; // number of trees
|
||||
int nbvh; // number of total boundary volume hierarchies
|
||||
int nbvhstatic; // number of static boundary volume hierarchies
|
||||
int nbvhdynamic; // number of dynamic boundary volume hierarchies
|
||||
int noct; // number of total octree cells
|
||||
int nflexnode; // number of nodes in all flexes
|
||||
int nflexvert; // number of vertices in all flexes
|
||||
int nflexedge; // number of edges in all flexes
|
||||
int nflexelem; // number of elements in all flexes
|
||||
int nflexelemdata; // number of element vertex ids in all flexes
|
||||
int nflexelemedge; // number of element edges in all flexes
|
||||
int nflexshelldata; // number of shell fragment vertex ids in all flexes
|
||||
int nflexevpair; // number of element-vertex pairs in all flexes
|
||||
int nflextexcoord; // number of vertex texture coordinates in all flexes
|
||||
int nJfe; // number of non-zeros in sparse flex edge constraint Jacobian
|
||||
int nJfv; // number of non-zeros in sparse flex vertex constraint Jacobian
|
||||
int nmeshvert; // number of vertices in all meshes
|
||||
int nmeshnormal; // number of normals in all meshes
|
||||
int nmeshtexcoord; // number of texture coordinates in all meshes
|
||||
int nmeshface; // number of triangular faces in all meshes
|
||||
int nmeshpoly; // number of polygon faces in all meshes
|
||||
int nmeshgraph; // number of ints in mesh auxiliary data
|
||||
int nmeshpolyvert; // number of vertices in all polygon faces
|
||||
int nmeshpolymap; // number of polygons in vertex map
|
||||
int nskinvert; // number of vertices in all skins
|
||||
int nskintexvert; // number of vertices with texcoord in all skins
|
||||
int nskinface; // number of faces in all skins
|
||||
int nskinbone; // number of bones in all skins
|
||||
int nskinbonevert; // number of vertices in all skins
|
||||
int nhfielddata; // number of data points in all hfields
|
||||
int ntexdata; // number of texture bytes
|
||||
int nwrap; // number of wrap objects in all tendon paths
|
||||
int nsensordata; // number of mjtNums in sensor data vector
|
||||
int nnumericdata; // number of mjtNums in all custom fields
|
||||
int ntextdata; // number of chars in all text fields, including 0
|
||||
int ntupledata; // number of objects in all tuple fields
|
||||
int npluginattr; // number of chars in all plugin config attributes
|
||||
int nnames; // number of chars in all names
|
||||
int npaths; // number of chars in all paths
|
||||
int nM; // number of non-zeros in sparse inertia matrix
|
||||
int nB; // number of non-zeros in sparse body-dof matrix
|
||||
int nC; // number of non-zeros in reduced sparse dof-dof matrix
|
||||
int nD; // number of non-zeros in sparse dof-dof matrix
|
||||
int nJmom; // number of non-zeros in sparse actuator_moment matrix
|
||||
mjtSize nq; // number of generalized coordinates = dim(qpos)
|
||||
mjtSize nv; // number of degrees of freedom = dim(qvel)
|
||||
mjtSize nu; // number of actuators/controls
|
||||
mjtSize na; // number of activation variables
|
||||
mjtSize ntree; // number of trees
|
||||
mjtSize nbvh; // number of total boundary volume hierarchies
|
||||
mjtSize nbvhstatic; // number of static boundary volume hierarchies
|
||||
mjtSize nbvhdynamic; // number of dynamic boundary volume hierarchies
|
||||
mjtSize noct; // number of total octree cells
|
||||
mjtSize nflexnode; // number of nodes in all flexes
|
||||
mjtSize nflexvert; // number of vertices in all flexes
|
||||
mjtSize nflexedge; // number of edges in all flexes
|
||||
mjtSize nflexelem; // number of elements in all flexes
|
||||
mjtSize nflexelemdata; // number of element vertex ids in all flexes
|
||||
mjtSize nflexelemedge; // number of element edges in all flexes
|
||||
mjtSize nflexshelldata; // number of shell fragment vertex ids in all flexes
|
||||
mjtSize nflexevpair; // number of element-vertex pairs in all flexes
|
||||
mjtSize nflextexcoord; // number of vertex texture coordinates in all flexes
|
||||
mjtSize nJfe; // number of non-zeros in sparse flex edge constraint Jacobian
|
||||
mjtSize nJfv; // number of non-zeros in sparse flex vertex constraint Jacobian
|
||||
mjtSize nmeshvert; // number of vertices in all meshes
|
||||
mjtSize nmeshnormal; // number of normals in all meshes
|
||||
mjtSize nmeshtexcoord; // number of texture coordinates in all meshes
|
||||
mjtSize nmeshface; // number of triangular faces in all meshes
|
||||
mjtSize nmeshpoly; // number of polygon faces in all meshes
|
||||
mjtSize nmeshgraph; // number of ints in mesh auxiliary data
|
||||
mjtSize nmeshpolyvert; // number of vertices in all polygon faces
|
||||
mjtSize nmeshpolymap; // number of polygons in vertex map
|
||||
mjtSize nskinvert; // number of vertices in all skins
|
||||
mjtSize nskintexvert; // number of vertices with texcoord in all skins
|
||||
mjtSize nskinface; // number of faces in all skins
|
||||
mjtSize nskinbone; // number of bones in all skins
|
||||
mjtSize nskinbonevert; // number of vertices in all skins
|
||||
mjtSize nhfielddata; // number of data points in all hfields
|
||||
mjtSize ntexdata; // number of texture bytes
|
||||
mjtSize nwrap; // number of wrap objects in all tendon paths
|
||||
mjtSize nsensordata; // number of mjtNums in sensor data vector
|
||||
mjtSize nnumericdata; // number of mjtNums in all custom fields
|
||||
mjtSize ntextdata; // number of chars in all text fields, including 0
|
||||
mjtSize ntupledata; // number of objects in all tuple fields
|
||||
mjtSize npluginattr; // number of chars in all plugin config attributes
|
||||
mjtSize nnames; // number of chars in all names
|
||||
mjtSize npaths; // number of chars in all paths
|
||||
mjtSize nM; // number of non-zeros in sparse inertia matrix
|
||||
mjtSize nB; // number of non-zeros in sparse body-dof matrix
|
||||
mjtSize nC; // number of non-zeros in reduced sparse dof-dof matrix
|
||||
mjtSize nD; // number of non-zeros in sparse dof-dof matrix
|
||||
mjtSize nJmom; // number of non-zeros in sparse actuator_moment matrix
|
||||
|
||||
// statistics, as computed by mj_setConst
|
||||
double meaninertia_auto; // mean diagonal inertia, as computed by mj_setConst
|
||||
|
||||
@@ -4825,7 +4825,7 @@ void mjCTexture::BuiltinCube(void) {
|
||||
if (w > std::numeric_limits<int>::max() / w) {
|
||||
throw mjCError(this, "Cube texture width is too large.");
|
||||
}
|
||||
int ww = width*width;
|
||||
mjtSize ww = width*width;
|
||||
|
||||
// convert fixed colors
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@@ -4838,7 +4838,7 @@ void mjCTexture::BuiltinCube(void) {
|
||||
|
||||
// gradient
|
||||
if (builtin == mjBUILTIN_GRADIENT) {
|
||||
if (ww > std::numeric_limits<int>::max() / 18) {
|
||||
if (ww > std::numeric_limits<std::int64_t>::max() / 18) {
|
||||
throw mjCError(this, "Gradient texture width is too large.");
|
||||
}
|
||||
for (int r = 0; r < w; r++) {
|
||||
@@ -5176,7 +5176,7 @@ void mjCTexture::LoadCubeSingle(std::string filename, const mjVFS* vfs) {
|
||||
|
||||
// allocate data
|
||||
std::int64_t size = static_cast<std::int64_t>(width)*height;
|
||||
if (size >= std::numeric_limits<int>::max() / 3 || size <= 0) {
|
||||
if (size >= std::numeric_limits<std::int64_t>::max() / 3 || size <= 0) {
|
||||
throw mjCError(this, "Cube texture too large");
|
||||
}
|
||||
try {
|
||||
@@ -5293,7 +5293,7 @@ void mjCTexture::LoadCubeSeparate(const mjVFS* vfs) {
|
||||
}
|
||||
height = 6*width;
|
||||
std::int64_t size = static_cast<std::int64_t>(width)*height;
|
||||
if (size >= std::numeric_limits<int>::max() / 3 || size <= 0) {
|
||||
if (size >= std::numeric_limits<mjtSize>::max() / 3 || size <= 0) {
|
||||
throw mjCError(this, "PNG texture too large");
|
||||
}
|
||||
try {
|
||||
@@ -5378,7 +5378,7 @@ void mjCTexture::Compile(const mjVFS* vfs) {
|
||||
}
|
||||
|
||||
std::int64_t size = static_cast<std::int64_t>(width)*height;
|
||||
if (size >= std::numeric_limits<int>::max() / nchannel || size <= 0) {
|
||||
if (size >= std::numeric_limits<int64_t>::max() / nchannel || size <= 0) {
|
||||
throw mjCError(this, "Builtin texture too large");
|
||||
}
|
||||
// allocate data
|
||||
|
||||
Reference in New Issue
Block a user