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

[geometry] Remove the non-BVH interface for rigid-soft mesh intersection #14110

Conversation

SeanCurtis-TRI
Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI commented Sep 22, 2020

For historical reasons, computing intersection between a soft volume mesh and a rigid surface mesh had two separate APIs. One used broadphase acceleration with a bounding volume hierarchy (BVH) one did not. Both APIs were propagated as a basis for measuring improvement. The need for both APIs is long gone. So, we'll simplify the API and eliminate the slow version. Going forward, improvements should be against strictly the best possible results. This change had several implications:

  • mesh_intersection_benchmark now only considers one case -- it reports the performance of queries with the current BVH implementation.
  • Unit tests in mesh_intersection_test would exploit the BVH-free API to shorten the tests. They needed to be expanded to use the BVH API.
    • One test in particular would produce a smoke test confirming that the test could be used with AutoDiffXd-valued meshes. That used the old BVH-free API. In removing that API, we need to be able to build a BVH for an AutoDiffXd-valued mesh.
  • Bvh and obb (and tests) have been updated to allow constructing a BVH for an AutoDiffXd-valued mesh.

Resolves #13861


This change is Reviewable

Copy link
Contributor Author

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@DamrongGuoy for feature review, please.

Reviewable status: LGTM missing from assignee DamrongGuoy, needs platform reviewer assigned, needs at least two assigned reviewers (waiting on @DamrongGuoy)

@SeanCurtis-TRI SeanCurtis-TRI added component: geometry proximity Contact, distance, signed distance queries and related properties priority: medium unused team: dynamics type: cleanup labels Sep 22, 2020
Copy link
Contributor

@DamrongGuoy DamrongGuoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finished feature review. PTAL.

Reviewed 10 of 10 files at r1.
Reviewable status: 15 unresolved discussions, LGTM missing from assignee DamrongGuoy, needs platform reviewer assigned, needs at least two assigned reviewers (waiting on @SeanCurtis-TRI)

a discussion (no related file):
This PR introduces convert_to_double() in obb.cc to temporarily allow AutoDiffXd. Could you please update this line of documentation in obb.h to reflect that?
obb.h

151  @tparam MeshType is either SurfaceMesh<double> or VolumeMesh<double>.  */
152 template <class MeshType>
153 class ObbMaker {

Right now it says only SurfaceMesh<double> or VolumeMesh<double>. Now it can takes SurfaceMesh<AutoDiffXd> and VolumeMesh<AutoDiffXd>; however, internally it converts AutoDiffXd to double.

I don't have a good way to describe these details, so I won't block this. Set to Discussing.



geometry/benchmarking/mesh_intersection_benchmark.cc, line 92 at r1 (raw file):

 - RigidSoftMesh/2/4/3: 107.44 m^2, 3808 triangles
 - RigidSoftMesh/2/3/1: 48.26 m^2, 2190 triangles
 - RigidSoftMesh/2/2/2: 1.52 m^2, 62 triangles

I think this table is out of date. Could you please update it?

I ran the benchmark and surprisingly got very different number of triangles:

Resulting contact surface sizes:
 - RigidSoftMesh/0/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/1/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/3/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/0/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/1/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/2/0: 1.50 m^2, 62 triangles
 - RigidSoftMesh/2/3/0: 1.14 m^2, 159 triangles
 - RigidSoftMesh/2/4/1: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/2: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/3: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/3/1: 1.17 m^2, 133 triangles
 - RigidSoftMesh/2/2/2: 1.52 m^2, 70 triangles

I also went back to master branch, so I can run WithoutBVH too.

Both WithBVH and WithoutBVH agree, but they are very different from the supposedly outdated table.


geometry/proximity/bvh.h, line 26 at r1 (raw file):

struct MeshTraits;

template <typename U>

Could it be T instead of U ?


geometry/proximity/bvh.h, line 31 at r1 (raw file):

};

template <typename U>

Could it be T instead of U ?


geometry/proximity/bvh.cc, line 156 at r1 (raw file):

    drake::geometry::VolumeMesh<double>>;

template class drake::geometry::internal::Bvh<

Could you please add a comment that these AutoDiffXd versions are here temporarily?


geometry/proximity/mesh_intersection.cc, line 381 at r1 (raw file):

/* A variant of ComputeContactSurfaceFromSoftVolumeRigidSurface but with
 broad-phase culling to reduce the number of element-pairs evaluated.  */

Remove the comment "A variant of ..." please. Now we have only one version not two variants.


geometry/proximity/mesh_intersection.cc, line 447 at r1 (raw file):

