protected override void PerformTreePrecalculations( GTree <Node, Edge, RectGeom <Node, Edge> > dataTree, uint lastNodeVersion, uint lastEdgeVersion) { if (this.bTreeDirty) { this.bDirty = true; } else if (this.bAdaptToSizeChanges) { this.RefreshBBox(dataTree); if (dataTree.GeomData.TreeBoundingBoxDirty) { this.bDirty = true; // This has to be done in order to reset // dTree.TreeBoundingBoxDirty to false in order to // accurately check for node size changes on the next // iteration. Otherwise, it remains true and the // positions will keep getting recalculated on each // iteration even if no size changes have occurred. dataTree.GeomData.CalculateTreeBoundingBox(); } } if (this.bDirty) { this.ComputePositions(dataTree); } this.bTreeDirty = false; this.bDirty = false; }
private GTree <Node, Edge, Geom> BuildDataBranch( Digraph <Node, Edge> .GNode root, Edge edge, bool undirected, bool reversed) { root.Color = GraphColor.Gray; GTree <Node, Edge, Geom> child, parent = this.CreateTree(root, edge); Digraph <Node, Edge> .GEdge gEdge; Digraph <Node, Edge> .GNode gNode; int i, rootIndex = root.Index; if (undirected || !reversed) { for (i = 0; i < this.mSTECount; i++) { gEdge = this.mSpanTreeEdges[i]; if (gEdge.SrcNode.Index == rootIndex) { gNode = gEdge.DstNode; if (gNode.Color == GraphColor.White) { child = this.BuildDataBranch(gNode, gEdge.Data, undirected, reversed); child.SetRoot(parent); } } } } if (undirected || reversed) { for (i = 0; i < this.mSTECount; i++) { gEdge = this.mSpanTreeEdges[i]; if (gEdge.DstNode.Index == rootIndex) { gNode = gEdge.SrcNode; if (gNode.Color == GraphColor.White) { child = this.BuildDataBranch(gNode, gEdge.Data, undirected, reversed); child.SetRoot(parent); } } } } root.Color = GraphColor.Black; return(parent); }
private void RefreshBBox(GTree <Node, Edge, RectGeom <Node, Edge> > root) { if (root.BranchCount > 0) { GTree <Node, Edge, RectGeom <Node, Edge> >[] branches = root.Branches; for (int i = branches.Length - 1; i >= 0; i--) { this.RefreshBBox(branches[i]); } } root.GeomData.BoundingBox = root.NodeData.LayoutBBox; }
protected override GTree <Node, Edge, RectGeom <Node, Edge> > CreateTree( Digraph <Node, Edge> .GNode node, Edge edge) { this.bTreeDirty = true; RectGeom <Node, Edge> geom = new RectGeom <Node, Edge>(node.Data.LayoutBBox); GTree <Node, Edge, RectGeom <Node, Edge> > tree = new GTree <Node, Edge, RectGeom <Node, Edge> >( node.Index, node.Data, edge, geom, node.TotalEdgeCount(false)); geom.SetOwner(tree); return(tree); }
void Start() { _mainView = this.GetComponent <UIPanel>().ui; _fileURL = "ui://TreeView/file"; _tree1 = _mainView.GetChild("tree").asTree; _tree1.onClickItem.Add(__clickNode); _tree2 = _mainView.GetChild("tree2").asTree; _tree2.onClickItem.Add(__clickNode); _tree2.treeNodeRender = RenderTreeNode; GTreeNode topNode = new GTreeNode(true); topNode.data = "I'm a top node"; _tree2.rootNode.AddChild(topNode); for (int i = 0; i < 5; i++) { GTreeNode node = new GTreeNode(false); node.data = "Hello " + i; topNode.AddChild(node); } GTreeNode aFolderNode = new GTreeNode(true); aFolderNode.data = "A folder node"; topNode.AddChild(aFolderNode); for (int i = 0; i < 5; i++) { GTreeNode node = new GTreeNode(false); node.data = "Good " + i; aFolderNode.AddChild(node); } for (int i = 0; i < 3; i++) { GTreeNode node = new GTreeNode(false); node.data = "World " + i; topNode.AddChild(node); } GTreeNode anotherTopNode = new GTreeNode(false); anotherTopNode.data = new string[] { "I'm a top node too", "ui://TreeView/heart" }; _tree2.rootNode.AddChild(anotherTopNode); }
private void DrawBalloonCirclesConvexHull(Graphics g, GTree <PrintArray <CircleNode>, int, CircleGeom <PrintArray <CircleNode>, int> > root) { int i; bool drawHull = true; if (this.bDrawSelectedConvexHullOnly) { if (this.mMouseUpHistory[0] == -1) { drawHull = false; } else { CircleNode node = this.mGraph.NodeAt(this.mMouseUpHistory[0]); CircleNode[] datas = root.NodeData.Data; drawHull = false; for (i = 0; i < datas.Length && !drawHull; i++) { drawHull = datas[i] == node; } } } float dx, dy, px, py, len; double a1, a2, hyp; // Draw the convex hull of the root itself CircleGeom <PrintArray <CircleNode>, int> .CHArc[] cvHull = root.GeomData.ConvexHull; if (drawHull && cvHull.Length == 1) { CircleGeom <PrintArray <CircleNode>, int> .CHArc ch1 = cvHull[0]; dx = (float)(ch1.Dst * Math.Cos(ch1.Ang) - ch1.Rad); dy = (float)(ch1.Dst * Math.Sin(ch1.Ang) - ch1.Rad); len = (float)(2.0 * ch1.Rad); g.DrawEllipse(this.mConvexHullPen, dx, dy, len, len); } if (drawHull && cvHull.Length > 1) { CircleGeom <PrintArray <CircleNode>, int> .CHArc arc = cvHull[cvHull.Length - 1]; if (arc.Dst == 0) { a1 = arc.Ang + arc.UpperWedge; px = (float)(arc.Rad * Math.Cos(a1)); py = (float)(arc.Rad * Math.Sin(a1)); } else { a1 = Math.PI - arc.UpperWedge; hyp = Math.Sqrt(arc.Rad * arc.Rad + arc.Dst * arc.Dst - 2 * arc.Rad * arc.Dst * Math.Cos(a1)); a2 = Math.Asin(arc.Rad * Math.Sin(a1) / hyp); a1 = arc.Ang + a2; px = (float)(hyp * Math.Cos(a1)); py = (float)(hyp * Math.Sin(a1)); } for (i = 0; i < cvHull.Length; i++) { arc = cvHull[i]; if (this.bDrawConvexHullAngleLines) { dx = (float)(arc.Dst * Math.Cos(arc.Ang)); dy = (float)(arc.Dst * Math.Sin(arc.Ang)); a1 = arc.Rad * Math.Cos(arc.Ang); a2 = arc.Rad * Math.Sin(arc.Ang); g.DrawLine(this.mConvexHullPen, 0f, 0f, dx + (float)a1, dy + (float)a2); a1 = arc.Rad * Math.Cos(arc.Ang - arc.LowerWedge); a2 = arc.Rad * Math.Sin(arc.Ang - arc.LowerWedge); g.DrawLine(this.mConvexHullPen, dx, dy, dx + (float)a1, dy + (float)a2); a1 = arc.Rad * Math.Cos(arc.Ang + arc.UpperWedge); a2 = arc.Rad * Math.Sin(arc.Ang + arc.UpperWedge); g.DrawLine(this.mConvexHullPen, dx, dy, dx + (float)a1, dy + (float)a2); } dx = (float)(arc.Dst * Math.Cos(arc.Ang) - arc.Rad); dy = (float)(arc.Dst * Math.Sin(arc.Ang) - arc.Rad); len = (float)(2.0 * arc.Rad); a1 = arc.Ang - arc.LowerWedge; a2 = arc.Ang + arc.UpperWedge - a1; if (a1 < -Math.PI) { a1 += 2 * Math.PI; } //if (a2 < -Math.PI) // a2 += 2 * Math.PI; a1 = 180.0 * a1 / Math.PI; a2 = 180.0 * a2 / Math.PI; g.DrawArc(this.mConvexHullPen, dx, dy, len, len, (float)a1, (float)a2); if (arc.Dst == 0) { a1 = arc.Ang - arc.LowerWedge; dx = (float)(arc.Rad * Math.Cos(a1)); dy = (float)(arc.Rad * Math.Sin(a1)); g.DrawLine(this.mConvexHullPen, px, py, dx, dy); a1 = arc.Ang + arc.UpperWedge; px = (float)(arc.Rad * Math.Cos(a1)); py = (float)(arc.Rad * Math.Sin(a1)); } else { a1 = Math.PI - arc.LowerWedge; hyp = Math.Sqrt(arc.Rad * arc.Rad + arc.Dst * arc.Dst - 2 * arc.Rad * arc.Dst * Math.Cos(a1)); a2 = Math.Asin(arc.Rad * Math.Sin(a1) / hyp); a1 = arc.Ang - a2; dx = (float)(hyp * Math.Cos(a1)); dy = (float)(hyp * Math.Sin(a1)); g.DrawLine(this.mConvexHullPen, px, py, dx, dy); a1 = Math.PI - arc.UpperWedge; hyp = Math.Sqrt(arc.Rad * arc.Rad + arc.Dst * arc.Dst - 2 * arc.Rad * arc.Dst * Math.Cos(a1)); a2 = Math.Asin(arc.Rad * Math.Sin(a1) / hyp); a1 = arc.Ang + a2; px = (float)(hyp * Math.Cos(a1)); py = (float)(hyp * Math.Sin(a1)); } } } // Draw the convex hull of the root's branches if (root.BranchCount > 0) { float ang; CircleGeom <PrintArray <CircleNode>, int> ct; GTree <PrintArray <CircleNode>, int, CircleGeom <PrintArray <CircleNode>, int> >[] branches = root.Branches; for (i = 0; i < branches.Length; i++) { ct = branches[i].GeomData; dx = (float)(ct.Distance * Math.Cos(ct.Angle)); dy = (float)(ct.Distance * Math.Sin(ct.Angle)); ang = (float)ct.DegAngle; g.TranslateTransform(dx, dy); g.RotateTransform(ang); this.DrawBalloonCirclesConvexHull(g, branches[i]); g.RotateTransform(-ang); g.TranslateTransform(-dx, -dy); } } }
protected override void OnDrawForeground(PaintEventArgs e) { if (this.mConvexHullPen.Color != Color.Transparent) { BalloonTreeLayoutForCircles btlfc = this.mLayout as BalloonTreeLayoutForCircles; if (btlfc != null) { Graphics g = e.Graphics; GTree <CircleNode, ArrowEdge, CircleGeom <CircleNode, ArrowEdge> > ct = btlfc.CircleTree; if (ct != null) { float dx = ct.NodeData.X; float dy = ct.NodeData.Y; float ang = (float)btlfc.DegRootAngle; g.TranslateTransform(dx, dy); g.RotateTransform(ang); this.DrawBalloonTreeConvexHull(g, ct); g.TranslateTransform(-dx, -dy); g.RotateTransform(-ang); } } BalloonCirclesLayoutForCircles bclfc = this.mLayout as BalloonCirclesLayoutForCircles; if (bclfc != null) { Graphics g = e.Graphics; GTree <PrintArray <CircleNode>, int, CircleGeom <PrintArray <CircleNode>, int> > ct = bclfc.DebugTree; if (ct != null) { Vec2F pos = bclfc.DebugRootPosition; float dx = pos.X; float dy = pos.Y; float ang = (float)bclfc.DegRootAngle; g.TranslateTransform(dx, dy); g.RotateTransform(ang); this.DrawBalloonCirclesConvexHull(g, ct); g.TranslateTransform(-dx, -dy); g.RotateTransform(-ang); } } } }
private void BuildDataTree() { this.mCCAlg.Reset(); this.mCCAlg.Compute(); this.mCompIds = this.mCCAlg.ComponentIds; int i, j, count; int tIndex = 0; int tMaxSize = 0; int tCount = this.mCCAlg.ComponentCount; Digraph <Node, Edge> .GNode root; Digraph <Node, Edge> .GEdge edge; GTree <Node, Edge, Geom> tree; GTree <Node, Edge, Geom>[] trees = new GTree <Node, Edge, Geom> [tCount]; count = this.mGraph.NodeCount; for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Hidden) { this.mCompIds[i] = -1; } root.Color = GraphColor.White; } GTree <Node, Edge, Geom>[] ts; Digraph <Node, Edge> .GEdge[] stEdges; switch (this.mRootFindingMethod) { case TreeRootFinding.UserDefined: tCount = 0; count = this.RootCount; for (i = 0; i < count; i++) { root = this.RootAt(i); if (root.Color == GraphColor.White && !root.Hidden) { tree = this.BuildDataBranch(root, null, true, true); trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } count = this.mGraph.NodeCount; for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Color == GraphColor.White && !root.Hidden) { tree = this.BuildDataBranch(root, null, true, true); trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } break; case TreeRootFinding.SourceDirected: tCount = 0; for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Color == GraphColor.White && !root.Hidden && root.IncomingEdgeCount == 0) { tree = this.BuildDataBranch(root, null, false, false); if (tCount == trees.Length) { ts = new GTree <Node, Edge, Geom> [2 * tCount]; Array.Copy(trees, 0, ts, 0, tCount); trees = ts; } trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Color == GraphColor.White && !root.Hidden) { tree = this.BuildDataBranch(root, null, false, false); if (tCount == trees.Length) { ts = new GTree <Node, Edge, Geom> [2 * tCount]; Array.Copy(trees, 0, ts, 0, tCount); trees = ts; } trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } break; case TreeRootFinding.SinkDirected: tCount = 0; for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Color == GraphColor.White && !root.Hidden && root.OutgoingEdgeCount == 0) { tree = this.BuildDataBranch(root, null, false, true); if (tCount == trees.Length) { ts = new GTree <Node, Edge, Geom> [2 * tCount]; Array.Copy(trees, 0, ts, 0, tCount); trees = ts; } trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } for (i = 0; i < count; i++) { root = this.mGraph.InternalNodeAt(i); if (root.Color == GraphColor.White && !root.Hidden) { tree = this.BuildDataBranch(root, null, false, true); if (tCount == trees.Length) { ts = new GTree <Node, Edge, Geom> [2 * tCount]; Array.Copy(trees, 0, ts, 0, tCount); trees = ts; } trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } } break; case TreeRootFinding.Center: stEdges = this.mSpanTreeEdges; this.mSpanTreeEdges = new Digraph <Node, Edge> .GEdge[stEdges.Length]; count = tCount; tCount = 0; for (i = 0; i < count; i++) { this.mSTECount = 0; for (j = 0; j < stEdges.Length; j++) { edge = stEdges[j]; if (this.mCompIds[edge.SrcNode.Index] == i && this.mCompIds[edge.DstNode.Index] == i) { this.mSpanTreeEdges[this.mSTECount++] = edge; } } root = this.FindCenter(i); // TODO: What if calculated center is already gray? tree = this.BuildDataBranch(root, null, true, true); trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } this.mSpanTreeEdges = stEdges; this.mSTECount = stEdges.Length; break; case TreeRootFinding.PathCenter: stEdges = this.mSpanTreeEdges; this.mSpanTreeEdges = new Digraph <Node, Edge> .GEdge[stEdges.Length]; count = tCount; tCount = 0; for (i = 0; i < count; i++) { this.mSTECount = 0; for (j = 0; j < stEdges.Length; j++) { edge = stEdges[j]; if (this.mCompIds[edge.SrcNode.Index] == i && this.mCompIds[edge.DstNode.Index] == i) { this.mSpanTreeEdges[this.mSTECount++] = edge; } } root = this.FindPathCenter(i); // TODO: What if calculated center is already gray? tree = this.BuildDataBranch(root, null, true, true); trees[tCount++] = tree; if (tree.TreeSize > tMaxSize) { tMaxSize = tree.TreeSize; tIndex = tCount - 1; } } this.mSpanTreeEdges = stEdges; this.mSTECount = stEdges.Length; break; } this.mDataTree = trees[tIndex]; for (i = 0; i < tCount; i++) { if (i != tIndex) { trees[i].SetRoot(this.mDataTree); } } }
protected virtual void PerformTreePrecalculations( GTree <Node, Edge, Geom> dataTree, uint lastNodeVersion, uint lastEdgeVersion) { }
// inicari la busqueda private void button1_Click(object sender, EventArgs e) { Estado EstadoInicial = this.EstadoInicial(); Estado EstadoFinal = this.EstadoFinal(); // crear Arbol de busqueda Arbol ArbolBusqueda = new Arbol(); ArbolBusqueda.InsertarRaiz(EstadoInicial); ArbolBusqueda.Dims += 1; // iterar hasta que se encuentre el estado final while (true) { // si la pila no esta vacia if (ArbolBusqueda.PilaSuc.Count > 0) { // sacar un elemento de la pila Estado EstadoExtraido = (Estado)ArbolBusqueda.PilaSuc.Pop(); if (EstadoExtraido != null) { // si el extraido es igual al estado final if (ArbolBusqueda.Comparar(EstadoExtraido, EstadoFinal)) { MessageBox.Show("solucion encontrada " + new String(EstadoExtraido.CosasLadoIzq) + " " + " " + new String(EstadoExtraido.CosasLadoDer)); this.GrafObliga(EstadoExtraido, 0, 200); this.GTree.Refresh(); this.GetPapi(EstadoExtraido); return; } else { // GENERAR SUCESPRES SOLO SI ES UN ESTADO VALIDO if (ArbolBusqueda.Reglas(EstadoExtraido) && !ArbolBusqueda.BuscarEstadoUsado(EstadoExtraido)) { ArbolBusqueda.GenerarSucesores(EstadoExtraido); } // meterlo a cola de usados ArbolBusqueda.ColaUsados.Enqueue(EstadoExtraido); // graficar sucesores this.GraficarEstado(ArbolBusqueda.Raiz, 0, 0); Thread.Sleep(200); GTree.Refresh(); } } } else { MessageBox.Show("la Pila esta Vacia!!!!"); break; } } }
private void AssignPositions( GTree <Node, Edge, RectGeom <Node, Edge> > root) { float layerSize = 0; //bool horizontal = // this.mDirection == LayoutDirection.LeftToRight || // this.mDirection == LayoutDirection.RightToLeft; //float[] newXs = this.NewXPositions; //float[] newYs = this.NewYPositions; //Digraph<Node, Edge>.GNode[] nodes; //Digraph<Node, Edge>.GNode node; //Vec2F size; NodeData d; float height; //float x, y, height; int i, j, nodeCount; GTree <Node, Edge, RectGeom <Node, Edge> > node; GTree <Node, Edge, RectGeom <Node, Edge> >[] nodes; for (i = 0; i < this.mLayerCount; i++) { nodes = this.mLayers[i].Nodes; nodeCount = this.mLayers[i].NodeCount; for (j = 0; j < nodeCount; j++) { node = nodes[j]; //size = this.mSizes[node.Index]; //height = this.mSizeHs[node.NodeData.Index]; height = this.bHorizontal ? node.GeomData.BBoxW : node.GeomData.BBoxH; d = this.mDatas[node.NodeIndex]; if (d.parent != null) { //d.position += this.mDatas[d.parent.Index].translate; //d.translate += this.mDatas[d.parent.Index].translate; d.posX += d.parent.translate; d.translate += d.parent.translate; } d.posY = this.mDir * (layerSize + height / 2); /*if (horizontal) * { * x = this.mDir * (layerSize + size.Y / 2.0); * y = d.position; * } * else * { * x = d.position; * y = this.mDir * (layerSize + size.Y / 2.0); * }/* */ //node.Data.NewX = (float)x; //node.Data.NewY = (float)y; //node.Data.SetPosition((float)x, (float)y); //newXs[node.Index] = (float)x; //newYs[node.Index] = (float)y; } if (i == 0) { NodeData pd = this.mDatas[root.NodeIndex]; if (this.bHorizontal) { for (j = 0; j < nodeCount; j++) { node = nodes[j]; d = this.mDatas[node.NodeIndex]; node.GeomData.OffsetX = d.posY - pd.posY; node.GeomData.OffsetY = d.posX - pd.posX; } } else { for (j = 0; j < nodeCount; j++) { node = nodes[j]; d = this.mDatas[node.NodeIndex]; node.GeomData.OffsetX = d.posX - pd.posX; node.GeomData.OffsetY = d.posY - pd.posY; } } } else if (this.bHorizontal) { for (j = 0; j < nodeCount; j++) { node = nodes[j]; d = this.mDatas[node.NodeIndex]; node.GeomData.OffsetX = d.posY - d.parent.posY; node.GeomData.OffsetY = d.posX - d.parent.posX; } } else { for (j = 0; j < nodeCount; j++) { node = nodes[j]; d = this.mDatas[node.NodeIndex]; node.GeomData.OffsetX = d.posX - d.parent.posX; node.GeomData.OffsetY = d.posY - d.parent.posY; } } layerSize += this.mLayers[i].Size; } }
/*private void GenerateSpanningTree() * { * ISpanningTreeAlgorithm<Node, Edge> alg = null; * switch (this.mSpanTreeGen) * { * case SpanningTreeGen.BFS: * BFSpanningTree<Node, Edge> bfst * = new BFSpanningTree<Node, Edge>( * this.mGraph, false, false); * bfst.RootCapacity = this.RootCount; * Digraph<Node, Edge>.GNode r1; * for (int i = this.RootCount - 1; i >= 0; i--) * { * r1 = this.RootAt(i); * bfst.AddRoot(r1.Index); * } * alg = bfst; * break; * case SpanningTreeGen.DFS: * DFSpanningTree<Node, Edge> dfst * = new DFSpanningTree<Node, Edge>( * this.mGraph, false, false); * dfst.RootCapacity = this.RootCount; * Digraph<Node, Edge>.GNode r2; * for (int j = this.RootCount - 1; j >= 0; j--) * { * r2 = this.RootAt(j); * dfst.AddRoot(r2.Index); * } * alg = dfst; * break; * case SpanningTreeGen.Boruvka: * alg = new BoruvkaMinSpanningTree<Node, Edge>(mGraph); * break; * case SpanningTreeGen.Kruskal: * alg = new KruskalMinSpanningTree<Node, Edge>(mGraph); * break; * case SpanningTreeGen.Prim: * alg = new PrimMinSpanningTree<Node, Edge>(mGraph); * break; * } * alg.Compute(); * this.mSpanningTree = alg.SpanningTree; * }/* */ //private float CalculatePosition(Digraph<Node, Edge>.GNode n, // Digraph<Node, Edge>.GNode parent, int lnum) private float CalculatePosition( GTree <Node, Edge, RectGeom <Node, Edge> > root, int lnum) { //if (n.Color == GraphColor.Gray) // return -1; // this node is already laid out if (lnum >= this.mLayerCount) { if (lnum >= this.mLayers.Length) { Layer[] layers = new Layer[2 * this.mLayers.Length]; Array.Copy(this.mLayers, 0, layers, 0, this.mLayerCount); this.mLayers = layers; } for (int j = this.mLayerCount; j <= lnum; j++) { this.mLayers[j] = new Layer(); } this.mLayerCount = lnum + 1; } Layer layer = this.mLayers[lnum]; //Vec2F size = this.mSizes[n.Index]; //float width = this.mSizeWs[root.NodeData.Index]; float width = this.bHorizontal ? root.GeomData.BBoxH : root.GeomData.BBoxW; float height = this.bHorizontal ? root.GeomData.BBoxW : root.GeomData.BBoxH; NodeData d = new NodeData(); d.parent = lnum == 0 ? null : this.mDatas[root.Root.NodeIndex]; this.mDatas[root.NodeIndex] = d; //d.parent = parent; //this.mDatas[n.Index] = d; //n.Color = GraphColor.Gray; //layer.NextPosition += size.X / 2.0; layer.NextPosition += width / 2; if (lnum > 0) { layer.NextPosition += this.mLayers[lnum - 1].LastTranslate; this.mLayers[lnum - 1].LastTranslate = 0; } //layer.Size = Math.Max(layer.Size, size.Y + this.mLayerGap); layer.Size = Math.Max(layer.Size, height + this.mLayerGap); //this.mSizeHs[root.NodeData.Index] + this.mLayerGap); if (layer.NodeCount == layer.Nodes.Length) { //Digraph<Node, Edge>.GNode[] nodes // = new Digraph<Node, Edge>.GNode[2 * layer.NodeCount]; int count = 2 * layer.NodeCount; GTree <Node, Edge, RectGeom <Node, Edge> >[] nodes = new GTree <Node, Edge, RectGeom <Node, Edge> > [count]; Array.Copy(layer.Nodes, 0, nodes, 0, layer.NodeCount); layer.Nodes = nodes; } layer.Nodes[layer.NodeCount++] = root;//n; //if (n.OutgoingEdgeCount == 0) if (root.BranchCount == 0) { d.posX = layer.NextPosition; layer.NextPosition += width / 2 + this.mVertexGap; } else { int i; float pos; float minPos = float.MaxValue; float maxPos = -float.MaxValue; // first put the children GTree <Node, Edge, RectGeom <Node, Edge> > child; GTree <Node, Edge, RectGeom <Node, Edge> >[] branches = root.Branches; //Digraph<Node, Edge>.GNode child; //for (int i = 0; i < this.mSpanTreeEdges.Length; i++) for (i = 0; i < branches.Length; i++) { /*child = this.mSpanTreeEdges[i].SrcNode; * if (child.Index != n.Index) * continue; * child = this.mSpanTreeEdges[i].DstNode;/* */ //childPos = this.CalculatePosition(child, n, lnum + 1); child = branches[i]; if (child.EdgeData != null) { pos = this.CalculatePosition(child, lnum + 1); //if (childPos >= 0) { minPos = Math.Min(minPos, pos); maxPos = Math.Max(maxPos, pos); } } } //if (minPos != float.MaxValue) d.posX = (minPos + maxPos) / 2; //else // d.position = layer.NextPosition; d.translate = Math.Max(layer.NextPosition - d.posX, 0); layer.LastTranslate = d.translate; d.posX += d.translate; layer.NextPosition = d.posX; layer.NextPosition += width / 2 + this.mVertexGap; for (i = 0; i < branches.Length; i++) { child = branches[i]; if (child.EdgeData == null) { this.CalculatePosition(child, lnum); } } } //layer.NextPosition += size.X / 2.0 + this.mVertexGap; return(d.posX); }
private void ComputePositions( GTree <Node, Edge, RectGeom <Node, Edge> > root) { //SimpleTreeLayoutParameters param = this.Parameters; //this.mVertexGap = param.VertexGap; //this.mLayerGap = param.LayerGap; //this.mDirection = param.Direction; //this.mSpanTreeGen = param.SpanningTreeGeneration; //Digraph<Node, Edge>.GNode node; int count = this.mGraph.NodeCount; if (this.mDatas.Length < count) { this.mDatas = new NodeData[count]; //this.mSizeWs = new float[count]; //this.mSizeHs = new float[count]; } //this.mSizes = new Vec2F[count]; //this.mDatas = new NodeData[count]; /*Box2F bbox; * if (this.mDirection == LayoutDirection.LeftToRight || * this.mDirection == LayoutDirection.RightToLeft) * { * for (i = 0; i < count; i++) * { * bbox = this.mGraph.NodeAt(i).LayoutBBox; * //this.mSizes[i] = new Vec2F(bbox.H, bbox.W); * this.mSizeWs[i] = bbox.H; * this.mSizeHs[i] = bbox.W; * } * } * else * { * for (i = 0; i < count; i++) * { * bbox = this.mGraph.NodeAt(i).LayoutBBox; * //this.mSizes[i] = new Vec2F(bbox.W, bbox.H); * this.mSizeWs[i] = bbox.W; * this.mSizeHs[i] = bbox.H; * } * }/* */ this.bHorizontal = this.mDirection == LayoutDirection.LeftToRight || this.mDirection == LayoutDirection.RightToLeft; if (this.mDirection == LayoutDirection.RightToLeft || this.mDirection == LayoutDirection.BottomToTop) { this.mDir = -1; } else { this.mDir = 1; } //this.GenerateSpanningTree(); if (this.mLayers == null) { this.mLayers = new Layer[2]; } this.mLayerCount = 0; this.CalculatePosition(root, 0); //this.mSpanTreeEdges = this.mSpanningTree.InternalEdges; /*count = this.mSpanningTree.NodeCount; * for (i = 0; i < count; i++) * { * node = this.mGraph.InternalNodeAt(i); * //nodes[i].Index = i; * node.Color = GraphColor.White; * } * // first layout the nodes with 0 src edges * for (i = 0; i < count; i++) * { * node = this.mSpanningTree.InternalNodeAt(i); * if (node.IncomingEdgeCount == 0) * this.CalculatePosition(node, null, 0); * } * // then layout the other nodes * for (i = 0; i < count; i++) * { * node = this.mSpanningTree.InternalNodeAt(i); * this.CalculatePosition(node, null, 0); * } * * this.mSpanTreeEdges = null;/* */ this.AssignPositions(root); }
protected override void PerformIteration(uint iteration) { GTree <Node, Edge, RectGeom <Node, Edge> > dTree = this.DataTree; /*if (this.bTreeDirty) * { * this.bDirty = true; * } * else if (this.bAdaptToSizeChanges) * { * this.RefreshBBox(dTree); * if (dTree.GeomData.TreeBoundingBoxDirty) * { * this.bDirty = true; * // This has to be done in order to reset * // dTree.TreeBoundingBoxDirty to false in order to * // accurately check for node size changes on the next * // iteration. Otherwise, it remains true and the * // positions will keep getting recalculated on each * // iteration even if no size changes have occurred. * dTree.GeomData.CalculateTreeBoundingBox(); * } * } * if (this.bDirty) * { * this.ComputePositions(dTree); * } * this.bTreeDirty = false; * this.bDirty = false;/* */ Node node; int i, sqIndex, sqCount; double cx, cy, dx, dy, fx, fy, r, dist, force; GTree <Node, Edge, RectGeom <Node, Edge> > ct, root; GTree <Node, Edge, RectGeom <Node, Edge> >[] branches; sqCount = this.mGraph.NodeCount; if (this.mStackQueue.Length < sqCount) { this.mStackQueue = new GTree <Node, Edge, RectGeom <Node, Edge> > [sqCount]; } if (this.bAdjustRoots) { // Pull roots towards their fixed branches sqCount = 1; this.mStackQueue[0] = dTree; while (sqCount > 0) { ct = this.mStackQueue[--sqCount]; if (ct.NodeData.PositionFixed) { root = ct.Root; while (root != null) { // Calculate force on root node = root.NodeData; dx = ct.GeomData.OffsetX; dy = ct.GeomData.OffsetY; dist = Math.Sqrt(dx * dx + dy * dy); dx = node.X - ct.NodeData.X; dy = node.Y - ct.NodeData.Y; if (dx == 0 && dy == 0) { fx = fy = dist / 10; } else { // Magnetic Force r = dx * dx + dy * dy; force = ct.GeomData.OffsetX + dx; fx = this.mMagnetMult * Math.Pow(force, this.mMagnetExp) / r; force = ct.GeomData.OffsetY + dy; fy = this.mMagnetMult * Math.Pow(force, this.mMagnetExp) / r; // Spring Force r = Math.Sqrt(r); force = this.mSpringMult * Math.Log(r / dist); fx += force * dx / r; fy += force * dy / r;/* */ }/* */ /*dist = ct.GeomData.OffsetX; * r = node.X - ct.NodeData.Data.X; * fx = r == 0 ? dist / 10 * : Math.Sign(dist) * this.mSpringMult * Math.Log(Math.Abs(r / dist)); * dist = ct.GeomData.OffsetY; * r = node.Y - ct.NodeData.Data.Y; * fy = r == 0 ? dist / 10 * : Math.Sign(dist) * this.mSpringMult * Math.Log(Math.Abs(r / dist));/* */ // Apply force to root position node.SetPosition(node.X - (float)fx, node.Y - (float)fy); // Progress up the ancestry chain ct = root; root = ct.Root; } } else if (ct.BranchCount > 0) { branches = ct.Branches; for (i = branches.Length - 1; i >= 0; i--) { this.mStackQueue[sqCount++] = branches[i]; } } } } // Pull movable branches towards their roots sqIndex = 0; sqCount = 1; this.mStackQueue[0] = dTree; while (sqIndex < sqCount) { ct = this.mStackQueue[sqIndex++]; cx = ct.NodeData.X; cy = ct.NodeData.Y; branches = ct.Branches; for (i = 0; i < branches.Length; i++) { ct = branches[i]; node = ct.NodeData; if (!node.PositionFixed) { fx = node.X; fy = node.Y; dx = ct.GeomData.OffsetX; dy = ct.GeomData.OffsetY; dist = Math.Sqrt(dx * dx + dy * dy); dx = cx - fx; dy = cy - fy; if (dx == 0 && dy == 0) { fx += dist / 10; fy += dist / 10; } else { // Magnetic Force r = dx * dx + dy * dy; force = ct.GeomData.OffsetX + dx; fx += this.mMagnetMult * Math.Pow(force, this.mMagnetExp) / r; force = ct.GeomData.OffsetY + dy; fy += this.mMagnetMult * Math.Pow(force, this.mMagnetExp) / r; // Spring Force r = Math.Sqrt(r); force = this.mSpringMult * Math.Log(r / dist); fx += force * dx / r; fy += force * dy / r;/* */ }/* */ /*dist = ct.GeomData.OffsetX; * r = cx - fx; * fx += r == 0 ? dist / 10 * : Math.Sign(dist) * this.mSpringMult * Math.Log(Math.Abs(r / dist)); * dist = ct.GeomData.OffsetY; * r = cy - fy; * fy += r == 0 ? dist / 10 * : Math.Sign(dist) * this.mSpringMult * Math.Log(Math.Abs(r / dist));/* */ // Apply force to node position node.SetPosition((float)fx, (float)fy); } this.mStackQueue[sqCount++] = ct; } } }
public SelectItemFromTreeViewModel(GTree Tree) { this.Tree = Tree; }