Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/01/13 13:01:40 (11 years ago)
Author:
bburlacu
Message:

#1772: Merged remaining trunk changes into the EvolutionaryTracking branch.

Location:
branches/HeuristicLab.EvolutionaryTracking
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionaryTracking

  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views

  • branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r9587 r9835  
    2525using System.Drawing.Imaging;
    2626using System.Windows.Forms;
     27using Point = System.Drawing.Point;
    2728
    2829namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    4849    }
    4950
     51    #region Public properties
    5052    private int spacing;
    5153    public int Spacing {
     
    106108      set { suspendRepaint = value; }
    107109    }
     110    #endregion
    108111
    109112    protected override void OnPaint(PaintEventArgs e) {
     
    250253
    251254    #region methods for painting the symbolic expression tree
     255
    252256    private void DrawFunctionTree(ISymbolicExpressionTree tree, Graphics graphics, int x, int y, int width, int height) {
    253       DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty);
     257      //      DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty);
     258      AlternateDraw(tree, graphics, 70, 46, 20, 50);
     259    }
     260
     261    private void AlternateDraw(ISymbolicExpressionTree tree, Graphics graphics, int preferredWidth, int preferredHeight, int minDistance, int maxDistance) {
     262      var tl = new TreeLayout();
     263      tl.Distance = 5;
     264      tl.SymbolicExpressionTree = tree;
     265
     266      var nodePositions = tl.GetNodeCoordinates();
     267      var bounds = tl.Bounds();
     268
     269      double sx = Width / bounds.Width;
     270      double sy = Height / bounds.Height;
     271
     272      double dx = tl.Distance * sx; // scaled horizontal distance
     273      double dy = tl.Distance * sy; // scaled vertical distance
     274
     275      int maxWidth = (int)Math.Round(dx);
     276      int maxHeight = (int)Math.Round(dy);
     277
     278      // instead of using the preferred with/height of each node inside the foreach loop below,
     279      // we assume the same width/height for all nodes
     280      int w = Math.Min(preferredWidth, maxWidth - minDistance / 2);
     281      int h = Math.Min(preferredHeight, maxHeight - minDistance / 2);
     282      // adjust scaling factor so that nodes will be at most maxDistance far from each other on the horizontal axis
     283      double offset = 0;
     284      if (maxDistance + w < maxWidth) {
     285        sx *= (double)(maxDistance + w) / maxWidth;
     286        offset = (Width - (sx * bounds.Width)) / 2;
     287      }
     288      foreach (var node in visualTreeNodes.Keys) {
     289        var visualNode = visualTreeNodes[node];
     290        var pos = nodePositions[node];
     291        visualNode.Width = w;
     292        visualNode.Height = h;
     293        visualNode.X = (int)Math.Round(pos.X * sx + offset); ;
     294        visualNode.Y = (int)Math.Round(pos.Y * sy);
     295        DrawTreeNode(graphics, visualNode);
     296      }
     297      graphics.ResetClip(); // reset clip region
     298      foreach (var visualNode in visualTreeNodes.Values) {
     299        var node = visualNode.SymbolicExpressionTreeNode;
     300        foreach (var subtree in node.Subtrees) {
     301          var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree);
     302          var visualSubtree = visualTreeNodes[subtree];
     303          var origin = new Point(visualNode.X + visualNode.Width / 2, visualNode.Y + visualNode.Height);
     304          var target = new Point(visualSubtree.X + visualSubtree.Width / 2, visualSubtree.Y);
     305          using (var linePen = new Pen(visualLine.LineColor)) {
     306            linePen.DashStyle = visualLine.DashStyle;
     307            graphics.DrawLine(linePen, origin, target);
     308          }
     309        }
     310      }
    254311    }
    255312
     
    257314    ///
    258315    /// </summary>
    259     /// <param name="functionTree"> function tree to draw</param>
     316    /// <param name="node">the root of the function tree to draw</param>
    260317    /// <param name="graphics">graphics object to draw on</param>
    261318    /// <param name="x">x coordinate of drawing area</param>
     
    365422    }
    366423    #endregion
    367 
    368424    #region save image
    369425    private void saveImageToolStripMenuItem_Click(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.