Source code for TimeTracks

# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Class managing a timetraack, an abstract object handling up timepoints
import logging, cv2, imp

[docs]class TimeTrack : def __init__(self) : self.times = [] self.pols = []
[docs] def add_timepoint(self, time, pol) : ex = self.get_index(time) # Check if the timepoint exists and get its index if ex[0] : # Edit it self.pols[ex[1]] = pol else :# Create it self.times.insert(ex[1], time) self.pols.insert(ex[1], pol)
[docs] def del_timepoint(self, time) : ex = self.get_index(time) if not ex[0] : logging.error('The timepoint %s cannot be removed because it does not exist.', time) else : self.times.pop(ex[1]) self.pols.pop(ex[1])
[docs] def get_index(self, time) : if time in self.times : return (True, self.times.index(time)) elif self.times == [] : return (False, 0) else : i = 0 while (self.times[i] < time) and (i < len(self.times)) : i+=1 return (False, i)