(args)
| 111 | |
| 112 | |
| 113 | def main(args): |
| 114 | logger.debug(args) |
| 115 | geometries = deserialize_geometries(args.input, args.input_format) |
| 116 | |
| 117 | canvas = vispy.scene.SceneCanvas(title=__file__, keys="interactive") |
| 118 | # TODO: After the points are loaded, use PCA to pick an appropriate default camera view? |
| 119 | # TODO: Perhaps default to an isometric view? |
| 120 | # TODO: Add an argument to allow a constantly spinning turntable axis. |
| 121 | view = canvas.central_widget.add_view(camera="arcball") |
| 122 | |
| 123 | points = [] |
| 124 | # Use vanilla Python list for segments, because it's optimized for repeated appends. |
| 125 | # Will be reshaped later into a contiguous numpy array of points. |
| 126 | # Each segment is a 2-tuple of 3D coordinates. |
| 127 | segments = [] |
| 128 | |
| 129 | logger.debug("Loading geometries...") |
| 130 | # TODO: Examine performance. |
| 131 | for geometry in geometries: |
| 132 | add(geometry, points, segments) |
| 133 | logger.info("Loaded %d segments and %d points.", len(segments), len(points)) |
| 134 | |
| 135 | segments = np.array(segments) |
| 136 | segments = segments.reshape((-1, 3)) |
| 137 | points = np.array(points) |
| 138 | points = points.reshape((-1, 3)) |
| 139 | logger.debug("segments: %s", segments) |
| 140 | logger.debug("points: %s", points) |
| 141 | |
| 142 | logger.debug("Adding geometries to scene...") |
| 143 | if len(points) != 0: |
| 144 | markers = vispy.scene.visuals.Markers(parent=view.scene) |
| 145 | markers.set_data( |
| 146 | points, |
| 147 | edge_color=None, |
| 148 | edge_width=0, |
| 149 | edge_width_rel=None, |
| 150 | face_color=(0.8, 0.8, 0.8, 0.4), |
| 151 | size=8, |
| 152 | ) |
| 153 | |
| 154 | if len(segments) != 0: |
| 155 | vispy.scene.visuals.Line( |
| 156 | segments, color=(0.8, 0.8, 0.8, 0.4), connect="segments", parent=view.scene |
| 157 | ) |
| 158 | |
| 159 | if args.axis: |
| 160 | # TODO: Figure out how to scale the axis up? |
| 161 | # TODO: Decide if I actually want the axis pinned to a corner of the viewbox. |
| 162 | # TODO: Put the axis at the geometries' centroid. |
| 163 | vispy.scene.visuals.XYZAxis(parent=view.scene) |
| 164 | logger.debug("Added geometries to scene.") |
| 165 | |
| 166 | # Auto-scale |
| 167 | view.camera.set_range() |
| 168 | canvas.show() |
| 169 | try: |
| 170 | # TODO: Add a button that, when clicked, outputs the geometries using the current camera's |
no test coverage detected