diff --git a/test/io/test_octree_compression.cpp b/test/io/test_octree_compression.cpp index f2c90aab877..936c8b32285 100644 --- a/test/io/test_octree_compression.cpp +++ b/test/io/test_octree_compression.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,9 @@ int total_runs = 0; char* pcd_file; +std::random_device rd; +pcl::common::UniformGenerator gen; + #define MAX_POINTS 10000.0 #define MAX_XYZ 1024.0 #define MAX_COLOR 255 @@ -57,9 +61,9 @@ char* pcd_file; TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA) { - srand(static_cast (time(NULL))); + gen.setSeed(rd()); - // iterate over all pre-defined compression profiles + // iterate over all pre-defined compression profiles for (int compression_profile = pcl::io::LOW_RES_ONLINE_COMPRESSION_WITHOUT_COLOR; compression_profile != pcl::io::COMPRESSION_PROFILE_COUNT; ++compression_profile) { // instantiate point cloud compression encoder/decoder @@ -71,7 +75,8 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA) { try { - int point_count = MAX_POINTS * rand() / RAND_MAX; + gen.setParameters(0, MAX_POINTS); + int point_count = gen.run(); if (point_count < 1) { // empty point cloud hangs decoder total_runs--; @@ -85,13 +90,15 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA) { // gereate a random point pcl::PointXYZRGBA new_point; - new_point.x = static_cast (MAX_XYZ * rand() / RAND_MAX); - new_point.y = static_cast (MAX_XYZ * rand() / RAND_MAX), - new_point.z = static_cast (MAX_XYZ * rand() / RAND_MAX); - new_point.r = static_cast (MAX_COLOR * rand() / RAND_MAX); - new_point.g = static_cast (MAX_COLOR * rand() / RAND_MAX); - new_point.b = static_cast (MAX_COLOR * rand() / RAND_MAX); - new_point.a = static_cast (MAX_COLOR * rand() / RAND_MAX); + gen.setParameters(0, MAX_XYZ); + new_point.x = gen.run(); + new_point.y = gen.run(); + new_point.z = gen.run(); + gen.setParameters(0, MAX_COLOR); + new_point.r = gen.run(); + new_point.g = gen.run(); + new_point.b = gen.run(); + new_point.a = gen.run(); // OctreePointCloudPointVector can store all points.. cloud->push_back(new_point); } @@ -113,7 +120,7 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA) TEST (PCL, OctreeDeCompressionRandomPointXYZ) { - srand(static_cast (time(NULL))); + gen.setSeed(rd()); // iterate over all pre-defined compression profiles for (int compression_profile = pcl::io::LOW_RES_ONLINE_COMPRESSION_WITHOUT_COLOR; @@ -126,17 +133,19 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZ) // loop over runs for (int test_idx = 0; test_idx < NUMBER_OF_TEST_RUNS; test_idx++, total_runs++) { - int point_count = MAX_POINTS * rand() / RAND_MAX; + gen.setParameters(0, MAX_POINTS); + int point_count = gen.run(); // create shared pointcloud instances pcl::PointCloud::Ptr cloud(new pcl::PointCloud()); // assign input point clouds to octree // create random point cloud + gen.setParameters(0, MAX_XYZ); for (int point = 0; point < point_count; point++) { // generate a random point - pcl::PointXYZ new_point(static_cast (MAX_XYZ * rand() / RAND_MAX), - static_cast (MAX_XYZ * rand() / RAND_MAX), - static_cast (MAX_XYZ * rand() / RAND_MAX)); + pcl::PointXYZ new_point(static_cast (gen.run()), + static_cast (gen.run()), + static_cast (gen.run())); cloud->push_back(new_point); } // std::cout << "Run: " << total_runs << " compression profile:" << compression_profile << " point_count: " << point_count; diff --git a/test/octree/test_octree.cpp b/test/octree/test_octree.cpp index 6d7b1005a1f..8564a22f701 100644 --- a/test/octree/test_octree.cpp +++ b/test/octree/test_octree.cpp @@ -45,15 +45,22 @@ using namespace std; #include +#include #include #include using namespace pcl; +using namespace pcl::common; #include #include #include +std::random_device rd; +common::CloudGenerator> cloud_gen; +common::UniformGenerator f_gen; +common::UniformGenerator u_gen; + using namespace octree; TEST (PCL, Octree_Test) @@ -76,8 +83,6 @@ TEST (PCL, Octree_Test) }; MyVoxel voxels[256]; - srand (static_cast (time (nullptr))); - // generate some voxel indices for (unsigned int i = 0; i < 256; i++) { @@ -292,17 +297,14 @@ TEST (PCL, Octree_Dynamic_Depth_Test) cloud->points.clear (); octree.deleteTree (); - for (int point = 0; point < pointcount; point++) - { - // gereate a random point - PointXYZ newPoint (static_cast (1024.0 * rand () / RAND_MAX), - static_cast (1024.0 * rand () / RAND_MAX), - static_cast (1024.0 * rand () / RAND_MAX)); - - // OctreePointCloudPointVector can store all points.. - cloud->push_back (newPoint); - } + UniformGenerator::Parameters x_params(0, 1024, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 1024, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 1024, rd()); + cloud_gen.setParametersForZ (z_params); + ASSERT_EQ(cloud_gen.fill (pointcount, 1, *cloud), 0); // check if all points from leaf data can be found in input pointcloud data sets octree.defineBoundingBox (); @@ -390,8 +392,6 @@ TEST (PCL, Octree2Buf_Test) int data[256]; MyVoxel voxels[256]; - srand (static_cast (time (nullptr))); - // generate some voxel indices for (unsigned int i = 0; i < 256; i++) { @@ -557,7 +557,7 @@ TEST (PCL, Octree2Buf_Base_Double_Buffering_Test) int data[TESTPOINTS]; MyVoxel voxels[TESTPOINTS]; - srand (static_cast (time (nullptr))); + u_gen.setSeed(rd()); const unsigned int test_runs = 20; @@ -568,20 +568,22 @@ TEST (PCL, Octree2Buf_Base_Double_Buffering_Test) octreeA.setTreeDepth (5); octreeB.setTreeDepth (5); - unsigned int runs = rand () % 20 + 1; + u_gen.setParameters(1, 20); + unsigned int runs = u_gen.run(); for (unsigned int k = 0; k < runs; k++) { // switch buffers octreeA.switchBuffers (); octreeB.switchBuffers (); + u_gen.setParameters(0, 4096); for (unsigned int i = 0; i < TESTPOINTS; i++) { - data[i] = rand (); + data[i] = u_gen.run(); - voxels[i].x = rand () % 4096; - voxels[i].y = rand () % 4096; - voxels[i].z = rand () % 4096; + voxels[i].x = u_gen.run(); + voxels[i].y = u_gen.run(); + voxels[i].z = u_gen.run(); // add data to octree @@ -638,19 +640,20 @@ TEST (PCL, Octree2Buf_Base_Double_Buffering_XOR_Test) int data[TESTPOINTS]; MyVoxel voxels[TESTPOINTS]; - srand (static_cast (time (nullptr))); + u_gen.setSeed(rd()); const unsigned int test_runs = 15; + u_gen.setParameters(0, 4096); for (unsigned int j = 0; j < test_runs; j++) { for (unsigned int i = 0; i < TESTPOINTS; i++) { - data[i] = rand (); + data[i] = u_gen.run(); - voxels[i].x = rand () % 4096; - voxels[i].y = rand () % 4096; - voxels[i].z = rand () % 4096; + voxels[i].x = u_gen.run(); + voxels[i].y = u_gen.run(); + voxels[i].z = u_gen.run(); // add data to octree @@ -689,7 +692,9 @@ TEST (PCL, Octree_Pointcloud_Test) constexpr float resolution = 0.01f; - // instantiate OctreePointCloudSinglePoint and OctreePointCloudPointVector classes + f_gen.setSeed(rd()); + +// instantiate OctreePointCloudSinglePoint and OctreePointCloudPointVector classes OctreePointCloudSinglePoint octreeA (resolution); OctreePointCloudSearch octreeB (resolution); OctreePointCloudPointVector octreeC (resolution); @@ -715,12 +720,11 @@ TEST (PCL, Octree_Pointcloud_Test) octreeC.deleteTree (); + f_gen.setParameters(0, 1024); for (int point = 0; point < pointcount; point++) { // gereate a random point - PointXYZ newPoint (static_cast (1024.0 * rand () / RAND_MAX), - static_cast (1024.0 * rand () / RAND_MAX), - static_cast (1024.0 * rand () / RAND_MAX)); + PointXYZ newPoint (f_gen.run(), f_gen.run(), f_gen.run()); if (!octreeA.isVoxelOccupiedAtPoint (newPoint)) { @@ -936,7 +940,12 @@ TEST(PCL, Octree_Pointcloud_Occupancy_Test) OctreePointCloudOccupancy octree (0.00001f); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 5, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 10, rd()); + cloud_gen.setParametersForZ (z_params); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { @@ -946,12 +955,7 @@ TEST(PCL, Octree_Pointcloud_Occupancy_Test) cloudIn->points.resize (cloudIn->width * cloudIn->height); // generate point data for point cloud - for (std::size_t i = 0; i < 1000; i++) - { - cloudIn->points[i] = PointXYZ (static_cast (5.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(*cloudIn), 0); // create octree octree.setInputCloud (cloudIn); @@ -975,19 +979,20 @@ TEST (PCL, Octree_Pointcloud_Change_Detector_Test) OctreePointCloudChangeDetector octree (0.01f); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 5, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 10, rd()); + cloud_gen.setParametersForZ (z_params); + f_gen.setSeed(rd()); cloudIn->width = 1000; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); // generate point data for point cloud - for (std::size_t i = 0; i < 1000; i++) - { - cloudIn->points[i] = PointXYZ (static_cast (5.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(*cloudIn), 0); // assign point cloud to octree octree.setInputCloud (cloudIn); @@ -1002,13 +1007,11 @@ TEST (PCL, Octree_Pointcloud_Change_Detector_Test) octree.addPointsFromInputCloud (); // add 1000 additional points + f_gen.setParameters(0, 10); for (std::size_t i = 0; i < 1000; i++) { octree.addPointToCloud ( - PointXYZ (static_cast (100.0 + 5.0 * rand () / RAND_MAX), - static_cast (100.0 + 10.0 * rand () / RAND_MAX), - static_cast (100.0 + 10.0 * rand () / RAND_MAX)), - cloudIn); + PointXYZ (100.0 + (f_gen.run() / 2), 100.0 + f_gen.run(), 100.0 + f_gen.run()), cloudIn); } std::vector newPointIdxVector; @@ -1036,8 +1039,6 @@ TEST (PCL, Octree_Pointcloud_Voxel_Centroid_Test) OctreePointCloudVoxelCentroid octree (1.0f); octree.defineBoundingBox (10.0, 10.0, 10.0); - srand (static_cast (time (nullptr))); - cloudIn->width = 10 * 3; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); @@ -1132,7 +1133,14 @@ TEST (PCL, Octree_Pointcloud_Nearest_K_Neighbour_Search) // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 5, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 10, rd()); + cloud_gen.setParametersForZ (z_params); + f_gen.setSeed(rd()); + u_gen.setSeed(rd()); std::priority_queue::VectorType> pointCandidates; @@ -1146,26 +1154,21 @@ TEST (PCL, Octree_Pointcloud_Nearest_K_Neighbour_Search) std::vector k_indices_bruteforce; std::vector k_sqr_distances_bruteforce; + u_gen.setParameters(1, 10); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { // define a random search point - PointXYZ searchPoint (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); + f_gen.setParameters(0, 10); + PointXYZ searchPoint (f_gen.run(), f_gen.run(), f_gen.run()); - unsigned int K = 1 + rand () % 10; + unsigned int K = u_gen.run(); // generate point cloud cloudIn->width = 1000; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); - for (std::size_t i = 0; i < 1000; i++) - { - cloudIn->points[i] = PointXYZ (static_cast (5.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(*cloudIn), 0); k_indices.clear (); k_sqr_distances.clear (); @@ -1231,7 +1234,13 @@ TEST (PCL, Octree_Pointcloud_Box_Search) // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 10, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 10, rd()); + cloud_gen.setParametersForZ (z_params); + f_gen.setSeed(rd()); // create octree OctreePointCloudSearch octree (1); @@ -1245,12 +1254,7 @@ TEST (PCL, Octree_Pointcloud_Box_Search) cloudIn->width = 300; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); - for (auto &point : cloudIn->points) - { - point = PointXYZ (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(*cloudIn), 0); // octree points to octree @@ -1258,13 +1262,10 @@ TEST (PCL, Octree_Pointcloud_Box_Search) octree.addPointsFromInputCloud (); // define a random search area - - Eigen::Vector3f lowerBoxCorner (static_cast (4.0 * rand () / RAND_MAX), - static_cast (4.0 * rand () / RAND_MAX), - static_cast (4.0 * rand () / RAND_MAX)); - Eigen::Vector3f upperBoxCorner (static_cast (5.0 + 4.0 * rand () / RAND_MAX), - static_cast (5.0 + 4.0 * rand () / RAND_MAX), - static_cast (5.0 + 4.0 * rand () / RAND_MAX)); + f_gen.setParameters(0, 4); + Eigen::Vector3f lowerBoxCorner (f_gen.run(), f_gen.run(), f_gen.run()); + f_gen.setParameters(5, 9); + Eigen::Vector3f upperBoxCorner (f_gen.run(), f_gen.run(), f_gen.run()); octree.boxSearch (lowerBoxCorner, upperBoxCorner, k_indices); @@ -1300,7 +1301,13 @@ TEST(PCL, Octree_Pointcloud_Approx_Nearest_Neighbour_Search) // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 5, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 10, rd()); + cloud_gen.setParametersForZ (z_params); + f_gen.setSeed(rd()); constexpr double voxelResolution = 0.1; @@ -1312,20 +1319,13 @@ TEST(PCL, Octree_Pointcloud_Approx_Nearest_Neighbour_Search) { // define a random search point - PointXYZ searchPoint (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); + PointXYZ searchPoint (f_gen.run(), f_gen.run(), f_gen.run()); // generate point cloud cloudIn->width = 1000; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); - for (std::size_t i = 0; i < 1000; i++) - { - cloudIn->points[i] = PointXYZ (static_cast (5.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(*cloudIn), 0); // brute force search double BFdistance = std::numeric_limits::max (); @@ -1373,26 +1373,26 @@ TEST (PCL, Octree_Pointcloud_Neighbours_Within_Radius_Search) PointCloud::Ptr cloudIn (new PointCloud ()); PointCloud::Ptr cloudOut (new PointCloud ()); - srand (static_cast (time (nullptr))); + UniformGenerator::Parameters x_params(0, 10, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 10, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 5, rd()); + cloud_gen.setParametersForZ (z_params); + f_gen.setSeed(rd()); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { + f_gen.setParameters(0, 0.10); // define a random search point - PointXYZ searchPoint (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); + PointXYZ searchPoint (f_gen.run(), f_gen.run(), f_gen.run()); cloudIn->width = 1000; cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); // generate point cloud data - for (std::size_t i = 0; i < 1000; i++) - { - cloudIn->points[i] = PointXYZ (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (5.0 * rand () / RAND_MAX)); - } + ASSERT_EQ(cloud_gen.fill(1000, 1, *cloudIn), 0); OctreePointCloudSearch octree (0.001); @@ -1401,7 +1401,8 @@ TEST (PCL, Octree_Pointcloud_Neighbours_Within_Radius_Search) octree.addPointsFromInputCloud (); double pointDist; - double searchRadius = 5.0 * static_cast (rand () / RAND_MAX); + f_gen.setParameters(0, 5.0); + double searchRadius = f_gen.run(); // bruteforce radius search std::vector cloudSearchBruteforce; @@ -1465,7 +1466,7 @@ TEST (PCL, Octree_Pointcloud_Ray_Traversal) // Indices in ray std::vector indicesInRay, indicesInRay2; - srand (static_cast (time (nullptr))); + f_gen.setSeed(rd()); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { @@ -1478,14 +1479,11 @@ TEST (PCL, Octree_Pointcloud_Ray_Traversal) cloudIn->height = 1; cloudIn->points.resize (cloudIn->width * cloudIn->height); - Eigen::Vector3f p (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); + f_gen.setParameters(0, 10); + Eigen::Vector3f p (f_gen.run(), f_gen.run(), f_gen.run()); // origin - Eigen::Vector3f o (static_cast (12.0 * rand () / RAND_MAX), - static_cast (12.0 * rand () / RAND_MAX), - static_cast (12.0 * rand () / RAND_MAX)); + Eigen::Vector3f o (f_gen.run(), f_gen.run(), f_gen.run()); cloudIn->points[0] = pcl::PointXYZ (p[0], p[1], p[2]); @@ -1537,18 +1535,18 @@ TEST (PCL, Octree_Pointcloud_Adjacency) { constexpr unsigned int test_runs = 100; - srand (static_cast (time (nullptr))); + f_gen.setSeed(rd()); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - float resolution = static_cast (0.01 * rand () / RAND_MAX) + 0.00001f; + f_gen.setParameters(0, 0.01); + float resolution = f_gen.run() + 0.00001f; //Define a random point - PointXYZ point (static_cast (0.5 * rand () / RAND_MAX), - static_cast (0.5 * rand () / RAND_MAX), - static_cast (0.5 * rand () / RAND_MAX)); + f_gen.setParameters(0, 0.5); + PointXYZ point (f_gen.run(), f_gen.run(), f_gen.run()); //This is done to define the grid PointXYZ p1 (10,10,10); PointXYZ p2 (-10,-10,-10); @@ -1576,11 +1574,10 @@ TEST (PCL, Octree_Pointcloud_Adjacency) static_cast (point.z + 10*resolution)); cloudIn->push_back (point2); // Add points which are not neighbors + f_gen.setParameters(0, 10); for (int i = 0; i < 100; ++i) { - PointXYZ not_neighbor_point (static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX), - static_cast (10.0 * rand () / RAND_MAX)); + PointXYZ not_neighbor_point (f_gen.run(), f_gen.run(), f_gen.run()); if ( (point2.getVector3fMap () - not_neighbor_point.getVector3fMap ()).norm () > 3*resolution ) { cloudIn->push_back(not_neighbor_point); diff --git a/test/registration/test_registration.cpp b/test/registration/test_registration.cpp index f05cf49523c..5ce2467ddba 100644 --- a/test/registration/test_registration.cpp +++ b/test/registration/test_registration.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -64,8 +65,14 @@ using namespace pcl; using namespace pcl::io; +using namespace pcl::common; using namespace std; +std::random_device rd; +CloudGenerator> cloud_gen; +UniformGenerator f_gen; + + PointCloud cloud_source, cloud_target, cloud_reg; PointCloud cloud_with_color; @@ -164,13 +171,14 @@ TEST(PCL, ICP_translated) pcl::PointCloud::Ptr cloud_in(new pcl::PointCloud(5,1)); pcl::PointCloud::Ptr cloud_out(new pcl::PointCloud); - // Fill in the CloudIn data - for (auto& point : *cloud_in) - { - point.x = 1024 * rand() / (RAND_MAX + 1.0f); - point.y = 1024 * rand() / (RAND_MAX + 1.0f); - point.z = 1024 * rand() / (RAND_MAX + 1.0f); - } + UniformGenerator::Parameters x_params(0, 1024, rd()); + cloud_gen.setParametersForX (x_params); + UniformGenerator::Parameters y_params (0, 1024, rd()); + cloud_gen.setParametersForY (y_params); + UniformGenerator::Parameters z_params (0, 1024, rd()); + cloud_gen.setParametersForZ (z_params); + + ASSERT_EQ(cloud_gen.fill(*cloud_in), 0); *cloud_out = *cloud_in; @@ -248,12 +256,12 @@ TEST (PCL, IterativeClosestPointWithNormals) void sampleRandomTransform (Eigen::Affine3f &trans, float max_angle, float max_trans) { - srand(0); + f_gen.setParameters(0, 1, rd()); // Sample random transform - Eigen::Vector3f axis((float)rand() / RAND_MAX, (float)rand() / RAND_MAX, (float)rand() / RAND_MAX); + Eigen::Vector3f axis(f_gen.run(), f_gen.run(), f_gen.run()); axis.normalize(); - float angle = (float)rand() / RAND_MAX * max_angle; - Eigen::Vector3f translation((float)rand() / RAND_MAX, (float)rand() / RAND_MAX, (float)rand() / RAND_MAX); + float angle = f_gen.run() * max_angle; + Eigen::Vector3f translation(f_gen.run(), f_gen.run(), f_gen.run()); translation *= max_trans; Eigen::Affine3f rotation(Eigen::AngleAxis(angle, axis)); trans = Eigen::Translation3f(translation) * rotation; diff --git a/test/search/CMakeLists.txt b/test/search/CMakeLists.txt index 86daad88dc6..799e7a8420c 100644 --- a/test/search/CMakeLists.txt +++ b/test/search/CMakeLists.txt @@ -22,7 +22,7 @@ PCL_ADD_TEST(flann_search test_flann_search PCL_ADD_TEST(organized_neighbor test_organized_search FILES test_organized.cpp - LINK_WITH pcl_gtest pcl_search pcl_kdtree) + LINK_WITH pcl_gtest pcl_search pcl_common pcl_kdtree) PCL_ADD_TEST(octree_search test_octree_search FILES test_octree.cpp diff --git a/test/search/test_organized.cpp b/test/search/test_organized.cpp index 654a74fc5a2..bab3e79596c 100644 --- a/test/search/test_organized.cpp +++ b/test/search/test_organized.cpp @@ -50,6 +50,11 @@ using namespace std; using namespace pcl; #include +#include + +std::random_device rd; +pcl::common::UniformGenerator u_gen; +pcl::common::UniformGenerator d_gen; // helper class for priority queue @@ -84,7 +89,8 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Nearest_K_Neighbour_Search) // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - srand (int (time (nullptr))); + u_gen.setSeed(rd()); + d_gen.setSeed(rd()); // create organized search search::OrganizedNeighbor organizedNeighborSearch; @@ -101,8 +107,8 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Nearest_K_Neighbour_Search) for (unsigned int test_id = 0; test_id < test_runs; test_id++) { // define a random search point - - const unsigned int K = (rand () % 10)+1; + u_gen.setParameters(1, 10); + const unsigned int K = u_gen.run(); // generate point cloud cloudIn->width = 128; @@ -110,20 +116,23 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Nearest_K_Neighbour_Search) cloudIn->points.clear(); cloudIn->points.reserve (cloudIn->width * cloudIn->height); + u_gen.setParameters(0, cloudIn->width * cloudIn->height); + d_gen.setParameters(0, 1); + int centerX = cloudIn->width >> 1; int centerY = cloudIn->height >> 1; for (int ypos = -centerY; ypos < centerY; ypos++) for (int xpos = -centerX; xpos < centerX; xpos++) { - double z = 15.0 * (double (rand ()) / double (RAND_MAX+1.0))+20; + double z = 15.0 * d_gen.run() + 20; double y = ypos * oneOverFocalLength * z; double x = xpos * oneOverFocalLength * z; cloudIn->points.emplace_back(float (x), float (y), float (z)); } - unsigned int searchIdx = rand()%(cloudIn->width * cloudIn->height); + unsigned int searchIdx = u_gen.run(); const PointXYZ& searchPoint = cloudIn->points[searchIdx]; k_indices.clear(); @@ -185,7 +194,8 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Neighbours_Within_Radius_Search) { constexpr unsigned int test_runs = 10; - srand (int (time (nullptr))); + u_gen.setSeed(rd()); + d_gen.setSeed(rd()); search::OrganizedNeighbor organizedNeighborSearch; @@ -202,6 +212,9 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Neighbours_Within_Radius_Search) cloudIn->points.clear(); cloudIn->points.resize (cloudIn->width * cloudIn->height); + u_gen.setParameters(0, cloudIn->width * cloudIn->height); + d_gen.setParameters(0, 1); + int centerX = cloudIn->width >> 1; int centerY = cloudIn->height >> 1; @@ -209,19 +222,19 @@ TEST (PCL, Organized_Neighbor_Pointcloud_Neighbours_Within_Radius_Search) for (int ypos = -centerY; ypos < centerY; ypos++) for (int xpos = -centerX; xpos < centerX; xpos++) { - double z = 5.0 * ( (double (rand ()) / double (RAND_MAX)))+5; + double z = 5.0 *d_gen.run() + 5; double y = ypos*oneOverFocalLength*z; double x = xpos*oneOverFocalLength*z; cloudIn->points[idx++]= PointXYZ (float (x), float (y), float (z)); } - unsigned int randomIdx = rand()%(cloudIn->width * cloudIn->height); + unsigned int randomIdx = u_gen.run(); const PointXYZ& searchPoint = cloudIn->points[randomIdx]; double pointDist; - double searchRadius = 1.0 * (double (rand ()) / double (RAND_MAX)); + double searchRadius = 1.0 * d_gen.run(); // bruteforce radius search std::vector cloudSearchBruteforce; diff --git a/test/search/test_organized_index.cpp b/test/search/test_organized_index.cpp index 24afaaedc5e..df04caf78af 100644 --- a/test/search/test_organized_index.cpp +++ b/test/search/test_organized_index.cpp @@ -43,10 +43,15 @@ #include #include #include +#include using namespace std; using namespace pcl; +std::random_device rd; +pcl::common::UniformGenerator u_gen; +pcl::common::UniformGenerator d_gen; + // helper class for priority queue class prioPointQueueEntry { @@ -78,7 +83,8 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search) // instantiate point cloud PointCloud::Ptr cloudIn (new PointCloud ()); - srand (time (NULL)); + u_gen.setSeed(rd()); + d_gen.setSeed(rd()); // create organized search pcl::search::OrganizedNeighbor organizedNeighborSearch; @@ -96,7 +102,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search) { // define a random search point - const unsigned int K = (rand () % 10)+1; + const unsigned int K = +1; // generate point cloud cloudIn->width = 128; @@ -104,20 +110,23 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search) cloudIn->points.clear(); cloudIn->points.reserve (cloudIn->width * cloudIn->height); + u_gen.setParameters(0, cloudIn->width * cloudIn->height); + d_gen.setParameters(0, 1); + int centerX = cloudIn->width >> 1; int centerY = cloudIn->height >> 1; for (int ypos = -centerY; ypos < centerY; ypos++) for (int xpos = -centerX; xpos < centerX; xpos++) { - double z = 15.0 * ((double)rand () / (double)(RAND_MAX+1.0))+20; + double z = 15.0 * d_gen.run() + 20; double y = (double)ypos*oneOverFocalLength*(double)z; double x = (double)xpos*oneOverFocalLength*(double)z; cloudIn->points.push_back(PointXYZ (x, y, z)); } - unsigned int searchIdx = rand()%(cloudIn->width * cloudIn->height); + unsigned int searchIdx = u_gen.run(); const PointXYZ& searchPoint = cloudIn->points[searchIdx]; k_indices.clear(); @@ -179,7 +188,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search_Kinec // instantiate point cloud - srand (time (NULL)); + u_gen.setSeed(rd()); // create organized search pcl::search::OrganizedNeighbor organizedNeighborSearch; @@ -202,18 +211,20 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search_Kinec return; } + u_gen.setParameters(0, cloudIn->width * cloudIn->height); while(1) { - searchIdx = rand()%(cloudIn->width * cloudIn->height); + searchIdx = u_gen.run(); if(cloudIn->points[searchIdx].z < 100) break; } + u_gen.setParameters(1, 10); for (unsigned int test_id = 0; test_id < test_runs; test_id++) { // define a random search point - const unsigned int K = (rand () % 10)+1; + const unsigned int K = u_gen.run(); // K = 16; // generate point cloud const PointXYZ& searchPoint = cloudIn->points[searchIdx]; @@ -262,9 +273,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Nearest_K_Neighbour_Search_Kinec TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search) { constexpr unsigned int test_runs = 10; + u_gen.setSeed(rd()); + d_gen.setSeed(rd()); - srand (time (NULL)); - pcl::search::OrganizedNeighbor organizedNeighborSearch; std::vector k_indices; @@ -286,6 +297,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search) cloudIn->points.clear(); cloudIn->points.resize (cloudIn->width * cloudIn->height); + u_gen.setParameters(0, cloudIn->width*cloudIn->height); + d_gen.setParameters(0, 1); + int centerX = cloudIn->width >> 1; int centerY = cloudIn->height >> 1; @@ -293,18 +307,18 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search) for (int ypos = -centerY; ypos < centerY; ypos++) for (int xpos = -centerX; xpos < centerX; xpos++) { - double z = 5.0 * ( ((double)rand () / (double)RAND_MAX))+5; + double z = 5.0 * d_gen.run() + 5; double y = ypos*oneOverFocalLength*z; double x = xpos*oneOverFocalLength*z; cloudIn->points[idx++]= PointXYZ (x, y, z); } - unsigned int randomIdx = rand()%(cloudIn->width * cloudIn->height); + unsigned int randomIdx = u_gen.run(); const PointXYZ& searchPoint = cloudIn->points[randomIdx]; - const double searchRadius = 1.0 * ((double)rand () / (double)RAND_MAX); + const double searchRadius = 1.0 * d_gen.run(); // double searchRadius = 1/10; // bruteforce radius search @@ -378,9 +392,10 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search) TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_Benchmark_Test) { constexpr unsigned int test_runs = 10; - srand (time (NULL)); + u_gen.setSeed(rd()); + d_gen.setSeed(rd()); - pcl::search::OrganizedNeighbor organizedNeighborSearch(); + pcl::search::OrganizedNeighbor organizedNeighborSearch; std::vector k_indices; std::vector k_sqr_distances; @@ -390,7 +405,7 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_ // typical focal length from kinect constexpr double oneOverFocalLength = 0.0018; - + double radiusSearchTime = 0, radiusSearchLPTime = 0; for (unsigned int test_id = 0; test_id < test_runs; test_id++) @@ -404,6 +419,9 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_ cloudIn->points.clear(); cloudIn->points.resize (cloudIn->width * cloudIn->height); + u_gen.setParameters(0, cloudIn->width*cloudIn->height); + d_gen.setParameters(0, 1); + int centerX = cloudIn->width >> 1; int centerY = cloudIn->height >> 1; @@ -411,18 +429,18 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_ for (int ypos = -centerY; ypos < centerY; ypos++) for (int xpos = -centerX; xpos < centerX; xpos++) { - double z = 5.0 * ( ((double)rand () / (double)RAND_MAX))+5; + double z = 5.0 * d_gen.run() + 5; double y = ypos*oneOverFocalLength*z; double x = xpos*oneOverFocalLength*z; cloudIn->points[idx++]= PointXYZ (x, y, z); } - const unsigned int randomIdx = rand() % (cloudIn->width * cloudIn->height); + const unsigned int randomIdx = u_gen.run(); const PointXYZ& searchPoint = cloudIn->points[randomIdx]; - const double searchRadius = 1.0 * ((double)rand () / (double)RAND_MAX); + const double searchRadius = 1.0 * d_gen.run(); // bruteforce radius search std::vector cloudSearchBruteforce; @@ -473,16 +491,17 @@ TEST (PCL, Organized_Neighbor_Search_Pointcloud_Neighbours_Within_Radius_Search_ return; } constexpr unsigned int test_runs = 10; - srand (time (NULL)); + u_gen.setSeed(rd()); - pcl::search::OrganizedNeighbor organizedNeighborSearch(); + pcl::search::OrganizedNeighbor organizedNeighborSearch; // typical focal length from kinect unsigned int randomIdx; + u_gen.setParameters(0, cloudIn->width * cloudIn->height); while (1) { - randomIdx = rand()%(cloudIn->width * cloudIn->height); + randomIdx = u_gen.run(); if(cloudIn->points[randomIdx].z <100)break; }