Esempio n. 1
0
        /// <summary>
        /// Collects data from the specified edge
        /// </summary>
        ///
        /// <param name="e">
        /// Edge to collect data from
        /// </param>
        private void AddEdgeData(TEdge e)
        {
            EdgeGroupData ed;
            var           key = new KeyPair(e.Source.ID, e.Target.ID);

            _edgeGroupData.TryGetValue(key, out ed);

            if (ed == null)
            {
                var p1 = VertexPositions[e.Source]; // e.Vertices[0].Location;
                var p2 = VertexPositions[e.Target]; //e.Vertices[1].Location;
                ed = new EdgeGroupData {
                    V1 = p1, V2 = p2, ID = key
                };
                var mid = VectorTools.MidPoint(p1, p2);
                ed.Middle           = mid;
                ed.Length           = VectorTools.Distance(p1, p2);
                ed.CompatibleGroups = new Dictionary <KeyPair, GroupPairData>();
                //ed.edges = new HashSet<int>();
                ed.EdgeCount = 0;
                _edgeGroupData.Add(key, ed);
            }
            //ed.edges.Add(e.ID);
            ed.EdgeCount++;
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates visibility coefficient of the two edges.
        /// </summary>
        ///
        /// <param name="ed1">
        /// First edge to be used in calculation
        /// </param>
        ///
        /// <param name="ed2">
        /// Second edge to be used in calculation
        /// </param>
        ///
        /// <returns>
        /// Compatibility coefficient ranging from 0 to 1
        /// </returns>
        private float VisibilityCoefficient(EdgeGroupData ed1, EdgeGroupData ed2)
        {
            float c;
            var   p1 = ed1.V1;
            var   p2 = ed1.V2;
            var   q1 = ed2.V1;
            var   q2 = ed2.V2;

            var pn = new Point();

            pn.X = p1.Y - p2.Y;
            pn.Y = p2.X - p1.X;

            var pn1 = VectorTools.Plus(pn, p1);
            var pn2 = VectorTools.Plus(pn, p2);

            var i1 = new Point();
            var i2 = new Point();

            float r1 = 0, r2 = 0;

            if (!Intersects(q1, q2, p1, pn1, ref i1))
            {
                return(0);
            }
            Intersects(q1, q2, p2, pn2, ref i2);

            if ((r1 < 0 && r2 < 0) || (r1 > 1 && r2 > 1))
            {
                return(0);
            }

            var im = VectorTools.MidPoint(i1, i2);

            var qm = ed2.Middle;

            var i = VectorTools.Distance(i1, i2);
            var m = VectorTools.Distance(qm, im);

            if (i == 0)
            {
                return(0);
            }

            c = 1f - 2f * m / i;

            if (c < 0)
            {
                return(0);
            }
            else
            {
                return(c);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Calculates position compatibility of the two edges
        /// </summary>
        ///
        /// <param name="ed1">
        /// First edge to be used in calculation
        /// </param>
        ///
        /// <param name="ed2">
        /// Second edge to be used in calculation
        /// </param>
        ///
        /// <returns>
        /// Position compatibility coefficient ranging from 0 to 1
        /// </returns>
        private float PositionCompatibility(EdgeGroupData ed1, EdgeGroupData ed2)
        {
            var avg = (ed1.Length + ed2.Length) / 2;
            var dis = VectorTools.Distance(ed1.Middle, ed2.Middle);

            if ((avg + dis) == 0)
            {
                return(0);
            }
            return(avg / (avg + dis));
        }
Esempio n. 4
0
 /// <summary>
 /// Calculates directedness of the two edges.
 /// </summary>
 ///
 /// <param name="ed1">
 /// First edge to be used in calculation
 /// </param>
 ///
 /// <param name="ed2">
 /// Second edge to be used in calculation
 /// </param>
 ///
 /// <returns>
 /// True if edges have roughly the same direction, false otherwise
 /// </returns>
 private bool CalculateDirectedness(EdgeGroupData ed1, EdgeGroupData ed2)
 {
     if ((VectorTools.Distance(ed1.V1, ed2.V1) + VectorTools.Distance(ed1.V2, ed2.V2)) <
         (VectorTools.Distance(ed1.V1, ed2.V2) + VectorTools.Distance(ed1.V2, ed2.V1)))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Collects data from the specified edge.
        /// Used for edges that already have control points metadata.
        /// </summary>
        ///
        /// <param name="e">
        /// Edge to collect data from
        /// </param>
        private void AddExistingData(TEdge e)
        {
            EdgeGroupData ed;
            var           key = new KeyPair(e.Source.ID, e.Target.ID);

            _edgeGroupData.TryGetValue(key, out ed);

            if (ed == null)
            {
                var p1 = VertexPositions[e.Source]; // e.Vertices[0].Location;
                var p2 = VertexPositions[e.Target]; //e.Vertices[1].Location;
                ed = new EdgeGroupData {
                    V1 = p1, V2 = p2, ID = key
                };
                var mid = VectorTools.MidPoint(p1, p2);
                ed.Middle = mid;
                ed.Length = VectorTools.Distance(p1, p2);

                ed.ControlPoints = e.RoutingPoints; //e.GetValue(ReservedMetadataKeys.PerEdgeIntermediateCurvePoints);

                if (_subdivisionPoints == 0)
                {
                    _subdivisionPoints = ed.ControlPoints.Length;
                }
                ed.NewControlPoints = new Point[_subdivisionPoints];
                ed.K = _springConstant * (_subdivisionPoints + 1) / ed.Length;
                if (ed.K > 0.5f)
                {
                    ed.K = 0.5f;
                }
                //ed.edges = new HashSet<int>();
                ed.EdgeCount        = 0;
                ed.CompatibleGroups = new Dictionary <KeyPair, GroupPairData>();
                _edgeGroupData.Add(key, ed);
            }
            //ed.edges.Add(e.ID);
            ed.EdgeCount++;
        }