Skip to content

Commit

Permalink
ogre helpers point_cloud: calculate bounding radius
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
C. Andy Martin committed Jul 1, 2021
1 parent 5455c25 commit cfb3f81
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/rviz/ogre_helpers/point_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,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 +570,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_);
ROS_ASSERT(op->vertexData->vertexCount + op->vertexData->vertexStart <=
rend->getBuffer()->getNumVertices());

Expand Down Expand Up @@ -620,13 +620,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_ = Ogre::Math::boundingRadiusFromAABB(bounding_box_);

shrinkRenderables();

Expand Down

0 comments on commit cfb3f81

Please sign in to comment.