private void Nesting_CreateMitosisGraph(DGraph graph) { DNode inNode = graph.AddNode("Mi_in"); inNode.DrawingNode.Attr.Shape = MsaglShape.Circle; inNode.DrawingNode.Attr.FillColor = MsaglColor.Red; DNode g0Node = Nesting_Cell_AddNode(graph, "Mi_g0", "G0"); DNode cycleNode = Nesting_Cell_AddNode(graph, "Mi_cycle", null); DGraph cycleGraph = new DGraph() { Name = "Mitosis Cycle" }; cycleGraph.ConfigureIncrementalLayout(); DNode c_G1_Node = Nesting_Cell_AddNode(cycleGraph, "Mi_cycle_G1", "G1"); DNode c_S_Node = Nesting_Cell_AddNode(cycleGraph, "Mi_cycle_S", "S"); DNode c_G2_Node = Nesting_Cell_AddNode(cycleGraph, "Mi_cycle_G2", "G2"); DNode c_M_Node = Nesting_Cell_AddNode(cycleGraph, "Mi_cycle_M", "M"); Nesting_Cell_AddEdge(cycleGraph, c_G1_Node, c_S_Node, null); Nesting_Cell_AddEdge(cycleGraph, c_S_Node, c_G2_Node, null); Nesting_Cell_AddEdge(cycleGraph, c_G2_Node, c_M_Node, null); cycleNode.Label = new DNestedGraphLabel(cycleNode, cycleGraph); Nesting_Cell_AddEdge(graph, cycleNode, g0Node, "exit cell\ncycle"); Nesting_Cell_AddEdge(graph, inNode, g0Node, null); DEdge g0_g1_edge = graph.AddEdgeBetweenNodes(g0Node, c_G1_Node); g0_g1_edge.DrawingEdge.Attr.Color = MsaglColor.Red;//*/ }
private void Nesting_CreateMeiosisGraph(DGraph graph) { DNode interNode = Nesting_Cell_AddNode(graph, "Me_inter", "Inter"); DNode restNode = Nesting_Cell_AddNode(graph, "Me_rest", "Rest"); DNode cycleNode = Nesting_Cell_AddNode(graph, "Me_cycle", null); DGraph cycleGraph = new DGraph() { Name = "Meiosis Cycle" }; cycleGraph.ConfigureSugiyamaLayout(Math.PI / 2.0); DNode c_Pro_Node = Nesting_Cell_AddNode(cycleGraph, "Me_cycle_Pro", "Pro"); DNode c_Meta_Node = Nesting_Cell_AddNode(cycleGraph, "Me_cycle_Meta", "Meta"); DNode c_Ana_Node = Nesting_Cell_AddNode(cycleGraph, "Me_cycle_Ana", "Ana"); DNode c_Telo_Node = Nesting_Cell_AddNode(cycleGraph, "Me_cycle_Telo", "Telo"); Nesting_Cell_AddEdge(cycleGraph, c_Pro_Node, c_Meta_Node, null); Nesting_Cell_AddEdge(cycleGraph, c_Meta_Node, c_Ana_Node, null); Nesting_Cell_AddEdge(cycleGraph, c_Ana_Node, c_Telo_Node, null); cycleNode.Label = new DNestedGraphLabel(cycleNode, cycleGraph); Nesting_Cell_AddEdge(graph, cycleNode, interNode, "exit cell\ncycle"); Nesting_Cell_AddEdge(graph, cycleNode, restNode, null); DEdge inter_pro_edge = graph.AddEdgeBetweenNodes(interNode, c_Pro_Node); inter_pro_edge.DrawingEdge.Attr.Color = MsaglColor.Red;//*/ }
private void PrintVector2D(DEdge edg) { int x1 = VertexCoords[edg.Begin].x; int y1 = VertexCoords[edg.Begin].y; int x2 = VertexCoords[edg.End].x; int y2 = VertexCoords[edg.End].y; double tx = x1 - x2; double ty = y1 - y2; double sq = Math.Sqrt(tx * tx + ty * ty); tx /= sq; ty /= sq; double v1x = 6.5 * tx + ty; double v1y = 6.5 * ty - tx; double v2x = 6.5 * tx - ty; double v2y = 6.5 * ty + tx; sq = Math.Sqrt(v1x * v1x + v1y * v1y); v1x /= sq; v1y /= sq; sq = Math.Sqrt(v2x * v2x + v2y * v2y); v2x /= sq; v2y /= sq; Gl.glBegin(Gl.GL_LINES); Gl.glVertex2d(x1, y1); Gl.glVertex2d(x2, y2); Gl.glVertex2d(x2, y2); Gl.glVertex2d(x2 + 25 * v1x, y2 + 25 * v1y); Gl.glVertex2d(x2, y2); Gl.glVertex2d(x2 + 25 * v2x, y2 + 25 * v2y); Gl.glEnd(); }
private DEdge Nesting_Cell_AddEdge(DGraph graph, DNode source, DNode target, string label) { DEdge ret = graph.AddEdgeBetweenNodes(source, target); if (label != null) { ret.Label = new DTextLabel(ret, label); } ret.DrawingEdge.Attr.Color = MsaglColor.Red; return(ret); }
private void rozbicieKrawedzi(Object sender, EventArgs e) { String edgeName = ""; //List<int> edgeList = new List<int>(); ////String edgeName = rozbicieTextBox.Text; //List<String> firstNodes = new List<String>(); //List<String> secondNodes = new List<String>(); //if(listBox1.SelectedIndices.Count == 0) //{ // return; //} //TreeNode tree = trees[listBox1.SelectedIndices[0]]; foreach (IViewerObject kuku in viewer.Entities) { if (kuku.GetType().Name == "DEdge") { DEdge abc = (DEdge)kuku; //abc.SelectedForEditing; if (abc.SelectedForEditing) { edgeName = abc.Edge.LabelText; MessageBox.Show(abc.Edge.Source + " " + abc.Edge.Target); // IViewerNode target = ((IViewerEdge)kuku).Target; } //edgeList.Add(abc.Edge.LabelText.Length); } var adsdsa = kuku.GetType(); } //collectNodes(tree, edgeName, firstNodes, secondNodes, false); //String rozbicieText = ""; //rozbicieText = "{{"; //foreach (String nodeName in firstNodes) //{ // rozbicieText += nodeName + ", "; //} //rozbicieText.Remove(rozbicieText.Length - 1); //rozbicieText += "},\n\n{"; //foreach (String nodeName in secondNodes) //{ // rozbicieText += nodeName + ", "; //} //rozbicieText.Remove(rozbicieText.Length - 1); //rozbicieText += "}}"; //const string caption = "Rozbicie krawedzi"; //var result = MessageBox.Show(rozbicieText, caption, // MessageBoxButtons.OK, // MessageBoxIcon.Information); }
int FindNext(int p, int q) { if (q % 5 == 0) { float xp = nodes[p].x - nodes[q].x; float yp = nodes[p].y - nodes[q].y; int p1 = p + 1; if (p1 - q >= 5) { p1 -= 4; } float xp1 = nodes[p1].x - nodes[q].x; float yp1 = nodes[p1].y - nodes[q].y; int p3 = p + 3; if (p3 - q >= 5) { p3 -= 4; } float xp3 = nodes[p3].x - nodes[q].x; float yp3 = nodes[p3].y - nodes[q].y; float ax = xp1 - xp; float ay = yp1 - yp; float bx = xp3 - xp; float by = yp3 - yp; float orientation = ax * by - ay * bx; if (orientation > 0) { return(p3); } else { return(p1); } } else { for (int e = 0; e < edges.Count; e++) { DEdge ee = edges[e]; if (ee.visible) { if (ee.s == q && ee.t != p) { return(ee.t); } if (ee.t == q && ee.s != p) { return(ee.s); } } } } return(-1); }
private void graphViewer_MouseLeave(object sender, EventArgs e) { if (mHoveredDNode != null) { SetBranchHighlighted(mHoveredDNode, false); mHoveredDNode = null; } if (mHoveredDEdge != null) { mHoveredDEdge.DrawingEdge.Attr.LineWidth -= 2; graphViewer.Invalidate(mHoveredDEdge); mHoveredDEdge = null; graphViewer.SetToolTip(mHoveredEdgeTooltip, ""); } }
private void UpdateHoveredObjects(IViewerObject hoveredObject) { // Update hovered node. var dNode = hoveredObject as DNode; if (mHoveredDNode != dNode) { if (mHoveredDNode != null) { SetBranchHighlighted(mHoveredDNode, false); mHoveredDNode = null; } if (dNode != null) { GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(dNode.DrawingNode.Id); if (nodeData != null) { mHoveredDNode = dNode; SetBranchHighlighted(mHoveredDNode, true); } } } // Update hovered edge. var dEdge = hoveredObject as DEdge; if (mHoveredDEdge != dEdge) { if (mHoveredDEdge != null) { mHoveredDEdge.DrawingEdge.Attr.LineWidth -= 2; graphViewer.Invalidate(mHoveredDEdge); mHoveredDEdge = null; graphViewer.SetToolTip(mHoveredEdgeTooltip, ""); } if (dEdge != null) { dEdge.DrawingEdge.Attr.LineWidth += 2; graphViewer.Invalidate(dEdge); mHoveredDEdge = dEdge; graphViewer.SetToolTip(mHoveredEdgeTooltip, mHoveredDEdge.Edge.UserData as string); } } }
bool Collapse(DEdge E) { int index0 = 0; int index1 = 0; DPoint Center = E.Ends[0]; DPoint Moved = E.Ends[1]; Triangle F0 = E.Faces[0]; Triangle F1 = E.Faces[1]; Triangle tmpF = F0; DEdge tmpE; DEdge left; DEdge right; int indexT = 0; int tmpEi; bool needCollapse = true; List <Triangle> needMoveT = new List <Triangle>(); List <DEdge> needMoveE = new List <DEdge>(); List <int> Tindex = new List <int>(); List <int> Eindex = new List <int>(); if (F0 == F1) { if (Center.Additional) { return(false); for (int i = 0; i < 3; i++) { if (F0.Vertices[i] == Center) { index0 = i; } } if (F0.Vertices[(index0 + 1) % 3] == Moved) { // 時計回り探索 right = F0.Edges[(index0 + 1) % 3]; tmpE = right; int rigi = right.Ends[0] == Center ? 0 : 1; int debug = 0; while (tmpE.Faces[0] != tmpE.Faces[1]) { debug++; if (debug > 10) { Debug.Log("Timeout1"); break; } tmpEi = tmpE.Ends[0] == Center ? 0 : 1; tmpF = tmpE.Faces[tmpEi]; for (int i = 0; i < 3; i++) { if (tmpF.Vertices[i] == Center) { indexT = i; break; } } if (Area(Moved, tmpF.Vertices[(indexT + 1) % 3], tmpF.Vertices[(indexT + 2) % 3]) < 0.5f) { needCollapse = false; break; } needMoveE.Add(tmpE); Eindex.Add(tmpEi); needMoveT.Add(tmpF); Tindex.Add(indexT); tmpE = tmpF.Edges[(indexT + 1) % 3]; } left = tmpE; if (needCollapse) { if (left == right) { Debug.Log("Left == right"); Debug.Log("Movement: " + Center.Pos + " -> " + Moved.Pos); Debug.Log("left (right): " + left.Ends[0].Pos + " -> " + left.Ends[1].Pos); } for (int i = 0; i < needMoveE.Count; i++) { needMoveE[i].Ends[Eindex[i]] = Moved; } for (int i = 0; i < needMoveT.Count; i++) { needMoveT[i].Vertices[Tindex[i]] = Moved; } tmpEi = F0.Edges[index0].Ends[0] == Moved ? 0 : 1; if (F0.Edges[index0].Faces[(tmpEi + 1) % 2] == F0) { right.Faces[(rigi + 1) % 2] = right.Faces[rigi]; } else { if (F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[0] == F0.Edges[index0]) { F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[0] = right; } if (F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[1] == F0.Edges[index0]) { F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[1] = right; } if (F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[2] == F0.Edges[index0]) { F0.Edges[index0].Faces[(tmpEi + 1) % 2].Edges[2] = right; } right.Faces[(rigi + 1) % 2] = F0.Edges[index0].Faces[(tmpEi + 1) % 2]; } LefList.Remove(F0); return(true); } } else { return(false); if (F0.Vertices[(index0 + 2) % 3] != Moved) { return(false); // 本来あり得ないはずなのにたまにこれに行く 要検討 } // 反時計回り探索 left = F0.Edges[(index0 + 2) % 3]; tmpE = left; int debug = 0; while (tmpE.Faces[0] != tmpE.Faces[1]) { debug++; if (debug > 10) { Debug.Log("Timeout3"); break; } tmpEi = tmpE.Ends[0] == Center ? 0 : 1; tmpF = tmpE.Faces[(tmpEi + 1) % 2]; for (int i = 0; i < 3; i++) { if (tmpF.Vertices[i] == Center) { indexT = i; break; } } if (Area(Moved, tmpF.Vertices[(indexT + 1) % 3], tmpF.Vertices[(indexT + 2) % 3]) < 0.5f) { needCollapse = false; break; } needMoveE.Add(tmpE); Eindex.Add(tmpEi); needMoveT.Add(tmpF); Tindex.Add(indexT); tmpE = tmpF.Edges[(indexT + 2) % 3]; } right = tmpE; if (needCollapse) { for (int i = 0; i < needMoveE.Count; i++) { needMoveE[i].Ends[Eindex[i]] = Moved; } for (int i = 0; i < needMoveT.Count; i++) { needMoveT[i].Vertices[Tindex[i]] = Moved; } tmpEi = F0.Edges[index0].Ends[0] == Moved ? 0 : 1; if (F0.Edges[index0].Faces[tmpEi] == F0) { Debug.Log("Eindex[0]: " + Eindex[0]); left.Faces[Eindex[0]] = left.Faces[(Eindex[0] + 1) % 2]; } else { if (F0.Edges[index0].Faces[tmpEi].Edges[0] == F0.Edges[index0]) { F0.Edges[index0].Faces[tmpEi].Edges[0] = left; } if (F0.Edges[index0].Faces[tmpEi].Edges[1] == F0.Edges[index0]) { F0.Edges[index0].Faces[tmpEi].Edges[1] = left; } if (F0.Edges[index0].Faces[tmpEi].Edges[2] == F0.Edges[index0]) { F0.Edges[index0].Faces[tmpEi].Edges[2] = left; } left.Faces[Eindex[0]] = F0.Edges[index0].Faces[tmpEi]; } LefList.Remove(F0); return(true); } } } return(false); } else { for (int i = 0; i < 3; i++) { if (F1.Vertices[i] == Center) { index1 = i; break; } } left = F1.Edges[(index1 + 2) % 3]; for (int i = 0; i < 3; i++) { if (F0.Vertices[i] == Center) { index0 = i; break; } } right = F0.Edges[(index0 + 1) % 3]; tmpE = right; int debug = 0; do { debug++; if (debug > 20) { Debug.Log("Timeout 2"); break; } if (tmpE.Faces[0] == tmpE.Faces[1]) // 輪郭が変わるような変形はNG → F0.Vertices[index0] が端なら これの移動はあきらめる { needCollapse = false; break; } needMoveE.Add(tmpE); // right は要素の最初 Eindex.Add(tmpE.Ends[0] == Center ? 0 : 1); tmpF = tmpE.Faces[tmpE.Ends[0] == Center ? 0 : 1]; for (int i = 0; i < 3; i++) { if (tmpF.Vertices[i] == Center) { indexT = i; break; } } if (Area(Moved, tmpF.Vertices[(indexT + 1) % 3], tmpF.Vertices[(indexT + 2) % 3]) <= 0.5f) { needCollapse = false; break; } needMoveT.Add(tmpF); Tindex.Add(indexT); tmpE = tmpF.Edges[(indexT + 1) % 3]; } while (tmpE != left); if (needCollapse) { for (int i = 0; i < Tindex.Count; i++) { needMoveT[i].Vertices[Tindex[i]] = Moved; } for (int i = 0; i < Eindex.Count; i++) { needMoveE[i].Ends[Eindex[i]] = Moved; } // 左 F1 側の参照関係修正 if (F1.Edges[index1].Faces[0] == F1.Edges[index1].Faces[1]) // left が輪郭辺となるとき { if (left.Ends[0] == Center) { left.Ends[0] = Moved; left.Faces[0] = left.Faces[1]; } else { left.Ends[1] = Moved; left.Faces[1] = left.Faces[0]; } } else { // leftが輪郭辺とならないとき if (left.Ends[0] == Center) { left.Ends[0] = Moved; if (F1.Edges[index1].Faces[0] == F1) { left.Faces[0] = F1.Edges[index1].Faces[1]; } else { left.Faces[0] = F1.Edges[index1].Faces[0]; } if (left.Faces[0].Edges[0] == F1.Edges[index1]) { left.Faces[0].Edges[0] = left; } if (left.Faces[0].Edges[1] == F1.Edges[index1]) { left.Faces[0].Edges[1] = left; } if (left.Faces[0].Edges[2] == F1.Edges[index1]) { left.Faces[0].Edges[2] = left; } } else { left.Ends[1] = Moved; if (F1.Edges[index1].Faces[0] == F1) { left.Faces[1] = F1.Edges[index1].Faces[1]; } else { left.Faces[1] = F1.Edges[index1].Faces[0]; } if (left.Faces[1].Edges[0] == F1.Edges[index1]) { left.Faces[1].Edges[0] = left; } if (left.Faces[1].Edges[1] == F1.Edges[index1]) { left.Faces[1].Edges[1] = left; } if (left.Faces[1].Edges[2] == F1.Edges[index1]) { left.Faces[1].Edges[2] = left; } } } if (F0.Edges[index0].Faces[0] == F0.Edges[index0].Faces[1]) // right が輪郭辺となるとき { right.Faces[(Eindex[0] + 1) % 2] = right.Faces[Eindex[0]]; } else { if (F0.Edges[index0].Faces[0] == F0) // 右 F0 側の参照関係修正 { right.Faces[(Eindex[0] + 1) % 2] = F0.Edges[index0].Faces[1]; } else { right.Faces[(Eindex[0] + 1) % 2] = F0.Edges[index0].Faces[0]; } if (right.Faces[(Eindex[0] + 1) % 2].Edges[0] == F0.Edges[index0]) { right.Faces[(Eindex[0] + 1) % 2].Edges[0] = right; } if (right.Faces[(Eindex[0] + 1) % 2].Edges[1] == F0.Edges[index0]) { right.Faces[(Eindex[0] + 1) % 2].Edges[1] = right; } if (right.Faces[(Eindex[0] + 1) % 2].Edges[2] == F0.Edges[index0]) { right.Faces[(Eindex[0] + 1) % 2].Edges[2] = right; } } LefList.Remove(F0); LefList.Remove(F1); return(true); } } return(false); }
bool Flip(DEdge E) { int index0 = 0; int index1 = 0; Triangle F0 = E.Faces[0]; Triangle F1 = E.Faces[1]; if (F0 != F1) { for (int i = 0; i < 3; i++) { if (F0.Edges[i] == E) { index0 = i; break; } } for (int i = 0; i < 3; i++) { if (F1.Edges[i] == E) { index1 = i; break; } } bool neadFlip = true; if (Area(F0.Vertices[index0], F0.Vertices[(index0 + 1) % 3], F1.Vertices[index1]) <= 0.5f || Area(F1.Vertices[index1], F1.Vertices[(index1 + 1) % 3], F0.Vertices[index0]) <= 0.5f) { neadFlip = false; } if (neadFlip) { DEdge Flipped = new DEdge(F0.Vertices[index0], F1.Vertices[index1], F1, F0); F0.Vertices[(index0 + 2) % 3] = F1.Vertices[index1]; F0.Edges[index0] = F1.Edges[(index1 + 1) % 3]; F1.Vertices[(index1 + 2) % 3] = F0.Vertices[index0]; F1.Edges[index1] = F0.Edges[(index0 + 1) % 3]; F0.Edges[(index0 + 1) % 3] = Flipped; F1.Edges[(index1 + 1) % 3] = Flipped; if (F0.Edges[index0].Faces[0] == F1) { F0.Edges[index0].Faces[0] = F0; } if (F0.Edges[index0].Faces[1] == F1) { F0.Edges[index0].Faces[1] = F0; } if (F1.Edges[index1].Faces[0] == F0) { F1.Edges[index1].Faces[0] = F1; } if (F1.Edges[index1].Faces[1] == F0) { F1.Edges[index1].Faces[1] = F1; } return(true); } } return(false); }
bool Split(DEdge E) { if (Area(E.Faces[0]) < 1.0f) { return(false); } if (Area(E.Faces[1]) < 1.0f) { return(false); } if (Vector2.Distance(E.Ends[0].Pos, E.Ends[1].Pos) < 2.0f) { return(false); } int index0 = 0; int index1 = 0; DPoint MidP = new DPoint((E.Ends[0].Pos + E.Ends[1].Pos) / 2.0f); MidP.Additional = true; PoiList.Add(MidP); Triangle F0 = E.Faces[0]; Triangle F1 = E.Faces[1]; for (int i = 0; i < 3; i++) { if (F0.Edges[i] == E) { index0 = i; break; } } Triangle NewF0 = new Triangle(F0.Vertices[index0], MidP, F0.Vertices[(index0 + 2) % 3]); LefList.Add(NewF0); NewF0.Edges[1] = F0.Edges[(index0 + 1) % 3]; DEdge split0 = new DEdge(F0.Vertices[index0], MidP, NewF0, F0); NewF0.Edges[2] = split0; F0.Edges[(index0 + 1) % 3] = split0; F0.Vertices[(index0 + 2) % 3] = MidP; F0.Edges[index0].Ends[1] = MidP; F0.Edges[index0].Ends[0] = F0.Vertices[(index0 + 1) % 3]; if (NewF0.Edges[1].Faces[0] == F0) { NewF0.Edges[1].Faces[0] = NewF0; } if (NewF0.Edges[1].Faces[1] == F0) { NewF0.Edges[1].Faces[1] = NewF0; } if (F0 == F1) { DEdge add0 = new DEdge(NewF0.Vertices[1], NewF0.Vertices[2], NewF0, NewF0); NewF0.Edges[0] = add0; } else { for (int i = 0; i < 3; i++) { if (E.Faces[1].Edges[i] == E) { index1 = i; break; } } Triangle NewF1 = new Triangle(F1.Vertices[index1], F1.Vertices[(index1 + 1) % 3], MidP); LefList.Add(NewF1); NewF0.Edges[0] = new DEdge(MidP, NewF0.Vertices[2], NewF0, NewF1); F1.Vertices[(index1 + 1) % 3] = MidP; DEdge split1 = new DEdge(F1.Vertices[index1], MidP, F1, NewF1); NewF1.Edges[0] = NewF0.Edges[0]; NewF1.Edges[1] = split1; NewF1.Edges[2] = F1.Edges[(index1 + 2) % 3]; F1.Edges[(index1 + 2) % 3] = split1; if (NewF1.Edges[2].Faces[0] == F1) { NewF1.Edges[2].Faces[0] = NewF1; } if (NewF1.Edges[2].Faces[1] == F1) { NewF1.Edges[2].Faces[1] = NewF1; } } return(true); }
void FindTriangle() { int nSize = nodes.Count; outer = new int[nSize]; for (int a = 0; a < nSize; a++) { outer[a] = -1; } int forSize = nSize / 5; for (int a = 0; a < forSize; a++) { for (int b = a + 1; b < forSize; b++) { for (int c = b + 1; c < forSize; c++) { int eAB_a = -1, eAB_b = -1; int eBC_b = -1, eBC_c = -1; int eCA_c = -1, eCA_a = -1; for (int e = 0; e < edges.Count; e++) { DEdge ee = edges[e]; int s = (int)(ee.s / 5); int t = (int)(ee.t / 5); if (s == a && t == b) { eAB_a = ee.s; eAB_b = ee.t; } else if (s == b && t == a) { eAB_b = ee.s; eAB_a = ee.t; } else if (s == b && t == c) { eBC_b = ee.s; eBC_c = ee.t; } else if (s == c && t == b) { eBC_c = ee.s; eBC_b = ee.t; } else if (s == c && t == a) { eCA_c = ee.s; eCA_a = ee.t; } else if (s == a && t == c) { eCA_a = ee.s; eCA_c = ee.t; } } if (eAB_a != -1 && eBC_b != -1 && eCA_c != -1) { Debug.Log("三角形見つけた!"); Debug.Log(eAB_a + "," + eAB_b + "," + eBC_b + "," + eBC_c + "," + eCA_c + "," + eCA_a); outer[0] = eCA_a; outer[1] = eAB_a; outer[2] = eAB_b; outer[3] = eBC_b; outer[4] = eBC_c; outer[5] = eCA_c; outerCount = 6; return; } } } } }
void OutputData() { int nodeNumber = nodes.Count; thisKnot.ClearAll(); for (int n = 0; n < nodeNumber; n++) { DNode nn = nodes[n]; if (n % 5 == 0) { // ジョイント Node nd = thisKnot.AddNode(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n Bead bd = thisKnot.AddBead(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n if (nn.ou) { nd.Theta = Mathf.Atan2(nodes[n + 1].y - nodes[n].y, nodes[n + 1].x - nodes[n].x); } else { nd.Theta = Mathf.Atan2(nodes[n + 2].y - nodes[n].y, nodes[n + 1].x - nodes[n].x); } nd.R[0] = nd.R[1] = nd.R[2] = nd.R[3] = 0.1f; nd.ID = n; nd.Joint = true; nd.MidJoint = false; bd.NumOfNbhd = 4; //あとで設定 bd.N1 = bd.N2 = null; //あとで設定 bd.U1 = bd.U2 = null; //あとで設定 bd.ID = n; bd.Joint = true; bd.MidJoint = false; nd.ThisBead = bd; } else { //非ジョイント Bead bd = thisKnot.AddBead(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n bd.NumOfNbhd = 2; //あとで設定 bd.N1 = bd.N2 = null; //あとで設定 bd.U1 = bd.U2 = null; //あとで設定 bd.ID = n; bd.Joint = false; bd.MidJoint = false; } } int BeadLastID = thisKnot.GetMaxIDOfBead(); // edges int A = -1, AR = -1, B = -1, BR = -1; for (int e = 0; e < edges.Count; e++) { DEdge ee = edges[e]; if (ee.visible) { A = AR = B = BR = -1; if (ee.s % 5 != 0 && ee.t % 5 != 0) { for (int es = 0; es < edges.Count; es++) { DEdge ees = edges[es]; // ee.sからたどれるジョイントを見つける if (ees.visible && ees.s % 5 == 0 && ees.t == ee.s) { int s0 = ees.s; float aX = nodes[s0 + 2].x - nodes[s0 + 1].x; float aY = nodes[s0 + 2].y - nodes[s0 + 1].y; float bX = nodes[s0 + 4].x - nodes[s0 + 1].x; float bY = nodes[s0 + 4].y - nodes[s0 + 1].y; float orientation = aX * bY - aY * bX; int t = ees.t - ees.s; if (orientation > 0) { if (nodes[ees.s].ou) { t = (t + 7) % 4; } else { t = (t + 6) % 4; } } else { if (nodes[ees.s].ou) { t = (5 - t) % 4; } else { t = (6 - t) % 4; } } A = ees.s;// ee.sからたどれるジョイント AR = t; } // ee.tからたどれるジョイント if (ees.visible && ees.s % 5 == 0 && ees.t == ee.t) { int s0 = ees.s; float aX = nodes[s0 + 2].x - nodes[s0 + 1].x; float aY = nodes[s0 + 2].y - nodes[s0 + 1].y; float bX = nodes[s0 + 4].x - nodes[s0 + 1].x; float bY = nodes[s0 + 4].y - nodes[s0 + 1].y; float orientation = aX * bY - aY * bX; int t = ees.t - ees.s; if (orientation > 0) { if (nodes[ees.s].ou) { t = (t + 7) % 4; } else { t = (t + 6) % 4; } } else { if (nodes[ees.s].ou) { t = (5 - t) % 4; } else { t = (6 - t) % 4; } } B = ees.s;// ee.tからたどれるジョイント BR = t; } } //// Edge ed = thisKnot.AddEdge(A, B, AR, BR, e); // iD = e (連番に限らない。) Bead bdJointA = thisKnot.GetBeadByID(A); Bead bdAR = thisKnot.GetBeadByID(ee.s); Bead bdBR = thisKnot.GetBeadByID(ee.t); Bead bdJointB = thisKnot.GetBeadByID(B); if (bdJointA == null || bdAR == null || bdBR == null || bdJointB == null) { continue; } bdJointA.SetNU12(AR, bdAR); bdAR.N1 = bdJointA; bdAR.N2 = bdBR; bdBR.N1 = bdJointB; bdBR.N2 = bdAR; bdJointB.SetNU12(BR, bdBR); } } } thisKnot.GetAllThings(); thisKnot.Modify(); // NodeEdgeからBeadsを整える thisKnot.UpdateBeads(); //グラフの形を整える。現状ではR[]を整えるだけ。 thisKnot.Modify(); Display.SetDrawKnotMode();// drawモードの変更 }
void DowkerModify() { int len = nodes.Count; //外周は固定する for (int a = 0; a < outerCount; a++) { nodes[outer[a]].x = 400 + 300 * Mathf.Cos(Mathf.PI * 2 * a / outerCount); nodes[outer[a]].y = 400 - 300 * Mathf.Sin(Mathf.PI * 2 * a / outerCount); } float[] dx = new float[len]; float[] dy = new float[len]; for (int repeat = 0; repeat < 2000; repeat++) { for (int n = 0; n < len; n++) { dx[n] = dy[n] = 0f; } for (int n = 0; n < len; n++) { DNode nn = nodes[n]; float zx = 0; float zy = 0; int count = 0; for (int e = 0; e < edges.Count; e++) { DEdge ee = edges[e]; if (ee.s == n) { zx += nodes[ee.t].x; zy += nodes[ee.t].y; count++; } else if (ee.t == n) { zx += nodes[ee.s].x; zy += nodes[ee.s].y; count++; } } zx /= count; zy /= count; float ax = zx - nn.x; float ay = zy - nn.y; ax *= 0.1f; ay *= 0.1f; dx[n] = ax; dy[n] = ay; } for (int n = 0; n < len; n++) { bool OK = true; for (int a = 0; a < outerCount; a++) { if (n == outer[a]) { OK = false; break; } } if (OK) { DNode nn = nodes[n]; nn.x += dx[n]; nn.y += dy[n]; } } } }
private void Nesting_CreateProliferationGraph(DGraph graph) { DNode inNode = graph.AddNode("Pr_in"); inNode.DrawingNode.Attr.Shape = MsaglShape.Circle; inNode.DrawingNode.Attr.FillColor = MsaglColor.Red; DNode mitosisNode = Nesting_Cell_AddNode(graph, "Pr_mitosis", null); Grid mitosisContainer = new Grid(); mitosisContainer.RowDefinitions.Add(new RowDefinition()); mitosisContainer.RowDefinitions.Add(new RowDefinition()); mitosisContainer.Children.Add(new TextBlock() { Text = "Mitosis", TextAlignment = TextAlignment.Center, FontWeight = FontWeights.Bold }); mitosisNode.Label = new DNestedGraphLabel(mitosisNode, mitosisContainer); DGraph mitosisGraph = new DGraph(mitosisNode.Label as DNestedGraphLabel) { Name = "Mitosis" }; Nesting_CreateMitosisGraph(mitosisGraph); Grid.SetRow(mitosisGraph, 1); mitosisContainer.Children.Add(mitosisGraph); (mitosisNode.Label as DNestedGraphLabel).Graphs.Add(mitosisGraph); DNode splitterNode = graph.AddNode("Pr_sp"); splitterNode.DrawingNode.Attr.Shape = MsaglShape.Circle; splitterNode.DrawingNode.Attr.FillColor = MsaglColor.Blue; DNode meiosisNode = Nesting_Cell_AddNode(graph, "Pr_meiosis", null); Grid meiosisContainer = new Grid(); meiosisContainer.RowDefinitions.Add(new RowDefinition()); meiosisContainer.RowDefinitions.Add(new RowDefinition()); meiosisContainer.Children.Add(new TextBlock() { Text = "Meiosis", TextAlignment = TextAlignment.Center, FontWeight = FontWeights.Bold }); meiosisNode.Label = new DNestedGraphLabel(meiosisNode, meiosisContainer); DGraph meiosisGraph = new DGraph(meiosisNode.Label as DNestedGraphLabel) { Name = "Meiosis" }; Nesting_CreateMeiosisGraph(meiosisGraph); Grid.SetRow(meiosisGraph, 1); meiosisContainer.Children.Add(meiosisGraph); (meiosisNode.Label as DNestedGraphLabel).Graphs.Add(meiosisGraph); Nesting_Cell_AddEdge(graph, inNode, mitosisNode, null); Nesting_Cell_AddEdge(graph, mitosisNode, splitterNode, "Early Meiosis"); DEdge splitter_g0_edge = graph.AddEdgeBetweenNodes(splitterNode, mitosisGraph.NodeMap["Mi_g0"]); splitter_g0_edge.DrawingEdge.Attr.Color = MsaglColor.Red; DEdge splitter_inter_edge = graph.AddEdgeBetweenNodes(splitterNode, meiosisGraph.NodeMap["Me_inter"]); splitter_inter_edge.DrawingEdge.Attr.Color = MsaglColor.Red;//*/ }
private void CreateNestedGraph() { var g = GraphControlForNesting.Graph; // Create first nested graph. var inner1 = new DGraph() { Name = "Inner 1" }; var node11 = inner1.AddNode("ID1.1"); var node12 = inner1.AddNode("ID1.2"); var edge11_12 = inner1.AddEdgeBetweenNodes(node11, node12); // Create second nested graph. var inner3 = new DGraph() { Name = "Inner 2" }; var node31 = inner3.AddNode("ID3.1"); var node32 = inner3.AddNode("ID3.2"); var edge31_32 = inner3.AddEdgeBetweenNodes(node31, node32); // Create outer graph. var node1 = g.AddNode("ID1"); node1.Label = new DNestedGraphLabel(node1, inner1); node1.DrawingNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; var node2 = g.AddNode("ID2"); var node3 = g.AddNode("ID3"); node3.Label = new DNestedGraphLabel(node3, inner3); node3.DrawingNode.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Box; var edge1_2 = g.AddEdgeBetweenNodes(node1, node2); var edge2_3 = g.AddEdgeBetweenNodes(node2, node3); // Set some labels. node11.Label = new DTextLabel(node11) { Text = "Node 1.1" }; node12.Label = new DTextLabel(node12) { Text = "Node 1.2" }; node31.Label = new DTextLabel(node31) { Text = "Node 3.1" }; node32.Label = new DTextLabel(node32) { Text = "Node 3.2" }; node2.Label = new DTextLabel(node2) { Text = "Node 2" }; DEdge crossEdge1 = g.AddEdgeBetweenNodes(node11, node3); crossEdge1.Label = new DTextLabel(crossEdge1, "cross edge"); DEdge crossEdge2 = g.AddEdgeBetweenNodes(node12, node31); g.BeginLayout(); }
void AddDPoint(DPoint P, Triangle T) { T.Children.Add(new Triangle(P, T.Vertices[0], T.Vertices[1])); T.Children.Add(new Triangle(P, T.Vertices[1], T.Vertices[2])); T.Children.Add(new Triangle(P, T.Vertices[2], T.Vertices[0])); T.Children[0].Edges[0] = T.Edges[2]; T.Children[1].Edges[0] = T.Edges[0]; T.Children[2].Edges[0] = T.Edges[1]; T.Children[0].Edges[2] = T.Children[2].Edges[1] = new DEdge(P, T.Vertices[0], T.Children[0], T.Children[2]); T.Children[0].Edges[1] = T.Children[1].Edges[2] = new DEdge(P, T.Vertices[1], T.Children[1], T.Children[0]); T.Children[1].Edges[1] = T.Children[2].Edges[2] = new DEdge(P, T.Vertices[2], T.Children[2], T.Children[1]); // もともとの三角形の稜線について、参照先の三角形を分割後のものに変更する if (T.Edges[0].Faces[0] == T) { T.Edges[0].Faces[0] = T.Children[1]; // 一番外側にある辺のFacesは同じものを指すようにしている } if (T.Edges[0].Faces[1] == T) { T.Edges[0].Faces[1] = T.Children[1]; } if (T.Edges[1].Faces[0] == T) { T.Edges[1].Faces[0] = T.Children[2]; } if (T.Edges[1].Faces[1] == T) { T.Edges[1].Faces[1] = T.Children[2]; } if (T.Edges[2].Faces[0] == T) { T.Edges[2].Faces[0] = T.Children[0]; } if (T.Edges[2].Faces[1] == T) { T.Edges[2].Faces[1] = T.Children[0]; } PoiList.Add(P); ; TriList.Remove(T); TriList.Add(T.Children[0]); TriList.Add(T.Children[1]); TriList.Add(T.Children[2]); // 違反辺チェック&フリップ処理 List <DEdge> doubtful = new List <DEdge>(); doubtful.Add(T.Edges[0]); doubtful.Add(T.Edges[1]); doubtful.Add(T.Edges[2]); while (doubtful.Count > 0) { if (doubtful[0].Faces[0] == doubtful[0].Faces[1]) // 一番外側の辺なら無条件で違反辺疑惑解除 { doubtful.RemoveAt(0); continue; } // 疑わしい辺がFaces[1]にとって何番目なのか: 向かい側の頂点がFaces[1]にとって何番目なのか を調べる int index0 = 0; int index1 = 0; for (int i = 0; i < 3; i++) { if (doubtful[0].Faces[1].Edges[i] == doubtful[0]) { index1 = i; break; } } if (doubtful[0].Faces[0].circleinclude(doubtful[0].Faces[1].Vertices[index1])) // Faces[0]の外接円がFaces[1]上の向かい側の点を含むなら { Triangle T0 = doubtful[0].Faces[0]; Triangle T1 = doubtful[0].Faces[1]; for (int i = 0; i < 3; i++) { // 同じようにFaces[0]についても頂点インデックスを調べる if (doubtful[0].Faces[0].Edges[i] == doubtful[0]) { index0 = i; break; } } // 新たな稜線・面の生成 DEdge Flipped = new DEdge(T0.Vertices[index0], T1.Vertices[index1], new Triangle(T0.Vertices[index0], T1.Vertices[index1], T0.Vertices[(index0 + 2) % 3]), new Triangle(T1.Vertices[index1], T0.Vertices[index0], T1.Vertices[(index1 + 2) % 3]) ); // 新たな面の参照関係の変更 Flipped.Faces[0].Edges[0] = T1.Edges[(index1 + 2) % 3]; Flipped.Faces[0].Edges[1] = T0.Edges[(index0 + 1) % 3]; Flipped.Faces[0].Edges[2] = Flipped; Flipped.Faces[1].Edges[0] = T0.Edges[(index0 + 2) % 3]; Flipped.Faces[1].Edges[1] = T1.Edges[(index1 + 1) % 3]; Flipped.Faces[1].Edges[2] = Flipped; // 元の面についての処理 T0.Children.Add(Flipped.Faces[0]); T0.Children.Add(Flipped.Faces[1]); T1.Children.Add(Flipped.Faces[0]); T1.Children.Add(Flipped.Faces[1]); // 周辺の稜線についての処理 if (T0.Edges[(index0 + 1) % 3].Faces[0] == T0) { T0.Edges[(index0 + 1) % 3].Faces[0] = Flipped.Faces[0]; } if (T0.Edges[(index0 + 1) % 3].Faces[1] == T0) { T0.Edges[(index0 + 1) % 3].Faces[1] = Flipped.Faces[0]; } if (T0.Edges[(index0 + 2) % 3].Faces[0] == T0) { T0.Edges[(index0 + 2) % 3].Faces[0] = Flipped.Faces[1]; } if (T0.Edges[(index0 + 2) % 3].Faces[1] == T0) { T0.Edges[(index0 + 2) % 3].Faces[1] = Flipped.Faces[1]; } if (T1.Edges[(index1 + 1) % 3].Faces[0] == T1) { T1.Edges[(index1 + 1) % 3].Faces[0] = Flipped.Faces[1]; } if (T1.Edges[(index1 + 1) % 3].Faces[1] == T1) { T1.Edges[(index1 + 1) % 3].Faces[1] = Flipped.Faces[1]; } if (T1.Edges[(index1 + 2) % 3].Faces[0] == T1) { T1.Edges[(index1 + 2) % 3].Faces[0] = Flipped.Faces[0]; } if (T1.Edges[(index1 + 2) % 3].Faces[1] == T1) { T1.Edges[(index1 + 2) % 3].Faces[1] = Flipped.Faces[0]; } // 描画のためのリストの処理 TriList.Remove(T0); TriList.Remove(T1); TriList.Add(Flipped.Faces[0]); TriList.Add(Flipped.Faces[1]); // 疑惑リストの変更 doubtful.RemoveAt(0); doubtful.Add(T0.Edges[(index0 + 1) % 3]); doubtful.Add(T0.Edges[(index0 + 2) % 3]); doubtful.Add(T1.Edges[(index1 + 1) % 3]); doubtful.Add(T1.Edges[(index1 + 2) % 3]); } else { doubtful.RemoveAt(0); } } }