def readBinvoxParams(binbox_f): with open(binbox_f, 'rb') as f: voxel = binvox_rw.read_as_3d_array(f) voxel_d = voxel.dims[0] voxel_t = voxel.translate voxel_s = voxel.scale return (voxel_d, *voxel_t, voxel_s)
def load_voxel(file): with open(file, 'rb') as f: voexl_array = binvoxel.read_as_3d_array(f) print(voexl_array.dims) print(voexl_array.scale) voexl_array = np.array(voexl_array.data.flatten())
def load_label(self, category, model_id): voxel_fn = get_voxel_file(category, model_id) with open(voxel_fn, 'rb') as f: voxel = read_as_3d_array(f) return voxel
with open(filename, 'w') as f: # write vertices f.write('g\n# %d vertex\n' % len(verts)) for vert in verts: f.write('v %f %f %f\n' % tuple(vert)) # write faces f.write('# %d faces\n' % len(faces)) for face in faces: f.write('f %d %d %d\n' % tuple(face)) def voxel2obj(filename, pred, surface_view=True): verts, faces = voxel2mesh(pred, surface_view) write_obj(filename, verts, faces) if __name__ == '__main__': # read binvox data and convert to ndarray from lib.binvox_rw import read_as_3d_array import theano with open("model.binvox", 'rb') as f: voxel = read_as_3d_array(f) voxel_data = voxel.data batch_voxel = np.zeros((1, 32, 2, 32, 32), dtype=theano.config.floatX) batch_voxel[0, :, 0, :, :] = voxel_data < 1 batch_voxel[0, :, 1, :, :] = voxel_data print(batch_voxel.shape) # write obj file voxel2obj("category1data2.obj", batch_voxel[0, :, 1, :, :])