Beispiel #1
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
Beispiel #2
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
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)
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)
Beispiel #5
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)
Beispiel #6
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()
Beispiel #7
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)
Beispiel #8
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()
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)
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)
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
class UVAnalysisImage(ImageViewer):
    open_button = Button
    define_points = Button
    define_points_label = String
    _defining_points = False

    #===============================================================================
    # handlers
    #===============================================================================

    def _set_reference_point(self, pt):
        '''
             assumes no rotation of the reference frames
             only scale and translate
        '''
        rp = ReferencePoint(pt)
        info = rp.edit_traits()
        if info.result:
            plot = self.plot
            self.points.append(((rp.x, rp.y), pt))

            #            if not self.reference_pt1:
            #                self.reference_pt1 = (rp.x, rp.y), pt
            #            else:
            #                # calculate bounds
            #                dp1, sp1 = self.reference_pt1
            #                dp2, sp2 = (rp.x, rp.y), pt
            #
            #
            #                w = plot.width
            #                h = plot.height
            #                if sp1[0] < sp2[0]:
            #                    sx1, sx2 = sp1[0], sp2[0]
            #                    x1, x2 = dp1[0], dp2[0]
            #                else:
            #                    sx2, sx1 = sp1[0], sp2[0]
            #                    x2, x1 = dp1[0], dp2[0]
            #
            #                if sp1[1] < sp2[1]:
            #                    sy1, sy2 = sp1[1], sp2[1]
            #                    y1, y2 = dp1[1], dp2[1]
            #                else:
            #                    sy2, sy1 = sp1[1], sp2[1]
            #                    y2, y1 = dp1[1], dp2[1]
            #
            #                pxperunit = abs((sx2 - sx1) / (x2 - x1))
            #
            #                li = x1 - sx1 / pxperunit
            #                hi = x2 + (w - sx2) / pxperunit
            #                lv = y1 - sy1 / pxperunit
            #                hv = y2 + (h - sy2) / pxperunit
            #
            #                plot.index_range.low_setting = li
            #                plot.index_range.high_setting = hi
            #                plot.value_range.low_setting = lv
            #                plot.value_range.high_setting = hv
            #
            plot.request_redraw()

    def _define_points_fired(self):
        if self.plot:
            plot = self.plot
            if not self._defining_points:
                self.points = []
                st = ReferencePointsTool(plot)
                st.on_trait_change(self._set_reference_point,
                                   'current_position')
                self.points_tool = st
                plot.tools.insert(0, st)
                self.define_points_label = 'Finish'
                plot.overlays.append(
                    ReferencePointsOverlay(tool=st, component=plot))

            else:
                self.define_points_label = 'Define Points'
                self.points_tool.on_trait_change(self._set_reference_point,
                                                 'current_position',
                                                 remove=True)
                plot.tools.pop(0)
                plot.overlays.pop(-1)
                self._calculate_affine_transform(self.points)

            self._defining_points = not self._defining_points

    def load_points(self, path):
        points = [(100, 100), (300, 400), (200, 300)]

        if os.path.isfile(path):
            points = loadtxt(path, delimiter=',')

        po = PointOverlay(component=self.plot, points=points)
        self.plot.overlays.append(po)

    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

    def traits_view(self):
        image = Item('container',
                     style='custom',
                     show_label=False,
                     editor=ComponentEditor())
        v = View(Item('open_button', show_label=False),
                 Item('define_points',
                      enabled_when='plot',
                      editor=ButtonEditor(label_value='define_points_label'),
                      show_label=False),
                 image,
                 resizable=True)
        return v
Beispiel #14
0
class UVAnalysisImage(ImageViewer):
    open_button = Button
    define_points = Button
    define_points_label = String
    _defining_points = False
#===============================================================================
# handlers
#===============================================================================

    def _set_reference_point(self, pt):
        '''
             assumes no rotation of the reference frames
             only scale and translate
        '''
        rp = ReferencePoint(pt)
        info = rp.edit_traits()
        if info.result:
            plot = self.plot
            self.points.append(((rp.x, rp.y), pt))


#            if not self.reference_pt1:
#                self.reference_pt1 = (rp.x, rp.y), pt
#            else:
#                # calculate bounds
#                dp1, sp1 = self.reference_pt1
#                dp2, sp2 = (rp.x, rp.y), pt
#
#
#                w = plot.width
#                h = plot.height
#                if sp1[0] < sp2[0]:
#                    sx1, sx2 = sp1[0], sp2[0]
#                    x1, x2 = dp1[0], dp2[0]
#                else:
#                    sx2, sx1 = sp1[0], sp2[0]
#                    x2, x1 = dp1[0], dp2[0]
#
#                if sp1[1] < sp2[1]:
#                    sy1, sy2 = sp1[1], sp2[1]
#                    y1, y2 = dp1[1], dp2[1]
#                else:
#                    sy2, sy1 = sp1[1], sp2[1]
#                    y2, y1 = dp1[1], dp2[1]
#
#                pxperunit = abs((sx2 - sx1) / (x2 - x1))
#
#                li = x1 - sx1 / pxperunit
#                hi = x2 + (w - sx2) / pxperunit
#                lv = y1 - sy1 / pxperunit
#                hv = y2 + (h - sy2) / pxperunit
#
#                plot.index_range.low_setting = li
#                plot.index_range.high_setting = hi
#                plot.value_range.low_setting = lv
#                plot.value_range.high_setting = hv
#
            plot.request_redraw()


    def _define_points_fired(self):
        if self.plot:
            plot = self.plot
            if not self._defining_points:
                self.points = []
                st = ReferencePointsTool(plot)
                st.on_trait_change(self._set_reference_point, 'current_position')
                self.points_tool = st
                plot.tools.insert(0, st)
                self.define_points_label = 'Finish'
                plot.overlays.append(ReferencePointsOverlay(tool=st, component=plot))


            else:
                self.define_points_label = 'Define Points'
                self.points_tool.on_trait_change(self._set_reference_point, 'current_position', remove=True)
                plot.tools.pop(0)
                plot.overlays.pop(-1)
                self._calculate_affine_transform(self.points)

            self._defining_points = not self._defining_points

    def load_points(self, path):
        points = [(100, 100),
                  (300, 400),
                  (200, 300)
                  ]

        if os.path.isfile(path):
            points = loadtxt(path, delimiter=',')


        po = PointOverlay(component=self.plot,
                          points=points
                          )
        self.plot.overlays.append(po)

    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

    def traits_view(self):
        image = Item('container', style='custom', show_label=False,
                     editor=ComponentEditor()
                     )
        v = View(

                 Item('open_button', show_label=False),
                 Item('define_points',
                      enabled_when='plot',
                      editor=ButtonEditor(label_value='define_points_label'),
                      show_label=False),
                 image,
                 resizable=True
                 )
        return v