Skip to content

Commit 9026032

Browse files
Clarify normal construction strategy.
Co-Authored-By: Kunal Tyagi <tyagi.kunal@live.com>
1 parent adc2da6 commit 9026032

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

test/filters/test_sampling.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,21 @@ 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
108+
// pcl::Normal is not precompiled by default so we use PointNormal
129109
auto cloud = pcl::make_shared<PointCloud<PointNormal>> ();
130-
cloud->reserve (points.size ());
131-
for (const auto& point : points)
132-
cloud->push_back (point);
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+
}
133122

134-
// pcl::Normal is not precompiled by default so we use PointNormal
135123
NormalSpaceSampling<PointNormal, PointNormal> normal_space_sampling;
136124
normal_space_sampling.setInputCloud (cloud);
137125
normal_space_sampling.setNormals (cloud);

0 commit comments

Comments
 (0)