Exemplo n.º 1
0
        public DrawCouplesGraphEdges(PedigreeModel model)
        {
            step = delegate(Graphics g)
            {
                if (model.parameters.drawCouplesGraph)
                {
                    int n = model.coupleEdges.Count;
                    crossedEdges.Clear();
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = i + 1; j < n; j++)
                        {
                            PedigreeCoupleEdge edgeA = model.coupleEdges[i];
                            PedigreeCoupleEdge edgeB = model.coupleEdges[j];

                            if (DetectPlanarity.EdgesCross(edgeA, edgeB, model.parameters.hideNonBloodRelatives))
                            {
                                crossedEdges.Add(edgeA);
                                crossedEdges.Add(edgeB);
                            }
                        }
                    }

                    foreach (PedigreeCoupleEdge edge in model.coupleEdges)
                    {
                        int x1 = (int)edge.u.point.x;
                        int y1 = (int)edge.u.point.y;
                        int x2 = (int)edge.v.point.x;
                        int y2 = (int)edge.v.point.y;

                        // Pen pen = model.couplesGraphIsPlanar ? couplesEdgePen : crossedEdgePen;
                        if (edge.intergenerational)
                        {
                            g.DrawLine(couplesEdgePen, x1, y1, x2, y2);
                        }
                        else
                        {
                            //if (x1 != x2 && y1 != y2)
                            //    g.DrawArc(couplesEdgePen, x1, y1,x2-x1, 50, 0, (float)Math.PI);
                            int height = model.parameters.halfSibsArcHeight;
                            int y      = (int)((y1 + y2) / 2) - height;
                            if (x2 > x1)
                            {
                                g.DrawArc(couplesEdgePen, x1, y, x2 - x1, height * 2, 0, -180);
                            }
                            else if (x1 > x2)
                            {
                                g.DrawArc(couplesEdgePen, x2, y, x1 - x2, height * 2, 0, -180);
                            }
                        }
                    }
                }
            };
        }
        private static void ShrinkEdge(PedigreeCoupleEdge edge, double strength)
        {
            PointWithVelocity a = edge.u.point;
            PointWithVelocity b = edge.v.point;

            double distance = b.x - a.x;

            double forceX = strength * distance;

            a.dx += forceX;
            b.dx -= forceX;
        }
Exemplo n.º 3
0
        public static bool EdgesCross(PedigreeCoupleEdge a, PedigreeCoupleEdge b, bool hiding)
        {
            if (a == null || b == null)
            {
                return(false);
            }

            if (hiding)
            {
                if (!a.u.mother.bloodRelative || !a.u.father.bloodRelative || !a.v.mother.bloodRelative || !a.v.father.bloodRelative)
                {
                    return(false);
                }
                if (!b.u.mother.bloodRelative || !b.u.father.bloodRelative || !b.v.mother.bloodRelative || !b.v.father.bloodRelative)
                {
                    return(false);
                }
            }
            bool aAndBShareAVertex = false;

            aAndBShareAVertex = aAndBShareAVertex || a.u == b.u;
            aAndBShareAVertex = aAndBShareAVertex || a.v == b.u;
            aAndBShareAVertex = aAndBShareAVertex || a.u == b.v;
            aAndBShareAVertex = aAndBShareAVertex || a.v == b.v;

            if (aAndBShareAVertex)
            {
                return(false);
            }

            double x1 = a.u.point.x;
            double y1 = a.u.point.y;
            double x2 = a.v.point.x;
            double y2 = a.v.point.y;
            double x3 = b.u.point.x;
            double y3 = b.u.point.y;
            double x4 = b.v.point.x;
            double y4 = b.v.point.y;

            return(PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4));
        }
        private static void CollapseEdge(PedigreeCoupleEdge edge, PedigreeModel model)
        {
            double avgX = (edge.u.point.x + edge.v.point.x) / 2;

            if (!model.pointsBeingDragged.Contains(edge.u.point))
            {
                edge.u.point.x = avgX;
            }
            if (!model.pointsBeingDragged.Contains(edge.v.point))
            {
                edge.v.point.x = avgX;
            }

            double avgY = (edge.u.point.y + edge.v.point.y) / 2;

            if (!model.pointsBeingDragged.Contains(edge.u.point))
            {
                edge.u.point.y = avgY;
            }
            if (!model.pointsBeingDragged.Contains(edge.v.point))
            {
                edge.v.point.y = avgY;
            }
        }
        private static void attractAdjacentCouplePairs(PedigreeModel model)
        {
            foreach (PedigreeCoupleEdge edge in model.coupleEdges)
            {
                ShrinkEdge(edge, attractionStrength);
            }

            int n = model.coupleEdges.Count;

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    PedigreeCoupleEdge edgeA = model.coupleEdges[i];
                    PedigreeCoupleEdge edgeB = model.coupleEdges[j];

                    if (DetectPlanarity.EdgesCross(edgeA, edgeB, model.parameters.hideNonBloodRelatives))
                    {
                        CollapseEdge(edgeA, model);
                        CollapseEdge(edgeB, model);
                    }
                }
            }
        }