Beispiel #1
0
def test_rotation_angle():

    # Make sure the rotation angle calculation is correct

    canvas = scene.SceneCanvas(keys=None, size=(800, 600), show=True)
    view = canvas.central_widget.add_view()
    view.camera = scene.cameras.TurntableCamera(parent=view.scene,
                                                fov=0.,
                                                distance=4.0,
                                                elevation=0,
                                                azimuth=0,
                                                roll=0.)

    axis1 = visuals.Axis(pos=[[-1.0, 0], [1.0, 0]], parent=view.scene)
    assert_allclose(axis1._rotation_angle, 0)

    axis2 = visuals.Axis(pos=[[-3**0.5 / 2., -0.5], [3**0.5 / 2., 0.5]],
                         parent=view.scene)
    assert_allclose(axis2._rotation_angle, 0.)

    view.camera.elevation = 90.

    assert_allclose(axis1._rotation_angle, 0)
    assert_allclose(axis2._rotation_angle, -30)

    view.camera.elevation = 45.

    assert_allclose(axis1._rotation_angle, 0)
    assert_allclose(axis2._rotation_angle, -22.207653)

    view.camera.fov = 20.

    assert_allclose(axis1._rotation_angle, 0)
    # OSX Travis has some small differences...sometimes
    assert_allclose(axis2._rotation_angle, -17.056795, rtol=0.05)
Beispiel #2
0
def test_text_position():

    # Test the labels text and position of the axis depending on its domain

    canvas = scene.SceneCanvas(keys=None, size=(800, 600), show=True)
    view = canvas.central_widget.add_view()
    view.camera = scene.cameras.PanZoomCamera(parent=view.scene)

    # tick length and label margin to 0 for nice values
    axis1 = visuals.Axis(pos=[[-1.0, 0], [1.0, 0]],
                         domain=(0., 1.25),
                         major_tick_length=0,
                         tick_label_margin=0,
                         parent=view.scene)

    canvas.draw_visual(axis1)
    assert_allclose(axis1._text.pos[:, 0], (-1, -0.2, 0.6))
    assert_array_equal(axis1._text.text, ('0', '0.5', '1'))

    # Flip the axis domain
    axis1.domain = (1.25, 0.)
    canvas.draw_visual(axis1)
    # Text should be unchanged and positions mirrored
    assert_allclose(axis1._text.pos[:, 0], (1, 0.2, -0.6))
    assert_array_equal(axis1._text.text, ('0', '0.5', '1'))
Beispiel #3
0
def test_tick_position():

    # Test the position of the ticks depending on the axis domain

    canvas = scene.SceneCanvas(keys=None, size=(800, 600), show=True)
    view = canvas.central_widget.add_view()
    view.camera = scene.cameras.PanZoomCamera(parent=view.scene)

    axis1 = visuals.Axis(pos=[[-1.0, 0], [1.0, 0]],
                         domain=(0., 1.25),
                         parent=view.scene)

    canvas.draw_visual(axis1)
    # Get a nice array of x ticks positions
    x_ticks_positions = axis1._ticks.pos[::2, ::2].flatten()
    # Compare major ticks first
    assert_allclose(x_ticks_positions[:3], (-1, -0.2, 0.6))
    # Then minor ticks
    assert_allclose(
        x_ticks_positions[3:],
        (-0.84, -0.68, -0.52, -0.36, -0.04, 0.12, 0.28, 0.44, 0.76, 0.92))

    # Flip the axis domain
    axis1.domain = (1.25, 0.)
    canvas.draw_visual(axis1)
    x_ticks_positions = axis1._ticks.pos[::2, ::2].flatten()
    # Positions should be mirrored
    assert_allclose(x_ticks_positions[:3], (1, 0.2, -0.6))
    assert_allclose(
        x_ticks_positions[3:],
        (0.84, 0.68, 0.52, 0.36, 0.04, -0.12, -0.28, -0.44, -0.76, -0.92))
Beispiel #4
0
    def init_canvas(self):
        if self.verbose == 1:
            print('init_canvas')
        app.use_app('ipynb_webgl')
        ca = vispy.scene.SceneCanvas(keys='interactive', show=True,size=(self.canvas_width,self.canvas_height),bgcolor=[1,1,1])
        ca.show()
        self.canvas = ca
        view = ca.central_widget.add_view()
        
        self.text = visuals.Text(anchor_x='right')
        view.add(self.text)
        self.label_texts = visuals.Text(anchor_x='right')
        view.add(self.label_texts)
               
        self.camera = CustomPanZoomCamera([self.text,self.label_texts])
        view.camera = self.camera

        axis = visuals.Axis(parent=view.scene)
        
        self.view = view
        
        self.line = visuals.Line()
        self.line.set_data(pos=np.array([[0,0,0]]),color=np.array([[0,0,0,0]]))
        self.line.order = 1
        self.view.add(self.line)
        
        self.mesh = visuals.Mesh()
        self.mesh.order = 0 
        self.view.add(self.mesh)
        
        app.run()
Beispiel #5
0
def test_axis_zero_domain():
    # Regression test for a bug that caused an overflow error when the domain
    # min was same as max
    with TestingCanvas() as c:
        axis = visuals.Axis(pos=[[-1.0, 0], [1.0, 0]],
                            domain=(0.5, 0.5),
                            parent=c.scene)
        c.draw_visual(axis)
Beispiel #6
0
def test_axis():
    with TestingCanvas() as c:
        axis = visuals.Axis(pos=[[-1.0, 0], [1.0, 0]], parent=c.scene)
        c.draw_visual(axis)