def test_blending(self):
        self.app.test_frame.SetSize((500, 500))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        tab = self.create_simple_tab_model()
        view = tab.focussedView.value
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        cnvs.SetBackgroundColour("#222222")
        # cnvs.background_brush = wx.BRUSHSTYLE_SOLID  # no special background
        cnvs.setView(view, tab)
        self.add_control(cnvs, flags=wx.EXPAND, proportion=1)

        darray_grey = generate_img_data(300, 300, 4, 255, (50, 50, 50))
        darray_orange = generate_img_data(99, 99, 4)
        darray_blue = generate_img_data(250, 250, 4, 102, (0, 0, 128))
        darray_green = generate_img_data(250, 250, 4, 204, (50, 205, 154))

        images = [
            (darray_grey, (0.0, 0.0), (0.0000003, 0.0000003), True, None, None,
             None, None, "grey"),
            (darray_orange, (0.0, 0.0), (0.0000003, 0.0000002), True, None,
             0.1, None, None, "orange"),
            # (darray_blue, (0.0, 0.0), (0.0000003, 0.0000003), True, 0.5, None, None, BLEND_SCREEN, "purple"),
            # (darray_green, (0.0, 0.0), (0.0000003, 0.0000003), True, 1.5, None, None, BLEND_SCREEN, "greem"),
        ]

        cnvs.set_images(images)
    def test_spot_mode_world_overlay(self):
        sem = simsem.SimSEM(**CONFIG_SEM)
        for child in sem.children.value:
            if child.name == CONFIG_SCANNER["name"]:
                ebeam = child
        # Simulate a stage move
        ebeam.updateMetadata({model.MD_POS: (1e-3, -0.2e-3)})

        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        cnvs.background_brush = wx.BRUSHSTYLE_CROSS_HATCH
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        spotPosition = model.TupleVA((0.1, 0.1))
        sol = wol.SpotModeOverlay(cnvs, spot_va=spotPosition, scanner=ebeam)
        sol.activate()
        cnvs.add_world_overlay(sol)
        cnvs.scale = 100000
        cnvs.update_drawing()
        test.gui_loop(1)

        spotPosition.value = (0.5, 0.5)

        test.gui_loop(1)

        spotPosition.value = (None, None)

        test.gui_loop()
        self.assertIsNone(sol.p_pos, None)
    def test(self):
        self.app.test_frame.SetSize((500, 500))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        # old_canvas = DraggableCanvas(self.panel)
        tab = self.create_simple_tab_model()
        view = tab.focussedView.value
        old_canvas = miccanvas.DblMicroscopeCanvas(self.panel)
        old_canvas.SetBackgroundColour("#444444")
        old_canvas.default_margin = 0
        old_canvas.use_threading = True
        # self.canvas.background_brush = wx.BRUSHSTYLE_SOLID # no special background
        old_canvas.setView(view, tab)
        self.add_control(old_canvas, flags=wx.EXPAND, proportion=1)

        darray_one = generate_img_data(250, 250, 4, color=(255, 0, 0))
        darray_two = generate_img_data(50, 50, 4, color=(0, 0, 255))
        print(darray_two)

        images = [
            (darray_one, (0.0, 0.0), (0.0000003, 0.0000003), True, None, 0.1,
             None, None, 'one'),
            (darray_two, (-0.000001, 0.0), (0.0000003, 0.0000003), True, 0.2,
             None, None, None, 'one'),
            # (darray_two, (0.0, 0.0), 0.33, True, None, None, None, None, 'two'),
            # (darray_thr, (0, 0.0), 1, True, None, None, None, None, 'three'),
        ]

        old_canvas.set_images(images)
