Move the map lookup outside of the mesh processing loop. Change to unordered_map.

PiperOrigin-RevId: 651745837
Change-Id: Ibfcbe4b8cefa53a3dbaa99c4ca68442e2e10bc5d
This commit is contained in:
Nimrod Gileadi
2024-07-12 05:44:33 -07:00
committed by Copybara-Service
parent 6e64dd10e8
commit 84108589c4
2 changed files with 6 additions and 3 deletions
+4 -2
View File
@@ -1365,6 +1365,8 @@ void mjCMesh::Process() {
// find centroid of faces
ComputeFaceCentroid(facecen);
double density = model->def_map[classname]->Geom().density;
// compute inertial properties for both inertia types
for ( const auto type : { mjtGeomInertia::mjINERTIA_VOLUME, mjtGeomInertia::mjINERTIA_SHELL } ) {
double CoM[3] = {0, 0, 0};
@@ -1423,7 +1425,7 @@ void mjCMesh::Process() {
// apply formula, accumulate
GetVolumeRef(type) += vol;
for (int j=0; j<6; j++) {
P[j] += model->def_map[classname]->Geom().density*vol /
P[j] += density*vol /
(type==mjINERTIA_SHELL ? 12 : 20) * (
2*(D[k[j][0]] * D[k[j][1]] +
E[k[j][0]] * E[k[j][1]] +
@@ -1464,7 +1466,7 @@ void mjCMesh::Process() {
}
// compute sizes of equivalent inertia box
double mass = GetVolumeRef(type) * model->def_map[classname]->Geom().density;
double mass = GetVolumeRef(type) * density;
double* boxsz = GetInertiaBoxPtr(type);
boxsz[0] = sqrt(6*(eigval[1]+eigval[2]-eigval[0])/mass)/2;
boxsz[1] = sqrt(6*(eigval[0]+eigval[2]-eigval[1])/mass)/2;
+2 -1
View File
@@ -20,6 +20,7 @@
#include <map>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -276,7 +277,7 @@ class mjCModel : public mjCModel_, private mjSpec {
void RestoreState(const mjModel* m, mjData** dest);
// map from default class name to default class pointer
std::map<std::string, mjCDef*> def_map;
std::unordered_map<std::string, mjCDef*> def_map;
private:
// settings for each defaults class