示例#1
0
 public PullToTargetPositions(PedigreeModel model)
 {
     step = delegate()
     {
         foreach (PedigreeIndividual pi in model.individuals)
         {
             PedigreeUtils.PullTowardX(model.TargetPositions[pi.HraPerson.relativeID].x, pi.point, 0.1, model);
             PedigreeUtils.PullTowardY(model.TargetPositions[pi.HraPerson.relativeID].y, pi.point, 0.1, model);
         }
     };
 }
示例#2
0
        /*************************************************************************************/
        public LayoutSipshipsTwo(PedigreeModel model)
        {
            step = delegate()
            {
                if (model.individuals.Count < 2)
                {
                    return;
                }

                //if (model.cycles > 150)
                //    return;
                //for each couple, layout their children
                foreach (PedigreeCouple parents in model.couples)
                {
                    parents.children.Sort(delegate(PedigreeIndividual a, PedigreeIndividual b)
                    {
                        double ax = EffectivePosition(a);
                        double bx = EffectivePosition(b);

                        return(ax.CompareTo(bx));
                    });

                    double sibWidth  = 0;
                    double leftEdge  = 0;
                    double rightEdge = 0;;

                    foreach (PedigreeIndividual child in parents.children)
                    {
                        leftEdge  = GetLeftEdge(child, double.MaxValue, model);
                        rightEdge = GetRightEdge(child, double.MinValue, model);

                        sibWidth += (rightEdge - leftEdge);
                    }
                    double spacing = sibWidth / ((double)(parents.children.Count));

                    double i = 0;
                    foreach (PedigreeIndividual child in parents.children)
                    {
                        //position the individuals vertically based on the
                        //positions of the parents:
                        double goalY    = parents.point.y + model.parameters.verticalSpacing;
                        double strength = model.parameters.verticalPositioningForceStrength;
                        PedigreeUtils.PullTowardY(goalY, child.point, strength, model);

                        double goalX = leftEdge + (spacing * i);
                        PedigreeUtils.PullTowardX(goalX, child.point, strength, model);

                        i++;
                    }
                }
            };
        }
示例#3
0
        private PointWithVelocity GetPointUnderCursor(PedigreeModel model, double x, double y)
        {
            PedigreeIndividual individual = PedigreeUtils.GetIndividualUnderPoint(model, x, y);

            if (individual != null)
            {
                return(individual.point);
            }
            else
            {
                return(null);
            }
        }
        public PullTowardCenterHorizontally(PedigreeModel model)
        {
            step = delegate()
            {
                if (model.individuals.Count < 2)
                {
                    return;
                }

                //pull everything gently toward the center horizontally
                //foreach (PointWithVelocity point in model.points)
                //{
                //    double goalX = (model.displayXMin + model.displayXMax) / 2;
                //    double strength = model.parameters.centeringForceStrength;
                //    //strength = 0.06;
                //    PedigreeUtils.PullTowardX(goalX, point,strength);
                //}

                //pull everything gently toward the center horizontally
                double minX = double.MaxValue;
                double maxX = -minX;

                foreach (PointWithVelocity point in model.points)
                {
                    if (point.x < minX)
                    {
                        minX = point.x;
                    }
                    else if (point.x > maxX)
                    {
                        maxX = point.x;
                    }
                }

                double centerX      = (minX + maxX) / 2;
                double idealCenterX = (model.displayXMin + model.displayXMax) / 2;
                double offset       = idealCenterX - centerX;
                foreach (PointWithVelocity point in model.points)
                {
                    double goalX    = point.x + offset;
                    double strength = model.parameters.centeringForceStrength;
                    PedigreeUtils.PullTowardX(goalX, point, strength, model);
                }
            };
        }
示例#5
0
        private void SeperateCouple(PedigreeCouple pc, PedigreeModel model, double sibMedian, ref List <PedigreeIndividual> kidsPulledToParents)
        {
            if (!model.parameters.hideNonBloodRelatives || (pc.mother.bloodRelative && pc.father.bloodRelative))
            {
                if (pc.mother.point.x < pc.father.point.x)
                {
                    PedigreeUtils.PullTowardX(pc.mother.point.x - 1, pc.mother.point, 0.1, model);
                    PedigreeUtils.PullTowardX(pc.father.point.x + 1, pc.father.point, 0.1, model);
                }
                else
                {
                    PedigreeUtils.PullTowardX(pc.mother.point.x + 1, pc.mother.point, 0.1, model);
                    PedigreeUtils.PullTowardX(pc.father.point.x - 1, pc.father.point, 0.1, model);
                }
            }
            else
            {
                double coupleAvg = (pc.mother.point.x + pc.father.point.x) / (2.0);
                pc.mother.point.x = coupleAvg;
                pc.father.point.x = coupleAvg;
            }

            double target = ((pc.mother.point.x + pc.father.point.x) / 2) - sibMedian;

            foreach (PedigreeIndividual pi in pc.children)
            {
                if (kidsPulledToParents.Contains(pi) == false)
                {
                    PedigreeUtils.PullTowardX((pc.mother.point.x + pc.father.point.x) / 2, pi.point, 0.075, model);
                    kidsPulledToParents.Add(pi);
                }
                //PedigreeUtils.PullTowardX(pi.point.x + target, pi.point, 0.1, model);
            }

            foreach (PedigreeCouple nested_pc in model.couples)
            {
                if (nested_pc != pc)
                {
                    if (pc.children.Contains(nested_pc.mother) || pc.children.Contains(nested_pc.father))
                    {
                        SeperateCouple(nested_pc, model, sibMedian, ref kidsPulledToParents);
                    }
                }
            }
        }
