Example #1
0
    def __init__(self, widget, sim, bg=(1, 1, 1, 0)):
        super().__init__(widget)
        self.t = time.time()
        self.sim = sim
        self.view.camera.set_range((0, self.sim.arena.size),
                                   (0, self.sim.arena.size))
        self.view.camera.aspect = 1
        self.cm = color.Colormap([
            self.sim.robot.SO.COLOURS[self.sim.robot.SO.SENSES["ORANGE"]],
            self.sim.robot.SO.COLOURS[self.sim.robot.SO.SENSES["PURPLE"]],
            self.sim.robot.SO.COLOURS[self.sim.robot.SO.SENSES["BLACK"]],
        ],
                                 # (0.0,0.33,0.50,0.66,1.0),
                                 )

        self.robot_marker = scene.Markers(
            pos=self.sim.robot.bonus_pos + 0.5,
            face_color=self.sim.robot.SO.COLOURS[3],
            symbol="square",
            parent=self.view.scene,
        )
        self.robot2_marker = scene.Markers(
            pos=self.sim.robot2.bonus_pos + 0.5,
            face_color="r",
            symbol="square",
            parent=self.view.scene,
        )

        self.grid = scene.visuals.Image(
            self.sim.arena.grid.T,
            interpolation="nearest",
            cmap=self.cm,
            parent=self.view.scene,
            method="subdivide",
        )
Example #2
0
def plot(mesh, show_k=False, show_v=False, show_f=False):
    points = mesh.points
    springs = mesh.springs

    canvas = scene.SceneCanvas(keys='interactive', show=True)
    view = canvas.central_widget.add_view()
    view.camera = 'panzoom'
    view.camera.aspect = 1
    edges = springs[['p0', 'p1']].view(('i8', 2))
    lines = scene.Line(pos=points,
                       connect=edges,
                       antialias=False,
                       method='gl',
                       color='green',
                       parent=view.scene)
    markers = scene.Markers(pos=points,
                            face_color='blue',
                            symbol='o',
                            parent=view.scene,
                            size=0.5,
                            scaling=True)

    view.camera.set_range()

    app.run()
Example #3
0
 def __init__(self, model, fn):
     self.model = model
     self.fn = fn
     self.roadcolors = np.empty((model.graph.roads * 2, 4),
                                dtype=np.float32)
     for i in range(model.graph.roads):
         self.roadcolors[2 * i:2 * i + 2] = np.array([0, 1, 0, 0.4])
     self.roadrots = np.zeros((model.graph.roads, 2, 2))
     roadlines = np.concatenate(model.graph.locs)
     self.canvas = scene.SceneCanvas(show=True, size=(2500, 2500))
     view = self.canvas.central_widget.add_view()
     view.camera = 'panzoom'
     view.camera.aspect = 1
     self.lines = scene.Line(pos=roadlines,
                             connect='segments',
                             method='gl',
                             parent=view.scene,
                             color=self.roadcolors)
     view.camera.set_range()
     self.markers = scene.Markers(parent=view.scene)
     for i in range(model.graph.roads):
         cos = model.graph.locs[i, 1, 0] - model.graph.locs[i, 0, 0]
         sin = model.graph.locs[i, 1, 1] - model.graph.locs[i, 0, 1]
         self.roadrots[i] = np.array([[cos, sin], [-sin, cos]
                                      ]) / model.graph.len
    def __init__(self, geometries_number, generated_data, generated_data_faces,
                 window_range_xmin, window_range_xmax, window_range_ymin,
                 window_range_ymax, window_range_zmin, window_range_zmax):
        scene.SceneCanvas.__init__(
            self,
            keys='interactive',
            size=(800, 550),
            show=True,
            title='Visualization of the generated model(s)')

        self.unfreeze()
        self.view = self.central_widget.add_view()
        self.view.camera = 'turntable'
        self.view.camera.set_range((window_range_xmin, window_range_xmax),
                                   (window_range_ymin, window_range_ymax),
                                   (window_range_zmin, window_range_zmax))
        self.selected_point = None
        scene.visuals.GridLines(parent=self.view.scene)

        for k in range(geometries_number):
            if generated_data_faces[k] is not None:
                mdata = MeshData(vertices=generated_data[k],
                                 faces=generated_data_faces[k])

                rng = np.random.RandomState(0)
                nf = mdata.n_faces
                fcolor = np.ones((nf, 4), dtype=np.float32)
                someColors = [
                    Color('green').RGBA,
                    Color('yellow').RGBA,
                    Color('blue').RGBA,
                    Color('red').RGBA,
                    Color('white').RGBA,
                    Color('fuchsia').RGBA
                ]

                for l in range(0, nf):
                    k_ind = k
                    if k >= len(someColors):
                        k_ind -= len(someColors)
                    fcolor[l] = someColors[k_ind]

                mdata.set_face_colors(fcolor)
                edge_v_index = mdata.get_edges()

                mesh = scene.visuals.Mesh(meshdata=mdata)

                mesh.set_gl_state('additive', depth_test=False)
                mlines = scene.visuals.Line(pos=generated_data[k],
                                            color='red',
                                            connect=edge_v_index)

                self.view.add(mesh)
                self.view.add(mlines)

            s = scene.Markers(pos=generated_data[k])

            self.view.add(s)

        self.freeze()