// triggers compile error because:
//   Bvh<VolumeMesh<T>>& bvh_M
// does not support VolumeMesh<AutoDiffXd>.

I think this comment is now outdated. Could you please update this comment in one of these ways?

  1. Remove it, because the template class SurfaceVolumeIntersector<AutoDiffXd> has no compile errors anymore, or
  2. Replace it with this line to confirm that it compiles:
template class SurfaceVolumeIntersector<AutoDiffXd>;
  1. Comment that it's not recommended to do it, or
  2. Other ways as you see fit?

geometry/proximity/test/mesh_intersection_test.cc, line 1161 at r1 (raw file):

  auto s_id = GeometryId::get_new_id();
  unique_ptr<VolumeMesh<double>> s_mesh_S = OctahedronVolume<double>();
  const Bvh<VolumeMesh<double>> bvh_S(*s_mesh_S);

s_bvh_S please. s_bvh_S conforms with s_mesh_S better. Otherwise, we have bvh_S and bvh_R that sound like the same bvh expressed in two different frames.


geometry/proximity/test/mesh_intersection_test.cc, line 1167 at r1 (raw file):

  auto r_id = GeometryId::get_new_id();
  unique_ptr<SurfaceMesh<double>> r_mesh_R = PyramidSurface<double>();
  const Bvh<SurfaceMesh<double>> bvh_R(*r_mesh_R);

r_bvh_R please. r_bvh_R conforms with r_mesh_R better. Otherwise, we have bvh_S and bvh_R that sound like the same bvh expressed in two different frames.


geometry/proximity/test/mesh_intersection_test.cc, line 1268 at r1 (raw file):

