예제 #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();
                ed.v1 = p1;
                ed.v2 = p2;
                ed.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++;
        }
예제 #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, ref r1))
            {
                return(0);
            }
            Intersects(q1, q2, p2, pn2, ref i2, ref r2);

            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);
            }
        }
예제 #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));
        }
예제 #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);
     }
 }
예제 #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();
                ed.v1 = p1;
                ed.v2 = p2;
                ed.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++;
        }