Example #5
0
	def add_event_xyz(self, data_xyz, event_id):
		if event_id == self._current_event.event_id:
			return
		if self._current_event.node_data is not None:
			self._remove_event(self._current_event.node_data)

		scatter = scene.Markers()
		scatter.set_data(data_xyz, edge_color=(0.0, 0.0, 0.0, .5), face_color=(1, 1, 1, 0.0), size=1)
		self.view.add(scatter)

		self._current_event = CurrentEvent(event_id, scatter)
Example #6
0
def run(mesh,
        show_k=False,
        show_v=False,
        show_f=False,
        run=None,
        verbose=False):
    points = mesh.points
    springs = mesh.springs

    canvas = scene.SceneCanvas(keys='interactive', show=True)
    view = canvas.central_widget.add_view()
    view.camera = 'panzoom'
    view.camera.aspect = 1
    edges = springs[['p0', 'p1']].view(('i8', 2))
    lines = scene.Line(pos=points,
                       connect=edges,
                       antialias=False,
                       method='gl',
                       color='green',
                       parent=view.scene)
    markers = scene.Markers(pos=points,
                            face_color='blue',
                            symbol='o',
                            parent=view.scene,
                            size=0.5,
                            scaling=True)

    view.camera.set_range()

    def update(ev):
        t0 = time.time()
        run(mesh)
        t1 = time.time()
        if verbose:
            print("run: %s" % (t1 - t0, ))
        if mesh.points.min() == numpy.nan or mesh.points.max() == numpy.nan:
            return False
        t0 = time.time()
        markers.set_data(pos=mesh.points, size=0.5, scaling=True)
        lines.set_data(pos=mesh.points)
        t1 = time.time()
        if verbose:
            print("set_data: %s" % (t1 - t0, ))

    if run is not None:
        timer = app.Timer(interval=0, connect=update, start=True)
    app.run()
Example #7
0
    def __init__(self, nx, ny, widget):
        ratio = nx / ny
        self._canvas = scene.SceneCanvas(show=True,
                                         size=widget.GetSize(),
                                         keys='interactive',
                                         parent=widget)
        grid = self._canvas.central_widget.add_grid()
        self._view = grid.add_view(row=0, col=0, camera='panzoom')
        self._view.camera.rect = (0., -0.5, ratio, 1.)

        for p in np.linspace(0., ratio, num=5 * nx + 1):
            scene.InfiniteLine(pos=p,
                               color=(0.3, 0.3, 0.3, 1.),
                               vertical=True,
                               parent=self._view.scene)
        for p in np.linspace(-0.5, 0.5, num=5 * ny + 1):
            if p == 0.:
                scene.InfiniteLine(pos=p,
                                   color=(0.5, 0.5, 0.5, 1.),
                                   vertical=False,
                                   parent=self._view.scene)
            else:
                scene.InfiniteLine(pos=p,
                                   color=(0.3, 0.3, 0.3, 1.),
                                   vertical=False,
                                   parent=self._view.scene)

        c_x = np.linspace(0., ratio, num=nx + 1)
        c_y = np.linspace(-0.5, 0.5, num=ny + 1)
        grid = np.array(np.meshgrid(c_x, c_y, indexing='ij')).T
        grid = grid.reshape((nx + 1) * (ny + 1), 2)
        scene.Markers(pos=grid,
                      symbol='square',
                      size=4,
                      face_color=(0.6, 0.6, 0.6, 1.),
                      parent=self._view.scene)
colors[:] = typ_colors[types]

# Add some RGB noise and clip
colors *= 1.1 ** np.random.normal(size=colors.shape)
colors = np.clip(colors, 0, 1)


# Display the data
canvas = scene.SceneCanvas(keys='interactive', show=True)
view = canvas.central_widget.add_view()
view.camera = 'arcball'
view.camera.aspect = 1