GTEST_TEST(MeshIntersectionTest, DoubleAutoDiffMixed) {
  unique_ptr<VolumeMesh<double>> soft_mesh = OctahedronVolume<double>();
  const Bvh<VolumeMesh<double>> bvh_S(*soft_mesh);

bvh_soft_S or soft_bvh_S please. Otherwise, bvh_S and bvh_R sound like the same bvh expressed in two different frames.


geometry/proximity/test/mesh_intersection_test.cc, line 1272 at r1 (raw file):

      OctahedronPressureField<double>(soft_mesh.get());
  unique_ptr<SurfaceMesh<double>> rigid_mesh = PyramidSurface<double>();
  const Bvh<SurfaceMesh<double>> bvh_R(*rigid_mesh);

bvh_rigid_R or rigid_bvh_R please. Otherwise, bvh_S and bvh_R sound like the same bvh expressed in two different frames.


geometry/proximity/test/mesh_to_vtk_test.cc, line 63 at r1 (raw file):

  const Box soft_box(4., 4., 2.);
  // resolution_hint 0.5 is enough to have vertices on the medial axis.
  const VolumeMesh<double> mesh_S = MakeBoxVolumeMesh<double>(soft_box, 0.5);

soft_mesh_S please. Otherwise, we have mesh_S and mesh_R, which sound like the same mesh expressed in two different frames. They are two different meshes of two different resolutions.


geometry/proximity/test/mesh_to_vtk_test.cc, line 67 at r1 (raw file):

  const VolumeMeshFieldLinear<double, double> field_S =
      MakeBoxPressureField<double>(soft_box, &mesh_S, kElasticModulus);
  const Bvh<VolumeMesh<double>> bvh_S(mesh_S);

soft_bvh_S please.


geometry/proximity/test/mesh_to_vtk_test.cc, line 73 at r1 (raw file):

  const Box rigid_box(4, 4, 2);
  // Very coarse resolution_hint 4.0 should give the coarsest mesh.
  const SurfaceMesh<double> mesh_R = MakeBoxSurfaceMesh<double>(rigid_box, 4.0);

rigid_mesh_R please. Otherwise, we have mesh_S and mesh_R, which sound like the same mesh expressed in two different frames. They are two different meshes.


geometry/proximity/test/mesh_to_vtk_test.cc, line 74 at r1 (raw file):

  // Very coarse resolution_hint 4.0 should give the coarsest mesh.
  const SurfaceMesh<double> mesh_R = MakeBoxSurfaceMesh<double>(rigid_box, 4.0);
  const Bvh<SurfaceMesh<double>> bvh_rigid(mesh_R);

rigid_bvh_R please.

@SeanCurtis-TRI SeanCurtis-TRI force-pushed the PR_remove_mesh_intersection_without_bvh branch from 0fb1e00 to 88c2e5f Compare September 24, 2020 20:30
Copy link
Contributor Author

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I homogenized the names of things: rather than s_mesh_S and soft_mesh_S (and the same for rigid), I opted to take the pre-existing pattern: volume_S, surface_R and propagate it around. Finally, for thing_X, I've named the Bvh bvh_thing_X. PTAL.

Reviewable status: 9 unresolved discussions, LGTM missing from assignee DamrongGuoy, needs platform reviewer assigned, needs at least two assigned reviewers (waiting on @DamrongGuoy)

a discussion (no related file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

This PR introduces convert_to_double() in obb.cc to temporarily allow AutoDiffXd. Could you please update this line of documentation in obb.h to reflect that?
obb.h

151  @tparam MeshType is either SurfaceMesh<double> or VolumeMesh<double>.  */
152 template <class MeshType>
153 class ObbMaker {

Right now it says only SurfaceMesh<double> or VolumeMesh<double>. Now it can takes SurfaceMesh<AutoDiffXd> and VolumeMesh<AutoDiffXd>; however, internally it converts AutoDiffXd to double.

I don't have a good way to describe these details, so I won't block this. Set to Discussing.

Done



geometry/benchmarking/mesh_intersection_benchmark.cc, line 92 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

I think this table is out of date. Could you please update it?

I ran the benchmark and surprisingly got very different number of triangles:

Resulting contact surface sizes:
 - RigidSoftMesh/0/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/1/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/3/4/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/0/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/1/0: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/2/0: 1.50 m^2, 62 triangles
 - RigidSoftMesh/2/3/0: 1.14 m^2, 159 triangles
 - RigidSoftMesh/2/4/1: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/2: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/4/3: 0.00 m^2, 0 triangles
 - RigidSoftMesh/2/3/1: 1.17 m^2, 133 triangles
 - RigidSoftMesh/2/2/2: 1.52 m^2, 70 triangles

I also went back to master branch, so I can run WithoutBVH too.

Both WithBVH and WithoutBVH agree, but they are very different from the supposedly outdated table.

The numbers are not supposed to represent what you will get if you run it. It's supposed to be representative of the kind of output you'll get. A such, it's fine as is.


geometry/proximity/bvh.h, line 26 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

Could it be T instead of U ?

Done


geometry/proximity/bvh.h, line 31 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

Could it be T instead of U ?

Done


geometry/proximity/bvh.cc, line 156 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

Could you please add a comment that these AutoDiffXd versions are here temporarily?

Done


geometry/proximity/mesh_intersection.cc, line 381 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

Remove the comment "A variant of ..." please. Now we have only one version not two variants.

Done


geometry/proximity/mesh_intersection.cc, line 447 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

I think this comment is now outdated. Could you please update this comment in one of these ways?

  1. Remove it, because the template class SurfaceVolumeIntersector<AutoDiffXd> has no compile errors anymore, or
  2. Replace it with this line to confirm that it compiles:
template class SurfaceVolumeIntersector<AutoDiffXd>;
  1. Comment that it's not recommended to do it, or
  2. Other ways as you see fit?

Done.


geometry/proximity/test/mesh_intersection_test.cc, line 1161 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

s_bvh_S please. s_bvh_S conforms with s_mesh_S better. Otherwise, we have bvh_S and bvh_R that sound like the same bvh expressed in two different frames.

Done.


geometry/proximity/test/mesh_intersection_test.cc, line 1167 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

r_bvh_R please. r_bvh_R conforms with r_mesh_R better. Otherwise, we have bvh_S and bvh_R that sound like the same bvh expressed in two different frames.

Done.


geometry/proximity/test/mesh_intersection_test.cc, line 1268 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

bvh_soft_S or soft_bvh_S please. Otherwise, bvh_S and bvh_R sound like the same bvh expressed in two different frames.

Done.


geometry/proximity/test/mesh_intersection_test.cc, line 1272 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

bvh_rigid_R or rigid_bvh_R please. Otherwise, bvh_S and bvh_R sound like the same bvh expressed in two different frames.

Done.


geometry/proximity/test/mesh_to_vtk_test.cc, line 63 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

soft_mesh_S please. Otherwise, we have mesh_S and mesh_R, which sound like the same mesh expressed in two different frames. They are two different meshes of two different resolutions.

Done.


geometry/proximity/test/mesh_to_vtk_test.cc, line 73 at r1 (raw file):

Previously, DamrongGuoy (Damrong Guoy) wrote…

rigid_mesh_R please. Otherwise, we have mesh_S and mesh_R, which sound like the same mesh expressed in two different frames. They are two different meshes.

Done.

Copy link
Contributor

@DamrongGuoy DamrongGuoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 6 of 6 files at r2.
Reviewable status: needs platform reviewer assigned, needs at least two assigned reviewers

Copy link
Contributor Author

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+@EricCousineau-TRI for platform review on Monday.

Reviewable status: LGTM missing from assignee EricCousineau-TRI(platform) (waiting on @EricCousineau-TRI)

Copy link
Contributor

@EricCousineau-TRI EricCousineau-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: with some BTWs.

Reviewed 5 of 10 files at r1, 6 of 6 files at r2.
Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees EricCousineau-TRI(platform),DamrongGuoy

a discussion (no related file):
BTW Your commits also have some minor cleanup that is not covered by your existing description.

Consider adding in a brief mention? e.g.
"Also cleans up existing code (better qualified name) and documentation (describe all arguments)."



geometry/proximity/bvh.h, line 354 at r2 (raw file):

    drake::geometry::VolumeMesh<double>>;

// TODO(SeanCurtis-TRI): Remove support for building a Bvh on an AutoDiff-valued

BTW Is there a specific issue that this is referencing? In isolation, I don't fully understand "cleaned up scalar types".


geometry/proximity/mesh_intersection.h, line 362 at r2 (raw file):

    const Bvh<SurfaceMesh<T>>& bvh_R, const math::RigidTransform<T>& X_WR);

// TODO(SeanCurtis-TRI): ComputeContactSurfaceFromSoftVolumeRigidSurface is

BTW Per above comment, this seems like the best description to describe the cleanup.
Can this be cross-referenced in that issue?

For historical reasons, computing intersection between a soft volume mesh
and a rigid surface mesh had two separate APIs. One used broadphase
acceleration with a bounding volume hierarchy (BVH) one did not. Both
APIs were propagated as a basis for measuring improvement. The need for
both APIs is long gone. So, we'll simplify the API and eliminate the slow
version. Going forward, improvements should be against strictly the best
possible results. This change had several implications:

 - mesh_intersection_benchmark now only considers one case -- it reports
   the performance of queries with the *current* BVH implementation.
 - Unit tests in mesh_intersection_test would exploit the BVH-free API to
   shorten the tests. They needed to be expanded to use the BVH API.
   - One test in particular would produce a smoke test confirming that the
     test could be used with AutoDiffXd-valued meshes. That used the old
     BVH-free API. In removing that API, we need to be able to build a
     BVH for an AutoDiffXd-valued mesh.
 - Bvh and obb (and tests) have been updated to allow constructing a BVH
   for an AutoDiffXd-valued mesh.
 - Incidentally, cleaned up names of meshes to match the quantity_F
   notation.
@SeanCurtis-TRI SeanCurtis-TRI force-pushed the PR_remove_mesh_intersection_without_bvh branch from 88c2e5f to fec5439 Compare September 28, 2020 20:43
Copy link
Contributor Author

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Reviewable status: :shipit: complete! all discussions resolved, LGTM from assignees EricCousineau-TRI(platform),DamrongGuoy (waiting on @DamrongGuoy and @EricCousineau-TRI)

a discussion (no related file):

Previously, EricCousineau-TRI (Eric Cousineau) wrote…

BTW Your commits also have some minor cleanup that is not covered by your existing description.

Consider adding in a brief mention? e.g.
"Also cleans up existing code (better qualified name) and documentation (describe all arguments)."

Done



geometry/proximity/bvh.h, line 354 at r2 (raw file):

Previously, EricCousineau-TRI (Eric Cousineau) wrote…

BTW Is there a specific issue that this is referencing? In isolation, I don't fully understand "cleaned up scalar types".

Done


geometry/proximity/mesh_intersection.h, line 362 at r2 (raw file):

Previously, EricCousineau-TRI (Eric Cousineau) wrote…

BTW Per above comment, this seems like the best description to describe the cleanup.
Can this be cross-referenced in that issue?

Done I've created an issue and cross-ref'd it.

@SeanCurtis-TRI SeanCurtis-TRI merged commit aef3590 into RobotLocomotion:master Sep 28, 2020
@SeanCurtis-TRI SeanCurtis-TRI deleted the PR_remove_mesh_intersection_without_bvh branch September 28, 2020 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: geometry proximity Contact, distance, signed distance queries and related properties priority: medium type: cleanup unused team: dynamics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[geometry] Eliminate non-BVH-dependent hydroelastic mesh intersection code
3 participants