|
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) |
|
|
|
|
|
|
|
|
|
points_padding = 0.1 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return_dict = {} |
|
return_dict['points'] = points |
|
return_dict['points.occ'] = occupancies |
|
return_dict['sf_sidx'] = index_surface |
|
|
|
|
|
|
|
return return_dict |
|
|