def import_point_cloud(scene, cache, in_file, min_octree_depth=2): batch.init_process("boxm2ImportPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, in_file) batch.set_input_unsigned(3, min_octree_depth) batch.run_process()
def batch_synoptic_function(self): """ Create synoptic function (cubic function) at each voxel """ # write image identifiers to file image_id_fname = self.model_dir + "/image_list.txt" fd = open(image_id_fname, "w") print >> fd, 2 * len(self.imgList) for i, img in enumerate(self.imgList): print >> fd, "img_%05d" % i for i, img in enumerate(self.imgList): print >> fd, "viewdir_%05d" % i fd.close() 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("boxm2OclBatchSynopticFunctionProcess") 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_unsigned(3, len(self.imgList)) batch.set_input_string(4, image_id_fname) batch.set_input_float(5, 0.09) batch.run_process()
def batch_synoptic_function(self): """ Create synoptic function (cubic function) at each voxel """ # write image identifiers to file image_id_fname = self.model_dir + "/image_list.txt" fd = open(image_id_fname, "w") print >> fd, 2 * len(self.imgList) for i, img in enumerate(self.imgList): print >> fd, "img_%05d" % i for i, img in enumerate(self.imgList): print >> fd, "viewdir_%05d" % i fd.close() 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("boxm2OclBatchSynopticFunctionProcess") 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_unsigned(3, len(self.imgList)) batch.set_input_string(4, image_id_fname) batch.set_input_float(5, 0.09) batch.run_process()
def img_sum(img, plane_index=0): boxm2_batch.init_process("vilImageSumProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_unsigned(1, plane_index) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) value = boxm2_batch.get_output_double(id) return value
def img_sum(img, plane_index=0): boxm2_batch.init_process("vilImageSumProcess") boxm2_batch.set_input_from_db(0,img) boxm2_batch.set_input_unsigned(1,plane_index) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) value = boxm2_batch.get_output_double(id) return value
def get_plane(img, plane_id): boxm2_batch.init_process("vilGetPlaneProcess"); boxm2_batch.set_input_from_db(0, img); boxm2_batch.set_input_unsigned(1, plane_id); boxm2_batch.run_process(); (id, type) = boxm2_batch.commit_output(0); img_plane = dbvalue(id, type); return img_plane;
def get_plane(img, plane_id): boxm2_batch.init_process("vilGetPlaneProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_unsigned(1, plane_id) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) img_plane = dbvalue(id, type) return img_plane
def mask_image_using_id(img, id_img, input_id): boxm2_batch.init_process("vilMaskImageUsingIDsProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_from_db(1, id_img) boxm2_batch.set_input_unsigned(2, input_id) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) masked_img = dbvalue(id, type) return masked_img
def mask_image_using_id(img, id_img, input_id): boxm2_batch.init_process("vilMaskImageUsingIDsProcess"); boxm2_batch.set_input_from_db(0, img); boxm2_batch.set_input_from_db(1, id_img); boxm2_batch.set_input_unsigned(2, input_id); boxm2_batch.run_process(); (id, type) = boxm2_batch.commit_output(0); masked_img = dbvalue(id, type); return masked_img;
def arf_seek_frame(rawStream, frame) : boxm2_batch.init_process("bilArfSeekFrameProcess") boxm2_batch.set_input_from_db(0,rawStream); boxm2_batch.set_input_unsigned(1,frame); boxm2_batch.run_process(); (id, type) = boxm2_batch.commit_output(0); img = dbvalue(id,type); (id, type) = boxm2_batch.commit_output(1); time = boxm2_batch.get_output_unsigned(id); return img, time
def seek_frame(rawStream, frame): boxm2_batch.init_process("bilSeekFrameProcess") boxm2_batch.set_input_from_db(0, rawStream) boxm2_batch.set_input_unsigned(1, frame) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) img = dbvalue(id, type) #(id, type) = boxm2_batch.commit_output(1); #time = boxm2_batch.get_output_unsigned(id); return img
def apply_filters_cpp(scene, cpp_cache, prob_thres, filter_basename, filter_id, octree_lvl): batch.init_process("boxm2CppFilterResponseProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cpp_cache) batch.set_input_float(2, prob_thres) batch.set_input_string(3, filter_basename) # id kernel --> read the kernel from filter_basename + str(filter_id) + # ".txt" batch.set_input_unsigned(4, filter_id) batch.set_input_unsigned(5, octree_lvl) # octree level to run kernel batch.run_process()
def create_view_directions(self, cam, ni, nj, viewNum): """ Create aux data for direction """ batch.init_process("boxm2OclAuxUpdateViewDirectionProcess") batch.set_input_from_db(0, self.device) batch.set_input_from_db(1, self.scene) batch.set_input_from_db(2, self.cpu_cache) batch.set_input_from_db(3, self.opencl_cache) batch.set_input_from_db(4, cam) batch.set_input_unsigned(5, ni) batch.set_input_unsigned(6, nj) batch.set_input_string(7, "viewdir_" + "%05d" % viewNum) batch.set_input_string(8, "cartesian") batch.run_process()
def batch_uncertainty(self, image_id_fname): """Calculate voxel uncertainty""" # write image identifiers to file # open the stream cache, this is a read-only cache batch.init_process("boxm2OclBatchUncertaintyProcess") 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_unsigned(3, len(self.imgList)) batch.set_input_string(4, image_id_fname) batch.run_process() self.write_cache(True)
def update_view_surface_density(device, scene, opencl_cache, cam, ni, nj, depth, std_depth, tnear=1000000, tfar=0.00001): print("Updating View Surface Density") batch.init_process("boxm2OclUpdateSurfaceDensityProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, opencl_cache) batch.set_input_from_db(3, cam) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) batch.set_input_from_db(6, depth) batch.set_input_from_db(7, std_depth) batch.set_input_float(8, tnear) batch.set_input_float(9, tfar) return batch.run_process()
def update_max_vis(device, scene, opencl_cache, cam, ni, nj, mask_ptr, tnear=1000000, tfar=0.00001): print("Updating Max Vis") batch.init_process("boxm2OclUpdateMaxVisScoreProcess") batch.set_input_from_db(0, device) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, opencl_cache) batch.set_input_from_db(3, cam) batch.set_input_unsigned(4, ni) batch.set_input_unsigned(5, nj) if(mask_ptr is not None): batch.set_input_from_db(6, mask_ptr) batch.set_input_float(7, tnear) batch.set_input_float(8, tfar) return batch.run_process()
def render_multi(scene, mcache, cam, ni=1280, nj=720, ident_string="", tnear=100000.0, tfar=100000.0): batch.init_process("boxm2MultiRenderProcess") batch.set_input_from_db(0, mcache) batch.set_input_from_db(1, scene) batch.set_input_from_db(2, cam) batch.set_input_unsigned(3, ni) batch.set_input_unsigned(4, nj) batch.set_input_string(5, ident_string) batch.set_input_float(6, tnear) batch.set_input_float(7, tfar) batch.run_process() (id, type) = batch.commit_output(0) exp_image = dbvalue(id, type) return exp_image
def gen_color_point_cloud(scene, cache, filename, thresh=0.3, ident="", depth=3): batch.init_process("boxm2ExtractPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_float(2, thresh) # prob threshold batch.set_input_unsigned(3, depth) # prob threshold batch.run_process() batch.init_process("boxm2ExportColorPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, filename) batch.set_input_float(3, thresh) batch.set_input_string(4, ident) batch.run_process()
def gen_point_cloud(scene, cache, filename, thresh=0.3, vis_thresh=0.5, depth=3): batch.init_process("boxm2ExtractPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_float(2, thresh) # prob threshold batch.set_input_unsigned(3, depth) # prob threshold batch.run_process() batch.init_process("boxm2ExportOrientedPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, filename) batch.set_input_float(4, vis_thresh) batch.set_input_float(6, thresh) batch.run_process()
def gen_error_point_cloud(scene, cache, filename, thresh=0.3, LE_thresh=-1.0, CE_thresh=-1.0, depth=3): batch.init_process("boxm2ExtractPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_float(2, thresh) # prob threshold batch.set_input_unsigned(3, depth) # prob threshold batch.run_process() batch.init_process("boxm2ExportErrorPointCloudProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_string(2, filename) # ply filename batch.set_input_float(3, thresh) # prob threshold batch.set_input_float(4, LE_thresh) # LE threshold batch.set_input_float(5, CE_thresh) # CE threshold batch.run_process()
def render_expected_albedo_normal(self, camera, ni, nj): batch.init_process("boxm2OclRenderExpectedAlbedoNormalProcess") 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 = dbvalue(id, type) (id, type) = batch.commit_output(1) exp_normal = dbvalue(id, type) (id, type) = batch.commit_output(2) mask_image = dbvalue(id, type) return(exp_albedo, exp_normal, mask_image)
def render_expected_albedo_normal(self, camera, ni, nj): batch.init_process("boxm2OclRenderExpectedAlbedoNormalProcess") 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 = dbvalue(id, type) (id, type) = batch.commit_output(1) exp_normal = dbvalue(id, type) (id, type) = batch.commit_output(2) mask_image = dbvalue(id, type) return (exp_albedo, exp_normal, mask_image)
def render_expected_image_naa(self, camera, ni, nj, metadata, atmospheric_params): batch.init_process("boxm2OclRenderExpectedImageNAAProcess") 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 = dbvalue(id, type) (id, type) = batch.commit_output(1) mask_image = dbvalue(id, type) return (exp_image, mask_image)
def render_expected_image_naa( self, camera, ni, nj, metadata, atmospheric_params): batch.init_process("boxm2OclRenderExpectedImageNAAProcess") 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 = dbvalue(id, type) (id, type) = batch.commit_output(1) mask_image = dbvalue(id, type) return(exp_image, mask_image)
def render_uncertainty_map(self, ni, nj, ident="", cam_dir_1="", cam_dir_2=""): """ Render Hemispherical Uncertainty Map """ # open the stream cache, this is a read-only cache batch.init_process("boxm2OclRenderSceneUncertaintyMapProcess") 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_unsigned(3, ni) batch.set_input_unsigned(4, nj) batch.set_input_string(5, ident) batch.set_input_string(6, cam_dir_1) batch.set_input_string(7, cam_dir_2) batch.run_process() (id, type) = batch.commit_output(0) exp_img = dbvalue(id, type) (id, type) = batch.commit_output(1) vis_img = dbvalue(id, type) return exp_img, vis_img
def crop_image(img,i0,j0,ni,nj): boxm2_batch.init_process("vilCropImageProcess") boxm2_batch.set_input_from_db(0,img) boxm2_batch.set_input_unsigned(1,i0) boxm2_batch.set_input_unsigned(2,j0) boxm2_batch.set_input_unsigned(3,ni) boxm2_batch.set_input_unsigned(4,nj) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) img_out = dbvalue(id,type) return img_out
def crop_image(img, i0, j0, ni, nj): boxm2_batch.init_process("vilCropImageProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_unsigned(1, i0) boxm2_batch.set_input_unsigned(2, j0) boxm2_batch.set_input_unsigned(3, ni) boxm2_batch.set_input_unsigned(4, nj) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) img_out = dbvalue(id, type) return img_out
def batch_synoptic_alpha_update(self): """ Create synoptic function (cubic function) at each voxel """ image_id_fname = self.model_dir + "/image_list.txt" fd = open(image_id_fname, "w") print >> fd, len(self.imgList) for i, img in enumerate(self.imgList): print img print >> fd, "img_%05d" % i fd.close() batch.init_process("boxm2OclSynopticUpdateAlphaProcess") 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_unsigned(3, len(self.imgList)) batch.set_input_string(4, image_id_fname) batch.run_process() self.write_cache()
def get_info_along_ray(scene, cache, cam, u, v, prefix, identifier=""): print("Ray Probe") batch.init_process("boxm2CppRayProbeProcess") batch.set_input_from_db(0, scene) batch.set_input_from_db(1, cache) batch.set_input_from_db(2, cam) batch.set_input_unsigned(3, u) batch.set_input_unsigned(4, v) batch.set_input_string(5, prefix) batch.set_input_string(6, identifier) batch.run_process() (id, type) = batch.commit_output(0) len_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) (id, type) = batch.commit_output(1) alpha_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) (id, type) = batch.commit_output(2) vis_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) (id, type) = batch.commit_output(3) tabs_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) (id, type) = batch.commit_output(4) res_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) if (prefix != ""): (id, type) = batch.commit_output(5) data_array_1d = batch.get_bbas_1d_array_float(id) batch.remove_data(id) (id, type) = batch.commit_output(6) nelems = batch.get_output_int(id) batch.remove_data(id) return len_array_1d, alpha_array_1d, vis_array_1d, tabs_array_1d, res_array_1d, data_array_1d, nelems else: return len_array_1d, alpha_array_1d, vis_array_1d, tabs_array_1d, res_array_1d
def init_float_img(ni,nj,np,val): boxm2_batch.init_process("vilInitFloatImageProcess") boxm2_batch.set_input_unsigned(0,ni) boxm2_batch.set_input_unsigned(1,nj) boxm2_batch.set_input_unsigned(2,np) boxm2_batch.set_input_float(3,val) boxm2_batch.run_process() (id,type) = boxm2_batch.commit_output(0) img_out = dbvalue(id,type) return img_out
def binary_edge_detection(img, max_size, min_size, threshold_id = 255): boxm2_batch.init_process("vilBinaryEdgeDetectionProcess") boxm2_batch.set_input_from_db(0, img) boxm2_batch.set_input_unsigned(1, max_size) boxm2_batch.set_input_unsigned(2, min_size) boxm2_batch.set_input_unsigned(3, threshold_id) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) edge_img = dbvalue(id,type) return edge_img
def init_float_img(ni, nj, np, val): boxm2_batch.init_process("vilInitFloatImageProcess") boxm2_batch.set_input_unsigned(0, ni) boxm2_batch.set_input_unsigned(1, nj) boxm2_batch.set_input_unsigned(2, np) boxm2_batch.set_input_float(3, val) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) img_out = dbvalue(id, type) return img_out
boxm2_batch.set_input_from_db(0, device) boxm2_batch.set_input_from_db(1, scene) boxm2_batch.set_input_from_db(2, openclcache) boxm2_batch.set_input_from_db(3, cam) boxm2_batch.set_input_from_db(4, img) boxm2_batch.run_process() print ("Refine") boxm2_batch.init_process("boxm2OclRefineProcess") boxm2_batch.set_input_from_db(0, device) boxm2_batch.set_input_from_db(1, scene) boxm2_batch.set_input_from_db(2, openclcache) boxm2_batch.set_input_float(3, 0.3) boxm2_batch.run_process() print ("Render") boxm2_batch.init_process("boxm2OclRenderExpectedImageProcess") boxm2_batch.set_input_from_db(0, device) boxm2_batch.set_input_from_db(1, scene) boxm2_batch.set_input_from_db(2, openclcache) boxm2_batch.set_input_from_db(3, cam) boxm2_batch.set_input_unsigned(4, 1280) boxm2_batch.set_input_unsigned(5, 720) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) exp_img = dbvalue(id, type) boxm2_batch.init_process("vilSaveImageViewProcess") boxm2_batch.set_input_from_db(0, exp_img) boxm2_batch.set_input_string(1, exp_fname) boxm2_batch.run_process()
def writeSceneFromBox(data_path, resolution, min_pt, max_pt, ntrees_x=64,ntrees_y=64,ntrees_z=64, max_num_lvls=4, appearance_model1 = "boxm2_mog3_grey", appearance_model2 = "boxm2_num_obs", appearance_model3 = "boxm2_sum_log_msg_pos", p_init=0.001,max_data_size=1500.0): """A function that takes the minimum and maximum points of a bounding box for the scene in real world coordinates and partitions the space into the appropriate number of boxes given a user specified number of trees. min_pt : A python list specifying the 3d position of the minimum corner of the box. This is interpreted by boxm2 as the 3d origin of the scene. max-pt : A python list specifying the 3d position of the maximum corner of the box. ntrees : Number of trees in all dimensions (the python interface only supports symmetric trees thus far) max_num_lvls : Maximum number of levels in the trees (a tree will have pow(2,max_num_lvls-1) possible cells) appearance_model : A string indicating desired appearance model occupancy_model : A string indicating desired occupancy model max_data_size : Maximum Sizer of a block in megabytes. Determined by GPU memory. Recomment 650MB for 1GB card and 1.1GB for 1.5GM card maximum_data_size : Maximum memory allowable for a superblock. The max_data_size is determined by GPU memory size. For a 1 GB card, a maximum data size of 650MB is recommended. For a 1.5GB card, a 1.1G maximum data size of 1.1GB is recommended. p_init : Initial occupancy probability.""" boxm2_batch.register_processes(); boxm2_batch.register_datatypes(); tree_size=resolution*pow(2,max_num_lvls-1); block_size_x=ntrees_x*tree_size; block_size_y=ntrees_y*tree_size; block_size_z=ntrees_z*tree_size; xsize=max_pt[0]-min_pt[0]; ysize=max_pt[1]-min_pt[1]; zsize=max_pt[2]-min_pt[2]; print "zsize: %f" % zsize print "block size: %f" % block_size_z nblocks_x=int(round(xsize/block_size_x)); nblocks_y=int(round(ysize/block_size_y)); nblocks_z=int(round(zsize/block_size_z)); print "nblocks_z : %f" % nblocks_z if(nblocks_x<=0):nblocks_x=1; if(nblocks_y<=0):nblocks_y=1; if(nblocks_z<=0):nblocks_z=1; print '\t Number of blocks in the x dimension: %d' % nblocks_x print '\t Number of blocks in the y dimension: %d' % nblocks_y print '\t Number of blocks in the z dimension: %d' % nblocks_z print("\t CREATING THE BOXM2_SCENE_SPTR") boxm2_batch.init_process("boxm2CreateSceneProcess"); boxm2_batch.set_input_string(0,data_path); boxm2_batch.set_input_string(1,appearance_model1); boxm2_batch.set_input_string(2,appearance_model2); boxm2_batch.set_input_string(3,appearance_model3); boxm2_batch.set_input_float(4,min_pt[0]); boxm2_batch.set_input_float(5,min_pt[1]); boxm2_batch.set_input_float(6,min_pt[2]); boxm2_batch.run_process(); (id,type)=boxm2_batch.commit_output(0); scene=dbvalue(id,type); for k in range(nblocks_z): for j in range(nblocks_y): for i in range(nblocks_x): block_origin_x=min_pt[0]+i*block_size_x; block_origin_y=min_pt[1]+j*block_size_y; block_origin_z=min_pt[2]+k*block_size_z; print '\t \t Creating block with id (%d,%d,%d) at origin (%s,%s,%s)' % (i,j,k,block_origin_x, block_origin_y, block_origin_z) boxm2_batch.init_process("boxm2AddBlockProcess"); boxm2_batch.set_input_from_db(0,scene); boxm2_batch.set_input_int(1,i); boxm2_batch.set_input_int(2,j); boxm2_batch.set_input_int(3,k); boxm2_batch.set_input_unsigned(4,ntrees_x); boxm2_batch.set_input_unsigned(5,ntrees_y); boxm2_batch.set_input_unsigned(6,ntrees_z); boxm2_batch.set_input_unsigned(7,max_num_lvls); boxm2_batch.set_input_float(8,block_origin_x); boxm2_batch.set_input_float(9,block_origin_y); boxm2_batch.set_input_float(10,block_origin_z); boxm2_batch.set_input_float(11,tree_size); boxm2_batch.set_input_float(12,max_data_size); boxm2_batch.set_input_float(13,p_init); boxm2_batch.set_input_unsigned(14,1); boxm2_batch.run_process(); boxm2_batch.init_process("boxm2WriteSceneXMLProcess") boxm2_batch.set_input_from_db(0,scene); boxm2_batch.set_input_string(1,"scene"); boxm2_batch.run_process();
print("\t----------------------WE ARE REFINING!--------------------------"); boxm2_batch.init_process("boxm2OclRefineProcess"); boxm2_batch.set_input_from_db(0,device); boxm2_batch.set_input_from_db(1,scene); boxm2_batch.set_input_from_db(2,openclcache); boxm2_batch.set_input_float(3, 0.3); #0.25 * (repeat+1) ); # originally set to .3 boxm2_batch.run_process(); print("Render"); boxm2_batch.init_process("boxm2OclRenderExpectedImageProcess"); boxm2_batch.set_input_from_db(0,device); boxm2_batch.set_input_from_db(1,scene); boxm2_batch.set_input_from_db(2,openclcache); boxm2_batch.set_input_from_db(3,cam); boxm2_batch.set_input_unsigned(4,NI); boxm2_batch.set_input_unsigned(5,NJ); boxm2_batch.run_process(); (id,type) = boxm2_batch.commit_output(0); exp_img = dbvalue(id,type); boxm2_batch.init_process("vilSaveImageViewProcess"); boxm2_batch.set_input_from_db(0,exp_img); boxm2_batch.set_input_string(1,exp_fname); boxm2_batch.run_process(); boxm2_batch.remove_data(exp_img.id) boxm2_batch.remove_data(img.id) boxm2_batch.remove_data(cam.id)
def boxm2WriteSceneXML(data_path, resolution, origin, nblocks_x, nblocks_y,nblocks_z,ntrees=64,max_num_lvls=4, appearance_model = "boxm2_mog3_grey", occupancy_model = "boxm2_num_obs", max_data_size=650.0,p_init=0.001): """This is boxm2WriteSceneXML.py Function to create a boxm2 scene XML file Author: Brandon Mayer Date: 4/6/2011 data_path : A directory to which the xml file should be saved origin : A python list specifying the 3d origin (x,y,z) nblocks_x : Number of superblocks in the x dimension nblocks_y : Number of superblocks in the y dimension nblocks_z : Number of superblocks in the z dimension ntrees : Number of trees in all dimensions (the python interface only supports symmetric trees thus far) max_num_lvls : Maximum number of levels in the trees (a tree will have pow(2,max_num_lvls-1) possible cells) appearance_model : A string indicating desired appearance model occupancy_model : A string indicating desired occupancy model maximum_data_size : Maximum memory allowable for a superblock. The max_data_size is determined by GPU memory size. For a 1 GB card, a maximum data size of 650MB is recommended. For a 1.5GB card, a 1.1G maximum data size of 1.1GB is recommended. p_init : Initial occupancy probability.""" boxm2_batch.register_processes(); boxm2_batch.register_datatypes(); tree_size=resolution*pow(2,max_num_lvls-1); block_size=ntrees*tree_size; print("\t Creating the boxm2_scene_sptr") boxm2_batch.init_process("boxm2CreateSceneProcess"); boxm2_batch.set_input_string(0,data_path); boxm2_batch.set_input_string(1,appearance_model); boxm2_batch.set_input_string(2,occupancy_model); boxm2_batch.set_input_float(3,origin[0]); boxm2_batch.set_input_float(4,origin[1]); boxm2_batch.set_input_float(5,origin[2]); boxm2_batch.run_process(); (id,type) = boxm2_batch.commit_output(0); scene = dbvalue(id,type); for i in range(nblocks_x): for j in range(nblocks_y): for k in range(nblocks_z): block_origin_x=origin[0]+i*block_size; block_origin_y=origin[1]+j*block_size; block_origin_z=origin[2]+k*block_size; print '\t Creating block with id (%d,%d,%d) at origin (%s,%s,%s)' % (i,j,k,block_origin_x, block_origin_y, block_origin_z) boxm2_batch.init_process("boxm2AddBlockProcess"); boxm2_batch.set_input_from_db(0,scene); boxm2_batch.set_input_unsigned(1,i); boxm2_batch.set_input_unsigned(2,j); boxm2_batch.set_input_unsigned(3,k); boxm2_batch.set_input_unsigned(4,ntrees); boxm2_batch.set_input_unsigned(5,ntrees); boxm2_batch.set_input_unsigned(6,ntrees); boxm2_batch.set_input_unsigned(7,max_num_lvls); boxm2_batch.set_input_float(8,block_origin_x); boxm2_batch.set_input_float(9,block_origin_y); boxm2_batch.set_input_float(10,block_origin_z); boxm2_batch.set_input_float(11,tree_size); boxm2_batch.set_input_float(12,max_data_size); boxm2_batch.set_input_float(13,p_init); boxm2_batch.run_process(); boxm2_batch.init_process("boxm2WriteSceneXMLProcess") boxm2_batch.set_input_from_db(0,scene) boxm2_batch.run_process();
def writeSceneFromBox(data_path, resolution, min_pt, max_pt, ntrees_x=64, ntrees_y=64, ntrees_z=64, max_num_lvls=4, appearance_model1="boxm2_mog3_grey", appearance_model2="boxm2_num_obs", appearance_model3="boxm2_sum_log_msg_pos", p_init=0.001, max_data_size=1500.0): """A function that takes the minimum and maximum points of a bounding box for the scene in real world coordinates and partitions the space into the appropriate number of boxes given a user specified number of trees. min_pt : A python list specifying the 3d position of the minimum corner of the box. This is interpreted by boxm2 as the 3d origin of the scene. max-pt : A python list specifying the 3d position of the maximum corner of the box. ntrees : Number of trees in all dimensions (the python interface only supports symmetric trees thus far) max_num_lvls : Maximum number of levels in the trees (a tree will have pow(2,max_num_lvls-1) possible cells) appearance_model : A string indicating desired appearance model occupancy_model : A string indicating desired occupancy model max_data_size : Maximum Sizer of a block in megabytes. Determined by GPU memory. Recomment 650MB for 1GB card and 1.1GB for 1.5GM card maximum_data_size : Maximum memory allowable for a superblock. The max_data_size is determined by GPU memory size. For a 1 GB card, a maximum data size of 650MB is recommended. For a 1.5GB card, a 1.1G maximum data size of 1.1GB is recommended. p_init : Initial occupancy probability.""" boxm2_batch.register_processes() boxm2_batch.register_datatypes() tree_size = resolution * pow(2, max_num_lvls - 1) block_size_x = ntrees_x * tree_size block_size_y = ntrees_y * tree_size block_size_z = ntrees_z * tree_size xsize = max_pt[0] - min_pt[0] ysize = max_pt[1] - min_pt[1] zsize = max_pt[2] - min_pt[2] print "zsize: %f" % zsize print "block size: %f" % block_size_z nblocks_x = int(round(xsize / block_size_x)) nblocks_y = int(round(ysize / block_size_y)) nblocks_z = int(round(zsize / block_size_z)) print "nblocks_z : %f" % nblocks_z if (nblocks_x <= 0): nblocks_x = 1 if (nblocks_y <= 0): nblocks_y = 1 if (nblocks_z <= 0): nblocks_z = 1 print '\t Number of blocks in the x dimension: %d' % nblocks_x print '\t Number of blocks in the y dimension: %d' % nblocks_y print '\t Number of blocks in the z dimension: %d' % nblocks_z print("\t CREATING THE BOXM2_SCENE_SPTR") boxm2_batch.init_process("boxm2CreateSceneProcess") boxm2_batch.set_input_string(0, data_path) boxm2_batch.set_input_string(1, appearance_model1) boxm2_batch.set_input_string(2, appearance_model2) boxm2_batch.set_input_string(3, appearance_model3) boxm2_batch.set_input_float(4, min_pt[0]) boxm2_batch.set_input_float(5, min_pt[1]) boxm2_batch.set_input_float(6, min_pt[2]) boxm2_batch.run_process() (id, type) = boxm2_batch.commit_output(0) scene = dbvalue(id, type) for k in range(nblocks_z): for j in range(nblocks_y): for i in range(nblocks_x): block_origin_x = min_pt[0] + i * block_size_x block_origin_y = min_pt[1] + j * block_size_y block_origin_z = min_pt[2] + k * block_size_z print '\t \t Creating block with id (%d,%d,%d) at origin (%s,%s,%s)' % ( i, j, k, block_origin_x, block_origin_y, block_origin_z) boxm2_batch.init_process("boxm2AddBlockProcess") boxm2_batch.set_input_from_db(0, scene) boxm2_batch.set_input_int(1, i) boxm2_batch.set_input_int(2, j) boxm2_batch.set_input_int(3, k) boxm2_batch.set_input_unsigned(4, ntrees_x) boxm2_batch.set_input_unsigned(5, ntrees_y) boxm2_batch.set_input_unsigned(6, ntrees_z) boxm2_batch.set_input_unsigned(7, max_num_lvls) boxm2_batch.set_input_float(8, block_origin_x) boxm2_batch.set_input_float(9, block_origin_y) boxm2_batch.set_input_float(10, block_origin_z) boxm2_batch.set_input_float(11, tree_size) boxm2_batch.set_input_float(12, max_data_size) boxm2_batch.set_input_float(13, p_init) boxm2_batch.set_input_unsigned(14, 1) boxm2_batch.run_process() boxm2_batch.init_process("boxm2WriteSceneXMLProcess") boxm2_batch.set_input_from_db(0, scene) boxm2_batch.set_input_string(1, "scene") boxm2_batch.run_process()