Exemple #4
0
    def test_world_select_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        tab_mod = self.create_simple_tab_model()
        view = tab_mod.focussedView.value

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        cnvs.setView(view, tab_mod)

        wsol = wol.WorldSelectOverlay(cnvs)
        wsol.activate()
        cnvs.add_world_overlay(wsol)

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool")
        cnvs.add_view_overlay(tol)

        test.gui_loop()

        def toggle(evt):
            if wsol.active:
                wsol.deactivate()
            else:
                wsol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)
    def test_threading(self):

        self.app.test_frame.SetSize((400, 400))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        test.gui_loop()

        tab = self.create_simple_tab_model()
        view = tab.focussedView.value

        # Changes in default values might affect other test, so we need to know
        self.assertEqual(view.mpp.value, 1e-6,
                         "The default mpp value has changed!")

        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        cnvs.default_margin = 0
        cnvs.fit_view_to_next_image = False
        # Create a even black background, so we can test pixel values
        cnvs.background_brush = wx.BRUSHSTYLE_SOLID

        self.add_control(cnvs, flags=wx.EXPAND, proportion=1)
        test.gui_loop()

        # Changes in default values might affect other test, so we need to know
        self.assertEqual(cnvs.scale, 1, "Default canvas scale has changed!")
        cnvs.setView(view, tab)

        # Setting the view, calls _onMPP with the view.mpp value
        # mpwu / mpp = scale => 1 (fixed, default) / view.mpp (1e-5)
        self.assertEqual(cnvs.scale, 1 / view.mpp.value)

        # Make sure the buffer is set at the right size
        # self.assertEqual(cnvs._bmp_buffer_size, (300, 300))

        ############ Create test image ###############

        img = generate_img_data(20, 20, 4)
        # 100 pixels is 1e-4 meters
        img.metadata[model.MD_PIXEL_SIZE] = (1e-6, 1e-6)
        img.metadata[model.MD_POS] = (0, 0)
        img.metadata[model.MD_DIMS] = "YXC"
        # im_scale = img.metadata[model.MD_PIXEL_SIZE][0] / cnvs.mpwu

        # self.assertEqual(im_scale, img.metadata[model.MD_PIXEL_SIZE][0])

        stream1 = RGBStream("s1", img)
        view.addStream(stream1)

        # Verify view mpp and canvas scale
        self.assertEqual(view.mpp.value, 1e-6,
                         "Default mpp value has changed!")
        self.assertEqual(cnvs.scale, 1 / view.mpp.value,
                         "Canvas scale should not have changed!")

        cnvs.update_drawing()

        view.mpp.value = 1e-5
        shift = (10, 10)
        cnvs.shift_view(shift)
Exemple #6
0
    def test_line_select_overlay(self):
        logging.getLogger().setLevel(logging.DEBUG)
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        tab_mod = self.create_simple_tab_model()
        view = tab_mod.focussedView.value

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        cnvs.setView(view, tab_mod)
        cnvs.current_mode = TOOL_LINE

        lsol = wol.LineSelectOverlay(cnvs)
        lsol.activate()
        lsol.enabled = True

        lsol.set_world_start((1e-4, 1e-4))
        lsol.set_world_end((-1e-4, -1e-4))
        cnvs.add_world_overlay(lsol)

        # Tool toggle for debugging

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool activation", (10, 10))
        cnvs.add_view_overlay(tol)

        def toggle(evt):
            if lsol.active:
                lsol.deactivate()
            else:
                lsol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)
    def test_spectrum_line_select_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        tab_mod = self.create_simple_tab_model()
        view = tab_mod.focussedView.value

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        cnvs.setView(view, tab_mod)
        cnvs.current_mode = TOOL_POINT

        slol = wol.SpectrumLineSelectOverlay(cnvs)
        slol.activate()

        cnvs.add_world_overlay(slol)

        slol.set_data_properties(1e-05, (0.0, 0.0), (17, 19))
        width_va = model.IntVA(1)
        line_va = model.TupleVA(((None, None), (None, None)))
        slol.connect_selection(line_va, width_va)
        view.mpp.value = 1e-06
        test.gui_loop()

        # Tool toggle for debugging

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool", (10, 30))
        cnvs.add_view_overlay(tol)

        test.gui_loop()
        line_va.value = ((0, 0), (8, 8))
        test.gui_loop()

        # Also connect the pixel va
        pixel_va = model.TupleVA((8, 8))
        slol.connect_selection(line_va, width_va, pixel_va)
        test.gui_loop()

        def toggle(evt):
            if slol.active:
                slol.deactivate()
            else:
                slol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)

        cnvs.disable_drag()

        def on_key(evt):
            k = evt.GetKeyCode()

            if k == wx.WXK_DOWN and width_va.value > 1:
                width_va.value -= 1
            elif k == wx.WXK_UP:
                width_va.value += 1
            else:
                pass

        cnvs.Bind(wx.EVT_KEY_UP, on_key)
