/// <summary> /// Subdivide this edge by adding new vertices between the start and /// end vertices /// </summary> /// <param name="divisions"></param> /// <param name="lastScale">The relative size of the last division</param> public void SubDivide(int divisions, double lastScale = 1.0) { _Vertices.Clear(); Vector startPt = Start.Position; Vector endPt = End.Position; Vector trans = endPt - startPt; double step = 1.0 / (divisions - 1 + lastScale); _Vertices.Add(Start); for (int i = 1; i < divisions; i++) { _Vertices.Add(new Vertex(startPt + trans * (step * i))); } _Vertices.Add(End); }
/// <summary> /// Create a collection of odd vertices /// </summary> /// <param name="g">graph to visit</param> /// <returns>colleciton of odd vertices</returns> /// <exception cref="ArgumentNullException">g is a null reference</exception> public static VertexCollection OddVertices(IVertexAndEdgeListGraph g) { if (g == null) { throw new ArgumentNullException("g"); } VertexIntDictionary counts = new VertexIntDictionary(); foreach (IVertex v in g.Vertices) { counts[v] = 0; } foreach (IEdge e in g.Edges) { ++counts[e.Source]; --counts[e.Target]; } VertexCollection odds = new VertexCollection(); foreach (DictionaryEntry de in counts) { if ((int)de.Value % 2 != 0) { odds.Add((IVertex)de.Key); } } return(odds); }
internal override VertexCollection GetVertices(PointF origin) { if (_cachedVerts != null) { return(_cachedVerts); } VertexCollection result = new VertexCollection() { Mode = BeginMode.LineStrip }; float deltaValue = 1f / (float)Resolution; for (int i = 0; i < Resolution; i++) { float value = (float)i * deltaValue; PointF interpolated01 = P0.LerpTo(P1, value); PointF interpolated12 = P1.LerpTo(P2, value); PointF interpolated23 = P2.LerpTo(P3, value); PointF interpolated01_12 = interpolated01.LerpTo(interpolated12, value); PointF interpolated12_23 = interpolated12.LerpTo(interpolated23, value); PointF interpolatedFinal = interpolated01_12.LerpTo(interpolated12_23, value); result.Add(interpolatedFinal.Add(Position)); } result = base.RotateVerts(result); _cachedVerts = result; return(_cachedVerts); }
/// <summary> /// Iteratively removes the dangling links from the rank map /// </summary> public void RemoveDanglingLinks() { VertexCollection danglings = new VertexCollection(); do { danglings.Clear(); // create filtered graph IVertexListGraph fg = new FilteredVertexListGraph( this.VisitedGraph, new InDictionaryVertexPredicate(this.ranks) ); // iterate over of the vertices in the rank map foreach (IVertex v in this.ranks.Keys) { // if v does not have out-edge in the filtered graph, remove if (fg.OutDegree(v) == 0) { danglings.Add(v); } } // remove from ranks foreach (IVertex v in danglings) { this.ranks.Remove(v); } // iterate until no dangling was removed }while(danglings.Count != 0); }
internal override VertexCollection GetVertices(PointF origin) { if (_cachedVerts != null) { return(_cachedVerts); } VertexCollection result = new VertexCollection() { Mode = BeginMode.Polygon }; for (int i = 0; i < Sides; i++) { float x = (float)Math.Cos(((float)i / (float)Sides) * PI2) * Width; float y = (float)Math.Sin(((float)i / (float)Sides) * PI2) * Height; result.Add(new PointF(x + X, y + Y)); } result = base.RotateVerts(result); _cachedVerts = result; return(result); }
/// <summary> /// Initialise a MultiElementVertex from a single elementvertex /// </summary> /// <param name="elementVertex"></param> public MultiElementVertex(ElementVertex elementVertex) { _Description = elementVertex.Description; _Elements = new ElementCollection(); _Vertices = new VertexCollection(); _Elements.Add(elementVertex.Element); _Vertices.Add(elementVertex.Vertex); }
/// <summary> /// Compute the condensation graph and store it in the supplied graph 'cg' /// </summary> /// <param name="cg"> /// Instance of mutable graph in which the condensation graph /// transformation is stored /// </param> public void Create(IMutableVertexAndEdgeListGraph cg) { if (cg == null) { throw new ArgumentNullException("cg"); } if (components == null) { ComputeComponents(); } // components list contains collection of // input graph Vertex for each SCC Vertex_ID // (i.e Vector< Vector<Vertex> > ) // Key = SCC Vertex ID sccVertexMap = BuildSCCVertexMap(components); // Lsit of SCC vertices VertexCollection toCgVertices = new VertexCollection(); IDictionaryEnumerator it = sccVertexMap.GetEnumerator(); while (it.MoveNext()) // as scc_vertex_map is a sorted list, order of SCC IDs will match CG vertices { IVertex curr = cg.AddVertex(); OnInitCondensationGraphVertex(new CondensationGraphVertexEventArgs(curr, (IVertexCollection)it.Value)); toCgVertices.Add(curr); } for (int srcSccId = 0; srcSccId < sccVertexMap.Keys.Count; srcSccId++) { VertexCollection adj = new VertexCollection(); foreach (IVertex u in (IVertexCollection)sccVertexMap[srcSccId]) { foreach (IEdge e in VisitedGraph.OutEdges(u)) { IVertex v = e.Target; int targetSccId = components[v]; if (srcSccId != targetSccId) { // Avoid loops in the condensation graph IVertex sccV = toCgVertices[targetSccId]; if (!adj.Contains(sccV)) // Avoid parallel edges { adj.Add(sccV); } } } } IVertex s = toCgVertices[srcSccId]; foreach (IVertex t in adj) { cg.AddEdge(s, t); } } }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="assg"></param> public void Transform(IBidirectionalGraph g, IMutableVertexAndEdgeListGraph assg) { VertexCollection avs = new VertexCollection(); // adding vertices foreach (IEdge e in g.Edges) { // xi_-(L) = g(xi_-(0), xi_+(L)) CharacteristicVertex avm = (CharacteristicVertex)assg.AddVertex(); avm.IncomingEdge = e; avm.Vertex = e.Target; avs.Add(avm); // xi_+(0) = g(xi_-(0), xi_+(L)) CharacteristicVertex avp = (CharacteristicVertex)assg.AddVertex(); avp.IncomingEdge = e; avp.Vertex = e.Source; avs.Add(avp); } // adding out edges foreach (CharacteristicVertex av in avs) { foreach (IEdge e in g.OutEdges(av.Vertex)) { // find target vertex: CharacteristicVertex avtarget = FindTargetVertex(e); // add xi_- CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av, avtarget); aem.Positive = false; aem.Edge = e; } foreach (IEdge e in g.InEdges(av.Vertex)) { // find target vertex: CharacteristicVertex avtarget = FindTargetVertex(e); // add xi_- CharacteristicEdge aem = (CharacteristicEdge)assg.AddEdge(av, avtarget); aem.Positive = true; aem.Edge = e; } } }
internal override VertexCollection GetVertices(PointF origin) { if (_cachedVerts != null) { return(_cachedVerts); } VertexCollection result = new VertexCollection() { Mode = BeginMode.Lines }; result.Add(origin.Add(Position)); result.Add(origin.Add(End)); result = base.RotateVerts(result); _cachedVerts = result; return(result); }
/// <summary> /// Initialise a MultiElementVertex helper object combining the /// specified set of ElementVertices. /// </summary> /// <param name="elementVertices"></param> public MultiElementVertex(IList <ElementVertex> elementVertices) { _Description = elementVertices.CombinedValue(i => i.Description, "[Multi]"); _Elements = new ElementCollection(); _Vertices = new VertexCollection(); foreach (var elVert in elementVertices) { _Elements.Add(elVert.Element); _Vertices.Add(elVert.Vertex); } }
public static VertexCollection ToVertexCollection(this IEnumerable <Vertex> source) { Util.Check.NotNull(source, "Parameter is null"); var result = new VertexCollection(); foreach (var vertex in source) { result.Add(vertex); } return(result); }
internal static void OutputVertex(Site site) { if (!triangulate && !plot && !debug) { Console.WriteLine(String.Format("vertex {0}, {1}", site.Coord.X, site.Coord.Y)); } if (debug) { Console.WriteLine(String.Format("vertex({0}) at {1}, {2}", site.SiteNumber, site.Coord.X, site.Coord.Y)); } VertexCollection.Add(new VoronoiVertex(site.Coord.X, site.Coord.Y, site.SiteNumber)); }
public override void Draw(OpenGL gl) { // Drawing metagons is fairly easy, we save the vertex data, make a copy of // it, apply gravity, then draw the polygon. Afterwards, we restore it. VertexCollection oldVertices = vertices; VertexCollection newVertices = new VertexCollection(); foreach (Vertex v in vertices) { // Apply gravity, this means we need to know what other metagons there // are. // Find the closest vertex from the other metagon. double finddistance = -1; Vertex gravPoint = null; foreach (Vertex mV in other.Vertices) { Vertex temp = (mV /* + other.Translate*/) - (v + Translate); double tempdist = temp.Magnitude(); if (finddistance == -1 || tempdist < finddistance) { gravPoint = mV; finddistance = tempdist; } } Vertex toGrav = gravPoint - v; double distance = toGrav.Magnitude(); // The 'force' of gravity is the square root of this value, so it // only works well up cloes. double force = System.Math.Sqrt(distance); double growForce = System.Math.Sqrt(force); toGrav.UnitLength(); // Now we push this vector along by the required amount. Vertex newV = v + (toGrav * (float)force); newVertices.Add(newV); } vertices = newVertices; // Draw it. base.Draw(gl); }
/// <summary> /// Removes all edges that match <paramref name="predicate" />. /// </summary> /// <param name="predicate"> /// A pure delegate that takes an <typeparamref name="TVertex" /> and returns true if the edge /// should be removed. /// </param> /// <returns>The number of vertices removed.</returns> public int RemoveVertex(Func <TVertex, bool> predicate) { var vertices = new VertexCollection <TVertex>(); foreach (var v in this.Vertices.Where(predicate)) { vertices.Add(v); } foreach (var v in vertices) { this.RemoveVertex(v); } return(vertices.Count); }
internal VertexCollection RotateVerts(VertexCollection verts) { VertexCollection result = new VertexCollection(); result.Mode = verts.Mode; foreach (PointF vert in verts) { float distanceX = vert.X - Center.X; float distanceY = vert.Y - Center.Y; float x = distanceX * (float)Math.Cos(-Rotation * PI2) - distanceY * (float)Math.Sin(-Rotation * PI2); float y = distanceX * (float)Math.Sin(-Rotation * PI2) + distanceY * (float)Math.Cos(-Rotation * PI2); result.Add(Center.X + x, Center.Y + y); } return(result); }
private void AnalysisMeshButton_Click(object sender, RoutedEventArgs e) { Random rng = new Random(); BoundingBox box = new BoundingBox(1, 9, -9, -1, 0, 0); int size = 100; //Geometry.Vector[] points = box.RandomPointsInside(rng, size); //VertexCollection verts = new VertexCollection(points); VertexCollection verts = new VertexCollection(); //verts.Add(new Vertex(1, -1)); int divs = 5; for (int i = 0; i <= divs; i++) { for (int j = 0; j <= divs; j++) { Geometry.Vector pt = new Geometry.Vector(box.X.ValueAt(((double)i) / divs), box.Y.ValueAt(((double)j) / divs)); verts.Add(new Vertex(pt)); } } MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts); faces.Quadrangulate(); //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces); //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries(); CurveCollection edges = faces.ExtractFaceBoundaries(); VertexGeometryCollection geometry = new VertexGeometryCollection(); foreach (var edge in edges) { var region = new PlanarRegion(edge); geometry.Add(region); region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128)); geometry.Add(edge); edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0)); } geometry.Add(new Cloud(verts.ExtractPoints())); DelaunayCanvas.Geometry = geometry; }
private SortedList BuildSCCVertexMap(VertexIntDictionary vSccMap) { // Construct a map of SCC ID as key & IVertexCollection of vertices contained within the SCC as value SortedList h = new SortedList(); VertexCollection vertices = null; foreach (DictionaryEntry de in vSccMap) { IVertex v = (IVertex)de.Key; int scc_id = (int)de.Value; if (h.ContainsKey(scc_id)) { ((VertexCollection)h[scc_id]).Add(v); } else { vertices = new VertexCollection(); vertices.Add(v); h.Add(scc_id, vertices); } } return(h); }
/// <summary> /// Adds temporary edges to the graph to make all vertex even. /// </summary> /// <param name="g"></param> /// <returns></returns> public EdgeCollection AddTemporaryEdges(IMutableVertexAndEdgeListGraph g) { if (g == null) { throw new ArgumentNullException("g"); } // first gather odd edges. VertexCollection oddVertices = AlgoUtility.OddVertices(g); // check that there are an even number of them if (oddVertices.Count % 2 != 0) { throw new Exception("number of odd vertices in not even!"); } // add temporary edges to create even edges: EdgeCollection ec = new EdgeCollection(); bool found, foundbe, foundadjacent; while (oddVertices.Count > 0) { IVertex u = oddVertices[0]; // find adjacent odd vertex. found = false; foundadjacent = false; foreach (IEdge e in g.OutEdges(u)) { IVertex v = e.Target; if (v != u && oddVertices.Contains(v)) { foundadjacent = true; // check that v does not have an out-edge towards u foundbe = false; foreach (IEdge be in g.OutEdges(v)) { if (be.Target == u) { foundbe = true; break; } } if (foundbe) { continue; } // add temporary edge IEdge tempEdge = g.AddEdge(v, u); // add to collection ec.Add(tempEdge); // remove u,v from oddVertices oddVertices.Remove(u); oddVertices.Remove(v); // set u to null found = true; break; } } if (!foundadjacent) { // pick another vertex if (oddVertices.Count < 2) { throw new Exception("Eulerian trail failure"); } IVertex v = oddVertices[1]; IEdge tempEdge = g.AddEdge(u, v); // add to collection ec.Add(tempEdge); // remove u,v from oddVertices oddVertices.Remove(u); oddVertices.Remove(v); // set u to null found = true; } if (!found) { oddVertices.Remove(u); oddVertices.Add(u); } } temporaryEdges = ec; return(ec); }
/// <summary> /// Merge an element vertex into this object /// </summary> /// <param name="elVert"></param> public void Merge(ElementVertex elVert) { _Elements.Add(elVert.Element); _Vertices.Add(elVert.Vertex); }