示例#6
0
        private static void pullParents(PedigreeModel model, PedigreeCouple couple, bool fatherToLeft)
        {
            double halfHSpacing = model.parameters.horizontalSpacing / 2;
            double reversal     = fatherToLeft ? 1 : -1;
            //position the father to the left
            {
                double            goalX    = couple.point.x - reversal * halfHSpacing;
                PointWithVelocity point    = couple.father.point;
                double            strength = model.parameters.layoutCouplesStrength;
                PedigreeUtils.PullTowardX(goalX, point, strength, model);
            }

            //position the mother to the right
            {
                double            goalX    = couple.point.x + reversal * halfHSpacing;
                PointWithVelocity point    = couple.mother.point;
                double            strength = model.parameters.layoutCouplesStrength;
                PedigreeUtils.PullTowardX(goalX, point, strength, model);
            }
        }
示例#7
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));
        }
示例#8
0
        public LayoutSibships(PedigreeModel model)
        {
            step = delegate()
            {
                if (model.individuals.Count < 2)
                {
                    return;
                }

                //if (model.cycles > 150)
                //    return;
                //for each couple, layout their children
                foreach (PedigreeCouple parents in model.couples)
                {
                    PedigreeCouple otherCouple = null;
                    foreach (PedigreeCouple otherparents in model.couples)
                    {
                        if (parents != otherparents && (parents.mother == otherparents.mother || parents.father == otherparents.father))
                        {
                            if (otherparents.alreadyHandledHalfSibship == false)
                            {
                                otherCouple = otherparents;
                                parents.alreadyHandledHalfSibship = true;
                                double oneleft  = double.MaxValue;
                                double oneright = double.MinValue;
                                double twoleft  = double.MaxValue;
                                double tworight = double.MinValue;
                                foreach (PedigreeIndividual one in parents.children)
                                {
                                    if (one.point.x < oneleft)
                                    {
                                        oneleft = one.point.x;
                                    }
                                    if (one.point.x > oneright)
                                    {
                                        oneright = one.point.x;
                                    }
                                }
                                foreach (PedigreeIndividual two in otherparents.children)
                                {
                                    if (two.point.x < twoleft)
                                    {
                                        twoleft = two.point.x;
                                    }
                                    if (two.point.x > tworight)
                                    {
                                        tworight = two.point.x;
                                    }
                                }
                                foreach (PedigreeIndividual two in otherparents.children)
                                {
                                    if (two.point.x < oneright && two.point.x > oneleft)
                                    {
                                        if (parents.point.x < otherparents.point.x)
                                        {
                                            PedigreeUtils.PullTowardX(tworight, two.point, 5, model);
                                        }
                                        else
                                        {
                                            PedigreeUtils.PullTowardX(oneleft, two.point, 5, model);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //Pull children toward their computed ideal locations as follows:
                    //Step 1 of 2: Sort sibship by x position
                    parents.children.Sort(delegate(PedigreeIndividual a, PedigreeIndividual b)
                    {
                        double ax = EffectivePosition(a);
                        double bx = EffectivePosition(b);

                        return(ax.CompareTo(bx));
                    });

                    //Step 2 of 2: Pull sibship members toward their ideal positions,
                    //spaced ideally and centered around thir parent couple, leaving
                    //open spaces for spouses (as they will be positioned by the
                    //layout step addressing couples).

                    double spacing;

                    //Compute the offset from the couple center for positioning individuals
                    double offset = 0;

                    int numIndividualsInSibshipSpan = 0;

                    //compute the center for the couple's sibship
                    double sibshipMinX = double.MaxValue;
                    double sibshipMaxX = -double.MaxValue;
                    for (int j = 0; j < parents.children.Count; j++)
                    {
                        PedigreeIndividual child = parents.children[j];

                        if (child.point.x < sibshipMinX)
                        {
                            sibshipMinX = (int)child.point.x;
                        }
                        if (child.point.x > sibshipMaxX)
                        {
                            sibshipMaxX = (int)child.point.x;
                        }

                        //double leftEdge = GetLeftEdge(child, double.MaxValue, model);
                        //double rightEdge = GetRightEdge(child, double.MinValue, model);

                        //if (leftEdge < sibshipMinX)
                        //    sibshipMinX = (int)leftEdge;
                        //if (rightEdge > sibshipMaxX)
                        //    sibshipMaxX = (int)rightEdge;


                        //count the child
                        numIndividualsInSibshipSpan++;

                        foreach (PedigreeCouple pc in child.spouseCouples)
                        {
                            //overlap += pc.childOverlap;
                            if (pc.mother != null && pc.father != null)
                            {
                                PedigreeIndividual spouse;
                                if (child.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                                {
                                    spouse = pc.father;
                                }
                                else
                                {
                                    spouse = pc.mother;
                                }

                                bool thisSpouseCounts = true;
                                bool spouseIsToRight  = spouse.point.x > child.point.x;

                                //don't count the spouse to the right of
                                //the sibship's rightmost child
                                if (j == parents.children.Count - 1 && spouseIsToRight)
                                {
                                    thisSpouseCounts = false;
                                }

                                //don't count the spouse to the left of
                                //the sibship's leftmost child
                                if (j == 0 && !spouseIsToRight)
                                {
                                    thisSpouseCounts = false;
                                }

                                if (model.parameters.hideNonBloodRelatives && !spouse.bloodRelative)
                                {
                                    thisSpouseCounts = false;
                                }

                                if (thisSpouseCounts)
                                {
                                    numIndividualsInSibshipSpan++;
                                }
                            }
                        }
                    }

                    double sibshipSpanSize = (sibshipMaxX - sibshipMinX) * model.parameters.sibshipShrinkingFacor;

                    if (numIndividualsInSibshipSpan == 1)
                    {
                        spacing = 0;
                    }
                    else
                    {
                        spacing = (sibshipSpanSize / (numIndividualsInSibshipSpan - 1));
                    }

                    if (spacing < model.parameters.horizontalSpacing)
                    {
                        spacing         = model.parameters.horizontalSpacing;
                        sibshipSpanSize = ((numIndividualsInSibshipSpan - 1) * spacing);
                    }

                    offset = parents.point.x - sibshipSpanSize / 2;

                    //position individuals ideally by applying a force to them
                    int i = 0;
                    foreach (PedigreeIndividual child in parents.children)
                    {
                        //position the individuals vertically based on the
                        //positions of the parents:
                        {
                            double goalY    = parents.point.y + model.parameters.verticalSpacing;
                            double strength = model.parameters.verticalPositioningForceStrength;
                            PedigreeUtils.PullTowardY(goalY, child.point, strength, model);
                        }

                        //position the individuals horizontally based on
                        //computation of their ideal horizontal positions
                        {
                            double goalX = offset;

                            //if the child has no spouse
                            if (child.spouseCouples.Count == 0)
                            {
                                //compute the position directly
                                //without incrementing i
                                goalX += i * spacing;
                            }

                            //if the child has a spouse, insert appropriate spacing
                            foreach (PedigreeCouple pc in child.spouseCouples)
                            {
                                if (pc.mother != null && pc.father != null)
                                {
                                    PedigreeIndividual spouse;
                                    if (child.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                                    {
                                        spouse = pc.father;
                                    }
                                    else
                                    {
                                        spouse = pc.mother;
                                    }

                                    if (!model.parameters.hideNonBloodRelatives || spouse.bloodRelative)
                                    {
                                        bool spouseIsToRight = spouse.point.x > child.point.x;
                                        int  index           = parents.children.IndexOf(child);
                                        //if the spouse is to the right...
                                        if (spouseIsToRight)
                                        {
                                            //...but not for the rightmost child
                                            if (index != parents.children.Count - 1)
                                            {
                                                //leave a space to the right.
                                                goalX = offset + (i++) * spacing;
                                            }
                                            else
                                            {
                                                goalX = offset + i * spacing;
                                            }
                                        }
                                        else//if the spouse is to the left...
                                            //...but not for the leftmost child
                                        if (index != 0)
                                        {
                                            //leave a space to the left.
                                            goalX = offset + (++i) * spacing;
                                        }
                                    }
                                    else
                                    {
                                        goalX += i * (spacing);
                                    }
                                }
                            }

                            double strength = model.parameters.layoutSibshipsStrength;
                            PedigreeUtils.PullTowardX(goalX, child.point, strength, model);
                            //increment i to account for enumeration this child
                            i++;
                        }
                    }
                }
            };
        }
示例#9
0
        public AttractCouples(PedigreeModel model)
        {
            step = delegate()
            {
                foreach (PedigreeCouple pc in model.couples)
                {
                    if ((pc.mother != null) && (pc.father != null))
                    {
                        if (pc.mother.Mother != null &&
                            pc.mother.Father != null &&
                            pc.father.Mother != null &&
                            pc.father.Father != null)
                        {
                            double motherAvgX = (pc.mother.Mother.point.x + pc.mother.Father.point.x) / 2;
                            double fatherAvgX = (pc.father.Mother.point.x + pc.father.Father.point.x) / 2;

                            if (pc.mother.point.x > pc.father.point.x && motherAvgX < fatherAvgX)
                            {
                                double temp = pc.mother.point.x;
                                pc.mother.point.x = pc.father.point.x;
                                pc.father.point.x = temp;
                            }
                            else if (pc.father.point.x > pc.mother.point.x && fatherAvgX < motherAvgX)
                            {
                                double temp = pc.mother.point.x;
                                pc.mother.point.x = pc.father.point.x;
                                pc.father.point.x = temp;
                            }
                        }

                        if (pc.children.Count > 0)
                        {
                            double xAcc   = 0;
                            double yAcc   = 0;
                            double sibMin = double.MaxValue;
                            double sibMax = double.MinValue;
                            foreach (PedigreeIndividual kid in pc.children)
                            {
                                xAcc += kid.point.x;
                                yAcc += kid.point.y;
                                if (sibMin > kid.point.x)
                                {
                                    sibMin = kid.point.x;
                                }
                                if (sibMax < kid.point.x)
                                {
                                    sibMax = kid.point.x;
                                }
                            }
                            xAcc  = (sibMin + sibMax) / 2;
                            yAcc /= (double)pc.children.Count;

                            double distance  = Math.Abs(pc.mother.point.x - pc.father.point.x);
                            double coupleAvg = (pc.mother.point.x + pc.father.point.x) / (2.0);

                            if (!model.parameters.hideNonBloodRelatives || (pc.mother.bloodRelative && pc.father.bloodRelative))
                            {
                                if (pc.mother.point.x < pc.father.point.x)
                                {
                                    PedigreeUtils.PullTowardX(xAcc - (distance / 2), pc.mother.point, 0.1, model);
                                    PedigreeUtils.PullTowardX(xAcc + (distance / 2), pc.father.point, 0.1, model);
                                }
                                else
                                {
                                    PedigreeUtils.PullTowardX(xAcc + (distance / 2), pc.mother.point, 0.1, model);
                                    PedigreeUtils.PullTowardX(xAcc - (distance / 2), pc.father.point, 0.1, model);
                                }


                                List <PedigreeIndividual> kidsPulledToParents = new List <PedigreeIndividual>();
                                if (Math.Abs(pc.mother.point.x - pc.father.point.x) < (0.90 * model.parameters.horizontalSpacing))
                                {
                                    SeperateCouple(pc, model, xAcc, ref kidsPulledToParents);
                                }
                            }
                            else
                            {
                                if (model.parameters.hideNonBloodRelatives)
                                {
                                    if (pc.mother.bloodRelative && !pc.father.bloodRelative)
                                    {
                                        PedigreeUtils.PullTowardX(pc.mother.point.x, pc.father.point, 0.1, model);
                                    }
                                    else if (!pc.mother.bloodRelative && pc.father.bloodRelative)
                                    {
                                        PedigreeUtils.PullTowardX(pc.father.point.x, pc.mother.point, 0.1, model);
                                    }
                                }

                                pc.mother.point.x = coupleAvg;
                                pc.father.point.x = coupleAvg;
                            }
                        }
                    }
                }
            };
        }
示例#10
0
        private bool LayoutIsValid(PedigreeModel model)
        {
            for (int generation = 0; generation < model.maxGenerationalLevel + 1; generation++)
            {
                //test for crossed edges
                foreach (PedigreeCouple coupleA in model.couples)
                {
                    if (coupleA.GenerationalLevel == generation)
                    {
                        foreach (PedigreeIndividual childA in coupleA.children)
                        {
                            foreach (PedigreeCouple coupleB in model.couples)
                            {
                                if (coupleB.GenerationalLevel == generation)
                                {
                                    foreach (PedigreeIndividual childB in coupleB.children)
                                    {
                                        if (coupleA != coupleB && childA != childB)
                                        {
                                            double x1 = coupleA.point.x;
                                            double y1 = coupleA.point.y;
                                            double x2 = childA.point.x;
                                            double y2 = childA.point.y;
                                            double x3 = coupleB.point.x;
                                            double y3 = coupleB.point.y;
                                            double x4 = childB.point.x;
                                            double y4 = childB.point.y;
                                            //does the edge from coupleA to childA
                                            //cross the edge from coupleB to childB?
                                            if (PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4))
                                            {
                                                //if yes then the layout is not valid
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //test for individuals inbetween fathers and mothers:
                //put all individuals in the current generation in a list
                PedigreeUtils.GetIndividualsInGeneration(model, generation, temp);



                if (model.couplesGraphIsPlanar)
                {
                    for (int i = 0; i < temp.Count; i++)
                    {
                        for (int j = 0; j < temp.Count; j++)
                        {
                            if (i != j)
                            {
                                if (Math.Abs(temp[i].point.x - temp[j].point.x) < (model.parameters.horizontalSpacing / 2))
                                {
                                    //if (model.couplesGraphIsPlanar && model.layoutIsValid == false)
                                    //{
                                    //if (model.parameters.repelIndividualSetsStrength < 10)
                                    //{
                                    //    model.parameters.repelIndividualSetsStrength += 0.5;
                                    //}
                                    //if (model.parameters.couplesAttractionStrength > 0.1)
                                    //{
                                    //    model.parameters.couplesAttractionStrength -= 0.1;
                                    //}
                                    //if (model.parameters.layoutCouplesStrength > 0.01)
                                    //{
                                    //    model.parameters.layoutCouplesStrength -= 0.01;
                                    //}
                                    //if (model.parameters.centeringForceStrength > 0.01)
                                    //{
                                    //    model.parameters.centeringForceStrength -= 0.01;
                                    //}
                                    //if (model.parameters.sibshipShrinkingFacor > 0.01)
                                    //{
                                    //    model.parameters.sibshipShrinkingFacor -= 0.01;
                                    //}
                                    //}
                                    return(false);
                                }
                            }
                        }
                    }
                }
                //for each person who has a spouse, make sure the spouse is next to that person,
                //otherwise report an invalid layout
                for (int i = 0; i < temp.Count; i++)
                {
                    PedigreeIndividual individual = temp[i];
                    foreach (PedigreeCouple pc in individual.spouseCouples)
                    {
                        if (!model.parameters.hideNonBloodRelatives || (pc.mother.bloodRelative && pc.father.bloodRelative))
                        {
                            PedigreeIndividual spouse;
                            if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                            {
                                spouse = pc.father;
                            }
                            else
                            {
                                spouse = pc.mother;
                            }

                            bool coupleIsSplit = true;
                            if (i > 0)
                            {
                                if (temp[i - 1].HraPerson.relativeID == spouse.HraPerson.relativeID)
                                {
                                    coupleIsSplit = false;
                                }
                            }
                            if (i < temp.Count - 1)
                            {
                                if (temp[i + 1].HraPerson.relativeID == spouse.HraPerson.relativeID)
                                {
                                    coupleIsSplit = false;
                                }
                            }
                            if (coupleIsSplit)
                            {
                                return(false);
                            }
                        }
                    }
                    //if (individual.spouseCouples.Count == 1)
                    //{
                    //    PedigreeIndividual spouse = individual.Spouse;
                    //    bool coupleIsSplit = true;
                    //    if (i > 0)
                    //        if (temp[i - 1].relativeID == spouse.relativeID)
                    //            coupleIsSplit = false;
                    //    if (i < temp.Count - 1)
                    //        if (temp[i + 1].relativeID == spouse.relativeID)
                    //            coupleIsSplit = false;
                    //    if (coupleIsSplit)
                    //        return false;
                    //}
                }
            }
            return(true);
        }
示例#11
0
        public LayoutCouples(PedigreeModel model)
        {
            step = delegate()
            {
                if (model.individuals.Count < 2)
                {
                    return;
                }

                double hSpacing     = model.parameters.horizontalSpacing;
                double halfHSpacing = hSpacing / 2;

                //for each couple, layout the mothers and fathers with no parents
                foreach (PedigreeCouple couple in model.couples)
                {
                    if (model.parameters.hideNonBloodRelatives && couple.mother.bloodRelative && !couple.father.bloodRelative)
                    {
                        couple.father.point.x = couple.mother.point.x;
                        couple.point.x        = couple.mother.point.x;
                    }
                    else if (model.parameters.hideNonBloodRelatives && couple.father.bloodRelative && !couple.mother.bloodRelative)
                    {
                        couple.mother.point.x = couple.father.point.x;
                        couple.point.x        = couple.father.point.x;
                    }
                    else
                    {
                        if (couple.mother != null && couple.father != null)
                        {
                            bool motherHasParents = couple.mother.Parents != null;
                            bool fatherHasParents = couple.father.Parents != null;

                            //if mother and father both have parents,
                            if (motherHasParents && fatherHasParents)
                            {
                                bool fatherToLeft = couple.father.Parents.point.x < couple.mother.Parents.point.x;
                                pullParents(model, couple, fatherToLeft);
                            }
                            //if the mother has parents but the father doesn't,
                            else if (motherHasParents && !fatherHasParents)
                            {
                                //then the mother will be pulled into position by
                                //the layout step for her sibship, so position the
                                //father depending on where the mother is:

                                //pull the father to the left of the mother
                                double            goalX    = couple.mother.point.x - hSpacing;
                                PointWithVelocity point    = couple.father.point;
                                double            strength = model.parameters.layoutCouplesStrength;
                                PedigreeUtils.PullTowardX(goalX, point, strength, model);
                            }
                            //if the father has parents but the mother diesn't,
                            else if (!motherHasParents && fatherHasParents)
                            {
                                //then the father will be pulled into position by
                                //the layout step for his sibship, so position the
                                //mother depending on where the father is:

                                //pull the mother to the right of the father
                                double            goalX    = couple.father.point.x + hSpacing;
                                PointWithVelocity point    = couple.mother.point;
                                double            strength = model.parameters.layoutCouplesStrength;
                                PedigreeUtils.PullTowardX(goalX, point, strength, model);
                            }
                            //if neither the father nor the mother has parents,
                            else if (!motherHasParents && !fatherHasParents)
                            {
                                //then position them according to their spouse position,
                                //placing the father on the left:
                                {
                                    //handle the case of half siblings:
                                    bool coupleIsReversed = false;
                                    if (couple.mother.spouseCouples.Count == 2)
                                    {
                                        PedigreeCouple oppositeCouple;
                                        if (couple.mother.spouseCouples[0].Equals(couple))
                                        {
                                            oppositeCouple = couple.mother.spouseCouples[1];
                                        }
                                        else
                                        {
                                            oppositeCouple = couple.mother.spouseCouples[0];
                                        }

                                        double oppositeX = oppositeCouple.point.x;
                                        double motherX   = couple.point.x;
                                        bool   oppositeCoupleIsLeftOfMother = oppositeX < motherX;

                                        coupleIsReversed = oppositeCoupleIsLeftOfMother;
                                    }

                                    bool fatherToLeft = !coupleIsReversed;
                                    pullParents(model, couple, fatherToLeft);
                                }
                            }
                        }
                    }
                }
            };
        }
示例#12
0
        private bool LayoutIsValid(PedigreeModel model)
        {
            List <PedigreeIndividual> temp = new List <PedigreeIndividual>();

            for (int generation = 0; generation <= model.maxGenerationalLevel + 1; generation++)
            {
                //test for crossed edges
                foreach (PedigreeCouple coupleA in model.couples)
                {
                    if (coupleA.GenerationalLevel == generation)
                    {
                        foreach (PedigreeIndividual childA in coupleA.children)
                        {
                            foreach (PedigreeCouple coupleB in model.couples)
                            {
                                if (coupleB.GenerationalLevel == generation)
                                {
                                    foreach (PedigreeIndividual childB in coupleB.children)
                                    {
                                        if (coupleA != coupleB && childA != childB)
                                        {
                                            double x1 = coupleA.point.x;
                                            double y1 = coupleA.point.y;
                                            double x2 = childA.point.x;
                                            double y2 = childA.point.y;
                                            double x3 = coupleB.point.x;
                                            double y3 = coupleB.point.y;
                                            double x4 = childB.point.x;
                                            double y4 = childB.point.y;
                                            //does the edge from coupleA to childA
                                            //cross the edge from coupleB to childB?
                                            if (PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4))
                                            {
                                                //if yes then the layout is not valid
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //test for individuals inbetween fathers and mothers:
                //put all individuals in the current generation in a list
                PedigreeUtils.GetIndividualsInGeneration(model, generation, temp);

                for (int i = 0; i < temp.Count; i++)
                {
                    for (int j = 0; j < temp.Count; j++)
                    {
                        if (i != j)
                        {
                            if (Math.Abs(temp[i].point.x - temp[j].point.x) < (model.parameters.horizontalSpacing / 2))
                            {
                                return(false);
                            }
                        }
                    }
                }
                //for each person who has a spouse, make sure the spouse is next to that person,
                //otherwise report an invalid layout
                for (int i = 0; i < temp.Count; i++)
                {
                    PedigreeIndividual individual = temp[i];
                    foreach (PedigreeCouple pc in individual.spouseCouples)
                    {
                        PedigreeIndividual spouse;
                        if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                        {
                            spouse = pc.father;
                        }
                        else
                        {
                            spouse = pc.mother;
                        }

                        bool coupleIsSplit = true;
                        if (i > 0)
                        {
                            if (temp[i - 1].HraPerson.relativeID == spouse.HraPerson.relativeID)
                            {
                                coupleIsSplit = false;
                            }
                        }
                        if (i < temp.Count - 1)
                        {
                            if (temp[i + 1].HraPerson.relativeID == spouse.HraPerson.relativeID)
                            {
                                coupleIsSplit = false;
                            }
                        }
                        if (coupleIsSplit)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
示例#13
0
        public StaticLayout(PedigreeModel model, PedigreeController layoutEngine)
        {
            transitionToStaticLayout = delegate()
            {
                if (model.cycles > 1000 || (model.cycles > 800 && model.couplesGraphIsPlanar && model.layoutIsValid == false))// && model.forcesHaveConverged)
                {
                    //switch modes from self organizing to static
                    if (layoutEngine.GetMode() == PedigreeController.SELF_ORGANIZING)
                    {
                        model.TargetPositions.Clear();
                        foreach (PedigreeIndividual pi in model.individuals)
                        {
                            PointWithVelocity pos = new PointWithVelocity();
                            pos.x = pi.point.x;
                            pos.y = pi.point.y;
                            model.TargetPositions.Add(pi.HraPerson.relativeID, pos);
                        }

                        layoutEngine.SetMode(PedigreeController.STATIC_LAYOUT);
                        generations = new List <List <PedigreeIndividual> >();
                        //initialize the per-level ordering lists for each generation
                        for (int generation = 0; generation <= model.maxGenerationalLevel + 1; generation++)
                        {
                            generations.Add(PedigreeUtils.GetIndividualsInGeneration(model, generation));
                        }

                        readyToRunStaticLayout = true;
                    }
                }
            };
            step = delegate()
            {
                if (runOnce && readyToRunStaticLayout)
                {
                    failedAttempts++;

                    readyToRunStaticLayout = false;
                    double spacing = model.parameters.verticalSpacing;
                    double centerY = (model.displayYMin + model.displayYMax) / 2;
                    double offset  = centerY - (model.maxGenerationalLevel + 1) * spacing / 2;

                    double initialX = 30;
                    double initialY = centerY;
                    //for each generation, bottom to top...
                    for (int g = generations.Count - 1; g >= 0; g--)
                    //for(int i = 0;i<generations.Count;i++)
                    {
                        List <PedigreeIndividual> generation = generations[g];

                        //compute the y positions
                        foreach (PedigreeIndividual individual in generation)
                        {
                            individual.point.y = g * spacing + offset;
                        }

                        //for the bottom level, just position with even spaces
                        if (g == generations.Count - 1)
                        {
                            double x = initialX;
                            foreach (PedigreeIndividual individual in generation)
                            {
                                individual.point.x  = x += model.parameters.horizontalSpacing;
                                individual.wasMoved = true;
                            }
                        }
                        //for all the other levels...
                        else
                        {
                            //First compute locations of parents centered around their children
                            //and place the parent couples exactly at those centers:

                            //for each individual in the current generation...
                            for (int j = 0; j < generation.Count; j++)
                            {
                                PedigreeIndividual individual = generation[j];

                                //if the current individual has a spouse...
                                foreach (PedigreeCouple pc in individual.spouseCouples)
                                {
                                    //so we compute the center of this couple's sibship,
                                    double sibshipCenterX = pc.GetSibshipCenterX(model);

                                    //and position the couple such that its center is the same as the sibship center

                                    if (pc.father.point.x < pc.mother.point.x)
                                    {
                                        pc.father.point.x = sibshipCenterX - model.parameters.horizontalSpacing / 2;
                                        pc.mother.point.x = sibshipCenterX + model.parameters.horizontalSpacing / 2;
                                    }
                                    else
                                    {
                                        pc.mother.point.x = sibshipCenterX - model.parameters.horizontalSpacing / 2;
                                        pc.father.point.x = sibshipCenterX + model.parameters.horizontalSpacing / 2;
                                    }
                                    pc.mother.wasMoved = pc.father.wasMoved = true;
                                }
                            }
                            /**/

                            //Second, position the outer children:
                            //find the leftmost individual that was placed
                            for (int inc = 1; inc >= -1; inc -= 2)
                            {
                                for (int j = inc == 1 ? 0 : generation.Count - 1;
                                     inc == 1 ? j < generation.Count : j >= 0;
                                     j += inc)
                                {
                                    if (generation[j].wasMoved)
                                    {
                                        for (int i = j - inc;
                                             inc == 1 ? i >= 0 : i < generation.Count; i -= inc)
                                        {
                                            generation[i].point.x  = generation[i + inc].point.x - inc * model.parameters.horizontalSpacing;
                                            generation[i].wasMoved = true;
                                        }
                                        break;
                                    }
                                }
                            }



                            //Third, detect "too close"ness and move individuals to be perfectly spaced,
                            //propagating left to right and downward through children
                            for (int j = 0; j < generation.Count - 1; j++)
                            {
                                PedigreeIndividual left  = generation[j];
                                PedigreeIndividual right = generation[j + 1];
                                //if folks are too close...
                                if (right.point.x - left.point.x < model.parameters.horizontalSpacing)
                                {
                                    //move the individual on the right such that spacing is perfect,
                                    //based on the current position of the individual on the left
                                    double dx = left.point.x + model.parameters.horizontalSpacing - right.point.x;
                                    right.point.x += dx;
                                    right.wasMoved = true;

                                    for (int z = j + 2; z < generation.Count - 1; z++)
                                    {
                                        PedigreeIndividual farRight = generation[z];
                                        farRight.point.x += dx;
                                        farRight.wasMoved = true;
                                    }
                                    //and through their children
                                    foreach (PedigreeCouple pc in left.spouseCouples)
                                    {
                                        PedigreeIndividual spouse;
                                        if (left.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                                        {
                                            spouse = pc.father;
                                        }
                                        else
                                        {
                                            spouse = pc.mother;
                                        }

                                        if (right.HraPerson.relativeID == spouse.HraPerson.relativeID)
                                        {
                                            //PedigreeCouple couple = GetCoupleFromLR(model, left, right);
                                            //if (couple != null)
                                            MoveChildren(dx, pc, model);
                                        }
                                    }
                                }
                            }
                        }
                    }


                    for (int g = 0; g < generations.Count - 1; g++)
                    {
                        List <PedigreeIndividual> generation = generations[g];
                        //for (int j = 0; j <  1; j++)
                        for (int j = generation.Count - 1; j >= 0; j--)
                        {
                            PedigreeIndividual left = generation[j];
                            if (left.HasSpouse())
                            {
                                //PedigreeCouple couple = GetCoupleFromLR(model, left, right);
                                foreach (PedigreeCouple pc in model.couples)
                                {
                                    double parentsX = (pc.mother.point.x + pc.father.point.x) / 2;
                                    if (pc.mother == left || pc.father == left)
                                    {
                                        double kidsX = 0;
                                        foreach (PedigreeIndividual kid in pc.children)
                                        {
                                            kidsX += kid.point.x;
                                        }
                                        kidsX = kidsX / ((double)(pc.children.Count));
                                        foreach (PedigreeIndividual kid in pc.children)
                                        {
                                            kid.point.x += (parentsX - kidsX);

                                            foreach (PedigreeCouple kidsPC in kid.spouseCouples)
                                            {
                                                PedigreeIndividual spouse;
                                                if (left.HraPerson.relativeID == pc.mother.HraPerson.relativeID)
                                                {
                                                    spouse = pc.father;
                                                }
                                                else
                                                {
                                                    spouse = pc.mother;
                                                }

                                                spouse.point.x += (parentsX - kidsX);
                                                spouse.wasMoved = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                    //after positioning everyone, center the pedigree on the screen:
                    double minX = double.MaxValue;
                    double maxX = -minX;

                    foreach (PointWithVelocity point in model.points)
                    {
                        if (point.x < minX)
                        {
                            minX = point.x;
                        }
                        else if (point.x > maxX)
                        {
                            maxX = point.x;
                        }
                    }

                    double centerX      = (minX + maxX) / 2;
                    double idealCenterX = (model.displayXMin + model.displayYMax) / 2;
                    double off          = idealCenterX - centerX;
                    foreach (PointWithVelocity point in model.points)
                    {
                        point.x = point.x + off;
                    }
                }

                //if (LayoutIsValid(model))
                if (true)
                {
                    //model.parameters.repelIndividualSetsStrength = 1;

                    layoutEngine.SetMode(PedigreeController.MANUAL);
                }
                //else
                //{

                //layoutEngine.SetMode(PedigreeController.SELF_ORGANIZING);

                //if (failedAttempts < 5)
                //{

                //model.parameters.repelIndividualSetsStrength += 0.5;
                //}
                //else if (failedAttempts < 10)
                //{
                //    model.parameters.repelIndividualSetsStrength = 1;
                //    foreach (PointWithVelocity p in model.points)
                //    {
                //        double newX = autoRand.NextDouble() * (model.displayXMax - 1);
                //        double newY = autoRand.NextDouble() * (model.displayYMax - 1);
                //        p.x = newX;
                //        p.dx = 0;
                //        p.y = newY;
                //        p.dy = 0;

                //    }
                //}
                //else
                //{
                //    layoutEngine.SetMode(PedigreeController.MANUAL);
                //}
                /**/
                //}
            };
        }
示例#14
0
 public void Repel(PedigreeIndividual pi, int delta, PedigreeModel model)
 {
     PedigreeUtils.PullTowardX(pi.point.x + delta, pi.point, model.parameters.repelIndividualSetsStrength, model);
 }
示例#15
0
        public RepelIndividuals(PedigreeModel model)
        {
            step = delegate()
            {
                foreach (PedigreeIndividual pi in model.individuals)
                {
                    foreach (PedigreeIndividual neighbor in model.individuals)
                    {
                        if (pi != neighbor)
                        {
                            if (Math.Abs(neighbor.point.y - pi.point.y) < (model.parameters.verticalSpacing / 2))
                            {
                                if (Math.Abs(neighbor.point.x - pi.point.x) < model.parameters.horizontalSpacing)
                                {
                                    if (!model.parameters.hideNonBloodRelatives || (neighbor.bloodRelative && pi.bloodRelative))
                                    {
                                        if (pi.Group == null || pi.Group.Contains(neighbor) == false)
                                        {
                                            if (neighbor.point.x < pi.point.x)
                                            {
                                                PedigreeUtils.PullTowardX(neighbor.point.x + model.parameters.horizontalSpacing, pi.point, model.parameters.repelIndividualSetsStrength, model);
                                            }
                                            else
                                            {
                                                PedigreeUtils.PullTowardX(neighbor.point.x - model.parameters.horizontalSpacing, pi.point, model.parameters.repelIndividualSetsStrength, model);
                                            }
                                        }
                                    }
                                }

                                //check for neighnor placed between person and spouse
                                if (neighbor.HraPerson.motherID == pi.HraPerson.motherID || neighbor.HraPerson.fatherID == pi.HraPerson.fatherID)
                                {
                                    foreach (PedigreeCouple pc in pi.spouseCouples)
                                    {
                                        PedigreeIndividual spouse;
                                        if (pc.mother == pi)
                                        {
                                            spouse = pc.father;
                                        }
                                        else
                                        {
                                            spouse = pc.mother;
                                        }

                                        if (spouse != null)
                                        {
                                            if (neighbor.point.x > Math.Min(pi.point.x, spouse.point.x) && neighbor.point.x < Math.Max(pi.point.x, spouse.point.x))
                                            {
                                                double x = neighbor.point.x;
                                                neighbor.point.x = pi.point.x;
                                                pi.point.x       = x;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
        }
        public PullTowardIdealVerticalPositions(PedigreeModel model)
        {
            step = delegate()
            {
                if (model.individuals.Count < 2)
                {
                    return;
                }

                double spacing = model.parameters.verticalSpacing;
                double centerY = (model.displayYMin + model.displayYMax) / 2;
                double offset  = centerY - (model.maxGenerationalLevel + 1) * spacing / 2;
                foreach (PedigreeCouple couple in model.couples)
                {
                    //pull the couples toward their optimal positions
                    //based on their generational level
                    int level = couple.GenerationalLevel;
                    if (level >= 0)
                    {
                        double goalY    = level * spacing + offset;
                        double strength = model.parameters.verticalPositioningForceStrength;
                        PedigreeUtils.PullTowardY(goalY, couple.point, strength, model);

                        //position the individuals vertically based on the
                        //positions of the couples:
                        goalY    = couple.point.y;
                        strength = model.parameters.verticalPositioningForceStrength;
                        if (couple.mother != null)
                        {
                            if (model.pointsBeingDragged.Contains(couple.mother.point) == false)
                            {
                                PedigreeUtils.PullTowardY(goalY, couple.mother.point, strength, model);
                                //foreach (PedigreeCouple pc in couple.mother.spouseCouples)
                                //{
                                //    PedigreeUtils.PullTowardY(goalY, pc.father.point, strength, model);
                                //}
                            }
                        }
                        if (couple.father != null)
                        {
                            if (model.pointsBeingDragged.Contains(couple.father.point) == false)
                            {
                                PedigreeUtils.PullTowardY(goalY, couple.father.point, strength, model);
                                //foreach (PedigreeCouple pc in couple.father.spouseCouples)
                                //{
                                //    PedigreeUtils.PullTowardY(goalY, pc.mother.point, strength, model);
                                //}
                            }
                        }
                        foreach (PedigreeIndividual pi in couple.children)
                        {
                            if (model.pointsBeingDragged.Contains(pi.point) == false)
                            {
                                if ((couple.mother != null) && (couple.father != null))
                                {
                                    double target = ((couple.mother.point.y + couple.father.point.y) / 2) + (model.parameters.verticalSpacing);
                                    pi.point.y = target;
                                    PedigreeUtils.PullTowardY(target, pi.point, model.parameters.verticalPositioningForceStrength, model);
                                }
                            }
                        }
                    }
                }
            };
        }