本文整理汇总了C++中VoxelGrid::memoryToWorld方法的典型用法代码示例。如果您正苦于以下问题:C++ VoxelGrid::memoryToWorld方法的具体用法?C++ VoxelGrid::memoryToWorld怎么用?C++ VoxelGrid::memoryToWorld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VoxelGrid
的用法示例。
在下文中一共展示了VoxelGrid::memoryToWorld方法的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);
}
}
}
}
}
示例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));
}
}
//.........这里部分代码省略.........