@@ -105,31 +105,44 @@ TEST (CovarianceSampling, Filters)
105105// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106106TEST (NormalSpaceSampling, Filters)
107107{
108+ // pcl::Normal is not precompiled by default so we use PointNormal
109+ auto cloud = pcl::make_shared<PointCloud<PointNormal>> ();
110+ // generate 16 points (8 unique) with unit norm
111+ cloud->reserve (16 );
112+ // ensure that the normals have unit norm
113+ const auto value = std::sqrt (1 /3 .f );
114+ for (int unique = 0 ; unique < 8 ; ++unique) {
115+ const auto i = ((unique % 2 ) < 1 ) ? -1 : 1 ; // points alternate sign
116+ const auto j = ((unique % 4 ) < 2 ) ? -1 : 1 ; // 2 points negative, 2 positive
117+ const auto k = ((unique % 8 ) < 4 ) ? -1 : 1 ; // first 4 points negative, rest positive
118+ for (int duplicate = 0 ; duplicate < 2 ; ++duplicate) {
119+ cloud->emplace_back (0 .f , 0 .f , 0 .f , i * value, j * value, k * value);
120+ }
121+ }
122+
108123 NormalSpaceSampling<PointNormal, PointNormal> normal_space_sampling;
109- normal_space_sampling.setInputCloud (cloud_walls_normals );
110- normal_space_sampling.setNormals (cloud_walls_normals );
111- normal_space_sampling.setBins (4 , 4 , 4 );
124+ normal_space_sampling.setInputCloud (cloud );
125+ normal_space_sampling.setNormals (cloud );
126+ normal_space_sampling.setBins (2 , 2 , 2 );
112127 normal_space_sampling.setSeed (0 );
113- normal_space_sampling.setSample (static_cast < unsigned int > (cloud_walls_normals-> size ()) / 4 );
128+ normal_space_sampling.setSample (8 );
114129
115- IndicesPtr walls_indices ( new std::vector< int > () );
130+ IndicesPtr walls_indices = pcl::make_shared<Indices > ();
116131 normal_space_sampling.filter (*walls_indices);
117132
118- CovarianceSampling<PointNormal, PointNormal> covariance_sampling;
119- covariance_sampling.setInputCloud (cloud_walls_normals);
120- covariance_sampling.setNormals (cloud_walls_normals);
121- covariance_sampling.setIndices (walls_indices);
122- covariance_sampling.setNumberOfSamples (0 );
123- double cond_num_walls_sampled = covariance_sampling.computeConditionNumber ();
124-
133+ // The orientation space of the normals is divided into 2x2x2 buckets
134+ // points are samples arbitrarily from each bucket in succession until the
135+ // requested number of samples is met. This means we expect to see only one index
136+ // for every two elements in the original array e.g. 0, 3, 4, 6, etc...
137+ // if 0 is sampled, index 1 can no longer be there and so forth
138+ std::array<std::set<index_t >, 8 > buckets;
139+ for (const auto index : *walls_indices)
140+ buckets[index/2 ].insert (index);
125141
126- EXPECT_NEAR (33.04893 , cond_num_walls_sampled, 1e-1 );
127142
128- EXPECT_EQ (1412 , (*walls_indices)[0 ]);
129- EXPECT_EQ (1943 , (*walls_indices)[walls_indices->size () / 4 ]);
130- EXPECT_EQ (2771 , (*walls_indices)[walls_indices->size () / 2 ]);
131- EXPECT_EQ (3215 , (*walls_indices)[walls_indices->size () * 3 / 4 ]);
132- EXPECT_EQ (2503 , (*walls_indices)[walls_indices->size () - 1 ]);
143+ EXPECT_EQ (8u , walls_indices->size ());
144+ for (const auto & bucket : buckets)
145+ EXPECT_EQ (1u , bucket.size ());
133146}
134147
135148// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments