4040#include < pcl/io/pcd_io.h>
4141#include < pcl/compression/octree_pointcloud_compression.h>
4242#include < pcl/compression/compression_profiles.h>
43+ #include < pcl/common/random.h>
4344
4445#include < string>
4546#include < exception>
@@ -50,16 +51,19 @@ int total_runs = 0;
5051
5152char * pcd_file;
5253
54+ std::random_device rd;
55+ pcl::common::UniformGenerator<float > gen;
56+
5357#define MAX_POINTS 10000.0
5458#define MAX_XYZ 1024.0
5559#define MAX_COLOR 255
5660#define NUMBER_OF_TEST_RUNS 2
5761
5862TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA)
5963{
60- srand ( static_cast < unsigned int > ( time ( NULL ) ));
64+ gen. setSeed ( rd ( ));
6165
62- // iterate over all pre-defined compression profiles
66+ // iterate over all pre-defined compression profiles
6367 for (int compression_profile = pcl::io::LOW_RES_ONLINE_COMPRESSION_WITHOUT_COLOR;
6468 compression_profile != pcl::io::COMPRESSION_PROFILE_COUNT; ++compression_profile) {
6569 // instantiate point cloud compression encoder/decoder
@@ -71,7 +75,8 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA)
7175 {
7276 try
7377 {
74- int point_count = MAX_POINTS * rand () / RAND_MAX;
78+ gen.setParameters (0 , MAX_POINTS);
79+ int point_count = gen.run ();
7580 if (point_count < 1 )
7681 { // empty point cloud hangs decoder
7782 total_runs--;
@@ -85,13 +90,15 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA)
8590 {
8691 // gereate a random point
8792 pcl::PointXYZRGBA new_point;
88- new_point.x = static_cast <float > (MAX_XYZ * rand () / RAND_MAX);
89- new_point.y = static_cast <float > (MAX_XYZ * rand () / RAND_MAX),
90- new_point.z = static_cast <float > (MAX_XYZ * rand () / RAND_MAX);
91- new_point.r = static_cast <int > (MAX_COLOR * rand () / RAND_MAX);
92- new_point.g = static_cast <int > (MAX_COLOR * rand () / RAND_MAX);
93- new_point.b = static_cast <int > (MAX_COLOR * rand () / RAND_MAX);
94- new_point.a = static_cast <int > (MAX_COLOR * rand () / RAND_MAX);
93+ gen.setParameters (0 , MAX_XYZ);
94+ new_point.x = gen.run ();
95+ new_point.y = gen.run ();
96+ new_point.z = gen.run ();
97+ gen.setParameters (0 , MAX_COLOR);
98+ new_point.r = gen.run ();
99+ new_point.g = gen.run ();
100+ new_point.b = gen.run ();
101+ new_point.a = gen.run ();
95102 // OctreePointCloudPointVector can store all points..
96103 cloud->push_back (new_point);
97104 }
@@ -113,7 +120,7 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZRGBA)
113120
114121TEST (PCL, OctreeDeCompressionRandomPointXYZ)
115122{
116- srand ( static_cast < unsigned int > ( time ( NULL ) ));
123+ gen. setSeed ( rd ( ));
117124
118125 // iterate over all pre-defined compression profiles
119126 for (int compression_profile = pcl::io::LOW_RES_ONLINE_COMPRESSION_WITHOUT_COLOR;
@@ -126,17 +133,19 @@ TEST (PCL, OctreeDeCompressionRandomPointXYZ)
126133 // loop over runs
127134 for (int test_idx = 0 ; test_idx < NUMBER_OF_TEST_RUNS; test_idx++, total_runs++)
128135 {
129- int point_count = MAX_POINTS * rand () / RAND_MAX;
136+ gen.setParameters (0 , MAX_POINTS);
137+ int point_count = gen.run ();
130138 // create shared pointcloud instances
131139 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>());
132140 // assign input point clouds to octree
133141 // create random point cloud
142+ gen.setParameters (0 , MAX_XYZ);
134143 for (int point = 0 ; point < point_count; point++)
135144 {
136145 // generate a random point
137- pcl::PointXYZ new_point (static_cast <float > (MAX_XYZ * rand () / RAND_MAX ),
138- static_cast <float > (MAX_XYZ * rand () / RAND_MAX ),
139- static_cast <float > (MAX_XYZ * rand () / RAND_MAX ));
146+ pcl::PointXYZ new_point (static_cast <float > (gen. run () ),
147+ static_cast <float > (gen. run () ),
148+ static_cast <float > (gen. run () ));
140149 cloud->push_back (new_point);
141150 }
142151// std::cout << "Run: " << total_runs << " compression profile:" << compression_profile << " point_count: " << point_count;
0 commit comments