Package SmootLight :: Package pixelmappers :: Module C5SignMapper
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.pixelmappers.C5SignMapper

  1  from operationscore.PixelMapper import * 
  2  import util.Geo as Geo 
  3  import sys 
  4  import math 
5 -class C5SignMapper(PixelMapper):
6 """C5SignMapper is a modification to SimpleMapper which maps events to the 7 nearest Pixel. In addtion, it also maps sign artifacts (letters, logo, etc) 8 to their representative locations if given in the form "ts rs :: conditions" 9 It also supports strings of the form: {x}>5, {y}<10, {x}*{y}<{x}, etc. 10 (Conditons, separated by commas. and and or may also be used).""" 11 12 signPosition = { 13 "ls" : { 14 'all' : [(2,2),(2,8), (2,14), (2,20)], 15 '1' : [(2,2)], 16 '2' : [(2,8)], 17 '3' : [(2,14)], 18 '4' : [(2,20)] }, 19 "ts" : { 20 'all' : [(4,22), (10,22), (16,22), (22,22), (27, 22), (33, 22), (39,22), (44, 22)], 21 '1' : [(4,22)], 22 '2' : [(10,22)], 23 '3' : [(16,22)], 24 '4' : [(22,22)], 25 '5' : [(27,22)], 26 '6' : [(33,22)], 27 '7' : [(39,22)], 28 '8' : [(44,22)] }, 29 "rs" : { 30 'all' : [(45,2), (45, 8), (45,14), (45,20)], 31 '1' : [(45,2)], 32 '2' : [(45,8)], 33 '3' : [(45,14)], 34 '4' : [(45,20)] }, 35 "bs" : { 36 'all' : [(4,2), (10,2), (16,2), (22, 2), (27,2), (34,2), (39,2), (44,2)], 37 '1' : [(4,2)], 38 '2' : [(10,2)], 39 '3' : [(16,2)], 40 '4' : [(22,2)], 41 '5' : [(27,2)], 42 '6' : [(33,2)], 43 '7' : [(39,2)], 44 '8' : [(44,2)] }, 45 "wt" : { 46 'all' : [(12,5), (13, 5), (16,5), (18,5), (21,5), (23,5), (26,5), (27,5), (30,5), (34,5), (37,5)], 47 '1' : [(12,5), (13,5)], 48 '2' : [(16,5)], 49 '3' : [(18,5)], 50 '4' : [(21,5)], 51 '5' : [(23,5)], 52 '6' : [(26,5),(27,5)], 53 '7' : [(30,5)], 54 '8' : [(34,5)], 55 '9' : [(37,5)] }, 56 "cl" : { 57 'all' : [(17,8), (21,10), (24,10), (26,12), (31,12)], 58 'in' : [(21,10),(24,10),(26,12)], 59 'out' : [(17,8),(31,12)], 60 '1' : [(17,8)], 61 '2' : [(21,10)], 62 '3' : [(24,10)], 63 '4' : [(26,12)], 64 '5' : [(31,12)] }, 65 "c5" : { 66 'all' : [(6,17), (11,17), (15,17), (19,17), (22, 17), (27,17), (33,16), (34, 16), (38,17), (42,17)], 67 'con' : [(6,17), (11,17), (15,17), (19,17), (22, 17), (27,17)], 68 'five': [(33,16), (34, 16), (38,17), (42,17)], 69 '1' : [(6,17)], 70 '2' : [(11,17)], 71 '3' : [(15,17)], 72 '4' : [(19,17)], 73 '5' : [(22,17)], 74 '6' : [(27,17)], 75 '7' : [(33,16)], 76 '8' : [(34,16)], 77 '9' : [(38,17)], 78 '10' : [(42,17)] }, 79 } 80
81 - def mappingFunction(self, eventLocation, screen):
82 if type(eventLocation) == type(tuple()): 83 bestDist = sys.maxint 84 bestPixel = None 85 [x,y] = eventLocation 86 for (x,pixel) in screen.pixelsInRange(x-self['CutoffDist'], \ 87 x+self['CutoffDist']): 88 pixelDist = Geo.dist(pixel.location, eventLocation) 89 if pixelDist < bestDist: 90 bestPixel = pixel 91 bestDist = pixelDist 92 if bestPixel != None: 93 return [(bestPixel,1)] 94 else: 95 return [] 96 else: 97 #pixel locs 98 eventLocSplit = eventLocation.split('@') 99 if len(eventLocSplit) == 2: 100 [eventLocation, signPart] = eventLocSplit 101 signParts = signPart.split('.') 102 pixelLocs = signPosition[signParts[0]][signParts[1]] 103 screenPixels = [p for p in screen if (p.location in pixelLocs)] 104 else: 105 screenPixels = [p for p in screen] 106 107 108 #{x}>5,{y}<k 109 ret = [] 110 eventLocation = eventLocation.replace('{x}', 'pixel.location[0]') 111 eventLocation = eventLocation.replace('{y}', 'pixel.location[1]') 112 if len(eventLocation) > 0: 113 conditions = eventLocation.split(',') 114 conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions] 115 else: 116 conditionLambdas = [] 117 for pixel in screenPixels: 118 try: 119 pixelValid = True 120 for p in conditionLambdas: 121 if p(pixel) == False: 122 pixelValid = False 123 continue 124 if pixelValid: 125 ret.append((pixel, 1)) 126 except Exception as exp: 127 import pdb; pdb.set_trace() 128 raise Exception('Bad event condition') 129 return ret
130