def test_square_draw(): """Test drawing squares without transforms using PolygonVisual""" pos = np.array([[-0.5, 0.5, 0], [0.5, 0.5, 0], [0.5, -0.5, 0], [-0.5, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square1.png') polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1), border_color=(1, 1, 1, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square2.png') polygon = visuals.Polygon(pos=pos, border_color=(1, 1, 1, 1)) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/square3.png', 0.45)
def test_rectangle_draw(): """Test drawing rectangles with transforms using PolygonVisual""" pos = np.array([[-0.1, 0.5, 0], [0.1, 0.5, 0], [0.1, -0.5, 0], [-0.1, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1)) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle1.png') polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1), border_color=(1, 0, 0, 1)) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle2.png') polygon = visuals.Polygon(pos=pos, border_color=(1, 0, 0, 1), border_width=1) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 49)) c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/rectangle3.png', 0.7)
def test_rectangle_draw(): """Test drawing rectangles with transforms using PolygonVisual""" pos = np.array([[-0.1, 0.5, 0], [0.1, 0.5, 0], [0.1, -0.5, 0], [-0.1, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1), parent=c.scene) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) assert_image_approved(c.render(), 'visuals/rectangle1.png') polygon.parent = None polygon = visuals.Polygon(pos=pos, color=(1, 1, 0, 1), border_color=(1, 0, 0, 1), parent=c.scene) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 50)) assert_image_approved(c.render(), 'visuals/rectangle2.png') polygon.parent = None polygon = visuals.Polygon(pos=pos, border_color=(1, 0, 0, 1), border_width=1, parent=c.scene) polygon.transform = transforms.STTransform(scale=(200.0, 25), translate=(50, 49)) assert_image_approved(c.render(), 'visuals/rectangle3.png', min_corr=0.7)
def test_square_draw(): """Test drawing squares without transforms using PolygonVisual""" pos = np.array([[-0.5, 0.5, 0], [0.5, 0.5, 0], [0.5, -0.5, 0], [-0.5, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1), parent=c.scene) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) assert_image_approved(c.render(), 'visuals/square1.png') polygon.parent = None polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1), border_color=(1, 1, 1, 1), parent=c.scene) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) assert_image_approved(c.render(), 'visuals/square2.png') polygon.parent = None polygon = visuals.Polygon(pos=pos, border_color=(1, 1, 1, 1), parent=c.scene) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) assert_image_approved(c.render(), 'visuals/square3.png', min_corr=0.45)
def on_mouse_press(self, event): """ Mouse button press event """ if event.button == 1 and self.rectselect == False: #Ray intersection on the CPU to highlight the selected point(s) data = self.tr.map(self.data)[:, :2] m1 = data > (event.pos - 4) m2 = data < (event.pos + 4) self.selected = np.argwhere(m1[:, 0] & m1[:, 1] & m2[:, 0] & m2[:, 1]) self.markselected() elif event.button == 1 and self.rectselect == True: #Panning pass elif event.button == 2 and self.rectselect == True: if self.selectionpolygon is None: origin = np.array( [event.pos[0], event.pos[1], -0.99799905, 1.0]) # origin = self.tr.simplified().imap(origin) self.polydata = np.empty((4, 3)) self.polydata[0] = origin[:3] self.selectionpolygon = visuals.Polygon(pos=self.polydata, color=(1.0, 0.0, 0.0, 1.0)) self.view.add(self.selectionpolygon)
def __init__(self): self.polygon = visuals.Polygon(pos=pos, color=(1, 0, 0, 1), border_color=(1, 1, 1, 1)) self.polygon.transform = vispy.scene.transforms.STTransform( scale=(500, 500), translate=(400, 400)) vispy.scene.SceneCanvas.__init__(self, keys='interactive') self.pos = np.array(pos) self.i = 1 self.size = (800, 800) self.show() self._timer = app.Timer('auto', connect=self.on_timer, start=True)
def test_reactive_draw(): """Test reactive polygon attributes""" pos = np.array([[-0.1, 0.5, 0], [0.1, 0.5, 0], [0.1, -0.5, 0], [-0.1, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color='yellow', parent=c.scene) polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) polygon.pos += [0.1, -0.1, 0] assert_image_approved(c.render(), 'visuals/reactive_polygon1.png') polygon.color = 'red' assert_image_approved(c.render(), 'visuals/reactive_polygon2.png') polygon.border_color = 'yellow' assert_image_approved(c.render(), 'visuals/reactive_polygon3.png', min_corr=0.8)
def __init__(self): global pos self.visuals = [] polygon = visuals.Polygon(pos=pos, color=(0.8, .2, 0, 1), border_color=(1, 1, 1, 1)) polygon.transform = transforms.STTransform(scale=(200, 200), translate=(600, 600)) self.visuals.append(polygon) ellipse = visuals.Ellipse(pos=(0, 0, 0), radius=(100, 150), color=(0.2, 0.2, 0.8, 1), border_color=(1, 1, 1, 1), start_angle=180., span_angle=150.) ellipse.transform = transforms.STTransform(scale=(0.9, 1.5), translate=(200, 300)) self.visuals.append(ellipse) rect = visuals.Rectangle(pos=(600, 200, 0), height=200., width=300., radius=[30., 30., 0., 0.], color=(0.5, 0.5, 0.2, 1), border_color='white') self.visuals.append(rect) rpolygon = visuals.RegularPolygon(pos=(200., 600., 0), radius=160, color=(0.2, 0.8, 0.2, 1), border_color=(1, 1, 1, 1), sides=6) self.visuals.append(rpolygon) SceneCanvas.__init__(self, keys='interactive') self.size = (800, 800) self.show()
def test_reactive_draw(): """Test reactive polygon attributes""" pos = np.array([[-0.1, 0.5, 0], [0.1, 0.5, 0], [0.1, -0.5, 0], [-0.1, -0.5, 0]]) with TestingCanvas() as c: polygon = visuals.Polygon(pos=pos, color='yellow') polygon.transform = transforms.STTransform(scale=(50, 50), translate=(50, 50)) c.draw_visual(polygon) polygon.pos += [0.1, -0.1, 0] c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/reactive_polygon1.png') polygon.color = 'red' c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/reactive_polygon2.png') polygon.border_color = 'yellow' c.draw_visual(polygon) assert_image_equal("screenshot", 'visuals/reactive_polygon3.png', 0.8)