modulo_index = 0 if len(sys.argv) > 3: modulo_index = max(0, int(sys.argv[3])) print('[Data] modulo index %d' % modulo_index) config_files = [config_file for config_file in os.listdir(config_folder)] config = utils.read_json(config_folder + config_files[-1]) scaled_directory = config['scaled_directory'] + '/' assert os.path.exists( scaled_directory), 'directory %s does not exist' % scaled_directory depth_directory = config['depth_directory'] + '/' utils.makedir(depth_directory) off_files = utils.read_ordered_directory(scaled_directory) timer = Timer() Rs = get_views(config['watertight_rendering']['n_views']) for n in range(len(off_files)): if (n - modulo_index) % modulo_base == 0: timer.reset() mesh = Mesh.from_off(off_files[n]) depths = render(mesh, Rs) depth_file = depth_directory + '%d.hdf5' % n utils.write_hdf5(depth_file, np.array(depths)) print('[Data] wrote %s (%f seconds)' % (depth_file, timer.elapsed()))
waited = True print('[Data] waiting for %s' % depth_file) time.sleep(10) # Wait for synchronization. if waited: time.sleep(10) try: # Sometimes signature of HDF5 files is still not available. depths = utils.read_hdf5(depth_file) except IOError: print('[Data] could not read %s' % depth_file) time.sleep(5) # Try again, now it can really fail if file is not there. depths = utils.read_hdf5(depth_file) timer.reset() tsdf = fusion(depths, Rs) tsdf = tsdf[0] utils.write_hdf5(tsdf_file, tsdf) print('[Data] wrote %s (%f seconds)' % (tsdf_file, timer.elapsed())) vertices, triangles = mcubes.marching_cubes(-tsdf, 0) vertices /= config['watertight_fusion']['resolution'] vertices -= 0.5 mcubes.export_off(vertices, triangles, off_file) print('[Data] wrote %s (%f seconds)' % (off_file, timer.elapsed()))
print('[Data] waiting for %s' % depth_file) time.sleep(10) # Wait for synchronization. if waited: time.sleep(10) try: # Sometimes signature of HDF5 files is still not available. depths = utils.read_hdf5(depth_file) except IOError: print('[Data] could not read %s' % depth_file) time.sleep(5) # Try again, now it can really fail if file is not there. depths = utils.read_hdf5(depth_file) timer.reset() tsdf = fusion(depths, Rs) tsdf = tsdf[0] utils.write_hdf5(tsdf_file, tsdf) print('[Data] wrote %s (%f seconds)' % (tsdf_file, timer.elapsed())) vertices, triangles = mcubes.marching_cubes(-tsdf, 0) vertices /= config['watertight_fusion']['resolution'] vertices -= 0.5 mcubes.export_off(vertices, triangles, off_file) print('[Data] wrote %s (%f seconds)' % (off_file, timer.elapsed()))