Refactor SDF coefficient computation into mjCOctree.
The logic for computing Signed Distance Function (SDF) coefficients using TriangleMeshDistance is moved from `mjCPlugin::Make` in `user_mesh.cc` to a new method `mjCOctree::ComputeSdfCoeffs` in `user_objects.cc`. This encapsulates the SDF computation within the octree class. PiperOrigin-RevId: 874572414 Change-Id: Ia2365c9c4527a252ff1d1bb43fe2c2593761e471
This commit is contained in:
committed by
Copybara-Service
parent
82e92cbcaa
commit
5fc580a8ba
+1
-47
@@ -34,7 +34,6 @@
|
||||
|
||||
#include <mujoco/mjspec.h>
|
||||
#include "user/user_api.h"
|
||||
#include <TriangleMeshDistance/include/tmd/TriangleMeshDistance.h>
|
||||
|
||||
#ifdef MUJOCO_TINYOBJLOADER_IMPL
|
||||
#define TINYOBJLOADER_IMPLEMENTATION
|
||||
@@ -780,52 +779,7 @@ void mjCMesh::TryCompile(const mjVFS* vfs) {
|
||||
|
||||
// compute sdf coefficients
|
||||
if (!plugin.active) {
|
||||
tmd::TriangleMeshDistance sdf(vert_.data(), nvert(), face_.data(), nface());
|
||||
|
||||
std::vector<double> coeffs(octree_.NumVerts());
|
||||
std::vector<bool> processed(octree_.NumVerts(), false);
|
||||
std::deque<int> queue;
|
||||
|
||||
if (octree_.NumNodes() > 0) {
|
||||
queue.push_back(0); // start traversal from the root node
|
||||
}
|
||||
|
||||
while (!queue.empty()) {
|
||||
int node_idx = queue.front();
|
||||
queue.pop_front();
|
||||
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
int vert_id = octree_.VertId(node_idx, j);
|
||||
if (processed[vert_id]) {
|
||||
continue;
|
||||
}
|
||||
if (octree_.Hang(vert_id).empty()) {
|
||||
coeffs[vert_id] = sdf.signed_distance(octree_.Vert(vert_id)).distance;
|
||||
} else {
|
||||
double sum_coeff = 0;
|
||||
for (int dep_id : octree_.Hang(vert_id)) {
|
||||
sum_coeff += coeffs[dep_id];
|
||||
if (!processed[dep_id]) {
|
||||
throw mjCError(this, "sdf coefficient computation failed");
|
||||
}
|
||||
}
|
||||
coeffs[vert_id] = sum_coeff / octree_.Hang(vert_id).size();
|
||||
}
|
||||
processed[vert_id] = true;
|
||||
}
|
||||
|
||||
for (int child_idx : octree_.Children(node_idx)) {
|
||||
if (child_idx != -1) {
|
||||
queue.push_back(child_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < octree_.NumNodes(); ++i) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
octree_.AddCoeff(i, j, coeffs[octree_.VertId(i, j)]);
|
||||
}
|
||||
}
|
||||
octree_.ComputeSdfCoeffs(vert_.data(), nvert(), face_.data(), nface());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user