Skip to content

Commit

Permalink
PointCloud: Fix calculation of bounding radius
Browse files Browse the repository at this point in the history
Bounding sphere should be local to bounding box, not consider max length of point vectors.
If the cloud is shifted strongly into some direction, those lengths will be large,
although the bounding box (and sphere) can be small.
  • Loading branch information
rhaschke committed Aug 22, 2021
1 parent a885152 commit 7ad7879
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/rviz/ogre_helpers/point_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
Ogre::AxisAlignedBox aabb;
aabb.setNull();
uint32_t current_vertex_count = 0;
bounding_radius_ = 0.0f;
uint32_t vertex_size = 0;
uint32_t buffer_size = 0;
for (uint32_t current_point = 0; current_point < num_points; ++current_point)
Expand Down Expand Up @@ -540,7 +539,6 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
}

aabb.merge(p.position);
bounding_radius_ = std::max(bounding_radius_, p.position.squaredLength());

float x = p.position.x;
float y = p.position.y;
Expand Down Expand Up @@ -571,6 +569,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_ = bounding_box_.getHalfSize().length();
ROS_ASSERT(op->vertexData->vertexCount + op->vertexData->vertexStart <=
rend->getBuffer()->getNumVertices());

Expand Down Expand Up @@ -620,13 +619,12 @@ void PointCloud::popPoints(uint32_t num_points)

// reset bounds
bounding_box_.setNull();
bounding_radius_ = 0.0f;
for (uint32_t i = 0; i < point_count_; ++i)
{
Point& p = points_[i];
bounding_box_.merge(p.position);
bounding_radius_ = std::max(bounding_radius_, p.position.squaredLength());
}
bounding_radius_ = bounding_box_.getHalfSize().length();

shrinkRenderables();

Expand Down

0 comments on commit 7ad7879

Please sign in to comment.