public LBT(LBT other) { if (other != null) { // clone stroke list strokes = new List <Stroke>(); if (other.strokes != null) { foreach (Stroke s in other.strokes) { strokes.Add(s); } } // clone tree root = new LBTNode(other.root); // rebuild dictionary stroke_to_node = new Dictionary <Stroke, LBTNode>(); Stack stack = new Stack(); stack.Push(root); while (stack.Count > 0) { LBTNode node = (LBTNode)stack.Pop(); if (node != root) { stroke_to_node.Add(node.stroke, node); } foreach (LBTNode ln in node.children) { stack.Push(ln); } } raw_data = null; } }
public LBTNode(LBTNode other) { stroke = other.stroke; children = new List <LBTNode>(); foreach (LBTNode n in other.children) { children.Add(new LBTNode(n)); } }
public void GraphFromStrokeList(LBT lbt, List <Stroke> strokes, AdjacentCriterion adjacent) { strokes.Sort(delegate(Stroke a, Stroke b) { return(Math.Sign(a.aabb.Left - b.aabb.Left)); //if(a.aabb.Left < b.aabb.Left) return -1; //if(a.aabb.Left > b.aabb.Left) return 1; //return 0; }); lbt.root = new LBTNode(); lbt.root.stroke = null; for (int k = 0; k < strokes.Count; k++) { LBTNode node = new LBTNode(); node.stroke = strokes[k]; lbt.stroke_to_node[strokes[k]] = node; if (k == 0) { lbt.root.children.Add(node); continue; } // iterate over boxes to the left of this box for (int j = k - 1; j >= 0; j--) { // if strokes don't overlap on y if (Math.Abs(strokes[k].aabb.Center.y - strokes[j].aabb.Center.y) > (strokes[k].aabb.Radius.y + strokes[j].aabb.Radius.y)) { if (j == 0) { lbt.root.children.Add(node); } continue; } if (adjacent(strokes[j].aabb, strokes[k].aabb)) { LBTNode parent = lbt.stroke_to_node[strokes[j]]; parent.children.Add(node); break; } } } }
private void print_node(StringBuilder sb, LBTNode node) { string node_name = ""; if (node.stroke == null) { node_name = "root"; } else { node_name = "_" + node.stroke.stroke_id; } for (int k = 0; k < node.children.Count; k++) { sb.Append("\t").Append(node_name).Append(" -> ").Append("_" + node.children[k].stroke.stroke_id).AppendLine(";"); print_node(sb, node.children[k]); } }