예제 #1
0
파일: Rectangle.cs 프로젝트: deblob/GaLi
        internal override VertexCollection GetVertices(PointF origin)
        {
            if (_cachedVerts != null)
            {
                return(_cachedVerts);
            }

            VertexCollection result = new VertexCollection()
            {
                Mode = BeginMode.Quads
            };

            result.AddRange(new List <PointF> {
                origin.Add(Position),
                origin.Add(new PointF(Position.X, Position.Y + Height)),
                origin.Add(new PointF(Position.X + Width, Position.Y + Height)),
                origin.Add(new PointF(Position.X + Width, Position.Y))
            });

            result = base.RotateVerts(result);

            _cachedVerts = result;
            if (result == null)
            {
                ;
            }
            return(result);
        }
예제 #2
0
        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);
        }
예제 #3
0
파일: Ellipse.cs 프로젝트: deblob/GaLi
        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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
        protected void Initialize()
        {
            this.front = new VertexCollection();
            this.front.AddRange(this.goals);
            this.newFront = new VertexCollection();
            this.probs    = new VertexDoublesDictionary();
            this.costs    = new VertexDoublesDictionary();

            foreach (IVertex v in this.TestGraph.Graph.Vertices)
            {
                // setting probs
                DoubleCollection col = new DoubleCollection();
                if (this.Goals.Contains(v))
                {
                    col.Add(0);
                }
                else
                {
                    col.Add(1);
                }

                this.probs.Add(v, col);

                // setting costs
                col = new DoubleCollection();
                col.Add(0);
                this.costs.Add(v, col);
            }

            foreach (IVertex v in this.TestGraph.States)
            {
                this.Strategy.SetChooseEdge(v, 0, null);
            }
        }
예제 #6
0
        private void DelaunayButton_Click(object sender, RoutedEventArgs e)
        {
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 100;

            Geometry.Vector[]  points = box.RandomPointsInside(rng, size);
            VertexCollection   verts  = new VertexCollection(points);
            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;
        }
예제 #7
0
        private void DelaunayRefine(int scenario)
        {
            var sw = new Stopwatch();

            sw.Start();
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 50;

            Geometry.Vector[] points;
            if (scenario == 1)
            {
                points = box.RandomPointsInside(rng, size);
            }
            else if (scenario == 2)
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -9.5),
                    new Geometry.Vector(0, -9.5),
                    new Geometry.Vector(2, -0.5),
                    new Geometry.Vector(8, -0.5)
                    //new Geometry.Vector(4.5,-0.5),
                    //new Geometry.Vector(5.5,-0.5)
                };
            }
            else
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -6),
                    new Geometry.Vector(10, -2),
                    new Geometry.Vector(0, -6),
                    //new Geometry.Vector(0, -6)
                };
            }
            VertexCollection   verts = new VertexCollection(points);
            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            faces = faces.Refine(0.5);
            //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()));
            sw.Stop();
            MeshingTimeText.Text    = "Completed: " + faces.Count + " faces in " + sw.Elapsed;
            DelaunayCanvas.Geometry = geometry;
        }
        /// <summary>
        /// Triangulation algorithm of building segments
        /// </summary>
        /// <param name="vertices">Collection of vertices</param>
        /// <returns>Collection of segments which is the result of triangulation</returns>
        /// <remarks><see cref="ITriangulation.Triangulate(VertexCollection)"/> implementation</remarks>
        public List <Edge> Triangulate(VertexCollection vertices)
        {
            var v     = vertices.ToList();
            var edges = new ConcurrentBag <Edge>();

            Parallel.For(0, vertices.Count(), (i) =>
            {
                Parallel.For(0, vertices.Count(), (j) =>
                {
                    if (i != j)
                    {
                        edges.Add(new Edge(v[i], v[j]));
                    }
                });
            });

            var orderedByLength = edges.OrderBy(e => e.Length);

            var result = new List <Edge>
            {
                orderedByLength.First()
            };

            foreach (var edge in orderedByLength.Skip(1))
            {
                if (result.TrueForAll(e => !e.IsIntersect(edge)) && !result.Contains(edge))
                {
                    result.Add(edge);
                }
            }
            return(result.DistinctEdge().ToList());
        }
예제 #9
0
		internal void FindFeasible()
		{
			this.negativeVertices = new VertexCollection();
			this.positiveVertices = new VertexCollection();
			int nn = 0, np = 0;
			foreach(IVertex u in VisitedGraph.Vertices)
			{
				int degree=Degree(u);
				if( degree < 0 ) 
					NegativeVertices.Add(u);
				else if( degree > 0 ) 
					PositiveVertices.Add(u);
			}

			int du,dv,f;
			foreach(IVertex u in NegativeVertices)
			{
				du = Degrees[u];
				foreach(IVertex v in PositiveVertices)
				{
					dv = Degrees[v];
					if (-du<dv)
						Adjoins[u,v] = f = -du;
					else
						Adjoins[u,v] = f = dv;

					Degrees[u] += f;
					Degrees[v] -= f;
				}
			}
		}
