private double EvaluateEdgeLength(
            CompoundGraph <object, IEdge <object> > compoundGraph,
            CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            Dictionary <object, Size> sizes,
            double idealEdgeLength,
            double nestingFactor)
        {
            double edgeLengthError = 0.0;

            foreach (var edge in compoundGraph.Edges)
            {
                var uPos  = algorithm.VertexPositions[edge.Source];
                var vPos  = algorithm.VertexPositions[edge.Target];
                var uSize = sizes[edge.Source];
                var vSize = sizes[edge.Target];

                var uPoint = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
                var vPoint = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

                double length      = (uPoint - vPoint).Length;
                bool   isInterEdge = compoundGraph.GetParent(edge.Source) != compoundGraph.GetParent(edge.Target);
                var    iel         = isInterEdge
                              ? idealEdgeLength *
                                     (algorithm.LevelOfVertex(edge.Source) + algorithm.LevelOfVertex(edge.Target) + 1) *
                                     nestingFactor
                              : idealEdgeLength;
                double err = Math.Pow(length - iel, 2);
                edgeLengthError += err;
            }
            return(edgeLengthError);
        }
示例#2
0
        private Vector GetRepulsionForce(Point uPos, Point vPos, Size uSize, Size vSize, double repulsionRange)
        {
            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                var compensationVector = new Vector(rnd.NextDouble(), rnd.NextDouble());
                positionVector = compensationVector * 2;
                uPos          += compensationVector;
                vPos          -= compensationVector;
            }
            positionVector.Normalize();

            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var F = c_u - c_v;
            var isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            var Fr = new Vector();

            if (isSameDirection && F.Length > repulsionRange)
            {
                return(new Vector());
            }
            double length = Math.Max(1, F.Length);

            //double length = F.LengthSquared;
            length = Math.Pow(isSameDirection ? length / (Parameters.IdealEdgeLength * 2.0) : 1 / length, 2);
            Fr     = Parameters.RepulsionConstant / length * positionVector * _phaseDependentRepulsionMultiplier;
            return(Fr);
        }
示例#3
0
        public Vector GetRepulsionForce(Point uPos, Point vPos, Size uSize, Size vSize, double repulsionRange)
        {
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                return(new Vector());
            }
            positionVector.Normalize();
            var F = c_u - c_v;
            var isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            var Fr = new Vector();

            /*if (isSameDirection)
             * {*/
            if (F.Length > repulsionRange)
            {
                return(new Vector());
            }
            double length = Math.Max(1, F.Length);

            length = Math.Pow(isSameDirection ? length : 1 / length, isSameDirection ? 2 : 1);
            Fr     = parameters.RepulsionConstant / length * positionVector;
            return(Fr);
        }
示例#4
0
        public void GetClippingPoint_Target_Outside_Source_Rect_ClippingPoint_OnBottomSide_Test()
        {
            Size  size     = new Size(10, 10);
            Point s        = new Point(5, 5);
            Point t        = new Point(20, 30);
            Point expected = new Point(8, 10);

            Point actual = LayoutUtil.GetClippingPoint(size, s, t);

            Assert.AreEqual(expected, actual);
        }
        private int EvaluateEdgeCrossing(
            CompoundGraph <object, IEdge <object> > compoundGraph,
            CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            Dictionary <object, Size> sizes)
        {
            int crossings = 0;

            foreach (var edge in compoundGraph.Edges)
            {
                var uPos1  = algorithm.VertexPositions[edge.Source];
                var vPos1  = algorithm.VertexPositions[edge.Target];
                var uSize1 = sizes[edge.Source];
                var vSize1 = sizes[edge.Target];

                var uPoint1 = LayoutUtil.GetClippingPoint(uSize1, uPos1, vPos1);
                var vPoint1 = LayoutUtil.GetClippingPoint(vSize1, vPos1, uPos1);
                foreach (var edge2 in compoundGraph.Edges)
                {
                    if (edge == edge2)
                    {
                        continue;
                    }

                    var uPos2  = algorithm.VertexPositions[edge.Source];
                    var vPos2  = algorithm.VertexPositions[edge.Target];
                    var uSize2 = sizes[edge.Source];
                    var vSize2 = sizes[edge.Target];

                    var uPoint2 = LayoutUtil.GetClippingPoint(uSize2, uPos2, vPos2);
                    var vPoint2 = LayoutUtil.GetClippingPoint(vSize2, vPos2, uPos2);

                    Vector v1 = (vPoint1 - uPoint1);
                    Vector v2 = (vPoint2 - uPoint2);

                    if (v1 == v2 || v1 == -v2)
                    {
                        continue; //parallel edges
                    }
                    var t2 = (uPoint1.Y - uPoint2.Y + (uPoint2.X - uPoint1.X) * v1.Y / v1.X) / (v2.Y - v2.X * v1.Y / v1.X);
                    var t1 = (uPoint2.X - uPoint1.X + t2 * v2.X) / v1.X;

                    var p  = uPoint1 + t1 * v1;
                    var b1 = t1 > 0 && (p - uPoint1).Length < (vPoint1 - uPoint1).Length;
                    var b2 = t2 > 0 && (p - uPoint2).Length < (vPoint2 - uPoint2).Length;

                    if (b1 && b2)
                    {
                        crossings++;
                    }
                }
            }
            return(crossings);
        }
