Ejemplo n.º 1
0
    def normal_left_down(self, event):
        super(MapCanvas, self).normal_left_down(event)

        if self.current_hole is not None:
            # and not event.handled
            ca = self.calibration_item
            if ca is not None:
                if hasattr(event, 'item'):
                    if hasattr(ca, 'right'):
                        if event.item.right is ca.right:
                            return

                rot = ca.rotation
                cpos = ca.center

                aff = AffineTransform()
                aff.translate(*cpos)
                aff.rotate(rot)
                aff.translate(-cpos[0], -cpos[1])
                aff.translate(*cpos)

                mpos = self.mp.get_hole_pos(self.current_hole)
                #                dpos = aff.transformPt(mpos)
                dpos = aff.transform(*mpos)
                spos = self.map_data((event.x, event.y))

                # not much point in adding an indicator because the hole
                # renders its own
                # self.markupdict['tweak'] = Indicator(*spos, canvas = self)

                tweak = spos[0] - dpos[0], spos[1] - dpos[1]
                ca.tweak_dict[self.current_hole] = tweak

                self.request_redraw()
Ejemplo n.º 2
0
    def normal_mouse_move(self, event):
        # over a hole
        ca = self.calibration_item
        if ca:

            for obj in self.mp.sample_holes:
                hole = obj.id
                pos = obj.x, obj.y

                rot = ca.rotation
                cpos = ca.center

                aff = AffineTransform()
                aff.translate(*cpos)
                aff.rotate(rot)
                aff.translate(-cpos[0], -cpos[1])
                aff.translate(*cpos)
                dpos = aff.transformPt(pos)

                pos = self.map_screen([dpos])[0]
                if abs(pos[0] - event.x) <= 10 and abs(pos[1] - event.y) <= 10:
                    event.window.set_pointer(self.select_pointer)
                    event.handled = True
                    self.current_hole = hole
                    break

        if not event.handled:
            self.current_hole = None
            super(MapCanvas, self).normal_mouse_move(event)
Ejemplo n.º 3
0
    def _calculate_affine_transform(self, pts):
        rps, ps = zip(*pts)
        s, r, t = calculate_rigid_transform(rps, ps)
        self.A = AffineTransform()
        self.A.scale(s, s)
        self.A.rotate(r)
        self.A.translate(-t[0], -t[1])

        print self.A
Ejemplo n.º 4
0
    def map_to_uncalibration(self, pos, cpos=None, rot=None, scale=None):
        cpos, rot, scale = self._get_calibration_params(cpos, rot, scale)
        a = AffineTransform()
        a.scale(1 / scale, 1 / scale)
        a.rotate(-rot)
        a.translate(cpos[0], cpos[1])
#        a.translate(-cpos[0], -cpos[1])
#        a.translate(*cpos)
#        a.rotate(-rot)
#        a.translate(-cpos[0], -cpos[1])

        pos = a.transform(*pos)
        return pos
Ejemplo n.º 5
0
def rubberband_pattern(cx, cy, offset, l, rotation):
    p1 = cx - offset, cy + offset
    p2 = cx + l + offset, cy + offset
    p3 = cx + l + offset, cy - offset
    p4 = cx - offset, cy - offset

    a = AffineTransform()

    a.translate(cx, cy)
    a.rotate(rotation)
    a.translate(-cx, -cy)

    ps = (p1, p2, p3, p4, p1)
    for p in ps:
        yield a.transform(*p)
Ejemplo n.º 6
0
def line_pattern(cx, cy, length, rotation, n):
    p1 = (cx, cy)
    p2 = (cx + length, cy)

    for i in xrange(n):
        a = AffineTransform()
        a.translate(cx, cy)
        a.rotate(rotation)
        a.translate(-cx, -cy)
        if i % 2 == 0:
            ps = (p1, p2)

        else:
            ps = (p2, p1)

        for x, y in ps:
            yield a.transform(x, y)
Ejemplo n.º 7
0
def raster_rubberband_pattern(cx, cy, offset, l, dx, rotation, single_pass):

    a = AffineTransform()
    a.translate(cx, cy)
    a.rotate(rotation)
    a.translate(-cx, -cy)
    # print offset, l
    n = int((l + 2 * offset) / dx)
    if n*dx<=l+2*offset:
        n = n+1 if n%2 else n
        dx = (l+2*offset)/float(n+1)
        n = int((l + 2 * offset) / dx)

    for i in xrange(0, n+1):
        y = cy - offset if i % 2 else cy + offset
        yield a.transform(cx - offset + dx * i, y)

    if not single_pass:
        for i in xrange(0, n+1):
            y = cy - offset if i % 2 else cy + offset
            yield a.transform(cx +l+offset - dx * i, y)
        yield a.transform(cx-offset, cy+offset)
