def load_traces(self): ''' replace the traces in dummySample with the one generated from scg_content :return: ''' strokes = scginkparser.parse_scg_ink_file(self.content, self.id) #for st in strokes: #print st traces = self.traces trace_id_int = 0 for st in strokes: coords = np.zeros((2, len(st))) idx = 0 for x_y in st: coords[:, idx] = [float(x_y[0]), float(x_y[1])] idx += 1 traces[trace_id_int] = Stroke(trace_id_int, coords) trace_id_int += 1 # //Compute bounding box of the input expression x_min, y_min, x_max, y_max = get_bounding_box(traces) # bounding box for the whole math expression # Just in case there is only one point or a sequence of points perfectly aligned with the x or y axis if x_max == x_min: x_max = x_min + 1; if y_max == y_min: y_max = y_min + 1; self.w_h_ratio = float(x_max - x_min) / (y_max - y_min) # Renormalize to height [0,100] keeping the aspect ratio H = 100.0 W = H * (x_max - x_min) / (y_max - y_min) for trace_key, trace_v in traces.iteritems(): trace_v.calc_coords_h10000(H, W, x_min, y_min, x_max, y_max)
traces = {} trace_id_int = 0 for st in strokes: coords = np.zeros((2, len(st))) idx = 0 for x_y in st: coords[:, idx] = [float(x_y[0]), float(x_y[1])] idx += 1 traces[trace_id_int] = Stroke(trace_id_int, coords) trace_id_int += 1 # //Compute bounding box of the input expression x_min, y_min, x_max, y_max = get_bounding_box(traces) # bounding box for the whole math expression # Just in case there is only one point or a sequence of points perfectly aligned with the x or y axis if x_max == x_min: x_max = x_min + 1; if y_max == y_min: y_max = y_min + 1; # Renormalize to height [0,10000] keeping the aspect ratio H = 10000.0 W = H * (x_max - x_min) / (y_max - y_min) for trace_key, trace_v in traces.iteritems(): trace_v.calc_coords_h10000(H, W, x_min, y_min, x_max, y_max) for trace_key, trace_v in traces.iteritems(): print trace_key, trace_v rx, ry, rs, rt = trace_v.get_bounding_box_h10000()