Exemple #8
0
    def test_crosshair_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        hol = vol.CrossHairOverlay(cnvs)
        cnvs.add_view_overlay(hol)

        test.gui_loop()
Exemple #9
0
    def test_spot_mode_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        sol = vol.SpotModeOverlay(cnvs)
        cnvs.add_view_overlay(sol)

        test.gui_loop()
    def test_roa_select_overlay_va(self):

        sem = simsem.SimSEM(**CONFIG_SEM)
        for child in sem.children.value:
            if child.name == CONFIG_SCANNER["name"]:
                ebeam = child
        # Simulate a stage move
        ebeam.updateMetadata({model.MD_POS: (1e-3, -0.2e-3)})

        # but it should be a simple miccanvas
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        roa = model.TupleVA(UNDEFINED_ROI)
        rsol = wol.RepetitionSelectOverlay(cnvs, roa=roa, scanner=ebeam)
        rsol.activate()
        cnvs.add_world_overlay(rsol)
        cnvs.scale = 100000
        cnvs.update_drawing()

        # Undefined ROA => sel = None
        roi_back = rsol.get_physical_sel()
        self.assertEqual(roi_back, None)

        # Full FoV
        roa.value = (0, 0, 1, 1)
        test.gui_loop(0.1)
        # Expect the whole SEM FoV
        fov = compute_scanner_fov(ebeam)
        ebeam_rect = get_fov_rect(ebeam, fov)
        roi_back = rsol.get_physical_sel()

        for o, b in zip(ebeam_rect, roi_back):
            self.assertAlmostEqual(o,
                                   b,
                                   msg="ebeam FoV (%s) != ROI (%s)" %
                                   (ebeam_rect, roi_back))

        # Hald the FoV
        roa.value = (0.25, 0.25, 0.75, 0.75)
        test.gui_loop(0.1)
        # Expect the whole SEM FoV
        fov = compute_scanner_fov(ebeam)
        fov = (fov[0] / 2, fov[1] / 2)
        ebeam_rect = get_fov_rect(ebeam, fov)
        roi_back = rsol.get_physical_sel()

        for o, b in zip(ebeam_rect, roi_back):
            self.assertAlmostEqual(o,
                                   b,
                                   msg="ebeam FoV (%s) != ROI (%s)" %
                                   (ebeam_rect, roi_back))

        test.gui_loop()

        sem.terminate()
    def test_spot_mode_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        cnvs.background_brush = wx.BRUSHSTYLE_CROSS_HATCH
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        sol = vol.SpotModeOverlay(cnvs)
        sol.activate()
        cnvs.add_view_overlay(sol)
        cnvs.update_drawing()
        test.gui_loop()
Exemple #12
0
    def setUp(self):
        test.gui_loop()
        self.mmodel = self.create_simple_tab_model()
        self.view = self.mmodel.focussedView.value
        self.canvas = miccanvas.DblMicroscopeCanvas(self.panel)
        self.canvas.background_brush = wx.BRUSHSTYLE_SOLID  # no special background
        self.add_control(self.canvas, flags=wx.EXPAND, proportion=1)
        test.gui_loop()

        self.canvas.setView(self.view, self.mmodel)
Exemple #13
0
    def test_view_select_overlay(self):
        # Create and add a miccanvas
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        vsol = vol.ViewSelectOverlay(cnvs)
        vsol.activate()
        cnvs.add_view_overlay(vsol)
        # cnvs.current_mode = guimodel.TOOL_ZOOM
        test.gui_loop()