lines = scene.Line(pos=pos, connect=edges, antialias=False, method='gl',
                   color=(1, 1, 1, 0.2), parent=view.scene)
markers = scene.Markers(pos=pos, face_color=colors, symbol='o',
                        parent=view.scene)

view.camera.set_range()

i = 1


def update(ev):
    global pos, edges, lines, markers, view, force, dist, i
    
    dx = np.empty((npts, npts, 2), dtype='float32')
    dx[:] = pos[:, np.newaxis, :]
    dx -= pos[np.newaxis, :, :]

    dist = (dx**2).sum(axis=2)**0.5
    dist[dist == 0] = 1.
Example #9
0
 def __init__(self, data, vid, *args, **kwargs) -> None:
     # init
     scene.SceneCanvas.__init__(self, *args, keys="interactive", **kwargs)
     self.unfreeze()
     self.grid = self.central_widget.add_grid(margin=10)
     cn = CONFIG["col_names"]
     # normalize data
     data_vals = data[[cn["x"], cn["y"], cn["z"]]].values
     dmax = data_vals.max()
     dmin = data_vals.min()
     data[[cn["x"], cn["y"], cn["z"]]] = (data_vals - dmin) / (dmax - dmin)
     # color data
     col_cls = CONFIG["col_names"]["class"]
     col_cmap = CONFIG["col_names"].get("color", None)
     cmaps = CONFIG.get("cmap", None)
     if col_cmap is not None and cmaps is not None:
         data["cweak"] = 0
         data["cstrong"] = 0
         if type(cmaps) is str:
             pass
         else:
             for lab, cmap in cmaps.items():
                 try:
                     cm = ScalarMappable(cmap=cmap)
                     data.loc[data[col_cls] == lab, "cweak"] = [
                         to_hex(c)
                         for c in cm.to_rgba(data.loc[data[col_cls] == lab,
                                                      col_cmap])
                     ]
                     data.loc[data[col_cls] == lab, "cstrong"] = [
                         to_hex(c)
                         for c in cm.to_rgba(data.loc[data[col_cls] == lab,
                                                      col_cmap])
                     ]
                 except ValueError:
                     data.loc[data[col_cls] == lab, "cweak"] = cmap
                     data.loc[data[col_cls] == lab, "cstrong"] = cmap
     else:
         data["cweak"] = data[col_cls].map({
             k: v
             for k, v in zip(data[col_cls].unique(),
                             cycle(Category20_20[0::2]))
         })
         data["cstrong"] = data[col_cls].map({
             k: v
             for k, v in zip(data[col_cls].unique(),
                             cycle(Category20_20[1::2]))
         })
     # scatter plot
     sct_title = scene.Label("State Space", color="white")
     sct_title.height_max = 30
     self.grid.add_widget(sct_title, row=0, col=0)
     self.sct_view = self.grid.add_view(row=1, col=0, border_color="white")
     self.sct_data = data
     self.mks = scene.Markers(
         parent=self.sct_view.scene,
         pos=self.sct_data[[cn["x"], cn["y"], cn["z"]]].values,
         face_color=ColorArray(list(self.sct_data["cweak"].values)),
         size=4,
         edge_width=0,
     )
     self.mks.attach(Alpha(0.6))
     self.cur_mks = scene.Markers(
         parent=self.sct_view.scene,
         pos=np.expand_dims(
             self.sct_data.iloc[0, :][[cn["x"], cn["y"], cn["z"]]].values,
             axis=0),
         face_color=self.sct_data.iloc[0, :]["cstrong"],
         size=8,
         edge_color="white",
     )
     self.cur_mks.set_gl_state(depth_test=False)
     self.axes = scene.XYZAxis(parent=self.sct_view.scene, width=100)
     self.sct_view.camera = "arcball"
     # behav cam
     im_title = scene.Label("Behavior Image", color="white")
     im_title.height_max = 30
     self.grid.add_widget(im_title, row=0, col=1)
     self.im_view = self.grid.add_view(row=1, col=1, border_color="white")
     self.im_data = vid
     fm0 = vid[int(self.sct_data.loc[0, CONFIG["col_names"]["frame"]])]
     self.im = scene.Image(parent=self.im_view.scene, data=fm0)
     self.im_view.camera = "panzoom"
     self.im_view.camera.flip = (False, True, False)
     self.im_view.camera.rect = (0, 0, fm0.shape[1], fm0.shape[0])
     self.im_view.camera.aspect = 1