Beispiel #1
0
def generate_sdf(synset_id, model_id):
    obj_file = params[
        "shapenet"] + synset_id + "/" + model_id + "/models/model_normalized.obj"
    sdf_file = params["shapenet_voxelized"] + synset_id + "/" + model_id

    if os.path.exists(sdf_file + ".npy"):
        print(sdf_file, "exists. Skipping.....")
        return

    mesh = trimesh.load(obj_file)
    voxels = mesh_to_voxels(mesh, 32, pad=False)
    np.save(sdf_file, voxels)
Beispiel #2
0
def voxelize_and_save():
    """Converts wavefront objects to 3D arrays representing voxels.
    """
    for filename in os.listdir('./square_rings_objs'):
        if filename.endswith('.obj'):
            name = re.search('(.*).obj', filename).group(1)
            name = name + '.npy'
            if name not in os.listdir('./square_rings_vox_64'):
                print("--- Voxelizing {} ---".format(filename))
                mesh = trimesh.load(os.path.join('square_rings_objs',
                                                 filename))
                voxels = mts.mesh_to_voxels(mesh, 62, pad=True)
                voxels = np.asarray(voxels)
                voxels = np.sign(voxels)
                voxels = (-1 * voxels + 1) / 2
                voxels = voxels.astype('int')
                np.save('.\\square_rings_vox_64\\' + name, voxels)
    print("finished voxelization")
Beispiel #3
0
from mesh_to_sdf import mesh_to_voxels

import os
import trimesh
import skimage
import skimage.measure

# Showing specific model in specific folder
folder = '02818832'
model = '10c15151ebe3d237240ea0cdca7b391a'

filename = os.path.join('data', folder, model, 'models',
                        'model_normalized.obj')
mesh = trimesh.load(filename)
voxels = mesh_to_voxels(mesh, 64, pad=True)

vrtcs, fcs, nrmls, _ = skimage.measure.marching_cubes_lewiner(voxels, level=0)
mesh = trimesh.Trimesh(vertices=vrtcs, faces=fcs, vertex_normals=nrmls)
mesh.show()
Beispiel #4
0
saveVoxels('/home/jd/Desktop/voxels.ply', voxels, voxel_scale, offset)
vertices, faces, normals, values = skimage.measure.marching_cubes_lewiner(
    voxels, 1)
V = numpy.zeros((len(vertices), 6)) * 255
V[:, :3] = vertices * voxel_scale
V[:, :3] += offset
savePLY('/home/jd/Desktop/marching_cubes.ply', V, faces)

sys.exit(1)

import mesh_to_sdf
import trimesh
import matplotlib.pyplot as plt

voxels = mesh_to_sdf.mesh_to_voxels(mesh, 100, pad=False)
print('voxels', voxels.shape, voxels.min(), voxels.max())

vertices, faces, normals, values = skimage.measure.marching_cubes_lewiner(
    voxels, 0)
V = np.zeros((len(vertices), 6)) * 255
V[:, :3] = vertices * voxel_scale
savePLY('/home/jd/Desktop/voxels.ply', V, faces)
voxels[voxels < 0] = 0
voxels_scaled = (voxels - voxels.min()) / (voxels.max() - voxels.min())
colors = plt.get_cmap('jet')(voxels_scaled.flatten())[:, :3]

output = np.zeros((np.prod(voxels.shape), 6))
output[:, 3:6] = colors * 255
n = 0
for i in range(voxels.shape[0]):