furniturefere.blogg.se

Cubify
Cubify









cubify

cubify

When `align="center"`, then the grid locations form the center of the cuboids. When `align="corner"`, then the corners of the output mesh span the whole grid. When `align="topleft"`, then the top left corner of each cuboid corresponds to the pixel coordinate of the input grid. We support three modes, as shown below for a 2x2 grid: X-X- X-X - | | | | | | | X | X | X-X- | | | | | | | X | X | - X-X - topleft corner center In the figure, X denote the grid locations and the squares represent the added cuboids. The alignment between the vertices of the cubified mesh and the voxel locations (or pixels) is defined by the choice of `align`. Returns: meshes: A Meshes object of the corresponding meshes. device: The device of the output meshes align: Defines the alignment of the mesh vertices and the grid locations. If a voxel occupancy is larger than thresh, the voxel is considered occupied. Args: voxels: A FloatTensor of shape (N, D, H, W) containing occupancy probabilities. Shared vertices are merged, and internal faces are removed. no_grad () def cubify ( voxels, thresh, device = None, align : str = "topleft" ) -> Meshes : r """ Converts a voxel to a mesh by replacing each occupied voxel with a cube consisting of 12 faces and 8 vertices.

cubify

shape != 3 : raise ValueError ( "Expects an index tensor of shape Nx3" ) H, W, D = dims linind = idx * W * D + idx * D + idx return linind Implemented only for dims=(H, W, D) """ if len ( dims ) != 3 : raise ValueError ( "Expects a 3-element list" ) if idx. dims: The shape of the array to be indexed. Each row corresponds to indices into an array of dimensions dims. It performs the reverse functionality of unravel_index Args: idx: A LongTensor of shape (N, 3). Tensor : """ Computes the linear index in an array of shape dims. stack (( n, h, w, d ), dim = 1 ) def ravel_index ( idx, dims ) -> torch. Implemented only for dims=(N, H, W, D) """ if len ( dims ) != 4 : raise ValueError ( "Expects a 4-element list." ) N, H, W, D = dims n = idx // ( H * W * D ) h = ( idx - n * H * W * D ) // ( W * D ) w = ( idx - n * H * W * D - h * W * D ) // D d = idx - n * H * W * D - h * W * D - w * D return torch. Tensor : r """ Equivalent to np.unravel_index Args: idx: A LongTensor whose elements are indices into the flattened version of an array of dimensions dims. import torch import torch.nn.functional as F from pytorch3d.structures import Meshes def unravel_index ( idx, dims ) -> torch.

#CUBIFY CODE#

# This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree.











Cubify