Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/17 16:10:31 (7 years ago)
Author:
rhanghof
Message:

#2817:

  • Added line projection based bin packing
  • Added residual spaces to the view
Location:
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml

    r15307 r15488  
    3333             >
    3434    <Grid Margin="0,0,-64,-57">
    35         <CheckBox Name="showExtremePointsCheckBox" Content="Show extreme points" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,6,0,0" Unchecked="showExtremePointsCheckBoxOnUnchecked" Checked="showExtremePointsCheckBoxOnChecked"/>
    36         <Border BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="0,30,0,0">
     35        <StackPanel>
     36            <CheckBox Name="showExtremePointsCheckBox"
     37                      Content="Show extreme points"
     38                      VerticalAlignment="Top"
     39                      HorizontalAlignment="Left"
     40                      Margin="10,6,0,0"
     41                      Unchecked="ShowExtremePointsCheckBoxOnUnchecked"
     42                      Checked="ShowExtremePointsCheckBoxOnChecked"/>
     43            <CheckBox Name="showResidualSpaceCheckBox"
     44                      Content="Show residual spaces"
     45                      VerticalAlignment="Top"
     46                      HorizontalAlignment="Left"
     47                      Margin="10,6,0,0"
     48                      Unchecked="ShowResidualSpacesCheckBoxOnUnchecked"
     49                      Checked="ShowResidualSpacesCheckBoxOnChecked"/>
     50        </StackPanel>
     51        <Border BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Margin="0,52,0,0">
    3752            <Viewport3D Name="viewport3D1" Margin="0,-1,0,0" >
    3853                <Viewport3D.Camera>
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r15307 r15488  
    2727using System.Windows.Media.Media3D;
    2828using HeuristicLab.Problems.BinPacking3D;
     29using HeuristicLab.Collections;
    2930
    3031namespace HeuristicLab.Problems.BinPacking.Views {
     
    4950    private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA);
    5051    private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA);
     52    private static readonly Color residualSpaceColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0x00);
    5153
    5254    private Point startPos;
     
    5557    private double startAngleY;
    5658    private int selectedItemKey;
     59    private int selectedExtremePointIndex;
    5760    private bool showExtremePoints;
     61    private bool showResidualSpaces;
    5862
    5963    private BinPacking<BinPacking3D.PackingPosition, PackingShape, PackingItem> packing;
     
    7074    private Dictionary<int, DiffuseMaterial> materials;
    7175
     76    public ObservableDictionary<BinPacking3D.PackingPosition, Tuple<int, int, int>> ResidualSpaces { get; set; }
     77    public ObservableCollection<BinPacking3D.PackingPosition> ExtremePoints { get; set; }
     78
    7279    public Container3DView() {
    7380      InitializeComponent();
    7481      camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position
    7582      materials = new Dictionary<int, DiffuseMaterial>();
     83      ResidualSpaces = new ObservableDictionary<BinPacking3D.PackingPosition, Tuple<int, int, int>>();
     84      ExtremePoints = new ObservableCollection<BinPacking3D.PackingPosition>();
     85      selectedExtremePointIndex = -1;
    7686      Clear();
    7787    }
     
    8595    }
    8696
     97    /// <summary>
     98    /// Selects another extreme point
     99    /// </summary>
     100    /// <param name="index"></param>
     101    public void SelectExtremePoint(int index) {
     102      selectedExtremePointIndex = index;
     103      UpdateVisualization();
     104    }
     105
    87106    public void SelectItem(int itemKey) {
    88107      // selection of an item should make all other items semi-transparent
     
    90109      UpdateVisualization();
    91110    }
     111
    92112    public void ClearSelection() {
    93113      // remove all transparency
    94114      selectedItemKey = -1;
     115      selectedExtremePointIndex = -1;
    95116      UpdateVisualization();
    96117    }
     
    98119    private void UpdateVisualization() {
    99120      Clear();
    100       if (packing == null) return; // nothing to display
     121      if (packing == null)
     122        return; // nothing to display
    101123
    102124      var modelGroup = (Model3DGroup)MyModel.Content;
     
    108130
    109131        var colorIdx = selectedItem.Value.Material;
    110         while (colorIdx < 0) colorIdx += colors.Length;
     132        while (colorIdx < 0)
     133          colorIdx += colors.Length;
    111134        colorIdx = colorIdx % colors.Length;
    112135        var color = colors[colorIdx];
     
    132155          modelGroup.Children.Add(model);
    133156        }
     157
     158
    134159      } else {
    135160        foreach (var item in packing.Items) {
     
    144169          if (!materials.TryGetValue(item.Value.Material, out material)) {
    145170            var colorIdx = item.Value.Material;
    146             while (colorIdx < 0) colorIdx += colors.Length;
     171            while (colorIdx < 0)
     172              colorIdx += colors.Length;
    147173            colorIdx = colorIdx % colors.Length;
    148174            var color = colors[colorIdx];
     
    156182      }
    157183
    158       if (showExtremePoints) {
    159         // draw extreme-points
    160         var maxMag = (int)Math.Log10(Math.Max(packing.BinShape.Depth, Math.Max(packing.BinShape.Height, packing.BinShape.Width)));
    161         var cubeSize = (int)Math.Max(Math.Pow(10, maxMag - 2), 1);
    162         foreach (var ep in packing.ExtremePoints) {
    163           var epModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = new DiffuseMaterial() { Brush = new SolidColorBrush(Colors.Red) } };
    164           AddSolidCube((MeshGeometry3D)epModel.Geometry, ep.X, ep.Y, ep.Z, cubeSize, cubeSize, cubeSize);
    165           modelGroup.Children.Add(epModel);
    166         }
    167       }
     184
     185      AddExtremePoints(modelGroup);
    168186
    169187      var container = packing.BinShape;
     
    191209    }
    192210
     211    private void AddExtremePoints(Model3DGroup modelGroup) {
     212      if (showExtremePoints) {
     213        // draw extreme-points
     214        var maxMag = (int)Math.Log10(Math.Max(packing.BinShape.Depth, Math.Max(packing.BinShape.Height, packing.BinShape.Width)));
     215        var cubeSize = (int)Math.Max(Math.Pow(10, maxMag - 2), 1);
     216        BinPacking3D.PackingPosition selectedExtremePoint = null;
     217        if (selectedExtremePointIndex < 0) {
     218          foreach (var ep in ExtremePoints) {
     219            AddResidualSpacesForExtremePoint(modelGroup, ep);
     220          }
     221        } else {
     222          selectedExtremePoint = ExtremePoints.ToList()[selectedExtremePointIndex];
     223          AddResidualSpacesForExtremePoint(modelGroup, selectedExtremePoint);
     224        }
     225
     226        foreach (var ep in ExtremePoints) {
     227          Color color;
     228          if (ep.Equals(selectedExtremePoint)) {
     229            color = Colors.Yellow;
     230          } else {
     231            color = Colors.Red;
     232          }
     233          var epModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = new DiffuseMaterial() { Brush = new SolidColorBrush(color) } };
     234          AddSolidCube((MeshGeometry3D)epModel.Geometry, ep.X, ep.Y, ep.Z, cubeSize, cubeSize, cubeSize);
     235          modelGroup.Children.Add(epModel);
     236        }
     237      }
     238    }
     239
     240    private void AddResidualSpacesForExtremePoint(Model3DGroup modelGroup, BinPacking3D.PackingPosition extremePoint) {
     241      if (showResidualSpaces) {
     242        var rs = ResidualSpaces[extremePoint];
     243        var containerModel1 = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(residualSpaceColor)));
     244
     245        modelGroup.Children.Add(containerModel1);
     246        AddWireframeCube((MeshGeometry3D)containerModel1.Geometry,
     247          extremePoint.X,
     248          extremePoint.Y,
     249          extremePoint.Z,
     250          rs.Item1,
     251          rs.Item2,
     252          rs.Item3);
     253
     254      }
     255    }
     256
    193257
    194258    private void Clear() {
     
    202266
    203267    private void Container3DView_MouseMove(object sender, MouseEventArgs e) {
    204       if (!mouseDown) return;
     268      if (!mouseDown)
     269        return;
    205270      var pos = e.GetPosition((IInputElement)this);
    206271
     
    235300      Focus(); // for mouse wheel events
    236301    }
    237     private void showExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) {
     302    private void ShowExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) {
    238303      showExtremePoints = true;
    239304      UpdateVisualization();
    240305    }
    241     private void showExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {
     306    private void ShowExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {
    242307      showExtremePoints = false;
     308      UpdateVisualization();
     309    }
     310
     311    private void ShowResidualSpacesCheckBoxOnChecked(object sender, RoutedEventArgs e) {
     312      showResidualSpaces = true;
     313      UpdateVisualization();
     314    }
     315    private void ShowResidualSpacesCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {
     316      showResidualSpaces = false;
    243317      UpdateVisualization();
    244318    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.Designer.cs

    r14162 r15488  
    4949      this.elementHost = new System.Windows.Forms.Integration.ElementHost();
    5050      this.packingPlan3D = new HeuristicLab.Problems.BinPacking.Views.Container3DView();
     51      this.extremePointsSelection = new System.Windows.Forms.ListBox();
    5152      this.SuspendLayout();
    5253      //
     
    5859      this.binSelection.Location = new System.Drawing.Point(3, 3);
    5960      this.binSelection.Name = "binSelection";
    60       this.binSelection.Size = new System.Drawing.Size(54, 290);
     61      this.binSelection.Size = new System.Drawing.Size(54, 264);
    6162      this.binSelection.TabIndex = 4;
    6263      this.binSelection.SelectedIndexChanged += new System.EventHandler(this.binSelection_SelectedIndexChanged);
     
    6970      this.itemSelection.Location = new System.Drawing.Point(58, 3);
    7071      this.itemSelection.Name = "itemSelection";
    71       this.itemSelection.Size = new System.Drawing.Size(55, 290);
     72      this.itemSelection.Size = new System.Drawing.Size(55, 264);
    7273      this.itemSelection.TabIndex = 5;
    7374      this.itemSelection.SelectedIndexChanged += new System.EventHandler(this.itemSelection_SelectedIndexChanged);
     
    7879            | System.Windows.Forms.AnchorStyles.Left)
    7980            | System.Windows.Forms.AnchorStyles.Right)));
    80       this.elementHost.Location = new System.Drawing.Point(119, 3);
     81      this.elementHost.Location = new System.Drawing.Point(198, 3);
    8182      this.elementHost.Name = "elementHost";
    82       this.elementHost.Size = new System.Drawing.Size(229, 290);
     83      this.elementHost.Size = new System.Drawing.Size(273, 264);
    8384      this.elementHost.TabIndex = 6;
    8485      this.elementHost.Text = "elementHost";
    8586      this.elementHost.Child = this.packingPlan3D;
     87      //
     88      // extremePointsSelection
     89      //
     90      this.extremePointsSelection.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     91            | System.Windows.Forms.AnchorStyles.Left)));
     92      this.extremePointsSelection.FormattingEnabled = true;
     93      this.extremePointsSelection.Location = new System.Drawing.Point(115, 3);
     94      this.extremePointsSelection.Name = "extremePointsSelection";
     95      this.extremePointsSelection.Size = new System.Drawing.Size(77, 264);
     96      this.extremePointsSelection.TabIndex = 7;
     97      this.extremePointsSelection.SelectedIndexChanged += new System.EventHandler(this.extremePointsSelection_SelectedIndexChanged);
    8698      //
    8799      // PackingPlan3DView
     
    89101      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    90102      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     103      this.Controls.Add(this.extremePointsSelection);
    91104      this.Controls.Add(this.elementHost);
    92105      this.Controls.Add(this.itemSelection);
    93106      this.Controls.Add(this.binSelection);
    94107      this.Name = "PackingPlan3DView";
    95       this.Size = new System.Drawing.Size(351, 299);
     108      this.Size = new System.Drawing.Size(489, 278);
    96109      this.ResumeLayout(false);
    97110
     
    104117    private System.Windows.Forms.Integration.ElementHost elementHost;
    105118    private Container3DView packingPlan3D;
     119    private System.Windows.Forms.ListBox extremePointsSelection;
    106120  }
    107121}
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs

    r14167 r15488  
    4747      } else {
    4848        int i = 0;
    49         foreach (var bp in Content.Bins)
     49        foreach (var bp in Content.Bins) {
    5050          binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");
     51        }
     52
    5153
    5254        binSelection.SelectedIndex = 0;
     
    6365      itemSelection.SelectedIndex = -1;
    6466      itemSelection.Items.Clear();
     67      extremePointsSelection.Items.Clear();
     68      packingPlan3D.ResidualSpaces.Clear();
     69      packingPlan3D.ExtremePoints.Clear();
    6570
    6671      // add items of this container
     
    6974      foreach (var item in packing.Items) {
    7075        itemSelection.Items.Add(item.Key);
     76      }
     77      foreach (var ep in packing.ExtremePoints) {
     78        var rs = ((BinPacking3D.BinPacking3D)packing).ResidualSpace[ep];
     79        extremePointsSelection.Items.Add($"({ep.X}, {ep.Y}, {ep.Z})");
     80        packingPlan3D.ExtremePoints.Add(ep);
     81        packingPlan3D.ResidualSpaces.Add(ep, rs);
    7182      }
    7283
     
    8192        packingPlan3D.ClearSelection();
    8293    }
     94
     95    private void extremePointsSelection_SelectedIndexChanged(object sender, EventArgs e) {
     96      if (extremePointsSelection != null && extremePointsSelection.SelectedIndex >= 0) {
     97        packingPlan3D.SelectExtremePoint(extremePointsSelection.SelectedIndex);
     98      } else {
     99        packingPlan3D.ClearSelection();
     100      }
     101    }
    83102  }
    84103}
Note: See TracChangeset for help on using the changeset viewer.