@@ -105,31 +105,56 @@ TEST (CovarianceSampling, Filters)
105105// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106106TEST (NormalSpaceSampling, Filters)
107107{
108+ // ensuring normals have unit norm
109+ std::array<PointNormal, 16 > points = {
110+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , -0 .57735027f , -0 .57735027f },
111+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , -0 .57735027f , -0 .57735027f },
112+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , -0 .57735027f , 0 .57735027f },
113+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , -0 .57735027f , 0 .57735027f },
114+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , 0 .57735027f , -0 .57735027f },
115+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , 0 .57735027f , -0 .57735027f },
116+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , 0 .57735027f , 0 .57735027f },
117+ PointNormal {0 .f , 0 .f , 0 .f , -0 .57735027f , 0 .57735027f , 0 .57735027f },
118+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , -0 .57735027f , -0 .57735027f },
119+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , -0 .57735027f , -0 .57735027f },
120+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , -0 .57735027f , 0 .57735027f },
121+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , -0 .57735027f , 0 .57735027f },
122+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , 0 .57735027f , -0 .57735027f },
123+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , 0 .57735027f , -0 .57735027f },
124+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , 0 .57735027f , 0 .57735027f },
125+ PointNormal {0 .f , 0 .f , 0 .f , 0 .57735027f , 0 .57735027f , 0 .57735027f },
126+ };
127+
128+ // Fill container
129+ auto cloud = pcl::make_shared<PointCloud<PointNormal>> ();
130+ cloud->reserve (points.size ());
131+ for (const auto & point : points)
132+ cloud->push_back (point);
133+
134+ // pcl::Normal is not precompiled by default so we use PointNormal
108135 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 );
136+ normal_space_sampling.setInputCloud (cloud );
137+ normal_space_sampling.setNormals (cloud );
138+ normal_space_sampling.setBins (2 , 2 , 2 );
112139 normal_space_sampling.setSeed (0 );
113- normal_space_sampling.setSample (static_cast < unsigned int > (cloud_walls_normals-> size ()) / 4 );
140+ normal_space_sampling.setSample (8 );
114141
115- IndicesPtr walls_indices ( new std::vector< int > () );
142+ IndicesPtr walls_indices = pcl::make_shared<Indices > ();
116143 normal_space_sampling.filter (*walls_indices);
117144
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-
145+ // The orientation space of the normals is divided into 2x2x2 buckets
146+ // points are samples arbitrarily from each bucket in succession until the
147+ // requested number of samples is met. This means we expect to see only one index
148+ // for every two elements in the original array e.g. 0, 3, 4, 6, etc...
149+ // if 0 is sampled, index 1 can no longer be there and so forth
150+ std::array<std::set<index_t >, 8 > buckets;
151+ for (const auto index : *walls_indices)
152+ buckets[index/2 ].insert (index);
125153
126- EXPECT_NEAR (33.04893 , cond_num_walls_sampled, 1e-1 );
127154
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 ]);
155+ EXPECT_EQ (8u , walls_indices->size ());
156+ for (const auto & bucket : buckets)
157+ EXPECT_EQ (1u , bucket.size ());
133158}
134159
135160// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments