本文整理汇总了C++中GridType::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ GridType::contains方法的具体用法?C++ GridType::contains怎么用?C++ GridType::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridType
的用法示例。
在下文中一共展示了GridType::contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: distanceGrid
Grid3D<uint32_t> computeDistanceMap26(const GridType& grid, Predicate isInObject, bool outsideIsObject) {
int w = grid.width(), h = grid.height(), d = grid.depth();
uint32_t maxDist = std::numeric_limits<uint32_t>::max();
Grid3D<uint32_t> distanceGrid(w, h, d, maxDist);
static const auto MASK_SIZE = 13;
auto processVoxel = [&distanceGrid, &grid, &isInObject, maxDist, outsideIsObject, w, h, d](const Vec3i* mask, int x, int y, int z) {
auto voxel = Vec3i(x, y, z);
if(!isInObject(x, y, z, grid)) {
distanceGrid(voxel) = 0u;
} else if(!outsideIsObject && (x == 0 || y == 0 || z == 0 || x == w - 1 || y == h - 1 || z == d - 1)) {
distanceGrid(voxel) = 1u;
}
auto currentDist = distanceGrid(voxel);
if(currentDist != maxDist) {
auto dist = currentDist + 1;
for(auto i = 0u; i < MASK_SIZE; ++i) {
auto offset = mask[i];
auto neighbour = voxel + offset;
if(grid.contains(neighbour) && isInObject(neighbour.x, neighbour.y, neighbour.z, grid) && dist < distanceGrid(neighbour)) {
distanceGrid(neighbour) = dist;
}
}
}
};
static const Vec3i masks[][MASK_SIZE] = {
{
Vec3i(1, 0, 0),
Vec3i(1, 1, 0),
Vec3i(0, 1, 0),
Vec3i(-1, 1, 0),
Vec3i(0, 0, 1),
Vec3i(1, 0, 1),
Vec3i(1, 1, 1),
Vec3i(0, 1, 1),
Vec3i(-1, 1, 1),
Vec3i(-1, 0, 1),
Vec3i(-1, -1, 1),
Vec3i(0, -1, 1),
Vec3i(1, -1, 1),
},
{
-Vec3i(1, 0, 0),
-Vec3i(1, 1, 0),
-Vec3i(0, 1, 0),
-Vec3i(-1, 1, 0),
-Vec3i(0, 0, 1),
-Vec3i(1, 0, 1),
-Vec3i(1, 1, 1),
-Vec3i(0, 1, 1),
-Vec3i(-1, 1, 1),
-Vec3i(-1, 0, 1),
-Vec3i(-1, -1, 1),
-Vec3i(0, -1, 1),
-Vec3i(1, -1, 1),
}
};
for(auto z = 0; z < d; ++z) {
for(auto y = 0; y < h; ++y) {
for(auto x = 0; x < w; ++x) {
processVoxel(masks[0], x, y, z);
}
}
}
for(auto z = d - 1; z >= 0; --z) {
for(auto y = h - 1; y >= 0; --y) {
for(auto x = w - 1; x >= 0; --x) {
processVoxel(masks[1], x, y, z);
}
}
}
return distanceGrid;
}