Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 17:41:38 (7 years ago)
Author:
abeham
Message:

#2762: Merged trunk into branch

Location:
branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views

  • branches/BinPackingExtension/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r14835 r15182  
    4646      Color.FromRgb(0x63, 0xC2, 0x16),
    4747    };
    48    
     48
    4949    private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA);
    5050    private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA);
     
    5252    private Point startPos;
    5353    private bool mouseDown = false;
    54     private bool ctrlDown = false;
    5554    private double startAngleX;
    5655    private double startAngleY;
     
    103102      var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor));
    104103
    105       foreach (var item in packing.Items) {
    106         var position = packing.Positions[item.Key];
    107 
    108         var w = position.Rotated ? item.Value.Depth : item.Value.Width;
    109         var h = item.Value.Height;
    110         var d = position.Rotated ? item.Value.Width : item.Value.Depth;
    111 
    112         var model = new GeometryModel3D { Geometry = new MeshGeometry3D() };
    113         DiffuseMaterial material;
    114         if (selectedItemKey >= 0 && selectedItemKey != item.Key)
    115           material = hiddenMaterial;
    116         else {
     104      if (selectedItemKey >= 0) {
     105        var selectedItem = packing.Items.Single(x => selectedItemKey == x.Key);
     106        var selectedPos = packing.Positions[selectedItem.Key];
     107
     108        var colorIdx = selectedItem.Value.Material;
     109        while (colorIdx < 0) colorIdx += colors.Length;
     110        colorIdx = colorIdx % colors.Length;
     111        var color = colors[colorIdx];
     112        var material = new DiffuseMaterial { Brush = new SolidColorBrush(color) };
     113        materials[selectedItem.Value.Material] = material;
     114
     115        var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material };
     116        AddSolidCube((MeshGeometry3D)selectedModel.Geometry, selectedPos.X, selectedPos.Y, selectedPos.Z,
     117          selectedPos.Rotated ? selectedItem.Value.Depth : selectedItem.Value.Width,
     118          selectedItem.Value.Height,
     119          selectedPos.Rotated ? selectedItem.Value.Width : selectedItem.Value.Depth);
     120        modelGroup.Children.Add(selectedModel);
     121
     122        foreach (var item in packing.Items.Where(x => selectedItemKey != x.Key)) {
     123          var position = packing.Positions[item.Key];
     124
     125          var w = position.Rotated ? item.Value.Depth : item.Value.Width;
     126          var h = item.Value.Height;
     127          var d = position.Rotated ? item.Value.Width : item.Value.Depth;
     128
     129          var model = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = hiddenMaterial };
     130          AddWireframeCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d, 1);
     131          modelGroup.Children.Add(model);
     132        }
     133      } else {
     134        foreach (var item in packing.Items) {
     135          var position = packing.Positions[item.Key];
     136
     137          var w = position.Rotated ? item.Value.Depth : item.Value.Width;
     138          var h = item.Value.Height;
     139          var d = position.Rotated ? item.Value.Width : item.Value.Depth;
     140
     141          var model = new GeometryModel3D { Geometry = new MeshGeometry3D() };
     142          DiffuseMaterial material;
    117143          if (!materials.TryGetValue(item.Value.Material, out material)) {
    118144            var colorIdx = item.Value.Material;
     
    123149            materials[item.Value.Material] = material;
    124150          }
     151          var selectedModel = new GeometryModel3D { Geometry = new MeshGeometry3D(), Material = material };
     152          AddSolidCube((MeshGeometry3D)selectedModel.Geometry, position.X, position.Y, position.Z, w, h, d);
     153          modelGroup.Children.Add(selectedModel);
    125154        }
    126         model.Material = material;
    127         modelGroup.Children.Add(model);
    128 
    129         AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d);
    130155      }
    131156
     
    140165      scale.ScaleZ = 1.0 / ratio;
    141166
    142       scale.CenterX = .5;
    143       scale.CenterY = .5;
    144       scale.CenterZ = 0;
     167      scaleZoom.CenterX = rotateX.CenterX = rotateY.CenterX = container.Width / (2.0 * ratio);
     168      scaleZoom.CenterY = rotateX.CenterY = rotateY.CenterY = container.Height / (2.0 * ratio);
     169      scaleZoom.CenterZ = rotateX.CenterZ = rotateY.CenterZ = container.Depth / (2.0 * ratio);
     170
     171      camMain.Position = new Point3D(
     172        scaleZoom.CenterX,
     173        3,
     174        3);
     175      camMain.LookDirection = new Vector3D(
     176        0,
     177        scaleZoom.CenterY - camMain.Position.Y,
     178        scaleZoom.CenterZ - camMain.Position.Z);
    145179    }
    146180
     
    149183      ((Model3DGroup)MyModel.Content).Children.Clear();
    150184      materials.Clear();
    151      
     185
    152186      mouseDown = false;
    153187      startAngleX = 0;
     
    158192      if (!mouseDown) return;
    159193      var pos = e.GetPosition((IInputElement)this);
    160      
    161       rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4;
    162       rotateY.Angle = startAngleY + (pos.Y - startPos.Y) / 4;
     194
     195      ((AxisAngleRotation3D)rotateX.Rotation).Angle = startAngleX + (pos.X - startPos.X) / 4;
     196      ((AxisAngleRotation3D)rotateY.Rotation).Angle = startAngleY + (pos.Y - startPos.Y) / 4;
    163197    }
    164198
    165199    private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) {
    166       startAngleX = rotateX.Angle;
    167       startAngleY = rotateY.Angle;
     200      startAngleX = ((AxisAngleRotation3D)rotateX.Rotation).Angle;
     201      startAngleY = ((AxisAngleRotation3D)rotateY.Rotation).Angle;
    168202      this.startPos = e.GetPosition((IInputElement)this);
    169203      this.mouseDown = true;
     
    189223      Focus(); // for mouse wheel events
    190224    }
    191 
    192     private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) {
    193       ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl);
    194     }
    195 
    196225
    197226    #region helper for cubes
     
    302331      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth));
    303332
    304       AddPlane(mesh, 0, 4, 6, 2);
    305       AddPlane(mesh, 0, 3, 5, 4);
    306 
    307       AddPlane(mesh, 4, 8, 10, 6);
    308       AddPlane(mesh, 4, 7, 9, 8);
    309 
    310       AddPlane(mesh, 8, 12, 14, 10);
    311       AddPlane(mesh, 8, 11, 13, 12);
    312 
    313       AddPlane(mesh, 0, 2, 14, 12);
    314       AddPlane(mesh, 0, 12, 15, 1);
    315 
    316       AddPlane(mesh, 0, 1, 17, 16);
    317       AddPlane(mesh, 0, 16, 19, 3);
    318 
    319       AddPlane(mesh, 4, 20, 23, 7);
    320       AddPlane(mesh, 4, 5, 21, 20);
    321 
    322       AddPlane(mesh, 8, 24, 27, 11);
    323       AddPlane(mesh, 8, 9, 25, 24);
    324 
    325       AddPlane(mesh, 12, 28, 31, 15);
    326       AddPlane(mesh, 12, 13, 29, 28);
    327 
    328       AddPlane(mesh, 16, 18, 22, 20);
    329       AddPlane(mesh, 16, 20, 21, 19);
    330 
    331       AddPlane(mesh, 20, 22, 26, 24);
    332       AddPlane(mesh, 20, 24, 25, 23);
    333 
    334       AddPlane(mesh, 24, 28, 29, 27);
    335       AddPlane(mesh, 24, 26, 30, 28);
    336 
    337       AddPlane(mesh, 28, 30, 18, 16);
    338       AddPlane(mesh, 28, 16, 17, 31);
     333      // Point 0, non-edge
     334      mesh.Positions.Add(new Point3D(x + thickness, y, z + thickness));
     335      mesh.Positions.Add(new Point3D(x, y + thickness, z + thickness));
     336      mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z));
     337
     338      // Point 1, non-edge
     339      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + thickness));
     340      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + thickness));
     341      mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z));
     342
     343      // Point 2, non-edge
     344      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + thickness));
     345      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + thickness));
     346      mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z));
     347
     348      // Point 3, non-edge
     349      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + thickness));
     350      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + thickness));
     351      mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z));
     352
     353      // Point 4, non-edge
     354      mesh.Positions.Add(new Point3D(x + thickness, y, z + depth - thickness));
     355      mesh.Positions.Add(new Point3D(x, y + thickness, z + depth - thickness));
     356      mesh.Positions.Add(new Point3D(x + thickness, y + thickness, z + depth));
     357
     358      // Point 5, non-edge
     359      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth - thickness));
     360      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth - thickness));
     361      mesh.Positions.Add(new Point3D(x + width - thickness, y + thickness, z + depth));
     362
     363      // Point 6, non-edge
     364      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth - thickness));
     365      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth - thickness));
     366      mesh.Positions.Add(new Point3D(x + width - thickness, y + height - thickness, z + depth));
     367
     368      // Point 7, non-edge
     369      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth - thickness));
     370      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth - thickness));
     371      mesh.Positions.Add(new Point3D(x + thickness, y + height - thickness, z + depth));
     372
     373      // Draw the 24 corner plates
     374      AddPlane(mesh, 0, 1, 32, 2);
     375      AddPlane(mesh, 0, 2, 33, 3);
     376      AddPlane(mesh, 0, 3, 34, 1);
     377
     378      AddPlane(mesh, 4, 6, 36, 7);
     379      AddPlane(mesh, 4, 5, 35, 6);
     380      AddPlane(mesh, 4, 7, 37, 5);
     381
     382      AddPlane(mesh, 8, 10, 39, 11);
     383      AddPlane(mesh, 8, 9, 38, 10);
     384      AddPlane(mesh, 8, 11, 40, 9);
     385
     386      AddPlane(mesh, 12, 13, 41, 14);
     387      AddPlane(mesh, 12, 14, 42, 15);
     388      AddPlane(mesh, 12, 15, 43, 13);
     389
     390      AddPlane(mesh, 16, 18, 44, 17);
     391      AddPlane(mesh, 16, 19, 45, 18);
     392      AddPlane(mesh, 16, 17, 46, 19);
     393
     394      AddPlane(mesh, 20, 23, 48, 22);
     395      AddPlane(mesh, 20, 22, 47, 21);
     396      AddPlane(mesh, 20, 21, 49, 23);
     397
     398      AddPlane(mesh, 24, 27, 51, 26);
     399      AddPlane(mesh, 24, 26, 50, 25);
     400      AddPlane(mesh, 24, 25, 52, 27);
     401
     402      AddPlane(mesh, 28, 31, 54, 30);
     403      AddPlane(mesh, 28, 30, 53, 29);
     404      AddPlane(mesh, 28, 29, 55, 31);
     405
     406      // Draw the connecting plates
     407      // on the bottom
     408      AddPlane(mesh, 1, 7, 36, 32);
     409      AddPlane(mesh, 1, 34, 37, 7);
     410
     411      AddPlane(mesh, 5, 11, 39, 35);
     412      AddPlane(mesh, 5, 37, 40, 11);
     413
     414      AddPlane(mesh, 9, 15, 42, 38);
     415      AddPlane(mesh, 9, 40, 43, 15);
     416
     417      AddPlane(mesh, 13, 3, 33, 41);
     418      AddPlane(mesh, 13, 43, 34, 3);
     419
     420      // between bottom and top
     421      AddPlane(mesh, 2, 32, 44, 18);
     422      AddPlane(mesh, 2, 18, 45, 33);
     423
     424      AddPlane(mesh, 6, 22, 48, 36);
     425      AddPlane(mesh, 6, 35, 47, 22);
     426
     427      AddPlane(mesh, 10, 26, 51, 39);
     428      AddPlane(mesh, 10, 38, 50, 26);
     429
     430      AddPlane(mesh, 14, 30, 54, 42);
     431      AddPlane(mesh, 14, 41, 53, 30);
     432
     433      // on the top
     434      AddPlane(mesh, 17, 44, 48, 23);
     435      AddPlane(mesh, 17, 23, 49, 46);
     436
     437      AddPlane(mesh, 21, 47, 51, 27);
     438      AddPlane(mesh, 21, 27, 52, 49);
     439
     440      AddPlane(mesh, 25, 50, 54, 31);
     441      AddPlane(mesh, 25, 31, 55, 52);
     442
     443      AddPlane(mesh, 29, 19, 46, 55);
     444      AddPlane(mesh, 29, 53, 45, 19);
    339445    }
    340446
Note: See TracChangeset for help on using the changeset viewer.