예제 #10
0
 /// <summary>
 /// Initializes a new, empty mesh.
 /// </summary>
 public HalfEdgeMesh()
 {
     Edges = new EdgeCollection(this);
     Faces = new FaceCollection(this);
     HalfEdges = new HalfedgeCollection(this);
     Vertices = new VertexCollection(this);
 }
예제 #11
0
 public void SetGraph(VertexCollection<String> okVertices, EdgeCollection<String> okEdges, AttributesDictionary<bool> okDialogAttributes, AttributesDictionary<string> okDraphAttributes)
 {
     vertices = okVertices;
     edges = okEdges;
     dialogAttributes = okDialogAttributes;
     graphAttributes = okDraphAttributes;
 }
        public VerticalPrismalSurface(IPolyline @base, Interval zRange, bool isClosed = false)
        {
            if (zRange.IsEmpty)
            {
                throw new ArgumentException("z range should not be empty", "zRange");
            }

            _base     = @base;
            _zRange   = zRange;
            _isClosed = isClosed;

            if (isClosed)
            {
                if ([email protected])
                {
                    throw new ArgumentException("Closed prism has to have closed base");
                }

                _closedBase         = (IClosedPolyline)@base;
                _isCounterclockwise = _closedBase.SignedArea() > 0;
            }

            _vertices = new VertexCollection(this);
            _edges    = new EdgeCollection(this);
            _faces    = new FaceCollection(this);

            _undirectedComparer = new UndirectedEdgeComparerImpl(this);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
 /// <summary>
 /// Initializes a new, empty mesh.
 /// </summary>
 public HalfEdgeMesh()
 {
     Edges     = new EdgeCollection(this);
     Faces     = new FaceCollection(this);
     HalfEdges = new HalfedgeCollection(this);
     Vertices  = new VertexCollection(this);
 }
예제 #15
0
        internal void ComputeNoInit(IVertex s)
        {
            VertexCollection         orderedVertices = new VertexCollection();
            TopologicalSortAlgorithm topoSorter      = new TopologicalSortAlgorithm(VisitedGraph, orderedVertices);

            topoSorter.Compute();

            OnDiscoverVertex(s);

            foreach (IVertex v in orderedVertices)
            {
                OnExamineVertex(v);

                foreach (IEdge e in VisitedGraph.OutEdges(v))
                {
                    OnDiscoverVertex(e.Target);
                    bool decreased = Relax(e);
                    if (decreased)
                    {
                        OnEdgeRelaxed(e);
                    }
                    else
                    {
                        OnEdgeNotRelaxed(e);
                    }
                }
                OnFinishVertex(v);
            }
        }
예제 #16
0
        private void VoronoiButton_Click(object sender, RoutedEventArgs e)
        {
            Random rng = null;

            if (VoronoiSeedBox.Text.IsNumeric())
            {
                int seed = int.Parse(VoronoiSeedBox.Text);
                rng = new Random(seed);
            }
            else
            {
                rng = new Random();
            }

            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 500;

            Geometry.Vector[]             points   = box.RandomPointsInside(rng, size);
            VertexCollection              verts    = new VertexCollection(points);
            MeshFaceCollection            faces    = Mesh.DelaunayTriangulationXY(verts, null, box, false);
            Dictionary <Vertex, MeshFace> voronoi  = Mesh.VoronoiFromDelaunay(verts, faces);
            MeshFaceCollection            outFaces = new MeshFaceCollection(voronoi.Values);
            PolyLine rect = PolyLine.Rectangle(0, -10, 10, 0);

            outFaces = outFaces.TrimToPolygonXY(rect.Vertices);
            outFaces = outFaces.TrimToPolygonXY(rect.Vertices); //Test duplicate edges
            VertexGeometryCollection geometry = new VertexGeometryCollection(outFaces.ExtractFaceBoundaries());

            //ShapeCollection geometry = faces.ExtractFaceBoundaries();
            geometry.Add(new Cloud(verts.ExtractPoints()));
            VoronoiCanvas.Geometry = geometry;
        }
예제 #17
0
 /// <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);
 }
