public IncrementControllerVariables(PedigreeModel model, PedigreeController layoutEngine) { step = delegate() { model.parameters.ControllerMode = layoutEngine.GetMode(); }; }
public LayoutHoldingPen(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; //pull everything gently toward the center horizontally int minX = int.MaxValue; int maxX = -minX; foreach (PedigreeIndividual pi in model.individuals) { if (model.HoldingPen.ContainsKey(pi.HraPerson.relativeID) == false) { if (pi.point.x < minX) minX = (int)pi.point.x; } } model.parameters.HoldingPenOrigin.X = minX; int count = 0; foreach (PedigreeIndividual pi in model.HoldingPen.Values) { pi.point.x = model.parameters.HoldingPenOrigin.X + (model.parameters.horizontalSpacing * count); pi.point.y = model.parameters.HoldingPenOrigin.Y + (model.parameters.verticalSpacing / 2); count++; } }; }
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 AutoSave(PedigreeModel model, PedigreeController layoutEngine) { step = delegate() { layoutEngine.Finished(); }; }
public DetectValidLayout(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; model.layoutIsValid = LayoutIsValid(model); }; }
public DetectPlanarity(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; model.couplesGraphIsPlanar = CouplesGraphIsPlanar(model); }; }
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); } }; }
private static bool CouplesGraphIsPlanar(PedigreeModel model) { //TODO use http://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm int n = model.coupleEdges.Count; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (EdgesCross(model.coupleEdges[i], model.coupleEdges[j], model.parameters.hideNonBloodRelatives)) return false; return true; }
internal DrawLasso(PedigreeModel model) { step = delegate(Graphics g) { //turn on anti-aliasing (smooth lines) g.SmoothingMode = SmoothingMode.AntiAlias; LassoPen.DashPattern = new float[] { 2, 3 }; if (model.SelectionLasso.Count > 2) g.DrawPolygon(LassoPen, model.SelectionLasso.ToArray()); }; }
public IncrementIOVariables(PedigreeModel model) { step = delegate() { model.io.mousePressed = !model.io.pMouseDown && model.io.mouseDown; model.io.mouseReleased = model.io.pMouseDown && !model.io.mouseDown; model.io.pMouseDown = model.io.mouseDown; model.io.pMouseX = model.io.mouseX; model.io.pMouseY = model.io.mouseY; }; }
/*************************************************************************************/ 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++; } } }; }
public DrawZoom(PedigreeModel model) { step = delegate(Graphics g) { g.ScaleTransform(model.parameters.scale, model.parameters.scale); g.TranslateTransform(model.parameters.hOffset, model.parameters.vOffset); //g.FillEllipse(Brushes.Thistle, new Rectangle(new Point((int)(model.displayXMax / 2)-10, (int)(model.displayYMax / 2)-10), new Size(20, 20))); //g.DrawRectangle(Pens.Black, new Rectangle( // (int)model.displayXMin, // (int)model.displayYMin, // (int)(model.displayXMax - model.displayXMin), // (int)(model.displayYMax - model.displayYMin))); }; }
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); } } } }; }
public PedigreeView(PedigreeModel model) { AddDrawingStep(new ClearBackground(model).step); AddDrawingStep(new DrawLasso(model).step); AddDrawingStep(new DrawZoom(model).step); AddDrawingStep(new DrawAncestralConnectionLines(model).step); AddDrawingStep(new DrawIndividuals(model).step); AddDrawingStep(new DrawCouplesGraphNodes(model).step); AddDrawingStep(new DrawCouplesGraphEdges(model).step); AddDrawingStep(new DrawLayoutSteps(model).step); //AddDrawingStep(new DrawLoading(model).step); }
public DrawCouplesGraphNodes(PedigreeModel model) { step = delegate(Graphics g) { if (model.parameters.drawCouplesGraph) { tempRect.Width = tempRect.Height = model.parameters.coupleNodeRadius * 2; foreach (PedigreeCouple couple in model.couples) { tempRect.X = (int)couple.point.x - model.parameters.coupleNodeRadius; tempRect.Y = (int)couple.point.y - model.parameters.coupleNodeRadius; g.FillEllipse(b, tempRect); } } }; }
public ComputeCenters(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; if (model.couplesGraphIsPlanar) { foreach (PedigreeCouple couple in model.couples) { if (!model.pointsBeingDragged.Contains(couple.point)) { //compute the center for the couple if (couple.mother != null && couple.father != null) { double motherX = couple.mother.point.x; double motherY = couple.mother.point.y + model.parameters.individualSize / 2; double fatherX = couple.father.point.x; double fatherY = couple.father.point.y + model.parameters.individualSize / 2; double coupleCenterX = (motherX + fatherX) / 2; //compute the center for the couple's sibship double sibshipMinX = double.MaxValue; double sibshipMaxX = -double.MaxValue; foreach (PedigreeIndividual child in couple.children) { if (child.point.x < sibshipMinX) sibshipMinX = (int)child.point.x; if (child.point.x > sibshipMaxX) sibshipMaxX = (int)child.point.x; } double sibshipY = couple.point.y + model.parameters.verticalSpacing - model.parameters.individualSize / 2; double sibshipCenterX = (sibshipMinX + sibshipMaxX) / 2; //this is the middle point between parents and children from which //ideal positions of both are derived double middleX = (sibshipCenterX + coupleCenterX) / 2; couple.point.x = middleX; } } } } }; }
public DragPoints(PedigreeModel model, PedigreeController layoutEngine) { step = delegate() { //if the mouse was pressed and there were no couples being dragged, //drag the one under the mouse point. if (model.io.mousePressed) { double x = model.io.mouseX;// -model.parameters.hOffset; double y = model.io.mouseY;// -model.parameters.vOffset; PointWithVelocity pointUnderCursor = GetPointUnderCursor(model, x, y); if (model.Selected.Count < 2) { if (pointUnderCursor != null) model.pointsBeingDragged.Add(pointUnderCursor); } else { bool found = false; foreach (PedigreeIndividual pi in model.Selected) { model.pointsBeingDragged.Add(pi.point); if (pi.point == pointUnderCursor) { found = true; } } if (found == false) { model.pointsBeingDragged.Clear(); } } } if (model.io.mouseReleased) { model.pointsBeingDragged.Clear(); } foreach (PointWithVelocity point in model.pointsBeingDragged) { point.x += ((model.io.mouseX - model.io.pMouseX) / model.parameters.scale); point.y += ((model.io.mouseY - model.io.pMouseY) / model.parameters.scale); } }; }
public PlaceIndividualsOverCouples(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; if(!model.couplesGraphIsPlanar) foreach (PedigreeCouple couple in model.couples) { couple.mother.point.Set(couple.point); couple.father.point.Set(couple.point); foreach(PedigreeIndividual child in couple.children) child.point.Set(couple.point); } }; }
public IncrementVelocities(PedigreeModel model) { step = delegate() { foreach (PointWithVelocity point in model.points) { if (!model.pointsBeingDragged.Contains(point)) { point.x += point.dx; point.y += point.dy; point.dx *= model.parameters.dampeningFactor; point.dy *= model.parameters.dampeningFactor; } else point.dx = point.dy = 0; } }; }
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); } } }
/// <summary> /// Returns the individul under the given point, or null if none. /// </summary> public static PedigreeIndividual GetIndividualUnderPoint(PedigreeModel model, double x, double y) { x /= model.parameters.scale; y /= model.parameters.scale; x -= model.parameters.hOffset; y -= model.parameters.vOffset; //x /= model.parameters.scale; //y /= model.parameters.scale; foreach (PedigreeIndividual individual in model.individuals) { double dx = Math.Abs(x - individual.point.x); double dy = Math.Abs(y - individual.point.y); if (dx < model.parameters.individualSize/2 && dy < model.parameters.individualSize/2) return individual; } return null; }
internal double GetSibshipCenterX(PedigreeModel model) { //compute the center for the couple's sibship double sibshipMinX = double.MaxValue; double sibshipMaxX = -double.MaxValue; foreach (PedigreeIndividual child in children) { if (child.point.x < sibshipMinX) { sibshipMinX = (int)child.point.x; } if (child.point.x > sibshipMaxX) { sibshipMaxX = (int)child.point.x; } } double sibshipCenterX = (sibshipMinX + sibshipMaxX) / 2; return(sibshipCenterX); }
/// <summary> /// Derives a list of individuals in the given generational level, sorted by their X positions. /// The results get written to the "list" argument (after clearing it first). /// </summary> public static void GetIndividualsInGeneration(PedigreeModel model, int generation, List<PedigreeIndividual> list) { list.Clear(); foreach (PedigreeCouple couple in model.couples) { if (couple.GenerationalLevel == generation) { if (!list.Contains(couple.mother)) { if (!model.parameters.hideNonBloodRelatives || couple.mother.bloodRelative) list.Add(couple.mother); } if (!list.Contains(couple.father)) { if (!model.parameters.hideNonBloodRelatives || couple.father.bloodRelative) list.Add(couple.father); } } else if (couple.GenerationalLevel == generation - 1) foreach (PedigreeIndividual child in couple.children) if (!list.Contains(child)) { if (!model.parameters.hideNonBloodRelatives || child.bloodRelative) list.Add(child); } } //sort the list by x position list.Sort(delegate(PedigreeIndividual a, PedigreeIndividual b) { if (a == null) return 1; if (b == null) return -1; return a.point.x.CompareTo(b.point.x); }); }
public DrawLoading(PedigreeModel model) { step = delegate(Graphics g) { //moved to clear background //if (model.parameters.allRelativesAccountedFor == false) //{ // float x = (float)(model.displayXMax / 2) - 100; // float y = (float)(model.displayYMax / 2); // g.FillRectangle(new SolidBrush(Color.FromArgb(64, Color.Gray)), new Rectangle(0, 0, (int)model.displayXMax, (int)model.displayYMax)); // g.DrawString("Loading...", theFont, Brushes.WhiteSmoke, new PointF(x, y)); //} //if (model.parameters.ControllerMode == PedigreeController.SELF_ORGANIZING) //{ // float x = (float)(model.displayXMax / 2) - 100; // float y = 30; // g.DrawString("Organizing...", theOrganizingFont, Brushes.Red, new PointF(x, y)); //} }; }
public EllapsedTimeCheck(PedigreeModel model) { step = delegate() { model.cycles++; if (model.cycles % 200 == 0 && model.cycles <= 800 && model.layoutIsValid == false) { 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; } } }; }
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); } }; }
public LevelRestrictedForceDirectedLayout(PedigreeModel model) { step = delegate() { if (model.individuals.Count < 2) return; if (!model.couplesGraphIsPlanar) { attractAdjacentCouplePairs(model); repelAllCouplePairs(model); //int n = model.coupleEdges.Count; //for (int i = 0; i < n; i++) // for (int j = i + 1; j < n; j++) // if (model.edgesCross(model.coupleEdges[i], model.coupleEdges[j])) // { // ShrinkEdge(model.coupleEdges[i]); // ShrinkEdge(model.coupleEdges[j]); // } } }; }
public bool SetPersonFromHraValues(PedigreeIndividual pi, PedigreeModel pm) { bool retval = true; if (pi.HraPerson.x_norm > int.MinValue) { pi.point.x = (pm.displayXMax / 2) + pi.HraPerson.x_norm; } else { if (pi.HraPerson.x_position == 0) { retval = false; pi.point.x = pm.displayXMax / 2; } else { pi.point.x = (800 / pi.HraPerson.x_position) + ((pm.displayXMax - 800) / 2); } } if (pi.HraPerson.y_norm > int.MinValue) { pi.point.y = (pm.displayYMax / 2) + pi.HraPerson.y_norm; } else { if (pi.HraPerson.y_position == 0) { retval = false; pi.point.y = pm.displayYMax / 2; } else { pi.point.y = (600 / pi.HraPerson.y_position) + ((pm.displayYMax - 600) / 2); } } return retval; }
/**************************************************************************************************/ public void SetPedigreeModel(PedigreeModel model) { }
/**************************************************************************************************/ private void LoadFamilyWorking_DoWork(object sender, DoWorkEventArgs e) { while (FHxQueue.Count > 0) { RiskApps3.Model.PatientRecord.FHx.FamilyHistory fhx = FHxQueue.Dequeue(); if (FHxQueue.Count == 0) { PedigreeModel pm = new PedigreeModel(fhx) { controlHeight = this.Height, controlWidth = this.Width }; previosPos.Clear(); List<PedigreeIndividual> unplaced = new List<PedigreeIndividual>(); int matAuntUncCount = 0; int patAuntUncCount = 0; int brosisCount = 0; int childCount = 0; foreach (PedigreeIndividual pi in pm.individuals) { if (SetPersonFromHraValues(pi, pm) == false) { unplaced.Add(pi); } else { switch (Relationship.Parse(pi.HraPerson.relationship)) { case RelationshipEnum.SPOUSE: case RelationshipEnum.BROTHER: case RelationshipEnum.SISTER: brosisCount++; break; case RelationshipEnum.SON: case RelationshipEnum.DAUGHTER: childCount++; break; case RelationshipEnum.AUNT: case RelationshipEnum.UNCLE: if (pi.HraPerson.bloodline == "Maternal") { matAuntUncCount++; } else if (pi.HraPerson.bloodline == "Paternal") { patAuntUncCount++; } break; } } } foreach (PedigreeCouple pc in pm.couples) { if (LoadFamilyWorking.CancellationPending) return; if (pc.mother == null) { pc.point.x = pc.father.point.x; pc.point.y = pc.father.point.y; } else if (pc.father == null) { pc.point.x = pc.mother.point.x; pc.point.y = pc.mother.point.y; } else { pc.point.x = (pc.mother.point.x + pc.father.point.x) / 2; pc.point.y = (pc.mother.point.y + pc.father.point.y) / 2; } } Groups = new Dictionary<int, List<PedigreeIndividual>>(); foreach (PedigreeIndividual pi in pm.individuals) { if (pi.HraPerson.pedigreeGroup > 0) { if (Groups.Keys.Contains(pi.HraPerson.pedigreeGroup)) { Groups[pi.HraPerson.pedigreeGroup].Add(pi); pi.Group = Groups[pi.HraPerson.pedigreeGroup]; } else { List<PedigreeIndividual> newGroup = new List<PedigreeIndividual>(); newGroup.Add(pi); pi.Group = newGroup; Groups.Add(pi.HraPerson.pedigreeGroup, newGroup); } } } if (model != null) pm.parameters.Set(model.parameters); this.model = pm; //List<PedigreeIndividual> remainder = StaticLayout(unplaced, brosisCount, matAuntUncCount, patAuntUncCount, childCount); if (FHxQueue.Count == 0) { view = new PedigreeView(model); if (controller != null) { controller = new PedigreeController(model, controller.GetMode()); } else { controller = new PedigreeController(model, ""); } controller.ModelConvergedCallback += ModelConverged; } } } }
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; } } } } }; }