-
Notifications
You must be signed in to change notification settings - Fork 66
Add GetBatchRayIntersectionFromLastStepFeature for CPU lidar #880
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
Open
apojomovsky
wants to merge
19
commits into
gazebosim:main
Choose a base branch
from
apojomovsky:feature/cpu-lidar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3192925
feat: add GetBatchRayIntersectionFromLastStepFeature
apojomovsky 42c0dc5
perf: accelerate batch raycasting with Bullet broadphase AABB culling
apojomovsky f50d96d
fix: use btCollisionWorld::rayTest() to avoid per-ray shape allocation
apojomovsky ad392b6
fix: warn once and return NaN for non-Bullet collision detectors
apojomovsky 7bd1af2
style: tighten comments to match codebase conventions
apojomovsky fbf94f7
style: add missing separator and fix alignment in SimulationFeatures
apojomovsky b06e55c
fix: add missing vector include in GetBatchRayIntersection
apojomovsky 27a3b86
nit: add explicit include
apojomovsky 9c0be3e
fix(dartsim): address batch ray intersection review feedback
apojomovsky 06ebb15
test(dartsim): add 12-ray batch intersection test
apojomovsky 8f1b799
fix(physics): remove unused VectorType alias from batch ray feature
apojomovsky d0ebb2a
refactor(dartsim): add virtual BatchRaycast to GzCollisionDetector
apojomovsky ff70ee6
Address review: std::optional BatchRaycast, move GzBulletCollisionGro…
apojomovsky 032dd33
refactor: alias GzRayResult to RayIntersectionT to eliminate redundan…
apojomovsky 0383bc5
fix: return std::nullopt instead of uninitialized results on error
apojomovsky 9dbd2d5
Merge branch 'main' into feature/cpu-lidar
apojomovsky 74bcefa
Merge branch 'main' into feature/cpu-lidar
apojomovsky 190c289
Merge branch 'main' into feature/cpu-lidar
apojomovsky 6d98b7b
Merge branch 'main' into feature/cpu-lidar
apojomovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,9 @@ | |
| #include <sstream> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
|
|
||
| #include <dart/collision/CollisionObject.hpp> | ||
|
|
@@ -38,8 +40,10 @@ | |
| #include <gz/math/Pose3.hh> | ||
| #include <gz/math/eigen3/Conversions.hh> | ||
|
|
||
| #include "gz/physics/GetBatchRayIntersection.hh" | ||
| #include "gz/physics/GetContacts.hh" | ||
|
|
||
| #include "GzCollisionDetector.hh" | ||
| #include "SimulationFeatures.hh" | ||
|
|
||
| #if DART_VERSION_AT_LEAST(6, 13, 0) | ||
|
|
@@ -238,6 +242,68 @@ SimulationFeatures::GetRayIntersectionFromLastStep( | |
| return intersection; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////// | ||
| std::vector<SimulationFeatures::BatchRayIntersection> | ||
| SimulationFeatures::GetBatchRayIntersectionFromLastStep( | ||
| const Identity &_worldID, | ||
| const std::vector<SimulationFeatures::BatchRayQuery> &_rays) const | ||
| { | ||
| std::vector<SimulationFeatures::BatchRayIntersection> results; | ||
apojomovsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| results.reserve(_rays.size()); | ||
|
|
||
| if (_rays.empty()) | ||
| return results; | ||
|
|
||
| constexpr double kNaN = std::numeric_limits<double>::quiet_NaN(); | ||
| const Eigen::Vector3d kNaNVec = Eigen::Vector3d::Constant(kNaN); | ||
|
|
||
| auto *const world = this->ReferenceInterface<DartWorld>(_worldID); | ||
| auto *const solver = world->getConstraintSolver(); | ||
|
|
||
| auto detector = solver->getCollisionDetector(); | ||
| auto *gzDetector = | ||
| dynamic_cast<dart::collision::GzCollisionDetector *>(detector.get()); | ||
|
|
||
| if (gzDetector) | ||
| { | ||
| std::vector<dart::collision::GzRay> gzRays; | ||
| gzRays.reserve(_rays.size()); | ||
| for (const auto &ray : _rays) | ||
| gzRays.push_back({ray.origin, ray.target}); | ||
|
Comment on lines
+283
to
+286
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was it not possible to just pass |
||
|
|
||
| std::vector<dart::collision::GzRayResult> gzResults; | ||
| if (gzDetector->BatchRaycast( | ||
| solver->getCollisionGroup().get(), gzRays, gzResults)) | ||
| { | ||
| for (const auto &r : gzResults) | ||
| { | ||
| SimulationFeatures::BatchRayIntersection intersection; | ||
| intersection.hit = r.hit; | ||
| intersection.point = r.point; | ||
| intersection.fraction = r.fraction; | ||
| intersection.normal = r.normal; | ||
| results.push_back(std::move(intersection)); | ||
| } | ||
apojomovsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return results; | ||
| } | ||
| } | ||
|
|
||
| // Collision detector does not support batch raycasting. | ||
| // Warn once per detector type and return NaN for all rays. | ||
| static std::unordered_set<std::string> warnedDetectors; | ||
apojomovsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const std::string detectorType = detector->getType(); | ||
| if (warnedDetectors.find(detectorType) == warnedDetectors.end()) | ||
| { | ||
| warnedDetectors.insert(detectorType); | ||
| gzwarn << "GetBatchRayIntersectionFromLastStep: collision detector [" | ||
| << detectorType << "] does not support batch raycasting. " | ||
| << "All ray results will be NaN.\n"; | ||
| } | ||
apojomovsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| results.assign(_rays.size(), {false, kNaNVec, kNaN, kNaNVec}); | ||
| return results; | ||
| } | ||
|
|
||
| std::vector<SimulationFeatures::ContactInternal> | ||
| SimulationFeatures::GetContactsFromLastStep(const Identity &_worldID) const | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.