1 from pixelcore.Pixel import *
2 from pixelcore.PixelStrip import *
3 from operationscore.PixelEvent import *
4 from operationscore.PixelMapper import *
5 import util.Search as Search
6 import util.ComponentRegistry as compReg
7 import util.Strings as Strings
8 import util.TimeOps as timeops
9 import itertools
10 import sys
11 import pdb
12 from logger import main_log
14 """Class representing a collection of Pixels grouped into PixelStrips. Needs a
15 PixelMapper, currently set via setMapper by may be migrated into the argDict."""
16
18 self.responseQueue = []
19 self.pixelStrips = []
20 self.xSortedPixels = []
21 self.xPixelLocs = []
22 sizeValid = False
23 self.pixelsSorted = False
24
26 self.pixelStrips.append(strip)
27 self.sizeValid = False
28 self.pixelsSorted = False
29
30
32 """Returns (pixelIndex, pixel). Does a binary search. Sorts first if neccesary."""
33 if not self.pixelsSorted:
34 self.computeXSortedPixels()
35 minIndex = Search.find_ge(self.xPixelLocs, minX)
36 maxIndex = Search.find_le(self.xPixelLocs, maxX)+1
37 return self.xSortedPixels[minIndex:maxIndex]
38
40 self.xSortedPixels = []
41 for pixel in self:
42 self.xSortedPixels.append((pixel.location[0], pixel))
43 self.xSortedPixels.sort()
44 self.xPixelLocs = [p[0] for p in self.xSortedPixels]
45 self.pixelsSorted = True
46
48 return itertools.chain(*[strip.__iter__() for strip in \
49 self.pixelStrips])
50
51
52
54 """Increments time -- This processes all queued responses, adding that to a queue that will
55 be processed on the next time step."""
56 if currentTime == None:
57 currentTime = timeops.time()
58 tempQueue = list(self.responseQueue)
59 self.responseQueue = []
60 for response in tempQueue:
61 self.processResponse(response, currentTime)
62
63
65 self.responseQueue.append(responseInfo)
66
68 """Returns the size of the screen in the form: (minx, miny, maxx, maxy)"""
69 if self.sizeValid:
70 return self.size
71 (minX, minY, maxX, maxY) = (sys.maxint,sys.maxint,-sys.maxint,-sys.maxint)
72 for light in self:
73 (x,y) = light.location
74
75 minX = min(x, minX)
76 maxX = max(x, maxX)
77
78 minY = min(y, minY)
79 maxY = max(y, maxY)
80 self.size = (0,0, maxX, maxY)
81 self.sizeValid = True
82 return (minX, minY, maxX, maxY)
83
84
86
87 if currentTime == None:
88 currentTime = timeops.time()
89 if type(responseInfo) != type(dict()):
90 pass
91 if 'Mapper' in responseInfo:
92 mapper = compReg.getComponent(responseInfo['Mapper'])
93 else:
94 mapper = compReg.getComponent(Strings.DEFAULT_MAPPER)
95 pixelWeightList = mapper.mapEvent(responseInfo['Location'], self)
96 main_log.debug('Screen processing response. ' + str(len(pixelWeightList)) + ' events\
97 generated')
98 PixelEvent.addPixelEventIfMissing(responseInfo)
99 for (pixel, weight) in pixelWeightList:
100 pixel.processInput(responseInfo['PixelEvent'], 0,weight, currentTime)
101