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

Fix misc point cloud ogre helper bounds issues #1644

Open
wants to merge 4 commits into
base: noetic-devel
Choose a base branch
from

Conversation

c-andy-martin
Copy link

There were a few circumstances where the point cloud ogre helper calculated incorrect bounds. These circumstances were mostly noticed when using the octomap_rviz_plugins to visualize octomaps where the maps would disappear when viewed from certain angles or zoom levels, or when using a non-unity alpha the different prune depths of the tree would render out-of-depth-order due to the bug in getSquaredViewDepth. Sorry I don't have any visuals right now to post with the PR as these commits were made on our branch of rviz a couple years ago and I'm just now getting a bit of time to send the fixes upstream.

C. Andy Martin added 4 commits July 1, 2021 16:50
The PointCloudRenderable returns an incorrect bounding radius when
the furthest corner of the box is not the minimum or maximum corner.

Use Ogre::Math::boundingRadiusFromAABB to return the correct value.
getSquaredViewDepth was not applying scene node transforms to the
camera position, resulting in incorrect values of squared depth.

Instead, find the distance in world coordinates from the bounding
box to the camera.
Instead of calculating the bounding radius of the entire cloud as
we go, calculate it once at the end when updating the bounding
box by calling Ogre::Math::boundingRadiusFromAABB on the bounding box.
Add the size of the point visual into the bounding box.
For small or zero sized points this makes little difference,
but for large points (such as visualizing an octomap with
large compressed regions), it is important to add the bounds
to keep the points visible at the very edges of the cloud.
@c-andy-martin
Copy link
Author

One of these commits (the getSquaredViewDepth) may fix #1186

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this contribution. While I agree that the original implementation is erroneous, I don't yet agree with your solution approach, which seems to overestimate the bounding box radius (see below). I started an alternative PR: #1656.
Also, I wasn't able to reproduce the actual issue. However, given a few issue reports, I agree that it exists. Could you, please, provide a simple example (ideally a cloud with a few points only that are generated programmatically) illustrating the issue?

Comment on lines +543 to +544
aabb.merge(p.position + point_size_offset);
aabb.merge(p.position - point_size_offset);
Copy link
Contributor

Choose a reason for hiding this comment

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

While I agree that the point size should be considered, I suggest doing so once in the end.
Also, you should adapt the bounding box(es) as soon as the point size changed via setDimensions().

vDist = cam->getDerivedPosition() - vMid;

return vDist.squaredLength();
return getWorldBoundingBox().squaredDistance(cam->getDerivedPosition());
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code attempted to compute the (squared) distance of the cam to the center of the bbox.
However, the new code computes the closest (squared) distance of the cam to the bbox!

@@ -571,6 +572,7 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
op->vertexData->vertexCount = current_vertex_count - op->vertexData->vertexStart;
rend->setBoundingBox(aabb);
bounding_box_.merge(aabb);
bounding_radius_ = Ogre::Math::boundingRadiusFromAABB(bounding_box_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid boundingRadiusFromAABB() is wrong as it computes the radius of the sphere around the origin that includes the bbox. However, here we need the radius of the local bounding sphere, don't we?

Only later they introduced boundingRadiusFromAABBCentered() to compute the latter.

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