Small cosmetic fixes to MakeBVH.

Remove the index member of BVElement, since it's redundant for the purpose of sorting. BVElement is now 32 bytes instead of 40, which should make things a bit better, as this data gets moved around during MakeBVH. Unfortunately, this has no measurable effect on the benchmark.

PiperOrigin-RevId: 616806520
Change-Id: I3b8a28c42a4a21dc25985e63ac57764fdb669afa
This commit is contained in:
Nimrod Gileadi
2024-03-18 06:18:28 -07:00
committed by Copybara-Service
parent acaf86a96f
commit de918a8b2d
2 changed files with 4 additions and 6 deletions
+2 -3
View File
@@ -301,7 +301,6 @@ void mjCBoundingVolumeHierarchy::CreateBVH() {
if (bvleaf_[i].conaffinity || bvleaf_[i].contype) {
BVElement element;
element.e = &bvleaf_[i];
element.index = i;
mjtNum vert[3] = {element.e->pos[0] - ipos_[0],
element.e->pos[1] - ipos_[1],
element.e->pos[2] - ipos_[2]};
@@ -398,10 +397,10 @@ int mjCBoundingVolumeHierarchy::MakeBVH(
axis = edges[axis] > edges[2] ? axis : 2;
// find median along the axis
auto m = nelements/2;
// Note: nth element performs a partial sort of elements
// note: nth_element performs a partial sort of elements
BVElementCompare compare;
compare.axis = axis;
int m = nelements / 2;
std::nth_element(elements_begin, elements_begin + m, elements_end, compare);
// recursive calls
+2 -3
View File
@@ -146,8 +146,6 @@ class mjCBoundingVolumeHierarchy : public mjCBoundingVolumeHierarchy_ {
// internal class used during BVH construction, for partial sorting of bounding volumes
struct BVElement {
const mjCBoundingVolume* e;
// index of the element in the original input to BVH, used to ensure a stable sort
int index;
// position of the element in the BVH axes
mjtNum lpos[3];
};
@@ -159,7 +157,8 @@ class mjCBoundingVolumeHierarchy : public mjCBoundingVolumeHierarchy_ {
if (e1.lpos[axis] != e2.lpos[axis]) {
return e1.lpos[axis] < e2.lpos[axis];
}
return e1.index < e2.index;
// comparing pointers gives a stable sort, because they both come from the same array
return e1.e < e2.e;
}
};