Skip to content

Add compute bounding box member method #3970

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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 60 additions & 114 deletions recognition/include/pcl/recognition/impl/linemod/line_rgbd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,72 +150,79 @@ LineRGBD<PointXYZT, PointRGBT>::loadTemplates (const std::string &file_name, con

// Compute 3D bounding boxes from the template point clouds
bounding_boxes_.resize (template_point_clouds_.size ());
for (std::size_t i = 0; i < template_point_clouds_.size (); ++i)
for (std::size_t i = 0; i < template_point_clouds_.size (); ++i)
{
PointCloud<PointXYZRGBA> & template_point_cloud = template_point_clouds_[i];
BoundingBoxXYZ & bb = bounding_boxes_[i];
bb.x = bb.y = bb.z = std::numeric_limits<float>::max ();
bb.width = bb.height = bb.depth = 0.0f;
computeBoundingBox (i);
}

float center_x = 0.0f;
float center_y = 0.0f;
float center_z = 0.0f;
float min_x = std::numeric_limits<float>::max ();
float min_y = std::numeric_limits<float>::max ();
float min_z = std::numeric_limits<float>::max ();
float max_x = -std::numeric_limits<float>::max ();
float max_y = -std::numeric_limits<float>::max ();
float max_z = -std::numeric_limits<float>::max ();
std::size_t counter = 0;
for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
const PointXYZRGBA & p = template_point_cloud.points[j];
return (true);
}

if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointXYZT, typename PointRGBT> void
pcl::LineRGBD<PointXYZT, PointRGBT>::computeBoundingBox (int i)
{
PointCloud<PointXYZRGBA> & template_point_cloud = template_point_clouds_[i];
BoundingBoxXYZ & bb = bounding_boxes_[i];
bb.x = bb.y = bb.z = std::numeric_limits<float>::max ();
bb.width = bb.height = bb.depth = 0.0f;

float center_x = 0.0f;
float center_y = 0.0f;
float center_z = 0.0f;
float min_x = std::numeric_limits<float>::max ();
float min_y = std::numeric_limits<float>::max ();
float min_z = std::numeric_limits<float>::max ();
float max_x = -std::numeric_limits<float>::max ();
float max_y = -std::numeric_limits<float>::max ();
float max_z = -std::numeric_limits<float>::max ();
std::size_t counter = 0;
for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
const PointXYZRGBA & p = template_point_cloud.points[j];

min_x = std::min (min_x, p.x);
min_y = std::min (min_y, p.y);
min_z = std::min (min_z, p.z);
max_x = std::max (max_x, p.x);
max_y = std::max (max_y, p.y);
max_z = std::max (max_z, p.z);
if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;

center_x += p.x;
center_y += p.y;
center_z += p.z;
min_x = std::min (min_x, p.x);
min_y = std::min (min_y, p.y);
min_z = std::min (min_z, p.z);
max_x = std::max (max_x, p.x);
max_y = std::max (max_y, p.y);
max_z = std::max (max_z, p.z);

++counter;
}
center_x += p.x;
center_y += p.y;
center_z += p.z;

center_x /= static_cast<float> (counter);
center_y /= static_cast<float> (counter);
center_z /= static_cast<float> (counter);
++counter;
}

bb.width = max_x - min_x;
bb.height = max_y - min_y;
bb.depth = max_z - min_z;
center_x /= static_cast<float> (counter);
center_y /= static_cast<float> (counter);
center_z /= static_cast<float> (counter);

bb.x = (min_x + bb.width / 2.0f) - center_x - bb.width / 2.0f;
bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f;
bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f;
Comment on lines -199 to -201
Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️ I'm embarrassed this exists in our code base.

bb.width = max_x - min_x;
bb.height = max_y - min_y;
bb.depth = max_z - min_z;

for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
PointXYZRGBA p = template_point_cloud.points[j];
bb.x = (min_x + bb.width / 2.0f) - center_x - bb.width / 2.0f;
bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f;
bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f;

if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;
for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
PointXYZRGBA p = template_point_cloud.points[j];

p.x -= center_x;
p.y -= center_y;
p.z -= center_z;
if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;

template_point_cloud.points[j] = p;
}
}
p.x -= center_x;
p.y -= center_y;
p.z -= center_z;

return (true);
template_point_cloud.points[j] = p;
}
}


Expand All @@ -238,68 +245,7 @@ LineRGBD<PointXYZT, PointRGBT>::createAndAddTemplate (
bounding_boxes_.resize (template_point_clouds_.size ());
{
const std::size_t i = template_point_clouds_.size () - 1;

PointCloud<PointXYZRGBA> & template_point_cloud = template_point_clouds_[i];
BoundingBoxXYZ & bb = bounding_boxes_[i];
bb.x = bb.y = bb.z = std::numeric_limits<float>::max ();
bb.width = bb.height = bb.depth = 0.0f;

float center_x = 0.0f;
float center_y = 0.0f;
float center_z = 0.0f;
float min_x = std::numeric_limits<float>::max ();
float min_y = std::numeric_limits<float>::max ();
float min_z = std::numeric_limits<float>::max ();
float max_x = -std::numeric_limits<float>::max ();
float max_y = -std::numeric_limits<float>::max ();
float max_z = -std::numeric_limits<float>::max ();
std::size_t counter = 0;
for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
const PointXYZRGBA & p = template_point_cloud.points[j];

if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;

min_x = std::min (min_x, p.x);
min_y = std::min (min_y, p.y);
min_z = std::min (min_z, p.z);
max_x = std::max (max_x, p.x);
max_y = std::max (max_y, p.y);
max_z = std::max (max_z, p.z);

center_x += p.x;
center_y += p.y;
center_z += p.z;

++counter;
}

center_x /= static_cast<float> (counter);
center_y /= static_cast<float> (counter);
center_z /= static_cast<float> (counter);

bb.width = max_x - min_x;
bb.height = max_y - min_y;
bb.depth = max_z - min_z;

bb.x = (min_x + bb.width / 2.0f) - center_x - bb.width / 2.0f;
bb.y = (min_y + bb.height / 2.0f) - center_y - bb.height / 2.0f;
bb.z = (min_z + bb.depth / 2.0f) - center_z - bb.depth / 2.0f;

for (std::size_t j = 0; j < template_point_cloud.size (); ++j)
{
PointXYZRGBA p = template_point_cloud.points[j];

if (!std::isfinite (p.x) || !std::isfinite (p.y) || !std::isfinite (p.z))
continue;

p.x -= center_x;
p.y -= center_y;
p.z -= center_z;

template_point_cloud.points[j] = p;
}
computeBoundingBox (i);
}

std::vector<pcl::QuantizableModality*> modalities;
Expand Down
4 changes: 4 additions & 0 deletions recognition/include/pcl/recognition/linemod/line_rgbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ namespace pcl
bool
readLTMHeader (int fd, pcl::io::TARHeader &header);

/** \brief Compute bounding box from PCD masks **/
Copy link
Member

Choose a reason for hiding this comment

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

Missing parameter description

void
computeBoundingBox (int i);

/** \brief Intersection volume threshold. */
float intersection_volume_threshold_;

Expand Down