Exemple #14
0
    def test_cryo_feature_overlay(self):
        """
        Test behavior of CryoFeatureOverlay
        """
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        tab_mod = self.create_cryo_tab_model()
        # Create a dummy stage & focus to attach to the view
        stage = TMCLController(name="test_stage",
                               role="stage",
                               port="/dev/fake3",
                               axes=["x", "y"],
                               ustepsize=[1e-6, 1e-6],
                               rng=[[-3e-3, 3e-3], [-3e-3, 3e-3]],
                               refproc="Standard")

        focus = TMCLController(name="test_focus",
                               role="focus",
                               port="/dev/fake3",
                               axes=["z"],
                               ustepsize=[1e-6],
                               rng=[[-3e-3, 3e-3]],
                               refproc="Standard")
        tab_mod.main.stage = stage
        tab_mod.main.focus = focus

        fview = FeatureOverviewView("fakeview", stage=stage)
        tab_mod.views.value.append(fview)
        tab_mod.focussedView.value = fview
        cnvs.setView(fview, tab_mod)
        # Save current empty canvas
        img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer)
        buffer_clear = wxImage2NDImage(img)

        cryofeature_overlay = wol.CryoFeatureOverlay(cnvs, tab_mod)
        cnvs.add_world_overlay(cryofeature_overlay)
        cryofeature_overlay.active.value = True

        # Add features to the tab's features list
        tab_mod.add_new_feature(0, 0)
        tab_mod.add_new_feature(0.001, 0.001)

        cnvs._dc_buffer.SelectObject(wx.NullBitmap)  # Flush the buffer
        cnvs._dc_buffer.SelectObject(cnvs._bmp_buffer)
        img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer)
        buffer_feature = wxImage2NDImage(img)
        # Compare empty canvas with the added _features_va
        assert_array_not_equal(
            buffer_clear,
            buffer_feature,
            msg=
            "Buffers are equal, which means the added _features_va didn't appear on the canvas."
        )
        test.gui_loop()
    def test_pixel_select_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        tab_mod = self.create_simple_tab_model()
        view = tab_mod.focussedView.value

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        # FIXME: when setView is called *before* the add_control, the picture goes black and no
        # pixels are visible
        cnvs.setView(view, tab_mod)
        cnvs.current_mode = TOOL_POINT

        psol = wol.PixelSelectOverlay(cnvs)
        psol.activate()
        psol.enabled = True

        cnvs.add_world_overlay(psol)

        psol.set_data_properties(1e-05, (0.0, 0.0), (17, 19))
        width_va = model.IntVA(1)

        psol.connect_selection(model.TupleVA(), width_va)
        view.mpp.value = 1e-06

        psol._selected_pixel_va.value = (8, 8)
        test.gui_loop()

        # Tool toggle for debugging

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool", (10, 30))
        cnvs.add_view_overlay(tol)

        def toggle(evt):
            if psol.active:
                psol.deactivate()
            else:
                psol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)

        cnvs.disable_drag()

        def on_key(evt):
            k = evt.GetKeyCode()

            if k == wx.WXK_DOWN and width_va.value > 1:
                width_va.value -= 1
            elif k == wx.WXK_UP:
                width_va.value += 1
            else:
                pass

        cnvs.Bind(wx.EVT_KEY_UP, on_key)
Exemple #16
0
    def test_streamicon_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        sol = vol.StreamIconOverlay(cnvs)
        cnvs.add_view_overlay(sol)
        test.gui_loop(2000)
        sol.hide_pause(False)
        test.gui_loop()
        test.gui_loop(2000)
        sol.hide_pause(True)
