def refine(scene, cpu_cache, p_threshold, time): batch.init_process("bstmCppRefineSpacetimeProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, p_threshold) batch.set_input_float(3, time) batch.run_process()
def change_btw_frames(scene, cpu_cache, time0, time1): batch.init_process("bstmCppChangeBtwFramesProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, time0) batch.set_input_float(3, time1) batch.run_process()
def create_stream_cache(self, imgs, interval=1, types="", max_gb=6.0): # write image identifiers to file # imgRange = range(0, len(imgs), interval); # num_imgs = len(imgRange); image_id_fname = self.model_dir + "/image_list.txt" fd = open(image_id_fname, "w") print >> fd, len(imgs) # for i in imgRange: # print >>fd, "img_%05d"%i for img in imgs: fname, fextension = splitext(img) bname = basename(fname) print >> fd, bname fd.close() # write type identifiers into file type_id_fname = self.model_dir + "/type_names_list.txt" fd2 = open(type_id_fname, "w") print >>fd2, 4 print >>fd2, "aux0" print >>fd2, "aux1" print >>fd2, "aux2" print >>fd2, "aux3" fd2.close() # open the stream cache, this is a read-only cache batch.init_process("bstmCreateStreamCacheProcess") batch.set_input_from_db(0, self.scene) batch.set_input_string(1, type_id_fname) batch.set_input_string(2, image_id_fname) batch.set_input_float(3, max_gb) batch.run_process() (cache_id, cache_type) = batch.commit_output(0) self.str_cache = batch.dbvalue(cache_id, cache_type)
def merge(scene, cpu_cache, p_threshold, time): batch.init_process("bstmCppMergeTTProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, p_threshold) batch.set_input_float(3, time) batch.run_process()
def trajectory_next(trajectory): batch.init_process("bstmViewTrajectoryNextProcess") batch.set_input_from_db(0, trajectory) batch.run_process() (id, type) = batch.commit_output(0) cam = dbvalue(id, type) return cam
def refine_time(scene, cpu_cache, change_prob_t, time): batch.init_process("bstmCppRefineTTProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpu_cache) batch.set_input_float(2, change_prob_t) batch.set_input_float(3, time) batch.run_process()
def trajectory_size(trajectory): batch.init_process("bstmViewTrajectorySizeProcess") batch.set_input_from_db(0, trajectory) batch.run_process() (id, type) = batch.commit_output(0) size = batch.get_output_unsigned(id) batch.remove_data(id) return size
def write_cache(cache, do_clear=0): if cache.type == "bstm_cache_sptr": batch.init_process("bstmWriteCacheProcess") batch.set_input_from_db(0, cache) batch.set_input_bool(1, do_clear) batch.run_process() else: print "ERROR: Cache type needs to be bstm_cache_sptr, not ", cache.type
def load_cpp(scene_str): scene = load_scene(scene_str) batch.init_process("bstmCreateCacheProcess") batch.set_input_from_db(0, scene) batch.set_input_string(1, "lru") batch.run_process() (id, type) = batch.commit_output(0) cache = bstm_register.dbvalue(id, type) return scene, cache
def boxm2_clear_cache(cache): if cache.type == "boxm2_cache_sptr": batch.init_process("boxm2ClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() elif cache.type == "boxm2_opencl_cache_sptr": batch.init_process("boxm2ClearOpenclCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() else: print "ERROR: Cache type needs to be boxm2_cache_sptr, not ", cache.type
def label_change(scene, device, cache, cam, change_img, change_t, label, time): batch.init_process("bstmOclLabelRayProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_from_db(4, change_img) batch.set_input_float(5, change_t) batch.set_input_float(6, time) batch.set_input_int(7, label) batch.run_process()
def clear_cache(cache): if cache.type == "bstm_cache_sptr": batch.init_process("bstmClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() elif cache.type == "bstm_opencl_cache_sptr": batch.init_process("bstmOclClearCacheProcess") batch.set_input_from_db(0, cache) batch.run_process() else: print "ERROR: Cache type needs to be bstm_cache_sptr, not ", cache.type
def ocl_info(): # print("Init Manager"); batch.init_process("boclInitManagerProcess") batch.run_process() (id, type) = batch.commit_output(0) mgr = dbvalue(id, type) print("Get OCL info") batch.init_process("bocl_info_process") batch.set_input_from_db(0, mgr) batch.run_process()
def scene_statistics(scene, cache): batch.init_process("bstmSceneStatisticsProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.run_process() (s1_id, s1_type) = batch.commit_output(0) (s2_id, s2_type) = batch.commit_output(1) (s3_id, s3_type) = batch.commit_output(2) s1 = batch.get_output_float(s1_id) s2 = batch.get_output_float(s2_id) s3 = batch.get_output_unsigned(s3_id) return [s1, s2, s3]
def transform(self, tx, ty, tz, rx, ry, rz, scale): batch.init_process("bstmTransformModelProcess") batch.set_input_from_db(0, self.scene) batch.set_input_float(1, tx) batch.set_input_float(2, ty) batch.set_input_float(3, tz) batch.set_input_float(4, rx) batch.set_input_float(5, ry) batch.set_input_float(6, rz) batch.set_input_float(7, scale) batch.run_process() return
def init_trajectory(scene, startInc, endInc, radius, ni=1280, nj=720): batch.init_process("bstmViewInitTrajectoryProcess") batch.set_input_from_db(0, scene) batch.set_input_double(1, float(startInc)) # incline0 batch.set_input_double(2, float(endInc)) # incline1 batch.set_input_double(3, float(radius)) # radius batch.set_input_unsigned(4, ni) # ni batch.set_input_unsigned(5, nj) # nj batch.run_process() (id, type) = batch.commit_output(0) trajectory = dbvalue(id, type) return trajectory
def scene_bbox(scene): batch.init_process("bstmSceneBboxProcess") batch.set_input_from_db(0, scene) batch.run_process() out = [] for outIdx in range(6): (id, type) = batch.commit_output(outIdx) pt = batch.get_output_double(id) batch.remove_data(id) out.append(pt) minPt = (out[0], out[1], out[2]) maxPt = (out[3], out[4], out[5]) return (minPt, maxPt)
def describe_scene(scene): batch.init_process("bstmDescribeSceneProcess") batch.set_input_from_db(0, scene) batch.run_process() (id, type) = batch.commit_output(0) dataPath = batch.get_output_string(id) batch.remove_data(id) (id, type) = batch.commit_output(1) appType = batch.get_output_string(id) batch.remove_data(id) (id, type) = batch.commit_output(2) voxel_size = batch.get_output_double(id) batch.remove_data(id) description = {'voxelLength': voxel_size, 'dataPath': dataPath, 'appType': appType} return description
def boxm2_load_opencl(scene_str, device_string="gpu"): scene = boxm2_load_scene(scene_str) ############################################################### # Create cache, opencl manager, device, and gpu cache ############################################################### # print("Create Main Cache"); batch.init_process("boxm2CreateCacheProcess") batch.set_input_from_db(0, scene) batch.set_input_string(1, "lru") result = batch.run_process() if not result: raise Exception('boxm2CreateCacheProcess returned false') (id, type) = batch.commit_output(0) cache = dbvalue(id, type) # print("Init Manager"); batch.init_process("boclInitManagerProcess") result = batch.run_process() if not result: raise Exception('boxm2InitManagerProcess returned false') # print("Get Gpu Device"); batch.init_process("boclGetDeviceProcess") batch.set_input_string(0, device_string) result = batch.run_process() if not result: raise Exception('boclGetDeviceProcess returned false') (id, type) = batch.commit_output(0) device = dbvalue(id, type) # print("Create Gpu Cache"); batch.init_process("boxm2CreateOpenclCacheProcess") batch.set_input_from_db(0, device) result = batch.run_process() if not result: raise Exception('boxm2CreateOpenclCacheProcess returned false') (id, type) = batch.commit_output(0) openclcache = dbvalue(id, type) return scene, cache, device, openclcache
def cpu_batch_compute_normal_albedo( self, metadata_filename_list, atmospheric_params_filename_list): batch.init_process("bstmCppBatchComputeNormalAlbedoProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, self.str_cache) batch.set_input_string(3, metadata_filename_list) batch.set_input_string(4, atmospheric_params_filename_list) batch.run_process() # close the files so that they can be reloaded after the next iteration batch.init_process("bstmStreamCacheCloseFilesProcess") batch.set_input_from_db(0, self.str_cache) batch.run_process()
def transform_to_scene(self, to_scene, trans, rot, scale): if self.opencl_cache.type == "bstm_opencl_cache_sptr": print("transforming scene") batch.init_process("bstmVecfOclTransformSceneProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, to_scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_double(3, trans[0]) batch.set_input_double(4, trans[1]) batch.set_input_double(5, trans[2]) batch.set_input_double(6, rot[0][0]) batch.set_input_double(7, rot[0][1]) batch.set_input_double(8, rot[0][2]) batch.set_input_double(9, rot[1][0]) batch.set_input_double(10, rot[1][1]) batch.set_input_double(11, rot[1][2]) batch.set_input_double(12, rot[2][0]) batch.set_input_double(13, rot[2][1]) batch.set_input_double(14, rot[2][2]) batch.set_input_double(15, scale[0]) batch.set_input_double(16, scale[1]) batch.set_input_double(17, scale[2]) return batch.run_process() else: print "ERROR: Cache type not recognized: ", self.opencl_cache.type return False
def render_expected_albedo_normal(self, camera, ni, nj): batch.init_process("bstmOclRenderExpectedAlbedoNormalProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.run_process() (id, type) = batch.commit_output(0) exp_albedo = batch.dvalue(id, type) (id, type) = batch.commit_output(1) exp_normal = batch.dvalue(id, type) (id, type) = batch.commit_output(2) mask_image = batch.dvalue(id, type) return(exp_albedo, exp_normal, mask_image)
def export_pt_cloud(scene, cache, output_filename, prob_t, time, output_aux=True): batch.init_process("bstmCppExtractPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_float(2, prob_t) batch.set_input_float(3, time) batch.run_process() batch.init_process("bstmCppExportPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, output_filename) batch.set_input_bool(3, output_aux) batch.set_input_float(4, time) batch.run_process() return
def refine_scene_around_geometry( self, filter_v, n_times, p_thresh, use_gpu): if self.opencl_cache.type == "bstm_opencl_cache_sptr": print("Refining around surface geometry") batch.init_process( "bstm_ocl_refine_scene_around_geometry_process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.opencl_cache) batch.set_input_from_db(2, self.device) batch.set_input_from_db(3, filter_v) batch.set_input_int(4, n_times) # use negative value to refine all batch.set_input_float(5, p_thresh) batch.set_input_bool(6, use_gpu) return batch.run_process() else: print "ERROR: Cache type not recognized: ", cache.type return False
def ocl_batch_compute_normal_albedo( self, img_id_list, metadata_filename_list, atmospheric_params_filename_list): batch.init_process( "bstmOclBatchComputeNormalAlbedoArrayProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_string(3, img_id_list) batch.set_input_string(4, metadata_filename_list) batch.set_input_string(5, atmospheric_params_filename_list) batch.run_process()
def render_change(scene, device, cache, cam, time=0, ni=1624, nj=1224): if cache.type == "bstm_cache_sptr": print "bstm_batch CPU render grey and vis not yet implemented" return elif cache.type == "bstm_opencl_cache_sptr" and device: batch.init_process("bstmOclRenderExpectedChangeProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_float(6, time) batch.run_process() (id, type) = batch.commit_output(0) exp_image = dbvalue(id, type) return exp_image else: print "ERROR: Cache type not recognized: ", cache.type
def boxm2_render_grey_view_dep(scene, cache, cam, ni=1280, nj=720, device=None, ident_string=""): if cache.type == "boxm2_opencl_cache_sptr" and device: batch.init_process("boxm2OclRenderViewDepExpectedImageProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cache) batch.set_input_from_db(3, cam) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_string(6, ident_string) batch.run_process() (id, type) = batch.commit_output(0) exp_image = dbvalue(id, type) return exp_image else: print "ERROR: Cache type not recognized: ", cache.type
def load_opencl(scene_str, device_string="gpu"): scene = load_scene(scene_str) ############################################################### # Create cache, opencl manager, device, and gpu cache ############################################################### # print("Create Main Cache"); batch.init_process("bstmCreateCacheProcess") batch.set_input_from_db(0, scene) batch.set_input_string(1, "lru") batch.run_process() (id, type) = batch.commit_output(0) cache = dbvalue(id, type) # print("Init Manager"); batch.init_process("boclInitManagerProcess") batch.run_process() (id, type) = batch.commit_output(0) mgr = dbvalue(id, type) # print("Get Gpu Device"); batch.init_process("boclGetDeviceProcess") batch.set_input_string(0, device_string) batch.set_input_from_db(1, mgr) batch.run_process() (id, type) = batch.commit_output(0) device = dbvalue(id, type) # print("Create Gpu Cache"); batch.init_process("bstmOclCreateCacheProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.run_process() (id, type) = batch.commit_output(0) openclcache = dbvalue(id, type) return scene, cache, mgr, device, openclcache
def batch_paint(self, imgs, cams, device_string=""): # verify stream cache if (self.str_cache is None): self.create_stream_cache(imgs) # sigma norm table? under_estimation_probability = 0.2 batch.init_process("bstaSigmaNormTableProcess") batch.set_input_float(0, under_estimation_probability) batch.run_process() (id, type) = batch.commit_output(0) n_table = batch.dvalue(id, type) # call batch paint process if device_string == "": batch.init_process("bstmOclPaintBatchProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, self.str_cache) batch.set_input_from_db(4, n_table) batch.run_process() elif device_string == "cpu": print "Can't use CPU for Paint Batch Process." # close the files so that they can be reloaded after the next iteration batch.init_process("bstmStreamCacheCloseFilesProcess") batch.set_input_from_db(0, self.str_cache) batch.run_process() # write out afterwards self.write_cache()
def cpu_batch_paint(self, imgs, cams): if (self.str_cache is None): self.create_stream_cache(imgs) # sigma norm table? under_estimation_probability = 0.2 batch.init_process("bstaSigmaNormTableProcess") batch.set_input_float(0, under_estimation_probability) batch.run_process() (id, type) = batch.commit_output(0) n_table = batch.dvalue(id, type) # loop over images creating aux data for idx in range(0, len(imgs)): # load cam/img img, ni, nj = vil.load_image(imgs[idx]) pcam = vpgl.load_perspective_camera(cams[idx]) gcam = vpgl.persp2gen(pcam, ni, nj) # create norm intensity (num rays...) batch.init_process("bstmCppCreateNormIntensitiesProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, gcam) batch.set_input_from_db(3, img) batch.set_input_string(4, "img_" + "%05d" % idx) batch.run_process() # create aux batch.init_process("bstmCppCreateAuxDataOPT2Process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, gcam) batch.set_input_from_db(3, img) batch.set_input_string(4, "img_" + "%05d" % idx) batch.run_process() self.write_cache(True) batch.init_process("bstmCppBatchUpdateOPT2Process") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.cpu_cache) batch.set_input_from_db(2, self.str_cache) batch.set_input_from_db(3, n_table) batch.run_process() # close the files so that they can be reloaded after the next iteration batch.init_process("bstmStreamCacheCloseFilesProcess") batch.set_input_from_db(0, self.str_cache) batch.run_process() self.write_cache()
def render_expected_image_naa( self, camera, ni, nj, metadata, atmospheric_params): batch.init_process("bstmOclRenderExpectedImageNAAProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_from_db(6, metadata) batch.set_input_from_db(7, atmospheric_params) batch.run_process() (id, type) = batch.commit_output(0) exp_image = batch.dvalue(id, type) (id, type) = batch.commit_output(1) mask_image = batch.dvalue(id, type) return(exp_image, mask_image)
def update_alpha_naa(self, image, camera, metadata, atmospheric_params, alt_prior, alt_density): batch.init_process("bstmOclUpdateAlphaNAAProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.opencl_cache) batch.set_input_from_db(3, camera) batch.set_input_from_db(4, image) batch.set_input_from_db(5, metadata) batch.set_input_from_db(6, atmospheric_params) batch.set_input_from_db(7, alt_prior) batch.set_input_from_db(8, alt_density) if not (batch.run_process()): print("ERROR: run_process() returned False") return
def cache_neighbor_info(self): batch.init_process("bstmVecfOclCacheNeighborInfoProcess") batch.set_input_from_db(0, self.scene) batch.set_input_from_db(1, self.opencl_cache) return batch.run_process()