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


C++ VoxelGrid::sizeX方法代码示例

本文整理汇总了C++中VoxelGrid::sizeX方法的典型用法代码示例。如果您正苦于以下问题:C++ VoxelGrid::sizeX方法的具体用法?C++ VoxelGrid::sizeX怎么用?C++ VoxelGrid::sizeX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VoxelGrid的用法示例。


在下文中一共展示了VoxelGrid::sizeX方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateGridMesh

void CreateGridMesh(
    const VoxelGrid<Discretizer>& vg,
    std::vector<Vector3>& vertices)
{
    std::vector<Vector3> voxel_mesh;
    CreateBoxMesh(vg.res().x(), vg.res().y(), vg.res().z(), voxel_mesh);

    vertices.reserve(voxel_mesh.size() * vg.sizeX() * vg.sizeY() * vg.sizeZ());

    for (int x = 0; x < vg.sizeX(); ++x) {
        for (int y = 0; y < vg.sizeY(); ++y) {
            for (int z = 0; z < vg.sizeZ(); ++z) {
                const MemoryCoord mc(x, y, z);
                const WorldCoord wc(vg.memoryToWorld(mc));

                Vector3 wp(wc.x, wc.y, wc.z);

                std::printf("%d, %d, %d -> %0.3f, %0.3f, %0.3f\n", x, y, z, wc.x, wc.y, wc.z);

                // translate all triangles by the voxel position
                for (const Vector3& v : voxel_mesh) {
                    vertices.push_back(v + wp);
                }
            }
        }
    }
}
开发者ID:aurone,项目名称:sbpl_manipulation,代码行数:27,代码来源:mesh_utils.hpp

示例2: CreateIndexedGridMesh

void CreateIndexedGridMesh(
    const VoxelGrid<Discretizer>& vg,
    std::vector<Vector3>& vertices,
    std::vector<int>& indices)
{
    // create all the vertices
    const size_t vertex_count = (vg.sizeX() + 1) * (vg.sizeY() + 1) * (vg.sizeZ() + 1);
    vertices.reserve(vertex_count);
    for (int ix = 0; ix < vg.sizeX() + 1; ix++) {
        for (int iy = 0; iy < vg.sizeY() + 1; iy++) {
            for (int iz = 0; iz < vg.sizeZ() + 1; iz++) {
                MemoryCoord mc(ix, iy, iz);
                WorldCoord wc(vg.memoryToWorld(mc));
                Vector3 p =
                        Vector3(wc.x, wc.y, wc.z) - 0.5 * vg.res();
                vertices.push_back(p);
            }
        }
    }

    const size_t voxel_count = vg.sizeX() * vg.sizeY() * vg.sizeZ();
    const size_t xplane_count = vg.sizeY() * vg.sizeZ();
    const size_t yplane_count = vg.sizeX() * vg.sizeZ();
    const size_t zplane_count = vg.sizeX() * vg.sizeY();
    indices.reserve(6 * voxel_count * + 2 * xplane_count + 2 * yplane_count + 3 * zplane_count);

    // for every voxel there are 12 triangles
    for (int ix = 0; ix < vg.sizeX(); ++ix) {
        for (int iy = 0; iy < vg.sizeY(); ++iy) {
            for (int iz = 0; iz < vg.sizeZ(); ++iz) {
                MemoryCoord a(ix,     iy,     iz);
                MemoryCoord b(ix,     iy,     iz + 1);
                MemoryCoord c(ix,     iy + 1, iz);
                MemoryCoord d(ix,     iy + 1, iz + 1);
                MemoryCoord e(ix + 1, iy,     iz);
                MemoryCoord f(ix + 1, iy,     iz + 1);
                MemoryCoord g(ix + 1, iy + 1, iz);
                MemoryCoord h(ix + 1, iy + 1, iz + 1);

                auto to_index = [&](const MemoryCoord& c) -> size_t
                {
                    return c.x * (vg.sizeY() + 1) * (vg.sizeZ() + 1) +
                           c.y * (vg.sizeZ() + 1) +
                           c.z;
                };

                // back face
                indices.push_back(to_index(a));
                indices.push_back(to_index(b));
                indices.push_back(to_index(d));
                indices.push_back(to_index(a));
                indices.push_back(to_index(d));
                indices.push_back(to_index(c));

                // left face
                indices.push_back(to_index(a));
                indices.push_back(to_index(f));
                indices.push_back(to_index(b));
                indices.push_back(to_index(a));
                indices.push_back(to_index(e));
                indices.push_back(to_index(f));

                // bottom face
                indices.push_back(to_index(a));
                indices.push_back(to_index(g));
                indices.push_back(to_index(e));
                indices.push_back(to_index(a));
                indices.push_back(to_index(c));
                indices.push_back(to_index(g));

                // front face?
                if (ix == vg.sizeX() - 1) {
                    indices.push_back(to_index(f));
                    indices.push_back(to_index(g));
                    indices.push_back(to_index(e));
                    indices.push_back(to_index(f));
                    indices.push_back(to_index(h));
                    indices.push_back(to_index(g));
                }

                // right face?
                if (iy == vg.sizeY() - 1) {
                    indices.push_back(to_index(h));
                    indices.push_back(to_index(d));
                    indices.push_back(to_index(c));
                    indices.push_back(to_index(h));
                    indices.push_back(to_index(c));
                    indices.push_back(to_index(g));
                }

                // top face?
                if (iz == vg.sizeZ() - 1) {
                    indices.push_back(to_index(b));
                    indices.push_back(to_index(d));
                    indices.push_back(to_index(h));
                    indices.push_back(to_index(b));
                    indices.push_back(to_index(h));
                    indices.push_back(to_index(f));
                }
            }
//.........这里部分代码省略.........
开发者ID:aurone,项目名称:sbpl_manipulation,代码行数:101,代码来源:mesh_utils.hpp


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