Exemple #17
0
    def test_focus_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        class FakeFocus(object):
            def moveRel(self, dummy):
                pass

        tab_mod = self.create_simple_tab_model()
        view = tab_mod.focussedView.value
        view._focus = [FakeFocus(), FakeFocus()]
        cnvs.setView(view, tab_mod)

        test.gui_loop()
    def setUp(self):
        self.app = wx.App(False)
        self.frame = wx.Frame(None)
        self.mmodel = FakeMicroscopeModel()
        self.view = self.mmodel.focussedView.value
        self.canvas = miccanvas.DblMicroscopeCanvas(self.frame)
        self.canvas.background_brush = wx.SOLID  # no special background
        self.canvas.setView(self.view, self.mmodel)

        self.frame.SetSize((400, 400))
        self.frame.Center()
        test.gui_loop()
        self.frame.Show(True)
        test.gui_loop()
Exemple #19
0
    def test_history_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        cnvs.disable_drag()
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        history_va = omodel.ListVA()

        hol = vol.HistoryOverlay(cnvs, history_va)
        cnvs.add_view_overlay(hol)

        test.gui_loop()

        for j in range(4):
            offset = ((j - 2) * 75)

            for i in range(10):
                history_va.value.append(
                    (((j * i) + offset, (j * -i) + offset), None)
                )

            for i in range(10):
                history_va.value.append(
                    (((j * -i) + offset, (j * -i) + offset), None)
                )

            for i in range(10):
                history_va.value.append(
                    (((j * -i) + offset, (j * i) + offset), None)
                )

            for i in range(10):
                history_va.value.append(
                    (((j * i) + offset, (j * i) + offset), None)
                )

        test.gui_loop()

        steps = 1000
        step_size = 10
        for i in xrange(0, steps * step_size, step_size):
            phi = (math.pi * 2) / steps
            x = (100 * i / (steps * 5)) * math.cos(i * phi)
            y = (100 * i / (steps * 5)) * math.sin(i * phi)
            # hol.history.append(((x, y), None))
            history_va.value.append(
                ((x, y), None)
            )
        # print "Done generating history"

        test.gui_loop()
Exemple #20
0
    def test_crosshair_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        hol = vol.CenteredLineOverlay(cnvs, shape=CROSSHAIR)
        cnvs.add_view_overlay(hol)
        test.gui_loop()

        hol = vol.CenteredLineOverlay(cnvs, shape=HORIZONTAL_LINE)
        cnvs.add_view_overlay(hol)
        test.gui_loop()

        hol = vol.CenteredLineOverlay(cnvs, shape=VERTICAL_LINE)
        cnvs.add_view_overlay(hol)
        test.gui_loop()
Exemple #21
0
    def xtest_calc_buffer_rect_img_data(self):

        im_data = numpy.array([
            [1, 2, 3, 4],
            [5, 6, 7, 8],
            [9, 10, 11, 12],
            [13, 14, 15, 16],
        ])

        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        brect = (1, -1, 4, 4)
        irect = (1, 0, 3, 3)

        print cnvs._calc_buffer_rect_img_data(irect, brect, im_data, 1)
