Skip to content

Commit 7ad7879

Browse files
committed
PointCloud: Fix calculation of bounding radius
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.
1 parent a885152 commit 7ad7879

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/rviz/ogre_helpers/point_cloud.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
481481
Ogre::AxisAlignedBox aabb;
482482
aabb.setNull();
483483
uint32_t current_vertex_count = 0;
484-
bounding_radius_ = 0.0f;
485484
uint32_t vertex_size = 0;
486485
uint32_t buffer_size = 0;
487486
for (uint32_t current_point = 0; current_point < num_points; ++current_point)
@@ -540,7 +539,6 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
540539
}
541540

542541
aabb.merge(p.position);
543-
bounding_radius_ = std::max(bounding_radius_, p.position.squaredLength());
544542

545543
float x = p.position.x;
546544
float y = p.position.y;
@@ -571,6 +569,7 @@ void PointCloud::addPoints(Point* points, uint32_t num_points)
571569
op->vertexData->vertexCount = current_vertex_count - op->vertexData->vertexStart;
572570
rend->setBoundingBox(aabb);
573571
bounding_box_.merge(aabb);
572+
bounding_radius_ = bounding_box_.getHalfSize().length();
574573
ROS_ASSERT(op->vertexData->vertexCount + op->vertexData->vertexStart <=
575574
rend->getBuffer()->getNumVertices());
576575

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

621620
// reset bounds
622621
bounding_box_.setNull();
623-
bounding_radius_ = 0.0f;
624622
for (uint32_t i = 0; i < point_count_; ++i)
625623
{
626624
Point& p = points_[i];
627625
bounding_box_.merge(p.position);
628-
bounding_radius_ = std::max(bounding_radius_, p.position.squaredLength());
629626
}
627+
bounding_radius_ = bounding_box_.getHalfSize().length();
630628

631629
shrinkRenderables();
632630

0 commit comments

Comments
 (0)