| 73 | |
| 74 | |
| 75 | def visualize(object_list, title="PiLiDAR", transformation=None, fullscreen=True, size=(1280,720), view="front", point_size=1, |
| 76 | unlit=False, backface=True, point_colors="color", bgcolor=(0.15, 0.15, 0.15), enable_fallback=True): |
| 77 | |
| 78 | object_list = __validate_object_list__(object_list) |
| 79 | |
| 80 | if enable_fallback: |
| 81 | opengl_fallback() |
| 82 | |
| 83 | if point_colors.lower() == "uniform": |
| 84 | point_colors = "color" |
| 85 | uniform_colors = True |
| 86 | else: |
| 87 | uniform_colors = False |
| 88 | |
| 89 | point_color_option = {"x" : o3d.visualization.PointColorOption.XCoordinate, |
| 90 | "y" : o3d.visualization.PointColorOption.YCoordinate, |
| 91 | "z" : o3d.visualization.PointColorOption.ZCoordinate, |
| 92 | "normal" : o3d.visualization.PointColorOption.Normal, |
| 93 | "color" : o3d.visualization.PointColorOption.Color |
| 94 | }[point_colors.lower()] |
| 95 | |
| 96 | # Deepcopy to avoid modifying the original data |
| 97 | if transformation is not None or point_color_option == 5: |
| 98 | object_list = copy.deepcopy(object_list) |
| 99 | |
| 100 | if transformation is not None: |
| 101 | # for i, object in enumerate(object_list): |
| 102 | # object_list[i] = transform(object, transformation=transformation) |
| 103 | object_list[0] = transform(object_list[0], transformation=transformation) # only transform the first object |
| 104 | |
| 105 | if uniform_colors: |
| 106 | object_list = copy.deepcopy(object_list) |
| 107 | |
| 108 | colors = __generate_colors__(len(object_list), float=True) |
| 109 | for i, object in enumerate(object_list): |
| 110 | object_list[i].paint_uniform_color(colors[i]) |
| 111 | |
| 112 | views = {"top": {"zoom": 0.1, "front": (0, 0, 1), "lookat": (0, 0, 0), "up": (0, 1, 0)}, |
| 113 | "front": {"zoom": 0.1, "front": (0, -1, 0), "lookat": (0, 0, 0), "up": (0, 0, 1)}, |
| 114 | "overview":{"zoom": 0.2, "front": (-1, -1, 1), "lookat": (0, 0, 0), "up": (0, 0, 1)}} |
| 115 | |
| 116 | if isinstance(view, dict): |
| 117 | # custom view |
| 118 | v = view |
| 119 | elif isinstance(view, str) and view in views.keys(): |
| 120 | # one of the predefined views |
| 121 | v = views[view] |
| 122 | else: |
| 123 | print("[Error] Invalid view. defaulting to front view") |
| 124 | v = views["front"] |
| 125 | |
| 126 | vis = o3d.visualization.Visualizer() |
| 127 | |
| 128 | if fullscreen: |
| 129 | vis.create_window(left=0, top=0, window_name=title) |
| 130 | else: |
| 131 | vis.create_window(left=20, top=50, window_name=title, width=size[0], height=size[1]) |
| 132 | |