Exemple #22
0
    def test_current_pos_crosshair_overlay(self):
        """
        Test behaviour of CurrentPosCrossHairOverlay
        """
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        tab_mod = self.create_simple_tab_model()
        # create a dummy stage to attach to the view
        stage = TMCLController(name="test",
                               role="test",
                               port="/dev/fake3",
                               axes=["x", "y"],
                               ustepsize=[1e-6, 1e-6],
                               rng=[[-3e-3, 3e-3], [-3e-3, 3e-3]],
                               refproc="Standard")

        # Add a tiled area view to the tab model
        logging.debug(stage.position.value)
        fview = FeatureOverviewView("fakeview", stage=stage)
        tab_mod.views.value.append(fview)
        tab_mod.focussedView.value = fview
        cnvs.setView(fview, tab_mod)
        cnvs.view.show_crosshair.value = False

        slol = wol.CurrentPosCrossHairOverlay(cnvs)
        slol.active.value = True
        cnvs.add_world_overlay(slol)
        # stage start at 0,0 (cross hair at center) -> move bt 1mm, 1mm -> then back to 0,0
        stage.moveAbs({'x': 1e-3, 'y': 1e-3}).result()
        img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer)
        buffer_ch_move = wxImage2NDImage(img)
        test.gui_loop(1)

        stage.moveAbs({'x': 0, 'y': 0}).result()
        cnvs.update_drawing()
        cnvs._dc_buffer.SelectObject(wx.NullBitmap)  # Flush the buffer
        cnvs._dc_buffer.SelectObject(cnvs._bmp_buffer)
        img = wx.Bitmap.ConvertToImage(cnvs._bmp_buffer)
        buffer_ch_center = wxImage2NDImage(img)
        assert_array_not_equal(
            buffer_ch_center,
            buffer_ch_move,
            msg=
            "Buffers are equal, which means the crosshair didn't change on stage movement."
        )

        test.gui_loop()
    def test_roa_select_overlay(self):
        # but it should be a simple miccanvas
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        rsol = wol.RepetitionSelectOverlay(cnvs)
        rsol.activate()
        cnvs.add_world_overlay(rsol)
        cnvs.scale = 400

        test.gui_loop()
        wroi = [-0.1, 0.3, 0.2, 0.4]  # in m
        rsol.set_physical_sel(wroi)
        test.gui_loop()
        wroi_back = rsol.get_physical_sel()

        for o, b in zip(wroi, wroi_back):
            self.assertAlmostEqual(o,
                                   b,
                                   msg="wroi (%s) != bak (%s)" %
                                   (wroi, wroi_back))

        rsol.repetition = (3, 2)
        rsol.fill = wol.RepetitionSelectOverlay.FILL_POINT

        pos = cnvs.margins[0] + 10, cnvs.margins[1] + 10
        rsol.add_label("Repetition fill will change in 3 seconds.",
                       pos,
                       colour=(0.8, 0.2, 0.1))

        cnvs.update_drawing()
        test.gui_loop()

        tol = vol.TextViewOverlay(cnvs)
        tol.add_label("Right click to toggle tool")
        cnvs.add_view_overlay(tol)

        def toggle(evt):
            if rsol.active:
                rsol.deactivate()
            else:
                rsol.activate()
            evt.Skip()

        cnvs.Bind(wx.EVT_RIGHT_UP, toggle)

        test.gui_loop()
    def test_reshape(self):

        darray = generate_img_data(100, 100, 4, 100)

        self.app.test_frame.SetSize((500, 500))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        tab = self.create_simple_tab_model()
        mpp = FloatContinuous(2, range=(0, 1), unit="m/px")
        tab.focussedView.value.mpp = mpp

        view = tab.focussedView.value
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)

        cnvs.setView(view, tab)
Exemple #25
0
    def xtest_reshape(self):

        darray = generate_img_data(100, 100, 4, 100)

        self.app.test_frame.SetSize((500, 500))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        mmodel = test.FakeMicroscopeModel()
        mpp = FloatContinuous(2, range=(0, 1), unit="m/px")
        mmodel.focussedView.value.mpp = mpp

        view = mmodel.focussedView.value
        canvas = miccanvas.DblMicroscopeCanvas(self.panel)

        canvas.setView(view, mmodel)
    def xtest_cairo_wander_bug_demo(self):
        """
        This method is not really a test, but demonstrates a possible bug in Cairo.

        When the image we want to draw is scaled by a large number, the position it is drawn at
        starts to periodically wander. It is most likely a result of the scaling that takes place
        inside the Cairo Context. The transformation matrix associated with the Context has correct
        values.

        Since the wandering is only noticible at high magnification, we're going to test if it is a
        problem in real-world scenarios. If it is, this problem should be revisited at a later
        point.

        Possible things to check include testing against a newer version of the Cairio library or
        seeking advice in the Cairo mailing list and/or Stack Overflow.

        """

        ######### Frame setup #########

        self.app.test_frame.SetSize((400, 400))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, flags=wx.EXPAND, proportion=1)
        test.gui_loop()

        ######### Test #########

        img = generate_img_data(200, 200, 4)
        steps = 10000

        try:
            for i in range(steps):
                images = [
                    # Simplest case with the image drawn in the center
                    (img, (0, 0), 1, True, 0.0, None, "wander bug test"),
                    # Image drawn at the bottom right
                    # (img, (100, 100), 1, True, 0.0, None, "wander bug test"),
                ]
                cnvs.set_images(images)
                cnvs.scale = (2.1 * i)
                cnvs.update_drawing()
                if i % 100 == 0:
                    test.gui_loop()
        except wx.PyDeadObjectError:
            pass
