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

[Citadel][TPE] Implement collision filtering using collide bitmasks and add CollisionFilterMaskFeature #69

Merged
merged 8 commits into from
Jul 6, 2020

Conversation

iche033
Copy link
Contributor

@iche033 iche033 commented Jun 23, 2020

Added collide bitmask to Collisions in tpelib for doing collision filtering.

Since collision detection in TPE is done between models (not collisions), I also added a function to Entity to get a single combined (bitwise OR'd) collide bitmask from all child collisions. e.g. if one collision within model A can collide with any one of the collisions in model B then the two models should collide.

Also added the CollisionFilterMaskFeature similar to the way it was done for dart in this pull reqeuest

iche033 added 2 commits June 23, 2020 15:33
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033 iche033 requested a review from mxgrey as a code owner June 23, 2020 22:52
@iche033 iche033 self-assigned this Jun 23, 2020
@github-actions github-actions bot added 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome labels Jun 23, 2020
@iche033 iche033 changed the title [TPE] Implement collision filtering using collide bitmasks and add CollisionFilterMaskFeature [Citadel][TPE] Implement collision filtering using collide bitmasks and add CollisionFilterMaskFeature Jun 23, 2020
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #69 into ign-physics2 will increase coverage by 0.27%.
The diff coverage is 98.36%.

Impacted file tree graph

@@               Coverage Diff                @@
##           ign-physics2      #69      +/-   ##
================================================
+ Coverage         82.46%   82.74%   +0.27%     
================================================
  Files               106      106              
  Lines              3587     3645      +58     
================================================
+ Hits               2958     3016      +58     
  Misses              629      629              
Impacted Files Coverage Δ
tpe/lib/src/Entity.hh 0.00% <ø> (ø)
tpe/lib/src/Entity.cc 85.34% <95.45%> (+2.36%) ⬆️
tpe/lib/src/Collision.cc 82.22% <100.00%> (+5.90%) ⬆️
tpe/lib/src/CollisionDetector.cc 100.00% <100.00%> (ø)
tpe/lib/src/Link.cc 100.00% <100.00%> (ø)
tpe/lib/src/Model.cc 100.00% <100.00%> (ø)
tpe/plugin/src/EntityManagementFeatures.cc 82.58% <100.00%> (+1.14%) ⬆️
tpe/plugin/src/SDFFeatures.cc 86.20% <100.00%> (+1.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2894ef4...82578e9. Read the comment docs.

Comment on lines 34 to 36
// cache of collide bitmasks
std::map<std::size_t, uint16_t> collideBitmasks;

Copy link
Member

@luca-della-vedova luca-della-vedova Jun 24, 2020

Choose a reason for hiding this comment

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

A few comments about this.
First of all you can probably see coming my "usual" feedback about using hash maps, since we are also doing quite a lot of operations on this map (number of models in the simulation squared).
But I am also not too sure about using a cache in the first place, from what I can see we are trying to avoid the overhead of iterating over the children in the Entity::GetCollideBitmask() function, what do you think about calculating / caching the entity bitmask in the Entity object in the first place?

Also small comment in the worldAabb map, if it's not out of the scope of the PR I would still suggest changing to a hash map to save a logn binary search in every find() and insert operation. All the function calls should be unchanged since the API is quite similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok yeah I think the cache for collide bitmask is probably premature optimization so I just removed it. The GetCollideBitmask function is just doing bitwise OR operations which should be fast. Updated worldAabb to use unordered_map. 1555caa

Copy link
Member

Choose a reason for hiding this comment

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

I'm still quite interested in the idea of caching the collide bitmask at the entity level (i.e. whenever a "child" is added / removed recalculate the bitmask and make the Get function be a simple property getter), do you think that would be a good approach? Otherwise this looks good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested the caching approach and ended up adding more code than I had planned so I created a separate pull request for it, #73. Feedback welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok merged #73 into this PR

Comment on lines +172 to +191
// set collide bitmask
uint16_t collideBitmask = 0xFF;
if (_sdfCollision.Element())
{
// TODO(anyone) add category_bitmask as well
auto elem = _sdfCollision.Element();
if (elem->HasElement("surface"))
{
elem = elem->GetElement("surface");
if (elem->HasElement("contact"))
{
elem = elem->GetElement("contact");
if (elem->HasElement("collide_bitmask"))
{
collideBitmask = elem->Get<unsigned int>("collide_bitmask");
this->SetCollisionFilterMask(collisionIdentity, collideBitmask);
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Just a note on this (you are probably aware of it already), the original implementation in the dart SDFFeatures was done before the availability of optional features and the ign-gazebo PR that takes care of this logic using the SDF Surface DOM. Admittedly when I did that PR I didn't double check that it could be compatible with Citadel, if that's the case we could probably backport it and get rid of this logic?

Copy link
Contributor Author

@iche033 iche033 Jun 24, 2020

Choose a reason for hiding this comment

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

I backported the collide bitmask changes to citadel in gazebosim/gz-sim#223

I just noticed that if the logic here is removed, ign-physics alone won't be able to consume the collide bitmasks flags from sdf as it will now rely on ign-gazebo to set these flags, This causes SimulationFeature_TEST.CollideBitmasks to fail unless we write extra logic in the integration test to set them. What do you think about leaving the logic here for ign-physics users that do not use ign-gazebo? I think it'll just be overriden by ign-gazebo as it parses SDF surface DOMs?

Copy link
Member

Choose a reason for hiding this comment

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

Admittedly I don't know much about use cases for ignition libraries (such as physics, or rendering) without ignition gazebo, but no strong feelings here we can leave it if it helps with testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok yeah let's leave it in there for testing purposes.

Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Copy link
Member

@luca-della-vedova luca-della-vedova left a comment

Choose a reason for hiding this comment

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

Thanks for the changes on the caching! Looks good to me

iche033 added 4 commits July 6, 2020 12:59
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
Signed-off-by: Ian Chen <ichen@osrfoundation.org>
@iche033 iche033 force-pushed the tpe_collide_bitmask branch from d753f1c to 82578e9 Compare July 6, 2020 21:41
@iche033
Copy link
Contributor Author

iche033 commented Jul 6, 2020

fixed windows build in 82578e9

@iche033 iche033 merged commit 31bc1f5 into ign-physics2 Jul 6, 2020
@iche033 iche033 deleted the tpe_collide_bitmask branch July 6, 2020 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel 🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants