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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Common.Resources;
|
---|
28 | using HEAL.Attic;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
31 |
|
---|
32 | [Item("HeatMap", "A heat map of 2D data")]
|
---|
33 | [StorableType("F37D5082-48E9-495C-9489-F63C7C76E33A")]
|
---|
34 | public class HeatMap : NamedItem {
|
---|
35 |
|
---|
36 | public static new Image StaticItemImage { get { return VSImageLibrary.Image; } }
|
---|
37 |
|
---|
38 | #region Persistence
|
---|
39 |
|
---|
40 | private IEnumerable<float> GetPointCoordinates() {
|
---|
41 | foreach (var p in points) {
|
---|
42 | yield return p.X;
|
---|
43 | yield return p.Y;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | [Storable(Name = "Points")]
|
---|
48 | private List<float> PointsPersistence {
|
---|
49 | get {
|
---|
50 | return new List<float>(GetPointCoordinates());
|
---|
51 | }
|
---|
52 | set {
|
---|
53 | points = new List<PointF>();
|
---|
54 | var iter = value.GetEnumerator();
|
---|
55 | while (iter.MoveNext()) {
|
---|
56 | float x = iter.Current;
|
---|
57 | iter.MoveNext();
|
---|
58 | float y = iter.Current;
|
---|
59 | points.Add(new PointF(x, y));
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | #endregion
|
---|
64 |
|
---|
65 | private List<PointF> points;
|
---|
66 | public IEnumerable<PointF> Points {
|
---|
67 | get { return points; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void Add(IEnumerable<PointF> points) {
|
---|
71 | this.points.AddRange(points);
|
---|
72 | }
|
---|
73 |
|
---|
74 | [StorableConstructor]
|
---|
75 | protected HeatMap(StorableConstructorFlag _) : base(_) { }
|
---|
76 | protected HeatMap(HeatMap original, Cloner cloner)
|
---|
77 | : base(original, cloner) {
|
---|
78 | points = new List<PointF>(original.points.Select(p => new PointF(p.X, p.Y)));
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | public HeatMap() {
|
---|
83 | points = new List<PointF>();
|
---|
84 | Name = "Heat Map";
|
---|
85 | }
|
---|
86 |
|
---|
87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
88 | return new HeatMap(this, cloner);
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | internal void Clear() {
|
---|
93 | var oldPoints = points;
|
---|
94 | points = new List<PointF>();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|