Skip to content

Instantly share code, notes, and snippets.

@jehutymax
Created December 1, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehutymax/e4769cf3b839b74ea75a6afb9aece586 to your computer and use it in GitHub Desktop.
Save jehutymax/e4769cf3b839b74ea75a6afb9aece586 to your computer and use it in GitHub Desktop.
struct SillyFunction
{
SillyFunction() {}
Vec3d operator()(const Vec3d& xyz) const
{
return Vec3d(3.0 * xyz.y() + 1.0, 5.0 * xyz.z() + 7.0, -1.0 * xyz.x() - 9.0);
}
};
TEST(Grids, MacGrid)
{
Vec3dGrid::Ptr grid = Vec3dGrid::create(Vec3d(0));
grid->setGridClass(GRID_STAGGERED);
CoordBBox bbox(Coord(0, 0, 0), Coord(6, 6, 6));
Vec3dGrid::Accessor acc = grid->getAccessor();
SillyFunction func;
for (int i = bbox.min()[0]; i < bbox.max()[0]; ++i)
for (int j = bbox.min()[1]; j < bbox.max()[1]; ++j)
for (int k = bbox.min()[2]; k < bbox.max()[2]; ++k)
acc.setValue(Coord(i, j, k), func(Vec3d(i, j, k)));
// tools::Sampler<2, false> sampler; // ==> this works!
tools::Sampler<2, true> sampler; // ==> this doesn't seem to.
for (int i = bbox.min()[0]; i < bbox.max()[0]; ++i)
for (int j = bbox.min()[1]; j < bbox.max()[1]; ++j)
for (int k = bbox.min()[2]; k < bbox.max()[2]; ++k)
{
Vec3d sampledValue = sampler.sample(grid->tree(), Vec3R(i, j, k));
Vec3d expected = func(Vec3d(i, j, k));
EXPECT_EQ(sampledValue.x(), expected.x());
EXPECT_EQ(sampledValue.y(), expected.y());
EXPECT_EQ(sampledValue.z(), expected.z());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment