-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Cleanup and improve unit test coverage for transformPointCloud functions #2245
Changes from 5 commits
0862bcb
655276b
993b04d
3b7c6d2
cc2c95b
a24da4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,16 @@ | |
#include <pcl/common/eigen.h> | ||
#include <pcl/point_types.h> | ||
#include <pcl/point_cloud.h> | ||
#include <pcl/io/pcd_io.h> | ||
#include <pcl/pcl_tests.h> | ||
|
||
#include <pcl/common/centroid.h> | ||
|
||
using namespace pcl; | ||
using pcl::test::EXPECT_EQ_VECTORS; | ||
|
||
pcl::PCLPointCloud2 cloud_blob; | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
TEST (PCL, compute3DCentroidFloat) | ||
{ | ||
|
@@ -1009,9 +1012,93 @@ TEST (PCL, computeCentroid) | |
EXPECT_FLOAT_EQ (-500, centroid.curvature); | ||
} | ||
|
||
TEST (PCL, demeanPointCloud) | ||
{ | ||
PointCloud<PointXYZ> cloud, cloud_demean; | ||
fromPCLPointCloud2 (cloud_blob, cloud); | ||
|
||
Eigen::Vector4f centroid; | ||
compute3DCentroid (cloud, centroid); | ||
EXPECT_NEAR (centroid[0], -0.0290809, 1e-4); | ||
EXPECT_NEAR (centroid[1], 0.102653, 1e-4); | ||
EXPECT_NEAR (centroid[2], 0.027302, 1e-4); | ||
EXPECT_NEAR (centroid[3], 1, 1e-4); | ||
|
||
// Check standard demean | ||
demeanPointCloud (cloud, centroid, cloud_demean); | ||
EXPECT_EQ (cloud_demean.is_dense, cloud.is_dense); | ||
EXPECT_EQ (cloud_demean.width, cloud.width); | ||
EXPECT_EQ (cloud_demean.height, cloud.height); | ||
EXPECT_EQ (cloud_demean.size (), cloud.size ()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are we expecting to happen to the previously set sensor origin and orientation? |
||
EXPECT_NEAR (cloud_demean[0].x, 0.034503, 1e-4); | ||
EXPECT_NEAR (cloud_demean[0].y, 0.010837, 1e-4); | ||
EXPECT_NEAR (cloud_demean[0].z, 0.013447, 1e-4); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firstly, there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I makes sense to initialize by default with 1.0, but from then onwards, we can't assume anything anymore. I'm not really sure how to handle this. In a sense, in most cases we're likely to have the homogeneous coordinate set to the same value in all points. But if it's not, I don't think demeanPointCloud is even handling it. So yeah, you've got a point. |
||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].x, -0.048849, 1e-4); | ||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].y, 0.072507, 1e-4); | ||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].z, -0.071702, 1e-4); | ||
|
||
std::vector<int> indices (cloud.size ()); | ||
for (int i = 0; i < static_cast<int> (indices.size ()); ++i) { indices[i] = i; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to try a case in which not all indices are used? Just the first and the last for instance? |
||
|
||
// Check standard demean w/ indices | ||
demeanPointCloud (cloud, indices, centroid, cloud_demean); | ||
EXPECT_EQ (cloud_demean.is_dense, cloud.is_dense); | ||
EXPECT_EQ (cloud_demean.width, cloud.width); | ||
EXPECT_EQ (cloud_demean.height, cloud.height); | ||
EXPECT_EQ (cloud_demean.size (), cloud.size ()); | ||
|
||
EXPECT_NEAR (cloud_demean[0].x, 0.034503, 1e-4); | ||
EXPECT_NEAR (cloud_demean[0].y, 0.010837, 1e-4); | ||
EXPECT_NEAR (cloud_demean[0].z, 0.013447, 1e-4); | ||
|
||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].x, -0.048849, 1e-4); | ||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].y, 0.072507, 1e-4); | ||
EXPECT_NEAR (cloud_demean[cloud_demean.size () - 1].z, -0.071702, 1e-4); | ||
|
||
// Check eigen demean | ||
Eigen::MatrixXf mat_demean; | ||
demeanPointCloud (cloud, centroid, mat_demean); | ||
EXPECT_EQ (mat_demean.cols (), int (cloud.size ())); | ||
EXPECT_EQ (mat_demean.rows (), 4); | ||
|
||
EXPECT_NEAR (mat_demean (0, 0), 0.034503, 1e-4); | ||
EXPECT_NEAR (mat_demean (1, 0), 0.010837, 1e-4); | ||
EXPECT_NEAR (mat_demean (2, 0), 0.013447, 1e-4); | ||
|
||
EXPECT_NEAR (mat_demean (0, cloud_demean.size () - 1), -0.048849, 1e-4); | ||
EXPECT_NEAR (mat_demean (1, cloud_demean.size () - 1), 0.072507, 1e-4); | ||
EXPECT_NEAR (mat_demean (2, cloud_demean.size () - 1), -0.071702, 1e-4); | ||
|
||
// Check eigen demean + indices | ||
demeanPointCloud (cloud, indices, centroid, mat_demean); | ||
EXPECT_EQ (mat_demean.cols (), int (cloud.size ())); | ||
EXPECT_EQ (mat_demean.rows (), 4); | ||
|
||
EXPECT_NEAR (mat_demean (0, 0), 0.034503, 1e-4); | ||
EXPECT_NEAR (mat_demean (1, 0), 0.010837, 1e-4); | ||
EXPECT_NEAR (mat_demean (2, 0), 0.013447, 1e-4); | ||
|
||
EXPECT_NEAR (mat_demean (0, cloud_demean.size () - 1), -0.048849, 1e-4); | ||
EXPECT_NEAR (mat_demean (1, cloud_demean.size () - 1), 0.072507, 1e-4); | ||
EXPECT_NEAR (mat_demean (2, cloud_demean.size () - 1), -0.071702, 1e-4); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider splitting these into 4 individual tests with a common fixture?
|
||
|
||
int | ||
main (int argc, char** argv) | ||
{ | ||
if (argc < 2) | ||
{ | ||
std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl; | ||
return (-1); | ||
} | ||
if (io::loadPCDFile (argv[1], cloud_blob) < 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to avoid having to load bunny from a PCD file. It would remove Why not populate randomly a 10x3 Eigen matrix and use that as a data source? |
||
{ | ||
std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl; | ||
return (-1); | ||
} | ||
|
||
testing::InitGoogleTest (&argc, argv); | ||
return (RUN_ALL_TESTS ()); | ||
} | ||
|
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.
❤️