Exemple #27
0
    def test_nanana(self):

        self.app.test_frame.SetSize((500, 500))
        self.app.test_frame.Center()
        self.app.test_frame.Layout()

        # old_canvas = DraggableCanvas(self.panel)
        tab = self.create_simple_tab_model()
        mpp = FloatContinuous(10e-6, range=(1e-3, 1), unit="m/px")
        tab.focussedView.value.mpp = mpp

        view = tab.focussedView.value
        canvas = miccanvas.DblMicroscopeCanvas(self.panel)

        shape = (5, 5, 4)
        rgb = numpy.empty(shape, dtype=numpy.uint8)
        rgb[::2, ...] = [
                    [255, 0, 0, 255],
                    [0, 255, 0, 255],
                    [255, 255, 0, 255],
                    [255, 0, 255, 255],
                    [0, 0, 255, 255]
                ][:shape[1]]
        rgb[1::2, ...] = [
                    [127, 0, 0, 255],
                    [0, 127, 0, 255],
                    [127, 127, 0, 255],
                    [127, 0, 127, 255],
                    [0, 0, 127, 255]
                ][:shape[1]]

        rgb[..., [0, 1, 2, 3]] = rgb[..., [2, 1, 0, 3]]
        darray = DataArray(rgb)

        canvas.setView(view, tab)
        self.add_control(canvas, flags=wx.EXPAND, proportion=1)
        test.gui_loop()
        # Set the mpp again, because the on_size handler will have recalculated it
        view.mpp.value = 1

        images = [(darray, (0.0, 0.0), (2, 2), True, None, None, None, None, "nanana")]
        canvas.set_images(images)
        canvas.scale = 1
        canvas.update_drawing()
        test.gui_loop(0.1)
    def test_point_select_mode_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        slol = vol.PointSelectOverlay(cnvs)
        slol.activate()

        def print_pos(pos):
            logging.debug(pos)

        self.dummy = print_pos

        slol.v_pos.subscribe(print_pos)
        slol.p_pos.subscribe(print_pos)

        cnvs.add_view_overlay(slol)

        test.gui_loop()
    def test_dichotomy_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)

        lva = model.ListVA()

        dol = vol.DichotomyOverlay(cnvs, lva)
        cnvs.add_view_overlay(dol)

        def do_stuff(value):
            """ Test function that can be used to subscribe to VAs """
            print("Testing VA subscriber received value ", value)

        self.dummy = do_stuff
        dol.sequence_va.subscribe(do_stuff, init=True)
        dol.sequence_va.value = [0, 1, 2, 3, 0]
        dol.activate()

        test.gui_loop()
Exemple #30
0
    def test_marking_line_overlay(self):
        cnvs = miccanvas.DblMicroscopeCanvas(self.panel)
        mlol = vol.MarkingLineOverlay(cnvs, orientation=1)
        mlol.activate()
        cnvs.add_view_overlay(mlol)
        self.add_control(cnvs, wx.EXPAND, proportion=1, clear=True)
        test.gui_loop()

        mlol.v_pos.value = (100, 100)
        cnvs.Refresh()

        test.gui_loop(500)
        mlol.orientation = 2
        mlol.v_pos.value = (200, 200)
        cnvs.Refresh()

        test.gui_loop(500)
        mlol.orientation = 3
        mlol.v_pos.value = (300, 300)
        cnvs.Refresh()