当前位置: 首页>>代码示例>>C++>>正文


C++ GridType::contains方法代码示例

本文整理汇总了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;
}
开发者ID:Celeborn2BeAlive,项目名称:pg2015-code,代码行数:79,代码来源:discrete_functions.hpp


注:本文中的GridType::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。