Spaces:
Running
on
L40S
Running
on
L40S
File size: 2,175 Bytes
2252f3d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import os
import trimesh
import numpy as np
from .utils.libmesh import check_mesh_contains
def get_occ_gt(
in_path=None,
vertices=None,
faces=None,
pts_num=1000,
points_sigma=0.01,
with_dp=False,
points=None,
extra_points=None
):
if in_path is not None:
mesh = trimesh.load(in_path, process=False)
print(type(mesh.vertices), mesh.vertices.shape, mesh.faces.shape)
mesh = trimesh.Trimesh(vertices=vertices, faces=faces, process=False)
# print('get_occ_gt', type(mesh.vertices), mesh.vertices.shape, mesh.faces.shape)
# points_size = 100000
points_padding = 0.1
# points_sigma = 0.01
points_uniform_ratio = 0.5
n_points_uniform = int(pts_num * points_uniform_ratio)
n_points_surface = pts_num - n_points_uniform
if points is None:
points_scale = 2.0
boxsize = points_scale + points_padding
points_uniform = np.random.rand(n_points_uniform, 3)
points_uniform = boxsize * (points_uniform - 0.5)
points_surface, index_surface = mesh.sample(n_points_surface, return_index=True)
points_surface += points_sigma * np.random.randn(n_points_surface, 3)
points = np.concatenate([points_uniform, points_surface], axis=0)
if extra_points is not None:
extra_points += points_sigma * np.random.randn(len(extra_points), 3)
points = np.concatenate([points, extra_points], axis=0)
occupancies = check_mesh_contains(mesh, points)
index_surface = None
# points = points.astype(dtype)
# print('occupancies', occupancies.dtype, np.sum(occupancies), occupancies.shape)
# occupancies = np.packbits(occupancies)
# print('occupancies bit', occupancies.dtype, np.sum(occupancies), occupancies.shape)
# print('occupancies', points.shape, occupancies.shape, occupancies.dtype, np.sum(occupancies), index_surface.shape)
return_dict = {}
return_dict['points'] = points
return_dict['points.occ'] = occupancies
return_dict['sf_sidx'] = index_surface
# export_pointcloud(mesh, modelname, loc, scale, args)
# export_points(mesh, modelname, loc, scale, args)
return return_dict
|