def import_points_from_pcd_file(filename, name_prefix="", select_ob=True): """ Import 3D coordinates of vertices from a PointCloud (.pcd) file. "name_prefix" : see documentation of "object_name_from_filename()" "select_ob" : select the imported pointcloud object Note: currently, colors are not yet supported. """ # Import point cloud verts, colors, found_alpha = dataset_tools.load_3D_points_from_pcd_file( filename, use_alpha=True) ob, is_new_ob = create_mesh( object_name_from_filename(filename, name_prefix), verts) # Mark object as a pointcloud ob["is_pointcloud"] = True # Mark object as a colored pointcloud, if applicable ob["pointcloud_has_rgba"] = (colors != None) if ob["pointcloud_has_rgba"]: if is_new_ob: # only change transparency in this case ob.show_transparent = found_alpha # render alpha channel # Open mesh for editing vertex custom data bm = bmesh.new() bm.from_mesh(ob.data) # Create custom data layers, for the vertex color r = bm.verts.layers.float.new('r') g = bm.verts.layers.float.new('g') b = bm.verts.layers.float.new('b') a = bm.verts.layers.float.new('a') # Color vertices for vert, color in zip(bm.verts, colors / 255.): vert[b], vert[g], vert[r] = color[0:3] vert[a] = color[3] # Save colors bm.to_mesh(ob.data) del bm if select_ob: # Select the generated object if bpy.context.mode != "OBJECT": bpy.ops.object.mode_set() # switch to object mode bpy.ops.object.select_all(action="DESELECT") ob.select = True bpy.context.scene.objects.active = ob
def scene_3D_points(r=1.0, filename="scene_3D_points.pcd"): """ Load 3D coordinates of points from a PointCloud .pcd-file given by filename "filename". Use "r" as geometry scaling factor. The points are assumed to be confined in a cube with edges of length 2. """ points = dataset_tools.load_3D_points_from_pcd_file(filename)[0] # only load verts, not colors points *= r points = np.concatenate((points, np.ones((len(points), 1))), axis=1) # to homogeneous coordinates return points
def scene_3D_points(r=1., filename="scene_3D_points.pcd"): """ Load 3D coordinates of points from a PointCloud .pcd-file given by filename "filename". Use "r" as geometry scaling factor. The points are assumed to be confined in a cube with edges of length 2. """ points = dataset_tools.load_3D_points_from_pcd_file(filename)[0] # only load verts, not colors points *= r points = np.concatenate((points, np.ones((len(points), 1))), axis=1) # to homogeneous coordinates return points
def import_points_from_pcd_file(filename, name_prefix="", select_ob=True): """ Import 3D coordinates of vertices from a PointCloud (.pcd) file. "name_prefix" : see documentation of "object_name_from_filename()" "select_ob" : select the imported pointcloud object Note: currently, colors are not yet supported. """ # Import point cloud verts, colors, found_alpha = dataset_tools.load_3D_points_from_pcd_file(filename, use_alpha=True) ob, is_new_ob = create_mesh(object_name_from_filename(filename, name_prefix), verts) # Mark object as a pointcloud ob["is_pointcloud"] = True # Mark object as a colored pointcloud, if applicable ob["pointcloud_has_rgba"] = (colors != None) if ob["pointcloud_has_rgba"]: if is_new_ob: # only change transparency in this case ob.show_transparent = found_alpha # render alpha channel # Open mesh for editing vertex custom data bm = bmesh.new() bm.from_mesh(ob.data) # Create custom data layers, for the vertex color r = bm.verts.layers.float.new('r') g = bm.verts.layers.float.new('g') b = bm.verts.layers.float.new('b') a = bm.verts.layers.float.new('a') # Color vertices for vert, color in zip(bm.verts, colors / 255.): vert[b], vert[g], vert[r] = color[0:3] vert[a] = color[3] # Save colors bm.to_mesh(ob.data) del bm if select_ob: # Select the generated object if bpy.context.mode != "OBJECT": bpy.ops.object.mode_set() # switch to object mode bpy.ops.object.select_all(action="DESELECT") ob.select = True bpy.context.scene.objects.active = ob
def main(): traj_to_file, traj_from_file, traj_input_files, map_input_files, at_frame, offset_time = parse_cmd_args( ) print("Calculating transformation...") cam_trajectory_from = dataset_tools.load_cam_trajectory_TUM(traj_from_file) cam_trajectory_to = dataset_tools.load_cam_trajectory_TUM(traj_to_file) transformation = dataset_tools.transform_between_cam_trajectories( cam_trajectory_from, cam_trajectory_to, at_frame=at_frame, offset_time=offset_time) print("Results:") delta_quaternion, delta_scale, delta_location = transformation print("delta_quaternion:") print("\t %s" % delta_quaternion) print("delta_scale:") print("\t %s" % delta_scale) print("delta_location:") print("\t %s" % delta_location) print() for traj_input_file in traj_input_files: print('Transforming traj "%s"...' % traj_input_file) dataset_tools.save_cam_trajectory_TUM( "%s-trfm%s" % tuple(os.path.splitext(traj_input_file)), dataset_tools.transformed_cam_trajectory( dataset_tools.load_cam_trajectory_TUM(traj_input_file), transformation)) for map_input_file in map_input_files: print('Transforming map "%s"...' % map_input_file) points, colors, _ = dataset_tools.load_3D_points_from_pcd_file( map_input_file, use_alpha=True) dataset_tools.save_3D_points_to_pcd_file( "%s-trfm%s" % tuple(os.path.splitext(map_input_file)), dataset_tools.transformed_points(points, transformation), colors) print("Done.")
def main(): traj_to_file, traj_from_file, traj_input_files, map_input_files, at_frame, offset_time = parse_cmd_args() print "Calculating transformation..." cam_trajectory_from = dataset_tools.load_cam_trajectory_TUM(traj_from_file) cam_trajectory_to = dataset_tools.load_cam_trajectory_TUM(traj_to_file) transformation = dataset_tools.transform_between_cam_trajectories( cam_trajectory_from, cam_trajectory_to, at_frame=at_frame, offset_time=offset_time ) print "Results:" delta_quaternion, delta_scale, delta_location = transformation print "delta_quaternion:" print "\t %s" % delta_quaternion print "delta_scale:" print "\t %s" % delta_scale print "delta_location:" print "\t %s" % delta_location print for traj_input_file in traj_input_files: print 'Transforming traj "%s"...' % traj_input_file dataset_tools.save_cam_trajectory_TUM( "%s-trfm%s" % tuple(os.path.splitext(traj_input_file)), dataset_tools.transformed_cam_trajectory( dataset_tools.load_cam_trajectory_TUM(traj_input_file), transformation ) ) for map_input_file in map_input_files: print 'Transforming map "%s"...' % map_input_file points, colors, _ = dataset_tools.load_3D_points_from_pcd_file(map_input_file, use_alpha=True) dataset_tools.save_3D_points_to_pcd_file( "%s-trfm%s" % tuple(os.path.splitext(map_input_file)), dataset_tools.transformed_points(points, transformation), colors ) print "Done."