def __init__(self, model_id, edge_length_threshold=0.1, filled=False, voxel_config=None): self._model_id = model_id self._edge_length_threshold = edge_length_threshold self._filled = filled self._voxel_config = VoxelConfig() if voxel_config is None else \ voxel_config
def check_archive(cat_desc, voxel_dim, example_ids=None): from shapenet.core import cat_desc_to_id, get_example_ids from shapenet.core.voxels.config import VoxelConfig cat_id = cat_desc_to_id(cat_desc) if example_ids is None or len(example_ids) == 0: example_ids = get_example_ids(cat_id) config = VoxelConfig(voxel_dim=voxel_dim) n_absent = 0 with config.get_zip_file(cat_id) as zf: namelist = set(zf.namelist()) for example_id in example_ids: if config.get_binvox_subpath(cat_id, example_id) not in namelist: n_absent += 1 if n_absent == 0: print('All %d %s voxels present' % (len(example_ids), cat_desc)) else: print('%d / %d voxel files missing from %s' % (n_absent, len(example_ids), cat_desc))
def create_archive(cat_desc, voxel_dim, example_ids=None, overwrite=False): import os import zipfile from shapenet.core.voxels.config import VoxelConfig from shapenet.core import get_example_ids, cat_desc_to_id cat_id = cat_desc_to_id(cat_desc) if example_ids is None or len(example_ids) == 0: example_ids = get_example_ids(cat_id) config = VoxelConfig(voxel_dim) with zipfile.ZipFile(config.get_zip_path(cat_id), 'a') as zf: if not overwrite: namelist = set(zf.namelist()) for example_id in example_ids: dst = config.get_binvox_subpath(cat_id, example_id) if not overwrite and dst in namelist: continue src = config.get_binvox_path(cat_id, example_id) if os.path.isfile(src): zf.write(src, dst) else: print('No file at %s for %s/%s: skipping' % (src, cat_id, example_id))
import os from path import get_inference_subdir import util3d.voxel.dataset as bvd import util3d.voxel.convert as bio from shapenet.core.voxels.config import VoxelConfig from meshes import get_inferred_mesh_dataset _default_config = VoxelConfig() def get_voxel_subdir(model_id, edge_length_threshold=0.1, voxel_config=None, filled=False): if voxel_config is None: voxel_config = _default_config es = 'base' if edge_length_threshold is None else \ str(edge_length_threshold) fs = 'filled' if filled else 'unfilled' args = ['voxels', es, voxel_config.voxel_id, model_id, fs] return get_inference_subdir(*args) def _get_base_voxel_dataset(model_id, edge_length_threshold=0.1, voxel_config=None, filled=False, auto_save=True): kwargs = dict(model_id=model_id, edge_length_threshold=edge_length_threshold, voxel_config=voxel_config,
def convert_multi(cat_id, example_ids, overwrite=False, **kwargs): from shapenet.core.voxels.config import VoxelConfig config = VoxelConfig(**kwargs) config.create_voxel_data(cat_id, example_ids, overwrite=overwrite)
def get_unfilled_gt_voxel_dataset(cat_id): config = VoxelConfig() return config.get_dataset(cat_id)
def __init__(self, model_id, filled=True, voxel_config=None): self._model_id = model_id self._filled = filled self._voxel_config = VoxelConfig() if voxel_config is None else \ voxel_config
from mayavi import mlab from shapenet.core.voxels.config import VoxelConfig from shapenet.core import cat_desc_to_id, get_example_ids from util3d.mayavi_vis import vis_voxels cat_desc = 'plane' cat_id = cat_desc_to_id(cat_desc) example_ids = get_example_ids(cat_id) config = VoxelConfig() with config.get_dataset(cat_id) as dataset: for example_id in example_ids: voxels = dataset[example_id] vis_voxels(voxels.dense_data(), color=(0, 0, 1)) mlab.show()
#!/usr/bin/python from __future__ import absolute_import from __future__ import division from __future__ import print_function from shapenet.core.voxels.config import VoxelConfig from shapenet.core import cat_desc_to_id from util3d.mayavi_vis import vis_sliced from mayavi import mlab import numpy as np cat_desc = 'watercraft' cat_id = cat_desc_to_id(cat_desc) base = VoxelConfig(voxel_dim=128) filled = base.filled('orthographic') with base.get_dataset(cat_id) as bds, filled.get_dataset(cat_id) as fds: for example_id in bds: base_data = bds[example_id].dense_data() filled_data = fds[example_id].dense_data() for dense_data in (base_data, filled_data): mlab.figure() vis_sliced(dense_data.astype(np.float32), axis_order='xyz') mlab.show() break