/// <summary> /// Takes sequence of vertices, turns them into face and returns active part of face in replacedBy /// </summary> /// <param name="selected">Sequence of original vertices.</param> /// <param name="replacedBy">Sequence of new vertices.</param> /// <param name="faceSize">size of face used when connecting selected.</param> void Replace(IList <VertexStack> selected, out List <VertexStack> replacedBy, int faceSize) { var newFace = selected.Select(x => x.ID).ToList(); //střed vybraných bude neaktivní for (int i = 1; i < selected.Count - 1; i++) { SingleVertex temp = selected[i].Peek().Clone(); temp.IsActive = false; selected[i].Push(temp); } replacedBy = new List <VertexStack>(); replacedBy.Add(selected[0]); selected[0].Push(selected[0].Peek().Clone()); for (int i = 0; i < faceSize - selected.Count; i++) { VertexStack tempVS = new VertexStack(triarc.CountOfVertices); newFace.Add(tempVS.ID); triarc.vertices.Add(tempVS); triarc.CountOfVertices++; SingleVertex tempV = new SingleVertex(); tempV.A = replacedBy[i]; tempV.IsActive = true; tempVS.Push(tempV); SingleVertex tempP = replacedBy[i].Pop(); if (tempP.B == null) { tempP.B = tempVS; } else { tempP.C = tempVS; } replacedBy[i].Push(tempP); replacedBy.Add(tempVS); } //and connect last { VertexStack tempVS = selected[selected.Count - 1]; SingleVertex tempV = tempVS.Peek().Clone(); tempV.C = replacedBy[replacedBy.Count - 1]; tempV.IsActive = true; tempVS.Push(tempV); SingleVertex tempP = replacedBy[replacedBy.Count - 1].Pop(); if (tempP.B == null) { tempP.B = tempVS; } else { tempP.C = tempVS; } replacedBy[replacedBy.Count - 1].Push(tempP); replacedBy.Add(tempVS); } triarc.Faces.Add(newFace); }
/// <summary> /// Finds next active vertex stack. (Each vertex has up to two active neighbours, so return value is uniquely defined.) /// </summary> /// <param name="predecessor">One of active neighbours, the other than will be returned</param> /// <returns>Active neighbour that isn't predecessor.</returns> public VertexStack Succescor(VertexStack predecessor) { if (A != null && A != predecessor && A.IsActive) { return(A); } if (B != null && B != predecessor && B.IsActive) { return(B); } if (C != null && C != predecessor && C.IsActive) { return(C); } return(null); }
public void CreateOuterBoundaryVertices(long boundary) { VertexStack Outside = new VertexStack(-1); SingleVertex o = new SingleVertex(); o.A = Outside; o.B = Outside; o.C = Outside; o.IsActive = false; Outside.Push(o); List <VertexStack> vrcholy = new List <VertexStack>(); for (int i = 0; i < NumberOfVerticesInOuterBoundary; i++) { vrcholy.Add(new VertexStack(i)); vrcholy[i].Push(new SingleVertex()); } //praví sousedé + aktivní for (int i = 0; i < NumberOfVerticesInOuterBoundary; i++) { SingleVertex temp = vrcholy[i].Pop(); temp.IsActive = true; temp.A = vrcholy[(i + 1) % NumberOfVerticesInOuterBoundary]; vrcholy[i].Push(temp); } //leví sousedé for (int i = 1; i < NumberOfVerticesInOuterBoundary + 1; i++) { SingleVertex temp = vrcholy[i % NumberOfVerticesInOuterBoundary].Pop(); temp.B = vrcholy[(i - 1) % NumberOfVerticesInOuterBoundary]; vrcholy[i % NumberOfVerticesInOuterBoundary].Push(temp); } for (int i = 0; i < NumberOfVerticesInOuterBoundary; i++) { if ((boundary & ((long)1 << i)) == 0) { SingleVertex temp = vrcholy[i].Pop(); temp.C = Outside; vrcholy[i].Push(temp); } } this.vertices = vrcholy; this.CountOfVertices = vertices.Count; }
List <VertexStack> tryActive(Random rnd, VertexStack start) { var result = new List <VertexStack>() { start }; result.Add(chooseRnd(start.ActiveNeighbours(), rnd)); var next = chooseRnd(result[1].ActiveNeighbours(start.ID), rnd); while (next != start) { var current = next; var last = result.Last(); result.Add(next); next = chooseRnd(current.ActiveNeighbours(last.ID), rnd); } return(result); }
/// <summary> /// Finds next active vertex stack. (Each vertex has up to two active neighbours, so return value is uniquely defined.) /// </summary> /// <param name="predecessor">One of active neighbours, the other than will be returned</param> /// <returns>Active neighbour that isn't predecessor.</returns> public VertexStack Succescor(VertexStack predecessor) { return(stack.Peek().Succescor(predecessor)); }