示例#6
0
        public void GetClippingPoint_Target_Inside_Source_Rect_ClippingPoint_OnBottomSide_Test()
        {
            Size  size     = new Size(10, 10);
            Point s        = new Point(5, 5);
            Point t        = new Point(5.3, 5.5);
            Point expected = new Point(8, 10);

            Point  actual  = LayoutUtil.GetClippingPoint(size, s, t);
            double epsilon = 0.0000001;

            Assert.IsTrue(Math.Abs(expected.X - actual.X) < epsilon);
            Assert.IsTrue(Math.Abs(expected.Y - actual.Y) < epsilon);
        }
示例#7
0
        private Vector GetSpringForce(double idealLength, Point uPos, Point vPos, Size uSize, Size vSize)
        {
            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                var compensationVector = new Vector(_random.NextDouble(), _random.NextDouble());
                positionVector = compensationVector * 2;
                uPos          += compensationVector;
                vPos          -= compensationVector;
            }

            positionVector.Normalize();

            //get the clipping points
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            Vector F = (c_u - c_v);
            bool   isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            double length          = 0;

            if (isSameDirection)
            {
                length = F.Length - idealLength;
            }
            else
            {
                length = F.Length + idealLength;
            }

            if (F.Length == 0)
            {
                F = -positionVector;
            }
            F.Normalize();
            if (length > 0)
            {
                F *= -1;
            }

            var Fs = Math.Pow(length / (idealLength), 2) / Parameters.ElasticConstant * F;

            return(Fs);
        }
        private void EvaluateNodeDistances(
            CompoundGraph <object, IEdge <object> > compoundGraph,
            CompoundFDPLayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            Dictionary <object, Size> sizes,
            out double minimalMinDistance,
            out double averageMinDistance,
            out double maximalMinDistance)
        {
            minimalMinDistance = 0.0;
            averageMinDistance = 0.0;
            maximalMinDistance = 0.0;
            double count = 0;

            foreach (var level in algorithm.Levels)
            {
                foreach (var u in level)
                {
                    double m = double.PositiveInfinity;
                    foreach (var v in level)
                    {
                        if (u == v || compoundGraph.GetParent(u) != compoundGraph.GetParent(v))
                        {
                            continue;
                        }

                        var uPoint = LayoutUtil.GetClippingPoint(sizes[u], algorithm.VertexPositions[u],
                                                                 algorithm.VertexPositions[v]);
                        var vPoint = LayoutUtil.GetClippingPoint(sizes[v], algorithm.VertexPositions[v],
                                                                 algorithm.VertexPositions[u]);
                        double distance = (uPoint - vPoint).Length;
                        m = Math.Min(m, distance);
                    }
                    if (double.IsPositiveInfinity(m))
                    {
                        continue;
                    }
                    minimalMinDistance  = Math.Min(minimalMinDistance, m);
                    averageMinDistance += m;
                    count++;
                    maximalMinDistance = Math.Max(maximalMinDistance, m);
                }
            }
        }
示例#9
0
        public Vector GetSpringForce(Point uPos, Point vPos, Size uSize, Size vSize)
        {
            double idealLength = parameters.IdealEdgeLength;

            //get the clipping points
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var positionVector = (uPos - vPos);

            positionVector.Normalize();

            Vector F = (c_u - c_v);
            bool   isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            double length          = 0;

            if (isSameDirection)
            {
                length = F.Length - idealLength;
            }
            else
            {
                length = F.Length + idealLength;
            }

            if (F.Length == 0)
            {
                F = -positionVector;
            }
            F.Normalize();
            if (length > 0)
            {
                F *= -1;
            }

            var Fs = Math.Pow(length, 2) / parameters.ElasticConstant * F;

            return(Fs);
        }