Changeset 15307 for branches/2817-BinPackingSpeedup
- Timestamp:
- 08/04/17 23:45:08 (7 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml
r15167 r15307 32 32 Focusable="true" 33 33 > 34 <Grid> 35 <Border BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"> 36 <Viewport3D Name="viewport3D1" > 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"> 37 <Viewport3D Name="viewport3D1" Margin="0,-1,0,0" > 37 38 <Viewport3D.Camera> 38 39 <PerspectiveCamera x:Name="camMain" Position="0.5 8 8" LookDirection="0 -1 -1"> <!-- camera position for design time--> -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r15306 r15307 55 55 private double startAngleY; 56 56 private int selectedItemKey; 57 private bool showExtremePoints; 57 58 58 59 private BinPacking<BinPacking3D.PackingPosition, PackingShape, PackingItem> packing; … … 155 156 } 156 157 157 // draw extreme-points 158 foreach (var ep in packing.ExtremePoints) { 159 var epModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = new DiffuseMaterial() { Brush = new SolidColorBrush(Colors.Red) } }; 160 AddSolidCube((MeshGeometry3D)epModel.Geometry, ep.X, ep.Y, ep.Z, 10, 10, 10); 161 modelGroup.Children.Add(epModel); 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 } 162 167 } 163 168 … … 229 234 private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) { 230 235 Focus(); // for mouse wheel events 236 } 237 private void showExtremePointsCheckBoxOnChecked(object sender, RoutedEventArgs e) { 238 showExtremePoints = true; 239 UpdateVisualization(); 240 } 241 private void showExtremePointsCheckBoxOnUnchecked(object sender, RoutedEventArgs e) { 242 showExtremePoints = false; 243 UpdateVisualization(); 231 244 } 232 245 … … 471 484 } 472 485 #endregion 473 474 486 } 475 487 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
r15306 r15307 125 125 sourcePoint = new Vector3D(position.X, position.Y, position.Z + newDepth); 126 126 if (sourcePoint.X < BinShape.Width && sourcePoint.Y < BinShape.Height && sourcePoint.Z < BinShape.Depth) { 127 // Projecting onto the XZ-plane 128 var below = ProjectDown(sourcePoint); 129 var residualSpace = CalculateResidualSpace(below); 130 if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) { 131 // add only if the projected point's residual space is not a sub-space 132 // of another extreme point's residual space 133 var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z); 134 AddExtremePoint(belowPoint); 135 } 127 136 // Projecting onto the YZ-plane 128 137 var left = ProjectLeft(sourcePoint); 129 varresidualSpace = CalculateResidualSpace(left);138 residualSpace = CalculateResidualSpace(left); 130 139 if (!IsWithinResidualSpaceOfAnotherExtremePoint(left, residualSpace)) { 131 140 // add only if the projected point's residual space is not a sub-space … … 134 143 AddExtremePoint(leftPoint); 135 144 } 136 // Projecting onto the XZ-plane137 var below = ProjectDown(sourcePoint);138 residualSpace = CalculateResidualSpace(below);139 if (!IsWithinResidualSpaceOfAnotherExtremePoint(below, residualSpace)) {140 // add only if the projected point's residual space is not a sub-space141 // of another extreme point's residual space142 var belowPoint = new PackingPosition(position.AssignedBin, below.X, below.Y, below.Z);143 AddExtremePoint(belowPoint);144 }145 145 } 146 146 } … … 148 148 private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> residualSpace) { 149 149 var eps = ExtremePoints.Where(x => pos.IsInside(x, ResidualSpace[x])); 150 return eps.Any(x => ResidualSpace[x].Item1 >= pos.X - x.X + residualSpace.Item1 151 && ResidualSpace[x].Item2 >= pos.Y - x.Y + residualSpace.Item2 152 && ResidualSpace[x].Item3 >= pos.Z - x.Z + residualSpace.Item3); 150 return eps.Any(x => IsWithinResidualSpaceOfAnotherExtremePoint(pos, residualSpace, x, ResidualSpace[x])); 151 } 152 private bool IsWithinResidualSpaceOfAnotherExtremePoint(Vector3D pos, Tuple<int, int, int> rsPos, PackingPosition ep, Tuple<int, int, int> rsEp) { 153 return rsEp.Item1 >= pos.X - ep.X + rsPos.Item1 154 && rsEp.Item2 >= pos.Y - ep.Y + rsPos.Item2 155 && rsEp.Item3 >= pos.Z - ep.Z + rsPos.Item3; 153 156 } 154 157 155 158 private bool AddExtremePoint(PackingPosition pos) { 156 159 if (ExtremePoints.Add(pos)) { 157 ResidualSpace.Add(pos, Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z)); 160 var rs = Tuple.Create(BinShape.Width - pos.X, BinShape.Height - pos.Y, BinShape.Depth - pos.Z); 161 ResidualSpace.Add(pos, rs); 162 // Check if existing extreme points are shadowed by the new point 163 // That is, their residual space fit entirely into the residual space of the new point 164 foreach (var ep in ExtremePoints.Where(x => x != pos && new Vector3D(x).IsInside(pos, rs)).ToList()) { 165 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(ep), ResidualSpace[ep], pos, rs)) { 166 ExtremePoints.Remove(ep); 167 ResidualSpace.Remove(ep); 168 } 169 } 158 170 return true; 159 171 }
Note: See TracChangeset
for help on using the changeset viewer.