def build(self): for line_name in self.db.db['lines']['name'].unique(): self.lines[line_name] = cp.Line(self.env, self.db) for store_name in self.db.db['stores']['name'].unique(): self.lines[store_name] = cp.Store(self.env, self.db)
def combine_contains2(self, op_tup, pos_offset): line1 = op_tup[1] # containee line2 = op_tup[2] # container o = line1.orien weights = [line1.count, line2.count] # dist line1_dist = line1.pos[o] line2_dist = line2.pos[o] + pos_offset[o] avg_dist = utils.wavg([line1_dist, line2_dist], weights) # length len_diff = line2.length - line1.length overlap_perc = line1.length / line2.length length_delta = len_diff * overlap_perc / max(line1.count, 1) length = max(line1.length + length_delta, 0.1) # offset offset = line1.pos[1-o] - (length_delta / 2) # pos pos = create_pos(avg_dist, offset, o) # thickness thickness = utils.wavg([line1.thickness, line2.thickness], weights) # count - by pixel mass line = components.Line(o, pos, length, thickness) line.count = ((line1.count * line1.length) + (line2.count * line2.length)) / line.length return line
def _read_line(ele, orien): ''' local function to process a single xml line element node ''' x = int(ele.get('x')) y = int(ele.get('y')) l = int(ele.get("length")) t = int(ele.get("thickness")) line = components.Line(orien, (x, y), l, t) return line
def combine_perfect(self, line1, line2, pos_offset): weights = [line1.count, line2.count] pos2_translated = utils.tup_sum([line2.pos, pos_offset]) avg_pos = utils.tup_avg([line1.pos, pos2_translated], weights) avg_len = max(utils.wavg([line1.length, line2.length], weights), 0.1) avg_thick = utils.wavg([line1.thickness, line2.thickness], weights) combined_line = components.Line(line1.orien, avg_pos, avg_len, avg_thick) combined_line.count = line1.count + line2.count return combined_line
def __init__(self, width, height, rows, cols, orien, f=None): super(GridLineFeatureSet, self).__init__(width, height, rows, cols) self.lines = list() self.orien = orien if f: line = f.readline().strip() while line: tokens = line.split() pos = ( int(tokens[0]), int(tokens[1]) ) length = int(tokens[2]) thick = int(tokens[3]) self.lines.append(components.Line(orien, pos, length, thick)) line = f.readline().strip()
def interpolate_lines(self, line1, line2): ''' Connects two lines. Takes their average distance, min of the offset, and fills the gap for length ''' o = line1.orien if line1.pos[1-o] > line2.pos[1-o]: line1, line2 = line2, line1 weights = [line1.count, line2.count] avg_dist = utils.wavg([line1.pos[o], line2.pos[o]], weights) offset = line1.pos[1-o] pos = create_pos(avg_dist, offset, o) length = max(line2.length + (line2.pos[1-o] - line1.pos[1-o]), 0.1) avg_thickness = utils.wavg([line1.thickness, line2.thickness], weights) line = components.Line(o, pos, length, avg_thickness) line.count = (line1.count * line1.length + line2.count * line2.length) / float(line.length) return line
def combine_overlap(self, op_tup, pos_offset): line1 = op_tup[1] line2 = op_tup[2] o = line1.orien overlap_len = utils.overlap_len(line1.length_range(), line2.length_range(offset=pos_offset[1-o])) overlap_perc1 = overlap_len / float(line1.length) weights = [line1.count, line2.count] # dist line1_dist = line1.pos[o] line2_dist = line2.pos[o] + pos_offset[o] avg_dist = utils.wavg([line1_dist, line2_dist], weights) # length length_delta = overlap_perc1 * (line2.length - overlap_len) / max(line1.count, 1) length = max(line1.length + length_delta, 0.1) # decide which end to grow if line1.pos[1-o] < (line2.pos[1-o] + pos_offset[1-o]): # line1 preceeds line2 offset = line1.pos[1-o] else: # moves line1 toward line2 offset = line1.pos[1-o] - length_delta # pos - combine relative dist and offset with the reference combined line pos = create_pos(avg_dist, offset, o) # thickness thickness = utils.wavg([line1.thickness, line2.thickness], weights) # count line = components.Line(o, pos, length, thickness) line.count = ((line1.count * line1.length) + (line2.count * line2.length)) / line.length return line
def combine_del(self, del_line, pos_offset): pos = utils.tup_sum([del_line.pos, pos_offset]) line = components.Line(del_line.orien, pos, del_line.length, del_line.thickness) line.count = del_line.count return line