Skip to content

Commit

Permalink
Clarify normal construction strategy.
Browse files Browse the repository at this point in the history
Co-Authored-By: Kunal Tyagi <tyagi.kunal@live.com>
  • Loading branch information
SergioRAgostinho and kunaltyagi authored Apr 18, 2020
1 parent adc2da6 commit 9026032
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions test/filters/test_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,21 @@ TEST (CovarianceSampling, Filters)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST (NormalSpaceSampling, Filters)
{
// ensuring normals have unit norm
std::array<PointNormal, 16> points = {
PointNormal {0.f, 0.f, 0.f, -0.57735027f, -0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, -0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, -0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, -0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, 0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, 0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, 0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, -0.57735027f, 0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, -0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, -0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, -0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, -0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, 0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, 0.57735027f, -0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, 0.57735027f, 0.57735027f},
PointNormal {0.f, 0.f, 0.f, 0.57735027f, 0.57735027f, 0.57735027f},
};

// Fill container
// pcl::Normal is not precompiled by default so we use PointNormal
auto cloud = pcl::make_shared<PointCloud<PointNormal>> ();
cloud->reserve (points.size ());
for (const auto& point : points)
cloud->push_back (point);
// generate 16 points (8 unique) with unit norm
cloud->reserve (16);
// ensure that the normals have unit norm
const auto value = std::sqrt(1/3.f);
for (int unique = 0; unique < 8; ++unique) {
const auto i = ((unique % 2) < 1) ? -1 : 1; // points alternate sign
const auto j = ((unique % 4) < 2) ? -1 : 1; // 2 points negative, 2 positive
const auto k = ((unique % 8) < 4) ? -1 : 1; // first 4 points negative, rest positive
for (int duplicate = 0; duplicate < 2; ++duplicate) {
cloud->emplace_back (0.f, 0.f, 0.f, i * value, j * value, k * value);
}
}

// pcl::Normal is not precompiled by default so we use PointNormal
NormalSpaceSampling<PointNormal, PointNormal> normal_space_sampling;
normal_space_sampling.setInputCloud (cloud);
normal_space_sampling.setNormals (cloud);
Expand Down

0 comments on commit 9026032

Please sign in to comment.