Skip to content

Enable ray query for depth, segmentation and thermal cameras #483

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

Merged

Conversation

srmainwaring
Copy link
Contributor

@srmainwaring srmainwaring commented Nov 2, 2021

🦟 Bug fix

Fixes #414

Summary

This PR enables depth, segmentation and thermal cameras to set a ray query for the ogre and ogre2 render engines.

The approach Introduces mix-in classes to provide access to underlying Ogre objects in the OgreCamera / Ogre2Camera and related camera classes.

Update the mouse handling in the segmentation_camera and thermal_camera examples.

ogre_ray-query_thermal-camera

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

@srmainwaring srmainwaring requested a review from iche033 as a code owner November 2, 2021 11:12
@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #483 (2b2e72b) into main (50410bf) will decrease coverage by 0.03%.
The diff coverage is 30.55%.

❗ Current head 2b2e72b differs from pull request most recent head a5c1aaf. Consider uploading reports for the commit a5c1aaf to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #483      +/-   ##
==========================================
- Coverage   53.52%   53.48%   -0.04%     
==========================================
  Files         194      198       +4     
  Lines       19655    19679      +24     
==========================================
+ Hits        10520    10526       +6     
- Misses       9135     9153      +18     
Impacted Files Coverage Δ
...ude/ignition/rendering/ogre/OgreObjectInterface.hh 0.00% <0.00%> (ø)
ogre/src/OgreCamera.cc 0.00% <0.00%> (ø)
ogre/src/OgreDepthCamera.cc 0.00% <0.00%> (ø)
ogre/src/OgreObjectInterface.cc 0.00% <0.00%> (ø)
ogre/src/OgreRayQuery.cc 0.00% <0.00%> (ø)
ogre/src/OgreThermalCamera.cc 0.00% <0.00%> (ø)
ogre2/src/Ogre2DepthCamera.cc 86.96% <0.00%> (-0.34%) ⬇️
ogre2/src/Ogre2ObjectInterface.cc 0.00% <0.00%> (ø)
ogre2/src/Ogre2SegmentationCamera.cc 74.86% <0.00%> (-0.81%) ⬇️
ogre2/src/Ogre2ThermalCamera.cc 89.00% <0.00%> (-0.48%) ⬇️
... and 5 more

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 50410bf...a5c1aaf. Read the comment docs.

@srmainwaring srmainwaring marked this pull request as draft November 2, 2021 12:30
@srmainwaring
Copy link
Contributor Author

srmainwaring commented Nov 2, 2021

Converting to draft: while this works I'm concerned that using RTTI will result in maintenance problems later.

Using a virtual function to access the Ogre::Camera would be better, but it's not clear to me the on best way to alter the inheritance structure or introduce a mix-in class.

(There is also a problem with variable shadowing in the if - else clause which can be fixed with additional scoping if we did want to proceed with this approach).

@iche033
Copy link
Contributor

iche033 commented Nov 2, 2021

looks like the problem is that the depth, thermal, segmentation camera etc does not derive from OgreCamera / Ogre2Camera so it can't access the camera member variable.

Not sure what the consequence of changing them to derive from OgreCamera / Ogre2Camera but that's one possible option.

Another workaround I can think off is to add a function function called OgreObject() to OgreSensor / Ogre2Sensor that returns an Ogre::MovableObject object, and in the derived Ogre/Ogre2 classes just return the Ogre::Camera object. In the ray query class, you can then call the OgreObject() function and cast it to a Ogre::Camera.

open to other ideas.

@srmainwaring
Copy link
Contributor Author

Another workaround I can think off is to add a function function called OgreObject() to OgreSensor / Ogre2Sensor that returns an Ogre::MovableObject object, and in the derived Ogre/Ogre2 classes just return the Ogre::Camera object. In the ray query class, you can then call the OgreObject() function and cast it to a Ogre::Camera

This might be a good way forward. It retains some type safety and doesn't require a change to the inheritance structure. All the ignition cameras contain the ogre camera object required so can implement the function. We could add a parameter to request the type of object needed (similar to the getCustomObject() method on the Ogre::TextureGpu class that we added for Metal support). That allows for other objects to be requested if needed later without a further change to the interface. I'll update the PR with the changes for review.

- Enable depth, segmentation and thermal cameras to set a ray query for ogre and ogre2 render engines
- Make the RayQuery a friend of the various camera classes
- Update the mouse handling in the segmentation_camera and thermal_camera examples

Signed-off-by: Rhys Mainwaring <[email protected]>
- Remove line end whitespace and shorten long lines.

Signed-off-by: Rhys Mainwaring <[email protected]>
@iche033
Copy link
Contributor

iche033 commented Nov 2, 2021

sounds good, thanks

- Enable depth, segmentation and thermal cameras to set a ray query for ogre and ogre2 render engines
- Introduce mixin classes to the cameras to expose the underlying Ogre objects
- Implement methods to access Ogre::Camera and Ogre::MovableObject pointers on camera implementations
- Update ray query to use the new interface

Signed-off-by: Rhys Mainwaring <[email protected]>
@srmainwaring srmainwaring force-pushed the feature/fix-depth-camera-ray-query branch from 6af944a to f6a6e09 Compare November 3, 2021 11:04
@srmainwaring
Copy link
Contributor Author

I took a slightly different tack here: OgreSensor / Ogre2Sensor is concerned with scene nodes rather than movable objects. Rather than alter their purpose I've introduced small abstract mix-in classes to expose the underlying Ogre objects and implemented their methods in the cameras. In some cases these coincide with existing non-virtual methods on the camera class.

The mix-in class has two accessors. A specific one to access an Ogre::Camera and a general one to access an Ogre::MovableObject. I have not implemented the general case (so could remove it), but it may be useful to have if other underlying objects are required and you don't want to break ABI.

Coming up with a mix-in class name that makes sense and does not clash with existing objects is always a challenge, I went with OgreObjectInterface which is a bit clumsy and I'm not tied to it by any means. The camera access method has been chosen to coincide with any existing accessor already used (which happen to be different for the Ogre and Ogre2 render engines).

- Fix code check errors

Signed-off-by: Rhys Mainwaring <[email protected]>
- Fix code check errors - unused parameters.

Signed-off-by: Rhys Mainwaring <[email protected]>
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

ok yeah your approach is fine. Given that the OgreMovableObject accessor function is currently not used, one suggestion is to make it non-pure-virtual and just return nullptr inline so that the derived classes do not have to implement it. I think it may break ABI if the derived classes decide to override the function later but I'm leaning towards reducing the overhead of adding new camera classes for now.

inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

/// \brief Mixin class to provide direct access to Ogre objects.
class Ogre2ObjectInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll need to add IGNITION_RENDERING_OGRE2_VISIBLE here for ignition to export the symbols, i.e.

class IGNITION_RENDERING_OGRE2_VISIBLE Ogre2ObjectInterface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added export declarations and provided a default implementation for the OgreMovableObject method. Removed empty methods from the camera classes.

I'm not sure that a const char* _typename parameter is the best choice, something like the Ogre::IdString would be better but I'm not sure of the Ignition equivalent. Given that the function is a placeholder to signal intent, and that any changes to implement the method in camera classes would require a major release in any case, it's probably ok to leave it as is for now.

- Provide default implementation for method `OgreMovableObject` and add file for definition.
- Remove empty implementation of `OgreMovableObject` from cameras
- Add export declaration to class

Signed-off-by: Rhys Mainwaring <[email protected]>
@srmainwaring srmainwaring marked this pull request as ready for review November 4, 2021 09:32
- Fix incorrect include path

Signed-off-by: Rhys Mainwaring <[email protected]>
- Fix issue with the configuration of class exports

Signed-off-by: Rhys Mainwaring <[email protected]>
- Fix code check errors - unused parameters in default implementation.

Signed-off-by: Rhys Mainwaring <[email protected]>
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

works well for me. Just one minor comment, otherwise good to go.

- Fix code check errors - unused parameters in default implementation.

Signed-off-by: Rhys Mainwaring <[email protected]>
@iche033 iche033 merged commit a49ebcf into gazebosim:main Nov 5, 2021
@srmainwaring srmainwaring deleted the feature/fix-depth-camera-ray-query branch November 6, 2021 11:25
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

Successfully merging this pull request may close these issues.

2 participants