Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/FDC/HeatMap.cs @ 13401

Last change on this file since 13401 was 7202, checked in by epitzer, 13 years ago

#1696: Add static item image according to #1651

File size: 2.7 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.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Common.Resources;
29
30namespace HeuristicLab.Analysis.FitnessLandscape {
31
32  [Item("HeatMap", "A heat map of 2D data")]
33  [StorableClass]
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(bool deserializing) : base(deserializing) { }
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}
Note: See TracBrowser for help on using the repository browser.