示例#1
0
def batch_load_gt_data(j, meshes, gt_corners, sem_cls_label, batch_id, voxel_size):
    mesh_data = meshes[j]
    obj_points = mesh_data.vertices
    obj_points = fit_shapenet_obj_to_votenet_box(obj_points, gt_corners[batch_id, j])
    mesh_data.vertices = obj_points

    dimension = int(max((obj_points.max(0) - obj_points.min(0))) / voxel_size)
    dimension = max(dimension, 2)
    # internal voxels
    voxel_data_internal = voxelize_mesh(mesh_data, dimension=dimension, wireframe=True, dilated_carving=True)
    # surface voxels
    voxel_data_surface = voxelize_mesh(mesh_data, exact=True, dimension=dimension)
    return (sem_cls_label[batch_id, j], gt_corners[batch_id, j], (voxel_data_internal, voxel_data_surface))
示例#2
0
def batch_load_pred_data_wo_cls(j, proposal_ids, meshes, pred_corners, batch_id, pred_sem_cls, obj_prob, voxel_size):
    mesh_data = meshes[list(proposal_ids[batch_id, :, 0]).index(j)]
    obj_points = mesh_data.vertices
    obj_points = fit_shapenet_obj_to_votenet_box(obj_points, pred_corners[batch_id, j])
    mesh_data.vertices = obj_points

    dimension = int(max((obj_points.max(0) - obj_points.min(0))) / voxel_size)
    dimension = max(dimension, 2)
    # internal voxels
    voxel_data_internal = voxelize_mesh(mesh_data, dimension=dimension, wireframe=True, dilated_carving=True)
    # surface voxels
    voxel_data_surface = voxelize_mesh(mesh_data, exact=True, dimension=dimension)

    return (pred_sem_cls[batch_id, j], pred_corners[batch_id, j], obj_prob[batch_id, j],
            (voxel_data_internal, voxel_data_surface))
示例#3
0
def voxelize_binvox(mesh,
                    pitch=None,
                    dimension=None,
                    bounds=None,
                    **binvoxer_kwargs):
    """
    Voxelize via binvox tool.

    Parameters
    --------------
    mesh : trimesh.Trimesh
      Mesh to voxelize
    pitch : float
      Side length of each voxel. Ignored if dimension is provided
    dimension: int
      Number of voxels along each dimension. If not provided, this is
        calculated based on pitch and bounds/mesh extents
    bounds: (2, 3) float
      min/max values of the returned `VoxelGrid` in each instance. Uses
      `mesh.bounds` if not provided.
    **binvoxer_kwargs:
      Passed to `trimesh.exchange.binvox.Binvoxer`.
      Should not contain `bounding_box` if bounds is not None.

    Returns
    --------------
    `VoxelGrid` instance

    Raises
    --------------
    `ValueError` if `bounds is not None and 'bounding_box' in binvoxer_kwargs`.
    """
    from trimesh.exchange import binvox

    if dimension is None:
        # pitch must be provided
        if bounds is None:
            extents = mesh.extents
        else:
            mins, maxs = bounds
            extents = maxs - mins
        dimension = int(np.ceil(np.max(extents) / pitch))
    if bounds is not None:
        if 'bounding_box' in binvoxer_kwargs:
            raise ValueError('Cannot provide both bounds and bounding_box')
        binvoxer_kwargs['bounding_box'] = np.asanyarray(bounds).flatten()

    binvoxer = binvox.Binvoxer(dimension=dimension, **binvoxer_kwargs)
    return binvox.voxelize_mesh(mesh, binvoxer)
示例#4
0
文件: voxel.py 项目: Gmadges/trimesh
    chair_mesh = trimesh.load(os.path.join(dir_models, '%s.obj' % base_name))
    if isinstance(chair_mesh, trimesh.scene.Scene):
        chair_mesh = trimesh.util.concatenate([
            trimesh.Trimesh(mesh.vertices, mesh.faces)
            for mesh in chair_mesh.geometry.values()
        ])

    binvox_path = os.path.join(dir_models, '%s.binvox' % base_name)
    chair_voxels = trimesh.load(binvox_path)

    chair_voxels = v.VoxelGrid(chair_voxels.encoding.dense,
                               chair_voxels.transform)

    print('white: voxelized chair (binvox, exact)')
    show(chair_mesh,
         voxelize_mesh(chair_mesh, exact=True),
         colors=(1, 1, 1, 0.3))

    print('red: binvox-loaded chair')
    show(chair_mesh, chair_voxels, colors=(1, 0, 0, 0.3))

    voxelized_chair_mesh = chair_mesh.voxelized(
        np.max(chair_mesh.extents) / 32)
    print('green: voxelized chair (default).')
    show(chair_mesh, voxelized_chair_mesh, colors=(0, 1, 0, 0.3))

    shape = (50, 17, 63)
    revox = chair_voxels.revoxelized(shape)
    print('cyan: revoxelized.')
    show(chair_mesh, revox, colors=(0, 1, 1, 0.3))