예제 #18
0
    public static IEnumerable <(Vertex a, Vertex b)> CyclicPairs(this VertexCollection vertexCollection)
    {
        if (vertexCollection.Count == 0)
        {
            yield break;
        }

        var prev = vertexCollection[^ 1];
예제 #19
0
 public GraphEventArgs(VertexCollection<String> vertices, EdgeCollection<String> edges, AttributesDictionary<bool> dialogAttributes, AttributesDictionary<string> graphAttributes)
 {
     Type = Types.GraphGenerated;
     Vertices = vertices;
     Edges = edges;
     DialogAttributes = dialogAttributes;
     GraphAttributes = graphAttributes;
 }
예제 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="vertices"></param>
 public VertexRecorderVisitor(VertexCollection vertices)
 {
     if (vertices == null)
     {
         throw new ArgumentNullException("vertices");
     }
     this.vertices = vertices;
 }
예제 #21
0
    public static void NormalizeUV(this VertexCollection vertices)
    {
        if (vertices.Count == 0)
        {
            return;
        }

        var minX = vertices.Select(static _ => _.UV.X).Min();
예제 #22
0
 /// <summary>
 /// Constructor, uses the given predecessor map.
 /// </summary>
 /// <param name="predecessors">Predecessor map</param>
 /// <exception cref="ArgumentNullException">
 /// predecessors is null
 /// </exception>
 public PredecessorRecorderVisitor(VertexEdgeDictionary predecessors)
 {
     if (predecessors == null)
     {
         throw new ArgumentNullException("predecessors");
     }
     this.predecessors    = predecessors;
     this.endPathVertices = new VertexCollection();
 }
예제 #23
0
 public MatrixService(VertexCollection vertices, List <Triangle> triangles)
 {
     Vertices              = vertices;
     Triangles             = triangles;
     SystemService         = new SystemService(Vertices);
     GlobalStiffnessMatrix = Matrix.Create <double>(vertices.Count, vertices.Count);
     GlobalForceVector     = Vector.Create <double>(vertices.Count);
     CalculateIndexMatrix();
 }
예제 #24
0
 public TrackData(string trackName, bool originalTrack, TrackItemsBlock items, VertexCollection verts, F3DEXCommandCollection commands,// List<TrackTextureRef> textures,
                  uint VertexBank, uint Unknown1, uint TableSeg, uint Unknown2)
     : this(trackName, originalTrack)
 {
     TrackItems  = items;
     Vertices    = verts;
     F3DCommands = commands;
     //TextureReferences = textures;
 }
예제 #25
0
        /// <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);
                }
            }
        }
예제 #26
0
        /// <summary>
        /// Creates a new Vertex structure object
        /// </summary>
        public VertexStructure(int verticesCapacity)
        {
            m_name        = string.Empty;
            m_description = string.Empty;

            m_vertices = new List <Vertex>(verticesCapacity);
            m_surfaces = new List <VertexStructureSurface>();

            m_vertexCollection  = new VertexCollection(m_vertices);
            m_surfaceCollection = new SurfaceCollection(m_surfaces);
        }
        public TransformedPolysurface(IPolysurface localSurface, RotoTranslation3 localToGlobal)
        {
            _localSurface  = localSurface;
            _localToGlobal = localToGlobal;

            _vertexCollection = new VertexCollection(this);
            _edgeCollection   = new EdgeCollection(this);
            _faceCollection   = new FaceCollection(this);

            _undirectedComparer = new UndirectedEdgeComparerImpl(this);
        }
예제 #28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="avs"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 protected CharacteristicVertex FindTargetVertex(VertexCollection avs, IEdge e)
 {
     foreach (CharacteristicVertex avtarget in avs)
     {
         if (avtarget.IncomingEdge == e)
         {
             return(avtarget);
         }
     }
     throw new Exception("could not find target vertex");
 }
예제 #29
0
 /// <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);
     }
 }
예제 #30
0
        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);
        }
        //private ProblemService _problemService;

        //private IterationSystemService _iterationSystemService;

        /// <summary>
        /// Window constructor, receiving vertices collection
        /// </summary>
        /// <param name="vertices"></param>
        public TriangulationData(VertexCollection vertices, List <Triangle> triangles, Boundary boundary)
        {
            InitializeComponent();
            // this._problemService = new ProblemService(vertices, triangles, boundary);
            DataContext          = this;
            this.vertices        = vertices;
            this.triangles       = triangles;
            dataGrid.ItemsSource = this.vertices;
            problemService       = new ProblemService(this.vertices, this.triangles, new Boundary((0, 0), (2, 0), (2, 2), (0, 2)));
            MatrixService        = new MatrixService(vertices, triangles);
            InitData();
        }
예제 #32
0
        public MultiPolygon3(IEnumerable <IPolygon3> components)
        {
            _components = components.ToReadOnlyList();

            _componentCount   = _components.Count();
            _totalVertexCount = _components.Select(p => p.InPlane.CountVertices()).Sum();

            _vertices = new VertexCollection(this);
            _edges    = new EdgeColllection(this);
            _faces    = new FaceCollection(this);
            _undirectedEdgeComparer = new UndirectedEdgeComparerImpl(this);
        }
예제 #33
0
        public MultiPolygon3(IPolygon3 uniqueCompoenent)
        {
            _components = uniqueCompoenent.AsSingleton();

            _componentCount   = 1;
            _totalVertexCount = uniqueCompoenent.InPlane.CountVertices();

            _vertices = new VertexCollection(this);
            _edges    = new EdgeColllection(this);
            _faces    = new FaceCollection(this);
            _undirectedEdgeComparer = new UndirectedEdgeComparerImpl(this);
        }