/// <summary> /// move gird /// </summary> void move_gird() { if (move_way == MOVE_WAY.SINGLE) { grid_array.pCol [grid_array.foucs_col].pRow [grid_array.foucs_row].pt.y += move_shift.y; grid_array.pCol [grid_array.foucs_col].pRow [grid_array.foucs_row].pt.x += move_shift.x; } else if (move_way == MOVE_WAY.FOUR_CONNER) { move_gird_four_conner(); } else if (move_way == MOVE_WAY.BY_COL) { move_gird_by_col(); } else if (move_way == MOVE_WAY.BY_ROW) { move_gird_by_row(); } else if (move_way == MOVE_WAY.SINGLE_SMOOTH) { move_gird_by_single_smooth(); } for (int ti = 0; ti < edge_sides.Length; ti++) { EDGE e = edge_sides[ti]; e.isUpdate = true; } UpdateAll(); }
Create_NFAConcatenation (NFA_GRAPH graphOne, NFA_GRAPH graphTwo) { NFA_GRAPH newGraph = null; if (graphOne == null && graphTwo != null) { newGraph = graphTwo; } else if (graphOne != null && graphTwo == null) { newGraph = graphOne; } else if (graphOne != null && graphTwo != null) { graphOne.endNode.nodeType = NODE_TYPE.TRANSITIONING; graphTwo.startNode.nodeType = NODE_TYPE.TRANSITIONING; EDGE newEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, graphTwo.startNode); graphOne.endNode.edges.Add(newEdge); graphOne.endNode = graphTwo.endNode; newGraph = graphOne; } return(newGraph); }
public static BOOL DrawEdge(HandleRef hdc, ref RECT qrc, EDGE edge, BF grfFlags) { BOOL result = DrawEdge(hdc.Handle, ref qrc, edge, grfFlags); GC.KeepAlive(hdc.Wrapper); return(result); }
public static NFA_GRAPH Create_NFAKleeneClosure(NFA_GRAPH nfaGraph) { NFA_GRAPH newGraph = null; if (nfaGraph != null) { nfaGraph.startNode.nodeType = NODE_TYPE.TRANSITIONING; nfaGraph.endNode.nodeType = NODE_TYPE.TRANSITIONING; NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); EDGE endEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); nfaGraph.endNode.edges.Add(endEdge); EDGE endToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); nfaGraph.endNode.edges.Add(endToStartEdge); EDGE newStartToStartEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, nfaGraph.startNode); startNode.edges.Add(newStartToStartEdge); EDGE newStartToNewEndEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); startNode.edges.Add(newStartToNewEndEdge); newGraph = new NFA_GRAPH(startNode, endNode); } return(newGraph); }
public static Vertex[] GetParasolidVertices(this Edge edge) { unsafe { EDGE_t psEdge = (int)edge.GetParasolidTag(); List <Vertex> verticesList = new List <Vertex>(); VERTEX_t[] array = new VERTEX_t[2]; fixed(VERTEX_t *ptr = array) { EDGE.ask_vertices(psEdge, ptr); } VERTEX_t vertex_t = array[0]; VERTEX_t vertex_t2 = array[1]; if (vertex_t != VERTEX_t.@null) { verticesList.Add(new Vertex(vertex_t)); } if (vertex_t2 != VERTEX_t.@null && vertex_t2 != vertex_t) { verticesList.Add(new Vertex(vertex_t2)); } return(verticesList.ToArray()); } }
/// <summary> /// init edges add fours edge /// </summary> void InitEages() { for (int ti = 0; ti < edge_sides.Length; ti++) { edge_sides[ti] = new EDGE(); } edge_sides[0].edge_type = EDGE_WAY.LEFT; edge_sides[1].edge_type = EDGE_WAY.RIGHT; edge_sides[2].edge_type = EDGE_WAY.UP; edge_sides[3].edge_type = EDGE_WAY.DOWN; }
/// <summary> /// detect edge isOpen and create it or delete it /// </summary> void UpdateEdge() { for (int ti = 0; ti < edge_sides.Length; ti++) { EDGE e = edge_sides[ti]; if (!e.isUpdate) { continue; } e.isUpdate = false; if (e.isOpen) { if (e.edge_type == EDGE_WAY.LEFT) { made_edge_left(); } else if (e.edge_type == EDGE_WAY.RIGHT) { made_edge_right(); } else if (e.edge_type == EDGE_WAY.UP) { made_edge_up(); } else if (e.edge_type == EDGE_WAY.DOWN) { made_edge_down(); } } else { if (e.edge_type == EDGE_WAY.LEFT) { delete_edge("Edge_left"); } else if (e.edge_type == EDGE_WAY.RIGHT) { delete_edge("Edge_right"); } else if (e.edge_type == EDGE_WAY.UP) { delete_edge("Edge_up"); } else if (e.edge_type == EDGE_WAY.DOWN) { delete_edge("Edge_down"); } } } }
private void InitET(List <EDGE>[] edges, int minY) { List <int> tmpList = new List <int>(); EDGE e; for (int i = 0; i < points.Count; i++) { Point start = points[i]; Point end = points[(i + 1) % points.Count]; Point prevStart = points[(i - 1 + points.Count) % points.Count]; Point afterEnd = points[(i + 2) % points.Count]; if (start.Y != end.Y) { e = new EDGE(); e.SetDx(start, end); if (end.Y > start.Y) { e.SetX((double)start.X); if (afterEnd.Y >= end.Y) { e.SetYmax(end.Y - 1); } else { e.SetYmax(end.Y); } edges[start.Y - minY].Add(e); tmpList.Add(start.Y - minY); } else { e.SetX((double)end.X); if (prevStart.Y >= start.Y) { e.SetYmax(start.Y - 1); } else { e.SetYmax(start.Y); } edges[end.Y - minY].Add(e); tmpList.Add(end.Y - minY); } } } for (int i = 0; i < tmpList.Count; i++) { My_Sort(ref edges[tmpList[i]]); } }
Create_NFAOneChar (char character) { NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); EDGE edge = new EDGE(character, endNode); startNode.edges.Add(edge); NFA_GRAPH newGraph = new NFA_GRAPH(startNode, endNode); return(newGraph); }
/// <summary> /// 初始化新边表 /// 算法通过遍历所有的顶点获得边的信息,然后根据与此边有关的前后两个顶点的情况 /// 确定此边的ymax是否需要-1修正。ps和pe分别是当前处理边的起点和终点,pss是起 /// 点的前一个相邻点,pee是终点的后一个相邻点,pss和pee用于辅助判断ps和pe两个 /// 点是否是左顶点或右顶点,然后根据判断结果对此边的ymax进行-1修正,算法实现非 /// 常简单,注意与扫描线平行的边是不处理的,因为水平边直接在HorizonEdgeFill() /// 函数中填充了。 /// </summary> private void InitScanLineNewEdgeTable(List <EDGE>[] NET, List <Point> Q, int ymin, int ymax) { List <int> temp = new List <int>(); EDGE e; for (int i = 0; i < Q.Count; i++) { Point ps = Q[i]; Point pe = Q[(i + 1) % Q.Count]; Point pss = Q[(i - 1 + Q.Count) % Q.Count]; Point pee = Q[(i + 2) % Q.Count]; if (pe.Y != ps.Y)//不处理平行线 { e = new EDGE(); e.dx = (double)(pe.X - ps.X) / (double)(pe.Y - ps.Y) * XiangSu; if (pe.Y > ps.Y) { e.xi = ps.X; if (pee.Y >= pe.Y) { e.ymax = pe.Y - XiangSu; } else { e.ymax = pe.Y; } NET[ps.Y - ymin].Add(e);//加入对应的NET里 temp.Add(ps.Y - ymin); } else { e.xi = pe.X; if (pss.Y >= ps.Y) { e.ymax = ps.Y - XiangSu; } else { e.ymax = ps.Y; } NET[pe.Y - ymin].Add(e);//加入对应的NET里 temp.Add(pe.Y - ymin); } } } for (int i = 0; i < temp.Count; i++) { My_Sort(ref NET[temp[i]]); } }
public EDGE GetEdge <EDGE>() where EDGE : HBEdge { if (Edge == null) { return(null); } EDGE edge = Edge as EDGE; if (edge == null) { throw new InvalidCastException("Edge is not a " + typeof(EDGE)); } return(edge); }
private void My_Sort(ref List <EDGE> list) { EDGE d = new EDGE(); for (int i = 0; i < list.Count - 1; i++) { for (int j = i + 1; j < list.Count; j++) { if (list[j] < list[i]) { d = list[j]; list[j] = list[i]; list[i] = d; } } } }
public float this[EDGE Key] { get { switch (Key) { case EDGE.TopLeft: return(TopLeft); case EDGE.TopRight: return(TopRight); case EDGE.BottomLeft: return(BottomLeft); case EDGE.BottomRight: return(BottomRight); default: throw new ArgumentException(); } } }
/// <summary> /// open or close edge /// </summary> /// <param name="id"></param> public void change_edge(int id, ref float edge_gamma) { edge_sides[id].isOpen = !edge_sides[id].isOpen; edge_sides[id].isUpdate = true; if (edge_sides[id].isOpen) { focusedEdge = edge_sides[id]; } UpdateEdge(); if (edge_sides[id].mp_edge != null && edge_sides[id].mp_edge.gamma != null) { edge_gamma = edge_sides[id].mp_edge.gamma; } else if (edge_sides[id].mp_edge == null && edge_sides[id].preloadGamma != null) { edge_gamma = edge_sides[id].preloadGamma; } else { edge_gamma = 0.31f; } }
public static NFA_GRAPH Create_NFAUnion(NFA_GRAPH graphOne, NFA_GRAPH graphTwo) { NFA_GRAPH newGraph = null; if (graphOne == null && graphTwo != null) { newGraph = graphTwo; } else if (graphOne != null && graphTwo == null) { newGraph = graphOne; } else if (graphOne != null && graphTwo != null) { NODE startNode = NODE.CreateNode(NODE_TYPE.START); NODE endNode = NODE.CreateNode(NODE_TYPE.END); graphOne.startNode.nodeType = NODE_TYPE.TRANSITIONING; graphTwo.startNode.nodeType = NODE_TYPE.TRANSITIONING; graphOne.endNode.nodeType = NODE_TYPE.TRANSITIONING; graphTwo.endNode.nodeType = NODE_TYPE.TRANSITIONING; EDGE startOneEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, graphOne.startNode); EDGE startTwoEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, graphTwo.startNode); startNode.edges.Add(startOneEdge); startNode.edges.Add(startTwoEdge); EDGE endOneEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); EDGE endTwoEdge = new EDGE(CONSTANTS.EMPTY_SYMBOL, endNode); graphOne.endNode.edges.Add(endOneEdge); graphTwo.endNode.edges.Add(endTwoEdge); newGraph = new NFA_GRAPH(startNode, endNode); } return(newGraph); }
public static Graph <NODE, EDGE> BuildMST(Graph <NODE, EDGE> graph, Func <Edge, double> edgecost) { Func <Graph.Edge, double> fnedgecost = delegate(Graph.Edge edge) { return(edgecost((Edge)edge)); }; Graph <Graph.Node, Graph.Edge> mst = Graph.Kruskal.BuildMST(graph.graph, fnedgecost); Graph <NODE, EDGE> mst2 = new Graph <NODE, EDGE>(); foreach (Graph.Node node in mst.GetNodeValues()) { NODE nodeval = graph.GetNodeValue((Node)node); HDebug.Verify(mst2.AddNode(nodeval) != null); } foreach (Graph.Edge edge in mst.GetEdgeValues()) { EDGE edgeval = ((Edge)edge).value; Node node0 = (Node)edge.nodes[0]; NODE nodeval0 = graph.GetNodeValue(node0); HDebug.Assert(mst2.GetNode(nodeval0) != null); Node node1 = (Node)edge.nodes[1]; NODE nodeval1 = graph.GetNodeValue(node1); HDebug.Assert(mst2.GetNode(nodeval1) != null); HDebug.Verify(mst2.AddEdge(nodeval0, nodeval1, edgeval) != null); } return(mst2); }
/// <summary> /// load default grid ans reset edge /// </summary> public void LoadDefault() { for (int i = 0; i < grid_array.pCol.Count; i++) { for (int j = 0; j < grid_array.pCol[i].pRow.Count; j++) { grid_array.pCol[i].pRow[j].pt = grid_array.pCol[i].pRow[j].uv; } } for (int ti = 0; ti < edge_sides.Length; ti++) { EDGE e = edge_sides[ti]; e.isUpdate = true; e.isOpen = false; } _base_shift_rgb = Vector3.zero; set_screen_color(Vector3.zero); UpdateArray2Mesh(); UpdateVecOnly(); UpdateLines(); updateCtrlPt(); }
private bool IsEdgeOutOfActive(EDGE obj) { return(line == obj.ymax); }
public static partial BOOL DrawEdge(Gdi32.HDC hdc, ref RECT qrc, EDGE edge, BF grfFlags);
public Edge(int id, Graph.Node node1, Graph.Node node2, EDGE value) : base(id, node1, node2) { this.value = value; }
private void UpdateAetEdgeInfo(EDGE e) { e.xi += e.dx; }
public static extern BOOL DrawEdge(Gdi32.HDC hdc, ref RECT qrc, EDGE edge, BF grfFlags);
public static Edge New(int id, Graph.Node node1, Graph.Node node2, EDGE value) { return(new Edge(id, node1, node2, value)); }
public float this[EDGE Key] { get { switch (Key) { case EDGE.TopLeft: return TopLeft; case EDGE.TopRight: return TopRight; case EDGE.BottomLeft: return BottomLeft; case EDGE.BottomRight: return BottomRight; default : throw new ArgumentException(); } } }
// the main function of the unwrapper public static float[] Unwrap2D(float[] wrapped_image, float[] unwrapped_image, int image_width, int image_height) { // SJ, 200419 // Original algorithm took an input_mask for unwrapping, so that the user could specify pixels they weren't interested in, // an int indicating if the phase unwrapping should loop the x-image around such that the left border of the // image is unwrapped against the right border (wrap_around_x) and similar for top and bottom borders (wrap_around_y). // These are int values representing booleans (0:False, 1: True). // I removed the arguments to facilitate a cleaner interface. // params_t does not support initialization single-line - initializing here params_t myparams; myparams.mod = TWOPI; //myparams.x_connectivity = 0; // wrap_around_x //myparams.y_connectivity = 0; // wrap_around_y myparams.no_of_edges = 0; int image_size = image_height * image_width; int No_of_Edges_initially = 2 * image_width * image_height + 2 * image_width; // Allocate arrays that will be modified by the program //byte[] input_mask = new byte[image_size]; //for (int i = 0; i < image_size; i++) //{ // input_mask[i] = NOMASK; //} // Initialize arrays for extended_mask, PIXELM, and EDGES //byte[] extended_mask = new byte[image_size]; PIXELM[] pixel_array = new PIXELM[image_size]; EDGE[] edge_array = new EDGE[No_of_Edges_initially]; // Use the fixed statements to maintain arrays? fixed(float *wrapped_image_ptr = &wrapped_image[0]) { fixed(float *unwrapped_image_ptr = &unwrapped_image[0]) { fixed(PIXELM *pixel = &pixel_array[0]) { fixed(EDGE *edge = &edge_array[0]) { initialisePIXELs(wrapped_image_ptr, pixel, image_width, image_height); calculate_reliability(wrapped_image_ptr, pixel, image_width, image_height, &myparams); // TEST/DEBUG: Create a new array from the reliabilities to test //float[] reliab = new float[image_size]; //for (int pp=0; pp<image_size; pp++) //{ // reliab[pp] = pixel_array[pp].reliability; //} //File.WriteAllBytes(@"C:\Reliabilities", byte[] bytes) horizontalEDGEs(pixel, edge, image_width, image_height, &myparams); verticalEDGEs(pixel, edge, image_width, image_height, &myparams); // Swapped the order of these (horz, vertical originally - that kept failing) } // Use C# LINQ sorting if (myparams.no_of_edges != 0) { // sort the EDGEs depending on their reiability. The PIXELs with higher // relibility (small value) first Array.Sort <EDGE>(edge_array, (x, y) => x.reliab.CompareTo(y.reliab)); } fixed(EDGE *edge = &edge_array[0]) { // gather PIXELs into groups gatherPIXELs(edge, &myparams); unwrapImage(pixel, image_width, image_height); //maskImage(pixel, input_mask_ptr, image_width, image_height); // copy the image from PIXELM structure to the unwrapped phase array // passed to this function returnImage(pixel, unwrapped_image_ptr, image_width, image_height); } } } } // Return the unwrapped_mask return(unwrapped_image); }
/// <summary> /// This function construct the underlying graph for Dijkstra algorithm. /// The graph is connected with each node represent a point on mesh or mesh edges. /// the parameter subdiviLevel controls the subdivision resolution, i.e., how many /// points are inserted in each mesh edge. The larger the "subdiviLevel", the /// better accuracy the computed geodesic distances. /// NOTES: /// The indices for the original mesh is remained as 0 to n, the added nodes /// are starting with index n. /// </summary> /// <param name="mesh"></param> /// <param name="subdivLevel"></param> private void ConstructGraph(Mesh mesh, int subdivLevel) { this.mesh = mesh; this.nodes = new List <NODE>(); int n = mesh.VertexCount; for (int i = 0; i < n; ++i) { Vector3d p = new Vector3d(mesh.VertexPos, i * 3); this.nodes.Add(new NODE(i, p)); } HashSet <EDGE> meshEdges = new HashSet <EDGE>(); List <FACE> meshFaces = new List <FACE>(); for (int i = 0, j = 0; i < mesh.FaceCount; ++i, j += 3) { meshFaces.Add(new FACE(i)); int c0 = mesh.FaceIndex[j]; int c1 = mesh.FaceIndex[j + 1]; int c2 = mesh.FaceIndex[j + 2]; Vector3d v0 = new Vector3d(mesh.VertexPos, c0 * 3); Vector3d v1 = new Vector3d(mesh.VertexPos, c1 * 3); Vector3d v2 = new Vector3d(mesh.VertexPos, c2 * 3); EDGE e0 = new EDGE(c0, c1, (v1 - v0).Length()); EDGE e1 = new EDGE(c1, c2, (v2 - v1).Length()); EDGE e2 = new EDGE(c2, c0, (v2 - v0).Length()); meshEdges.Add(e0); meshEdges.Add(e1); meshEdges.Add(e2); } /// now build the graph, first subdvids edges, then connect if (subdivLevel > 0) { foreach (EDGE e in meshEdges) { List <int> adjFaces = mesh.AdjVF[e.I].Intersect(mesh.AdjVF[e.J]).ToList(); foreach (int f in adjFaces) { meshFaces[f].edges.Add(e); } } this.edges = new HashSet <EDGE>(); int index = n; foreach (EDGE e in meshEdges) { NODE node1 = this.nodes[e.I], node2 = this.nodes[e.J]; e.onEdgeNodes = new List <NODE>(); for (int i = 0; i < subdivLevel; ++i) { double ratio = (double)(i + 1) / (subdivLevel + 1); Vector3d p = node2.pos * ratio + node1.pos * (1 - ratio); NODE node = new NODE(index++, p); this.nodes.Add(node); e.onEdgeNodes.Add(node); } } foreach (EDGE e in meshEdges) { NODE start = this.nodes[e.I], end = this.nodes[e.J]; int k = e.onEdgeNodes.Count; if (k > 0) { NODE n1 = e.onEdgeNodes[0], n2 = e.onEdgeNodes[k - 1]; EDGE e1 = new EDGE(start.index, n1.index, (start.pos - n1.pos).Length()); EDGE e2 = new EDGE(n2.index, end.index, (end.pos - n2.pos).Length()); this.edges.Add(e1); this.edges.Add(e2); } for (int i = 0; i < k - 1; ++i) { NODE n1 = e.onEdgeNodes[i], n2 = e.onEdgeNodes[i + 1]; EDGE ee = new EDGE(n1.index, n2.index, (n1.pos - n2.pos).Length()); this.edges.Add(ee); } } foreach (FACE face in meshFaces) { // connect points on edges foreach (EDGE e1 in face.edges) { foreach (NODE node1 in e1.onEdgeNodes) { foreach (EDGE e2 in face.edges) { if (e2 == e1) { continue; } // find the node opposite to e1 int opposite = e2.I; if (opposite == e1.I || opposite == e1.J) { opposite = e2.J; } this.edges.Add( new EDGE(opposite, node1.index, (node1.pos - this.nodes[opposite].pos).Length() ) ); // connect points on one edge to points on another foreach (NODE node2 in e2.onEdgeNodes) { EDGE ee = new EDGE(node1.index, node2.index, (node1.pos - node2.pos).Length() ); this.edges.Add(ee); } } } } } } else { this.edges = meshEdges; } foreach (EDGE e in this.edges) { NODE node1 = this.nodes[e.I], node2 = this.nodes[e.J]; node1.adjEdges.Add(e); node2.adjEdges.Add(e); } }
public override bool Equals(object obj) { EDGE rec = obj as EDGE; return(I == rec.I && J == rec.J); }
public int read_file(string filename) { string line; System.IO.StreamReader file = new System.IO.StreamReader(filename); bool newNode = false; int lastID = -1; int lastSource = -1; bool newEdge = false; float area = 25.0f; while ((line = file.ReadLine()) != null) { char[] delims = {' '}; string[] words = line.Split(delims); int i = 0; while (i < words.Length) { if (words[i].CompareTo("") == 0) { i++; continue; } else if (words[i].CompareTo("id") == 0) { newNode = true; // add new node to graph, set id as words[i+1] lastID = Convert.ToInt32(words[i + 1]); break; } else if (words[i].CompareTo("label") == 0) { if (newNode) { // get the last node created, add a label // ignore quotations NODE n = new NODE(); n.id = lastID; n.label = words[i + 1]; n.x_pos = Mathf.Floor (Random.Range(-area, area)); n.y_pos = Mathf.Floor (Random.Range(-area, area)); n.z_pos = Mathf.Floor (Random.Range(-area, area)); n.temp_x = -50.0f; n.temp_y = -50.0f; n.temp_z = -50.0f; n.edgeList = new List<EDGE> (); graph.nodes.Add(n.id, n); graph.n_nodes++; newNode = false; lastID = -1; break; } else { // unknown id read, no label accompanying break; } } else if (words[i].CompareTo("source") == 0) { newEdge = true; // add new edge from indexes lastSource = Convert.ToInt32(words[i + 1]); break; } else if (words[i].CompareTo("target") == 0) { if (newEdge) { // get last edge value created EDGE e = new EDGE(); e.source = lastSource; e.target = Convert.ToInt32(words[i + 1]); graph.edges.Insert(graph.n_edges, e); graph.n_edges++; graph.nodes [e.source].edgeList.Add (e); graph.nodes [e.target].edgeList.Add (e); newEdge = false; lastSource = -1; break; } else { // failure break; } } else // ignore any other line, namely "[" and "]" { break; } } } file.Close(); return 1; }
public static bool compareEdge(EDGE e1, EDGE e2) { return e1.target == e2.target && e1.source == e2.source; }
private bool IsEdgeInactive(EDGE e) { return(line == e.GetYmax()); }
private void UpdateEdge(EDGE e) { e.SetX(e.GetX() + e.GetDx()); }
private static extern BOOL DrawEdge(IntPtr hdc, ref RECT qrc, EDGE edge, BF grfFlags);