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:
committed by
Copybara-Service
parent
6e64dd10e8
commit
84108589c4
@@ -1365,6 +1365,8 @@ void mjCMesh::Process() {
|
|||||||
// find centroid of faces
|
// find centroid of faces
|
||||||
ComputeFaceCentroid(facecen);
|
ComputeFaceCentroid(facecen);
|
||||||
|
|
||||||
|
double density = model->def_map[classname]->Geom().density;
|
||||||
|
|
||||||
// compute inertial properties for both inertia types
|
// compute inertial properties for both inertia types
|
||||||
for ( const auto type : { mjtGeomInertia::mjINERTIA_VOLUME, mjtGeomInertia::mjINERTIA_SHELL } ) {
|
for ( const auto type : { mjtGeomInertia::mjINERTIA_VOLUME, mjtGeomInertia::mjINERTIA_SHELL } ) {
|
||||||
double CoM[3] = {0, 0, 0};
|
double CoM[3] = {0, 0, 0};
|
||||||
@@ -1423,7 +1425,7 @@ void mjCMesh::Process() {
|
|||||||
// apply formula, accumulate
|
// apply formula, accumulate
|
||||||
GetVolumeRef(type) += vol;
|
GetVolumeRef(type) += vol;
|
||||||
for (int j=0; j<6; j++) {
|
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) * (
|
(type==mjINERTIA_SHELL ? 12 : 20) * (
|
||||||
2*(D[k[j][0]] * D[k[j][1]] +
|
2*(D[k[j][0]] * D[k[j][1]] +
|
||||||
E[k[j][0]] * E[k[j][1]] +
|
E[k[j][0]] * E[k[j][1]] +
|
||||||
@@ -1464,7 +1466,7 @@ void mjCMesh::Process() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compute sizes of equivalent inertia box
|
// 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);
|
double* boxsz = GetInertiaBoxPtr(type);
|
||||||
boxsz[0] = sqrt(6*(eigval[1]+eigval[2]-eigval[0])/mass)/2;
|
boxsz[0] = sqrt(6*(eigval[1]+eigval[2]-eigval[0])/mass)/2;
|
||||||
boxsz[1] = sqrt(6*(eigval[0]+eigval[2]-eigval[1])/mass)/2;
|
boxsz[1] = sqrt(6*(eigval[0]+eigval[2]-eigval[1])/mass)/2;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -276,7 +277,7 @@ class mjCModel : public mjCModel_, private mjSpec {
|
|||||||
void RestoreState(const mjModel* m, mjData** dest);
|
void RestoreState(const mjModel* m, mjData** dest);
|
||||||
|
|
||||||
// map from default class name to default class pointer
|
// 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:
|
private:
|
||||||
// settings for each defaults class
|
// settings for each defaults class
|
||||||
|
|||||||
Reference in New Issue
Block a user