Ejemplo n.º 8
0
    def map_to_calibration(self, pos, cpos=None, rot=None,
                           use_modified=False,
                           scale=None,
                           translate=None):
        cpos, rot, scale = self._get_calibration_params(cpos, rot, scale)

        a = AffineTransform()
#         if translate:
#             a.translate(*translate)

#        if scale:
        a.scale(scale, scale)
        if use_modified:
            a.translate(*cpos)

#         print cpos, rot, scale
        a.rotate(rot)
        a.translate(-cpos[0], -cpos[1])
        if use_modified:
            a.translate(*cpos)
        pos = a.transform(*pos)
        return pos
Ejemplo n.º 9
0
def trough_pattern(cx, cy, length, width, rotation, use_x):
    """
    1 -------------- 2
    |                |
    4 -------------- 3
    """
    p1 = (cx, cy)
    p2 = (cx + length, cy)
    p3 = (cx + length, cy - width)
    p4 = (cx, cy - width)

    a = AffineTransform()
    a.translate(cx, cy)
    a.rotate(rotation)
    a.translate(-cx, -cy)

    if use_x:
        ps = (p1, p2, p4, p3, p1)
    else:
        ps = (p1, p2, p3, p4, p1)

    for p in ps:
        yield a.transform(*p)
Ejemplo n.º 10
0
    def predict_values(self, refresh=False):
        self.debug('predict values {}'.format(refresh))
        try:
            x, y, z, ze, j, je, sj, sje = self._extract_position_arrays()
            t = AffineTransform()
            t.rotate(self.rotation)

            x, y = t.transforms(x, y)
            # print(x)
        except ValueError as e:
            self.debug('no monitor positions to fit, {}'.format(e))
            return

        # print(x)
        # print(y)
        # print(z)
        # print(ze)
        n = x.shape[0]
        if n >= 3 or self.plotter_options.model_kind in (WEIGHTED_MEAN,
                                                         MATCHING, BRACKETING):
            # n = z.shape[0] * 10
            r = max((max(abs(x)), max(abs(y))))
            # r *= 1.25
            reg = self._regressor_factory(x, y, z, ze)
            self._regressor = reg
        else:
            msg = 'Not enough monitor positions. At least 3 required. Currently only {} active'.format(
                n)
            self.debug(msg)
            self.information_dialog(msg)
            return

        options = self.plotter_options
        ipositions = self.unknown_positions + self.monitor_positions

        if options.model_kind == LEAST_SQUARES_1D:
            k = options.one_d_axis.lower()
            pts = array([getattr(p, k) for p in ipositions])
        else:
            pts = array([[p.x, p.y] for p in ipositions])

        if options.use_monte_carlo and options.model_kind not in (MATCHING,
                                                                  BRACKETING,
                                                                  NN):
            fe = FluxEstimator(options.monte_carlo_ntrials, reg)

            split = len(self.unknown_positions)
            nominals, errors = fe.estimate(pts)
            if options.position_error:
                _, pos_errors = fe.estimate_position_err(
                    pts, options.position_error)
            else:
                pos_errors = zeros(pts.shape[0])

            for positions, s, e in ((self.unknown_positions, 0, split),
                                    (self.monitor_positions, split, None)):
                noms, es, ps = nominals[s:e], errors[s:e], pos_errors[s:e]
                for p, j, je, pe in zip(positions, noms, es, ps):
                    oj = p.saved_j
                    p.j = j
                    p.jerr = je
                    p.position_jerr = pe
                    p.dev = (oj - j) / j * 100
        else:
            js = reg.predict(pts)
            jes = reg.predict_error(pts)

            for j, je, p in zip(js, jes, ipositions):
                p.j = float(j)
                p.jerr = float(je)

                p.dev = (p.saved_j - j) / j * 100
                p.mean_dev = (p.mean_j - j) / j * 100

        if options.plot_kind == '2D':
            self._graph_contour(x, y, z, r, reg, refresh)
        elif options.plot_kind == 'Grid':
            self._graph_grid(x, y, z, ze, r, reg, refresh)
        else:
            if options.model_kind in (LEAST_SQUARES_1D, WEIGHTED_MEAN_1D):
                self._graph_linear_j(x, y, r, reg, refresh)
            else:
                self._graph_hole_vs_j(x, y, r, reg, refresh)