Package SmootLight :: Package operationscore :: Module PixelMapper
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.operationscore.PixelMapper

 1  from operationscore.SmootCoreObject import * 
 2  from logger import main_log 
 3  import pdb 
4 -class PixelMapper(SmootCoreObject):
5 """PixelMapper is the parent class for PixelMappers. Inheriting classes should define 6 mappingFunction which takes an eventLocation and a screen and returns a list of (weight, pixels). PixelMapper 7 handles caching automatically."""
8 - def init(self):
9 self.mem = {} #Dictionary of all seen events 10 self.totalCalls = 0 11 self.cachehits = 0
12 - def mapEvent(self, eventLocation, screen):
13 self.totalCalls += 1 14 if self.totalCalls % 100 == 0: 15 main_log.info('Cache percentage for :', self['Id'], self.cachehits /\ 16 float(self.totalCalls)) 17 if eventLocation in self.mem: 18 self.cachehits += 1 19 return self.mem[eventLocation] 20 else: 21 self.mem[eventLocation] = self.mappingFunction(eventLocation, screen) 22 return self.mem[eventLocation]
23 #Takes a Screen and returns a list of tuples 24 #(pixel, weight), with the sum of weights = 1
25 - def mappingFunction(self,eventLocation, screen):
26 """Takes a Screen and event location and returns a list of tuples (pixel,weight) with 27 sum(weights)=1""" 28 raise Exception('Mapping function not defined!')
29