Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Isolines/IsolineRenderer.cs @ 13777

Last change on this file since 13777 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Media;
6using System.Windows;
7using System.Diagnostics;
8using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
9using Microsoft.Research.DynamicDataDisplay.Charts.Shapes;
10using System.Windows.Threading;
11using System.Globalization;
12using Microsoft.Research.DynamicDataDisplay.Charts.NewLine;
13
14namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
15{
16  public abstract class IsolineRenderer : IsolineGraphBase
17  {
18    protected override void UpdateDataSource()
19    {
20      if (DataSource != null)
21      {
22        IsolineBuilder.DataSource = DataSource;
23        IsolineBuilder.MissingValue = MissingValue;
24        Collection = IsolineBuilder.BuildIsoline();
25      }
26      else
27      {
28        Collection = null;
29      }
30    }
31
32    protected IEnumerable<double> GetAdditionalLevels(IsolineCollection collection)
33    {
34      var dataSource = DataSource;
35      var visibleMinMax = dataSource.GetMinMax(Plotter2D.Visible);
36      double totalDelta = collection.Max - collection.Min;
37      double visibleMinMaxRatio = totalDelta / visibleMinMax.GetLength();
38      double defaultDelta = totalDelta / 12;
39
40      if (true || 2 * defaultDelta < visibleMinMaxRatio)
41      {
42        double number = Math.Ceiling(visibleMinMaxRatio * 4);
43        number = Math.Pow(2, Math.Ceiling(Math.Log(number) / Math.Log(2)));
44        double delta = totalDelta / number;
45        double x = collection.Min + Math.Ceiling((visibleMinMax.Min - collection.Min) / delta) * delta;
46
47        List<double> result = new List<double>();
48        while (x < visibleMinMax.Max)
49        {
50          result.Add(x);
51          x += delta;
52        }
53
54        return result;
55      }
56
57      return Enumerable.Empty<double>();
58    }
59
60    protected void RenderIsolineCollection(DrawingContext dc, double strokeThickness, IsolineCollection collection, CoordinateTransform transform)
61    {
62      foreach (LevelLine line in collection)
63      {
64        StreamGeometry lineGeometry = new StreamGeometry();
65        using (var context = lineGeometry.Open())
66        {
67          context.BeginFigure(line.StartPoint.ViewportToScreen(transform), false, false);
68          if (!UseBezierCurves)
69          {
70            context.PolyLineTo(line.OtherPoints.ViewportToScreen(transform).ToArray(), true, true);
71          }
72          else
73          {
74            context.PolyBezierTo(BezierBuilder.GetBezierPoints(line.AllPoints.ViewportToScreen(transform).ToArray()).Skip(1).ToArray(), true, true);
75          }
76        }
77        lineGeometry.Freeze();
78
79        Pen pen = new Pen(new SolidColorBrush(Palette.GetColor(line.Value01)), strokeThickness);
80
81        dc.DrawGeometry(null, pen, lineGeometry);
82      }
83    }
84
85  }
86}
Note: See TracBrowser for help on using the repository browser.