Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDF gradient outside of the bounding box #13

Open
quagla opened this issue Jan 12, 2024 · 2 comments
Open

SDF gradient outside of the bounding box #13

quagla opened this issue Jan 12, 2024 · 2 comments

Comments

@quagla
Copy link
Contributor

quagla commented Jan 12, 2024

I am having some issues using the SDF for collisions when the query points is outside of the bounding box. I came up with a workaround:

https://github.com/google-deepmind/mujoco/blob/main/plugin/sdf/sdflib.cc#L121

which computes the SDF as the sum of the distance from the bounding box and the SDF evaluated at the closest point that is on the boundary of the box. Is there any reason not to use this trick directly in SdfLib?

It would be even better if it was possible to select the domain of SDF independently from the bounding box, so one could make it a little larger to avoid this issue in practice.

@quagla
Copy link
Contributor Author

quagla commented Jan 12, 2024

Apologies, I realized only now that the margin is available, amazing!

However, I have a question:

  sdflib::BoundingBox box = mesh.getBoundingBox();
  const glm::vec3 modelBBsize = box.getSize();
  box.addMargin(
      0.1f * glm::max(glm::max(modelBBsize.x, modelBBsize.y), modelBBsize.z));
  printf("box: %f\n", box.getSize().x);
  printf("box: %f\n", box.getSize().y);
  printf("box: %f\n", box.getSize().z);
  sdf_func_ =
      sdflib::OctreeSdf(mesh, box, 8, 3, 1e-3,
                        sdflib::OctreeSdf::InitAlgorithm::CONTINUITY, 1);
  printf("sdf_func: %f\n", sdf_func_.getGridBoundingBox().getSize().x);
  printf("sdf_func: %f\n", sdf_func_.getGridBoundingBox().getSize().y);
  printf("sdf_func: %f\n", sdf_func_.getGridBoundingBox().getSize().z);

prints

box: 1.286686
box: 2.034012
box: 2.061491
sdf_func: 2.061491
sdf_func: 2.061491
sdf_func: 2.061491

Why did you decide to use the max for the final bounding box?

@triter3
Copy link
Member

triter3 commented Jan 21, 2024

Why did you decide to use the max for the final bounding box?

Hi @quagla. I'm getting the max of the bounding box right now because I suppose the octree subdivision starts at depth zero. I should change this to adapt better to the requested bounding box. I will add it to my to-do list.

Also, a few weeks ago, I added a new heuristic for the subdivisions, which allows the user to define the maximum desired error regarding the distance to the surface. This feature makes it easy to have bigger boxes without requiring much disk space. At the moment, this feature is only at the development brunch. Could it be useful for your use case?

which computes the SDF as the sum of the distance from the bounding box and the SDF evaluated at the closest point that is on the boundary of the box. Is there any reason not to use this trick directly in SdfLib?

I think is a good approximation for far points. I will integrated inside the getGradient function. Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants