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

Add get3DPatch to ViewPicker public API #657

Merged
merged 1 commit into from
Mar 17, 2021

Conversation

schornakj
Copy link
Contributor

@schornakj schornakj commented Mar 3, 2021

ViewPicker::get3DPatch is currently a private member function of the ViewPicker class. It would be very useful to make it public, since this lets us develop plugins that can use the orientations of mesh surfaces and point clouds in the 3D scene. This change moves it from the private API to the public API.

Additionally, the method in which OGRE packs depth pixel data has changed in the version currently used by RViz2. In ROS Melodic RViz each uint32 pixel was represented by 4 sequential uint8 elements in an array, but only the first 3 elements actually contained useful data and the 4th element was discarded. In the current version (I'm testing with Foxy right now) it looks like each depth pixel is now represented by just 3 sequential uint8 elements, without the 4th "empty" index. This means that the previous method of accessing the data for each pixel by index relative to the start of the array no longer works correctly and returns mangled or misaligned data for all pixels after the first. A change to the data pointer indexing method in the ViewPicker::getPatchDepthImage function was needed to correctly calculate distances from the scene camera when getting patches containing more than one pixel.

The data indexing bug did not cause problems previously because it does not affect the depth value for the first pixel in the array. ViewPicker::getPatchDepthImage is only used by ViewPicker::get3DPatch, which is itself only used by ViewPicker::get3DPoint to get a single-pixel patch. This issue is also somewhat challenging to demonstrate, since I think the current RViz test suite only uses mock versions of these functions.

#661 now contains the pixel byte indexing fix described above which was originally part of this PR.

Signed-off-by: Joe Schornak joe.schornak@gmail.com

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

The changes look okay to me. It would be nicer to keep the bug fix separate from the API change. It'll make it easier to backport the fix independent of the API change, for example. If you don't mind, could you open a separate API with the bug fix?

uint8_t c = data_ptr[4 * pixel + 2];
uint8_t a = data_ptr[3 * pixel];
uint8_t b = data_ptr[3 * pixel + 1];
uint8_t c = data_ptr[3 * pixel + 2];
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. I took a look through the code, and I think we expect three values per pixel because of the format set here:

It's possible in ROS 1, the format included an alpha channel, hence 4 bytes. It might be a good idea to assert that the pixel box data is three-channel, prior to extracting values. Could you try adding the following before this loop?

assert(Ogre::PF_R8G8B8 == depth_pixel_box_.format);

It might be worth leaving that in there just in case, or at least referencing in a comment where this format is coming from.

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 added this assert and an explanatory comment in #661

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 was trying to figure out where this actually changed as well, unfortunately without much success so far. The depth_render_texture_ is initialized with the same PF_R8G8B8 enum value in Melodic and Noetic RViz:

depth_render_texture_ = Ogre::TextureManager::getSingleton().createManual(
  tex_name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
  depth_texture_width_, depth_texture_height_, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);

@schornakj schornakj force-pushed the feature/view-picker-get3Dpatch branch from 9f25d21 to 308f99c Compare March 12, 2021 04:37
@schornakj schornakj changed the title Add get3DPatch to ViewPicker public API; Fix bug when getting depth image from OGRE Add get3DPatch to ViewPicker public API Mar 12, 2021
@schornakj schornakj force-pushed the feature/view-picker-get3Dpatch branch from 308f99c to 08d0ca2 Compare March 12, 2021 04:40
@schornakj
Copy link
Contributor Author

The changes look okay to me. It would be nicer to keep the bug fix separate from the API change. It'll make it easier to backport the fix independent of the API change, for example. If you don't mind, could you open a separate API with the bug fix?

I moved the bug fix to a new PR at #661. That's definitely a more sensible way to arrange things -- I was only thinking about getting these functions working in order to make my code work!

ViewPicker::get3DPatch is currently a private member function of the ViewPicker class.
It would be very useful to make it public, since this lets us develop plugins that
can use the orientations of mesh surfaces and point clouds in the 3D scene.
This change moves it from the private API to the public API.

Signed-off-by: Joe Schornak <joe.schornak@gmail.com>
@schornakj schornakj force-pushed the feature/view-picker-get3Dpatch branch from 08d0ca2 to 6466b2b Compare March 12, 2021 17:32
@jacobperron jacobperron added the enhancement New feature or request label Mar 16, 2021
Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@jacobperron jacobperron merged commit 88661c2 into ros2:ros2 Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants