Esempio n. 1
0
        private bool FCheckParallelLines(List <Vector> ptsBox, out IEnumerable <Vector> ptsToBeClipped)
        {
            // Do the required initialization of our out parameter
            ptsToBeClipped = null;

            // See if our cell is made up of two parallel lines.
            // This is the only case where we will have exactly two lines at
            // infinity - one connecting each end of the parallel lines.
            // We will have exactly six edges - it will look like the following:
            //
            //      Inf vtx-------------finite vtx 0 -----------------Inf vtx
            //      |                                                       |
            //      |<-Edge at infinity                   Edge at infinity->|
            //      |                                                       |
            //      Inf vtx-------------finite vtx 1 ------------------Inf vtx
            //
            // So that's a total of six edges and two of them at infinity.
            if (Edges.Count(e => e.FAtInfinity) == 2)
            {
                // Retrieve the two finite points
                var ptsFinite = Vertices.Where(v => !v.FAtInfinity).Select(v => v.Pt).ToArray();

                // Find out the max dist from any finite point to any finite point on the box and double it for good measure
                var maxDist0 = Math.Sqrt(ptsBox.Select(pt => DistanceSq(pt, ptsFinite[0])).Max());
                var maxDist1 = Math.Sqrt(ptsBox.Select(pt => DistanceSq(pt, ptsFinite[1])).Max());
                var maxDist  = 2.0 * Math.Max(maxDist0, maxDist1);

                // Use that as a ray length to get real vertices which will later be clipped to the box
                ptsToBeClipped = RealVertices(maxDist);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
    public void Write(BinaryWriter writer)
    {
      // Write a blank header now, and go back later and fix it up
      long HeaderPos = writer.BaseStream.Position;

      Header.DTMModelInternalName = ASCIIEncoding.ASCII.GetBytes(ModelName);
      if (Header.DTMModelInternalName.Length != HeaderConsts.kDTMInternalModelNameSize)
      {
        Array.Resize(ref Header.DTMModelInternalName, HeaderConsts.kDTMInternalModelNameSize);
      }

      Header.Write(writer);

      PadToBoundary(writer);

      Header.FileMajorVersion = Consts.TTMMajorVersion;
      Header.FileMinorVersion = Consts.TTMMinorVersion;

      Header.CoordinateUnits = 1; // Meters
      Header.VertexValueUnits = 1; // Meters
      Header.InterpolationMethod = 1; // Linear

      SetUpSizes();

      Header.StartOffsetOfVertices = (int) writer.BaseStream.Position;
      Header.NumberOfVertices = Vertices.Count;
      Header.VertexRecordSize = (short) (2 * Header.VertexCoordinateSize + Header.VertexValueSize);
      (Vertices as TTMVertices).Write(writer, Header);
      PadToBoundary(writer);

      Header.StartOffsetOfTriangles = (int) writer.BaseStream.Position;
      Header.NumberOfTriangles = Triangles.Count;
      Header.TriangleRecordSize = (short) (3 * Header.VertexNumberSize + 3 * Header.TriangleNumberSize);
      Vertices.NumberVertices();
      (Triangles as TTMTriangles).Write(writer, Header);
      PadToBoundary(writer);

      Header.StartOffsetOfEdgeList = (int) writer.BaseStream.Position;
      Header.NumberOfEdgeRecords = Edges.Count();
      Header.EdgeRecordSize = Header.TriangleNumberSize;
      Edges.Write(writer, Header);
      PadToBoundary(writer);

      Header.StartOffsetOfStartPoints = (int) (writer.BaseStream.Position);
      Header.NumberOfStartPoints = StartPoints.Count();
      Header.StartPointRecordSize = (short) (2 * Header.VertexCoordinateSize + Header.TriangleNumberSize);
      StartPoints.Write(writer, Header);

      // Fix up header
      long EndPos = writer.BaseStream.Position;
      writer.BaseStream.Position = HeaderPos;

      Header.Write(writer);

      writer.BaseStream.Position = EndPos;
    }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, int> > CalculateWeight()
        {
            foreach (var node in EnumerateNodes())
            {
                node.Weight             = Edges.Count(_ => _.To == node.Code);
                node.DirectOutputWeight = Edges.Count(_ => _.From == node.Code);
                node.DirectInputWeight  = node.Weight;
                node.Counted            = true;

                if (node.Weight != 0)
                {
                    node.Counted = false;
                }
            }

            var somethingDone = true;

            while (true)
            {
                if (somethingDone == false)
                {
                    break;
                }

                somethingDone = false;
                var nodes = EnumerateNodes().Where(_ => !_.Counted);

                if (!nodes.Any())
                {
                    break;
                }

                foreach (var node in nodes)
                {
                    var f = GetInNodes(node).ToList();

                    if (!f.Any())
                    {
                        continue;
                    }

                    if (f.All(_ => _.Counted))
                    {
                        node.Weight  += GetInNodes(node).Sum(_ => _.Weight);
                        node.Counted  = true;
                        somethingDone = true;
                    }
                }
            }


            return(EnumerateNodes().Select(_ => new KeyValuePair <string, int>(_.Code, _.Weight)));
        }
Esempio n. 4
0
 public void AddEdgeTopology(int s, int e)
 {
     if (Edges == null || Edges.Count() == 0)
     {
         Edges = new AKT_MeshEdgePairs[] { new AKT_MeshEdgePairs(s, e) }
     }
     ;
     else
     {
         this.Edges = this.Edges.Concat(new AKT_MeshEdgePairs[] { new AKT_MeshEdgePairs(s, e) });
     }
 }
 public void Draw()
 {
     for (int i = 0; i < Points.Count(); ++i)
     {
         Points[i].Draw();
     }
     for (int i = 0; i < VoronoiEdges.Count; ++i)
     {
         DrawVoronoiEdge(VoronoiEdges[i]);
     }
     for (int i = 0; i < Edges.Count(); ++i)
     {
         Edges[i].Draw();
     }
 }
        private void ResetGraphData()
        {
            if (Edges?.Count() > 0)
            {
                Edges.Clear();
            }
            if (Vertices?.Count() > 0)
            {
                Vertices.Clear();
            }
            if (UniverseGraph != null)
            {
                UniverseGraph.Clear();
            }

            UniverseGraph = GraphDataHelper.LoadGraphData(300);
        }
Esempio n. 7
0
        public void GraphMenu(string name, List <Edge> edges)
        {
            if (Nodes == null || Edges == null || Nodes.Count() == 0 || Edges.Count() == 0)
            {
                Console.WriteLine("Something went wrong with reading from file.\nTry upload your file one more time.\nI returned you to main menu.\n");
            }
            else
            {
                string tmp      = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\"));
                string fileName = $"yourFiles\\{name}.png";

                string fullPath = String.Concat(tmp, fileName);

                SaveGraphAsImage(fullPath, edges);

                Console.WriteLine($"Generated graph was saved in yourFiles folder successfully. Image of your graph has name {name}.png");
            }
        }
Esempio n. 8
0
        public double GraphAssortativity2()
        {
            cacheIsEmpty = false;
            if (!Double.IsNegativeInfinity(_graphAssortativity2))
            {
                return(_graphAssortativity2);
            }

            if (ExcessDegreeVariance == 0) // All vertices are the same degree, automatically perfect assortativity
            {
                return(_graphAssortativity2 = 1.0);
            }

            double M         = Edges.Count();
            double numerator = ((1 / M) * (EdgesAsNodes.Sum(e => e.Item1.Degree * e.Item2.Degree)) -
                                Math.Pow((1 / M) * 0.5 * EdgesAsNodes.Sum(e => e.Item1.Degree + e.Item2.Degree), 2.0));
            double denominator = ((1 / M) * 0.5 *
                                  EdgesAsNodes.Sum(e => Math.Pow(e.Item1.Degree, 2) + Math.Pow(e.Item2.Degree, 2)) -
                                  Math.Pow((1 / M) * 0.5 * EdgesAsNodes.Sum(e => e.Item1.Degree + e.Item2.Degree), 2.0));

            return(_graphAssortativity2 = numerator / denominator);
        }
Esempio n. 9
0
 public int InDegree(Node vertex)
 {
     return(Edges.Count(e => e[1] == vertex));
 }