Skip to content

Commit adc2da6

Browse files
Rewrite unit test for NormalSpaceSampling
1 parent 1c1994e commit adc2da6

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

filters/include/pcl/filters/impl/normal_space.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
155155

156156
unsigned int pos = 0;
157157
unsigned int random_index = 0;
158-
// std::uniform_int_distribution<unsigned> rng_uniform_distribution (0u, M - 1u); Test fails with this
159-
std::uniform_int_distribution<unsigned> rng_uniform_distribution (0u, input_->size ());
158+
std::uniform_int_distribution<unsigned> rng_uniform_distribution (0u, M - 1u);
160159

161160
// Picking up a sample at random from jth bin
162161
do
163162
{
164-
// random_index = rng_uniform_distribution (rng_); // Test fails with this combo
165-
random_index = rng_uniform_distribution (rng_) % M;
163+
random_index = rng_uniform_distribution (rng_);
166164
pos = start_index[j] + random_index;
167165
} while (is_sampled_flag.test (pos));
168166

test/filters/test_sampling.cpp

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,56 @@ TEST (CovarianceSampling, Filters)
105105
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106106
TEST (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

Comments
 (0)