Grid3D<uint32_t> computeDistanceMap26_WithQueue(const GridType& grid, Predicate isInObject, bool outsideIsObject) {
    auto 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);

    std::queue<Vec4i> queue;

    for(auto z = 0u; z < d; ++z) {
        for(auto y = 0u; y < h; ++y) {
            for(auto x = 0u; x < w; ++x) {
                auto voxel = Vec3i(x, y, z);
                if(!isInObject(x, y, z, grid)) {
                    queue.push(Vec4i(voxel, 0u));
                } else if(!outsideIsObject && (x == 0 || y == 0 || z == 0 || x == w - 1 || y == h - 1 || z == d - 1)) {
                    queue.push(Vec4i(voxel, 1u));
                }
            }
        }
    }

    while(!queue.empty()) {
        auto voxel = Vec3i(queue.front());
        auto dist = queue.front().w;
        queue.pop();

        if(dist < distanceGrid(voxel)) {
            distanceGrid(voxel) = dist;

            foreach26Neighbour(grid.resolution(), voxel, [&](const Vec3i& neighbour) {
                auto newDist = dist + 1;
                if(newDist < distanceGrid(neighbour)) {
                    queue.push(Vec4i(neighbour, newDist));
                }
            });
        }
    }

    return distanceGrid;
}