- Timestamp:
- 11/28/17 16:10:31 (7 years ago)
- 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 33 33 > 34 34 <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"> 37 52 <Viewport3D Name="viewport3D1" Margin="0,-1,0,0" > 38 53 <Viewport3D.Camera> -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r15307 r15488 27 27 using System.Windows.Media.Media3D; 28 28 using HeuristicLab.Problems.BinPacking3D; 29 using HeuristicLab.Collections; 29 30 30 31 namespace HeuristicLab.Problems.BinPacking.Views { … … 49 50 private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA); 50 51 private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA); 52 private static readonly Color residualSpaceColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0x00); 51 53 52 54 private Point startPos; … … 55 57 private double startAngleY; 56 58 private int selectedItemKey; 59 private int selectedExtremePointIndex; 57 60 private bool showExtremePoints; 61 private bool showResidualSpaces; 58 62 59 63 private BinPacking<BinPacking3D.PackingPosition, PackingShape, PackingItem> packing; … … 70 74 private Dictionary<int, DiffuseMaterial> materials; 71 75 76 public ObservableDictionary<BinPacking3D.PackingPosition, Tuple<int, int, int>> ResidualSpaces { get; set; } 77 public ObservableCollection<BinPacking3D.PackingPosition> ExtremePoints { get; set; } 78 72 79 public Container3DView() { 73 80 InitializeComponent(); 74 81 camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position 75 82 materials = new Dictionary<int, DiffuseMaterial>(); 83 ResidualSpaces = new ObservableDictionary<BinPacking3D.PackingPosition, Tuple<int, int, int>>(); 84 ExtremePoints = new ObservableCollection<BinPacking3D.PackingPosition>(); 85 selectedExtremePointIndex = -1; 76 86 Clear(); 77 87 } … … 85 95 } 86 96 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 87 106 public void SelectItem(int itemKey) { 88 107 // selection of an item should make all other items semi-transparent … … 90 109 UpdateVisualization(); 91 110 } 111 92 112 public void ClearSelection() { 93 113 // remove all transparency 94 114 selectedItemKey = -1; 115 selectedExtremePointIndex = -1; 95 116 UpdateVisualization(); 96 117 } … … 98 119 private void UpdateVisualization() { 99 120 Clear(); 100 if (packing == null) return; // nothing to display 121 if (packing == null) 122 return; // nothing to display 101 123 102 124 var modelGroup = (Model3DGroup)MyModel.Content; … … 108 130 109 131 var colorIdx = selectedItem.Value.Material; 110 while (colorIdx < 0) colorIdx += colors.Length; 132 while (colorIdx < 0) 133 colorIdx += colors.Length; 111 134 colorIdx = colorIdx % colors.Length; 112 135 var color = colors[colorIdx]; … … 132 155 modelGroup.Children.Add(model); 133 156 } 157 158 134 159 } else { 135 160 foreach (var item in packing.Items) { … … 144 169 if (!materials.TryGetValue(item.Value.Material, out material)) { 145 170 var colorIdx = item.Value.Material; 146 while (colorIdx < 0) colorIdx += colors.Length; 171 while (colorIdx < 0) 172 colorIdx += colors.Length; 147 173 colorIdx = colorIdx % colors.Length; 148 174 var color = colors[colorIdx]; … … 156 182 } 157 183 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); 168 186 169 187 var container = packing.BinShape; … … 191 209 } 192 210 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 193 257 194 258 private void Clear() { … … 202 266 203 267 private void Container3DView_MouseMove(object sender, MouseEventArgs e) { 204 if (!mouseDown) return; 268 if (!mouseDown) 269 return; 205 270 var pos = e.GetPosition((IInputElement)this); 206 271 … … 235 300 Focus(); // for mouse wheel events 236 301 } 237 private void showExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) {302 private void ShowExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) { 238 303 showExtremePoints = true; 239 304 UpdateVisualization(); 240 305 } 241 private void showExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) {306 private void ShowExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) { 242 307 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; 243 317 UpdateVisualization(); 244 318 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.Designer.cs
r14162 r15488 49 49 this.elementHost = new System.Windows.Forms.Integration.ElementHost(); 50 50 this.packingPlan3D = new HeuristicLab.Problems.BinPacking.Views.Container3DView(); 51 this.extremePointsSelection = new System.Windows.Forms.ListBox(); 51 52 this.SuspendLayout(); 52 53 // … … 58 59 this.binSelection.Location = new System.Drawing.Point(3, 3); 59 60 this.binSelection.Name = "binSelection"; 60 this.binSelection.Size = new System.Drawing.Size(54, 2 90);61 this.binSelection.Size = new System.Drawing.Size(54, 264); 61 62 this.binSelection.TabIndex = 4; 62 63 this.binSelection.SelectedIndexChanged += new System.EventHandler(this.binSelection_SelectedIndexChanged); … … 69 70 this.itemSelection.Location = new System.Drawing.Point(58, 3); 70 71 this.itemSelection.Name = "itemSelection"; 71 this.itemSelection.Size = new System.Drawing.Size(55, 2 90);72 this.itemSelection.Size = new System.Drawing.Size(55, 264); 72 73 this.itemSelection.TabIndex = 5; 73 74 this.itemSelection.SelectedIndexChanged += new System.EventHandler(this.itemSelection_SelectedIndexChanged); … … 78 79 | System.Windows.Forms.AnchorStyles.Left) 79 80 | System.Windows.Forms.AnchorStyles.Right))); 80 this.elementHost.Location = new System.Drawing.Point(1 19, 3);81 this.elementHost.Location = new System.Drawing.Point(198, 3); 81 82 this.elementHost.Name = "elementHost"; 82 this.elementHost.Size = new System.Drawing.Size(2 29, 290);83 this.elementHost.Size = new System.Drawing.Size(273, 264); 83 84 this.elementHost.TabIndex = 6; 84 85 this.elementHost.Text = "elementHost"; 85 86 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); 86 98 // 87 99 // PackingPlan3DView … … 89 101 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 90 102 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 103 this.Controls.Add(this.extremePointsSelection); 91 104 this.Controls.Add(this.elementHost); 92 105 this.Controls.Add(this.itemSelection); 93 106 this.Controls.Add(this.binSelection); 94 107 this.Name = "PackingPlan3DView"; 95 this.Size = new System.Drawing.Size( 351, 299);108 this.Size = new System.Drawing.Size(489, 278); 96 109 this.ResumeLayout(false); 97 110 … … 104 117 private System.Windows.Forms.Integration.ElementHost elementHost; 105 118 private Container3DView packingPlan3D; 119 private System.Windows.Forms.ListBox extremePointsSelection; 106 120 } 107 121 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs
r14167 r15488 47 47 } else { 48 48 int i = 0; 49 foreach (var bp in Content.Bins) 49 foreach (var bp in Content.Bins) { 50 50 binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)"); 51 } 52 51 53 52 54 binSelection.SelectedIndex = 0; … … 63 65 itemSelection.SelectedIndex = -1; 64 66 itemSelection.Items.Clear(); 67 extremePointsSelection.Items.Clear(); 68 packingPlan3D.ResidualSpaces.Clear(); 69 packingPlan3D.ExtremePoints.Clear(); 65 70 66 71 // add items of this container … … 69 74 foreach (var item in packing.Items) { 70 75 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); 71 82 } 72 83 … … 81 92 packingPlan3D.ClearSelection(); 82 93 } 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 } 83 102 } 84 103 }
Note: See TracChangeset
for help on using the changeset viewer.