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

Conversation

truhoang
Copy link
Contributor

As requested by @kunaltyagi in #3946

@kunaltyagi kunaltyagi added changelog: enhancement Meta-information for changelog generation module: recognition needs: more work Specify why not closed/merged yet labels Apr 25, 2020
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

LGTM except inline

@kunaltyagi kunaltyagi added needs: code review Specify why not closed/merged yet and removed needs: more work Specify why not closed/merged yet labels Apr 27, 2020
@kunaltyagi kunaltyagi added needs: more work Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Apr 30, 2020
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

LGTM, except the naming of the function (but that's not a blocking concern, just a bikeshedding topic)

@kunaltyagi kunaltyagi added needs: code review Specify why not closed/merged yet and removed needs: more work Specify why not closed/merged yet labels May 4, 2020
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

I missed that 👀

@kunaltyagi
Copy link
Member

kunaltyagi commented May 20, 2020

@Morwenn could you give this a look over again please?

Also, thoughts on renaming the function to use BBox or AABB instead of longer BoundingBox? The word template isn't needed in either the function name or the parameter name. A better idea for the name?

@truhoang
Copy link
Contributor Author

@Morwenn Updated with suggestions

@kunaltyagi kunaltyagi added needs: more work Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels May 29, 2020
@kunaltyagi
Copy link
Member

Ubuntu Build is failing

@@ -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

Comment on lines +165 to +166
BoundingBoxXYZ bb;
bb.x = bb.y = bb.z = std::numeric_limits<float>::max ();
Copy link
Member

Choose a reason for hiding this comment

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

Move this definition to where you actually use it. Line 187. No need to initialize it's members x, y, and z

Comment on lines +168 to +169
Eigen::Vector4f geometric_center = Eigen::Vector4f::Zero ();
Eigen::Vector4f min_pos, max_pos;
Copy link
Member

Choose a reason for hiding this comment

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

Use Eigen::Arrays and instead of matrices to express better your intent for coefficient-wise operations.

Comment on lines +173 to +185
for (const PointXYZRGBA & p : template_point_cloud.points)
{
if (!isXYZFinite(p))
continue;

center_x /= static_cast<float> (counter);
center_y /= static_cast<float> (counter);
center_z /= static_cast<float> (counter);
min_pos = min_pos.cwiseMin (p.getVector4fMap ());
max_pos = max_pos.cwiseMax (p.getVector4fMap ());

bb.width = max_x - min_x;
bb.height = max_y - min_y;
bb.depth = max_z - min_z;
geometric_center += p.getVector4fMap ();

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;
++counter;
}
geometric_center /= static_cast<float> (counter);
Copy link
Member

Choose a reason for hiding this comment

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

Have a look at this to prevent the need for having a foor loop, in case the point cloud is dense.

dim=4
stride=sizeof(PointXYZRGBA)/sizeof(float) (confirm this is an actual integer even if you did floating point division. it should be 5)
offset=0

Then use eigen function for mean and extracting min and max element.

Comment on lines +181 to +185
geometric_center += p.getVector4fMap ();

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;
++counter;
}
geometric_center /= static_cast<float> (counter);
Copy link
Member

Choose a reason for hiding this comment

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

This is not a geometric center, this is the center of mass of all points. Did you expect this to be the center of the bounding box? If so, this is a bug.

Comment on lines +187 to +190
Eigen::Vector4f bb_dim = max_pos - min_pos;
bb.width = bb_dim[0];
bb.height = bb_dim[1];
bb.depth = bb_dim[2];
Copy link
Member

@SergioRAgostinho SergioRAgostinho Jul 1, 2020

Choose a reason for hiding this comment

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

To compute the geometric center

 Eigen::Vector4f geometric_center = 0.5*(max_pos + min_pos);

p.x -= center_x;
p.y -= center_y;
p.z -= center_z;
for (PointXYZRGBA & p : template_point_cloud.points)
Copy link
Member

Choose a reason for hiding this comment

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

  for (PointXYZRGBA & p : template_point_cloud)

Comment on lines -199 to -201
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;
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.

Comment on lines +197 to +202
for (PointXYZRGBA & p : template_point_cloud.points)
{
if (!isXYZFinite(p))
continue;

template_point_cloud[j] = p;
}
p.getVector4fMap () -= geometric_center;
Copy link
Member

@SergioRAgostinho SergioRAgostinho Jul 1, 2020

Choose a reason for hiding this comment

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

No need to check if the point is finite. if it isn't the subtraction operation will generate more nans on the same points. Meaning you can use a matrix wise row subtraction with the Mapping I mentioned earlier.

@stale
Copy link

stale bot commented Aug 1, 2020

Marking this as stale due to 30 days of inactivity. Commenting or adding a new commit to the pull request will revert this.

@stale stale bot added the status: stale label Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Meta-information for changelog generation module: recognition needs: more work Specify why not closed/merged yet status: stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants