-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except inline
There was a problem hiding this 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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that 👀
@Morwenn could you give this a look over again please? Also, thoughts on renaming the function to use |
@Morwenn Updated with suggestions |
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 **/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parameter description
BoundingBoxXYZ bb; | ||
bb.x = bb.y = bb.z = std::numeric_limits<float>::max (); |
There was a problem hiding this comment.
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
Eigen::Vector4f geometric_center = Eigen::Vector4f::Zero (); | ||
Eigen::Vector4f min_pos, max_pos; |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
Eigen::Vector4f bb_dim = max_pos - min_pos; | ||
bb.width = bb_dim[0]; | ||
bb.height = bb_dim[1]; | ||
bb.depth = bb_dim[2]; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
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; |
There was a problem hiding this comment.
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.
for (PointXYZRGBA & p : template_point_cloud.points) | ||
{ | ||
if (!isXYZFinite(p)) | ||
continue; | ||
|
||
template_point_cloud[j] = p; | ||
} | ||
p.getVector4fMap () -= geometric_center; |
There was a problem hiding this comment.
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.
Marking this as stale due to 30 days of inactivity. Commenting or adding a new commit to the pull request will revert this. |
As requested by @kunaltyagi in #3946