Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/VisualGenealogyGraphNode.cs @ 7779

Last change on this file since 7779 was 7779, checked in by bburlacu, 12 years ago

#1772: Implemented new View, improved functionality (tracking of fragments and operators)

File size: 3.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using HeuristicLab.Visualization;
26
27namespace HeuristicLab.EvolutionaryTracking.Views {
28  public class VisualGenealogyGraphNode : Ellipse {
29    public GenealogyGraphNode Data { get; internal set; }
30    internal List<VisualGenealogyGraphArc> IncomingArcs = new List<VisualGenealogyGraphArc>();
31    internal List<VisualGenealogyGraphArc> OutgoingArcs = new List<VisualGenealogyGraphArc>();
32
33    public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight)
34      : base(chart, lowerLeft, upperRight) {
35    }
36    public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2)
37      : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
38    }
39    public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
40      : base(chart, lowerLeft, upperRight, pen, brush) {
41    }
42    public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
43      : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
44    }
45
46    // compute the intersection point of an ellipse and a line passing through its center with the angular coordinate theta
47    public PointD CalculateIntersection(double theta) {
48      double sin = Math.Sin(theta);
49      double cos = Math.Cos(theta);
50      double a = Size.Width / 2;
51      double b = Size.Height / 2;
52      double r = a * b / Math.Sqrt(Math.Pow(a * sin, 2) + Math.Pow(b * cos, 2)); // radius at intersection point
53      double rx = r * cos; // X-component (relative to the origin/center of the ellipse)
54      double ry = r * sin; // Y-component (relative to the origin/center of the ellipse)
55      return new PointD(rx, ry);
56    }
57
58    public override void SetPosition(PointD lowLeft, PointD upRight) {
59      base.SetPosition(lowLeft, upRight);
60      foreach (var a in IncomingArcs) a.UpdatePosition();
61      foreach (var a in OutgoingArcs) a.UpdatePosition();
62    }
63
64    public PointD Center {
65      get { return new PointD((LowerLeft.X + UpperRight.X) / 2, (LowerLeft.Y + UpperRight.Y) / 2); }
66    }
67
68    public Color ToColor() {
69      return Color.FromArgb((int)((1 - Data.Quality) * 255), (int)(Data.Quality * 255), 0);
70    }
71
72    public override void Draw(Graphics graphics) {
73      if (Data.IsElite) {
74        Point p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
75        Size s = Chart.TransformWorldToPixel(Size);
76        if (Brush != null)
77          graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height);
78        graphics.DrawEllipse(Pen, p.X, p.Y, s.Width, s.Height);
79        graphics.DrawEllipse(Pen, p.X + 2, p.Y + 2, s.Width - 4, s.Height - 4);
80      } else {
81        base.Draw(graphics);
82      }
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.