Changeset 13497


Ignore:
Timestamp:
01/12/16 10:42:58 (5 years ago)
Author:
gkronber
Message:

#1966: fixed various problems: bugs in cloning, bugs in persistence, method names, various minor improvements of source code for readability.

Location:
branches/HeuristicLab.BinPacking
Files:
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingBin/RectangularPackingBin.cs

    r13461 r13497  
    3232
    3333    public RectangularPackingBin(int width, int height) : base(width, height) { }
    34     public RectangularPackingBin()
    35       : base() {
    36 
    37     }
     34    public RectangularPackingBin() : base() { }
    3835
    3936    [StorableConstructor]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingItem/CuboidPackingItem.cs

    r13461 r13497  
    2929
    3030namespace HeuristicLab.Problems.BinPacking.PackingItem {
    31   [Item ("CuboidPackingItem", "Represents a cuboidic packing-item for bin-packing problems.")]
     31  [Item("CuboidPackingItem", "Represents a cuboidic packing-item for bin-packing problems.")]
    3232  [StorableClass]
    3333  public class CuboidPackingItem : CuboidPackingShape, IPackingItem {
     34    [Storable]
     35    public CuboidPackingBin TargetBin { get; set; }
    3436
    35     public CuboidPackingBin TargetBin { get; set; }
     37    [Storable]
    3638    public double Weight { get; set; }
     39
     40    [Storable]
    3741    public int Material { get; set; }
     42
    3843    public bool SupportsStacking(IPackingItem other) {
    3944      return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
     
    4449    protected CuboidPackingItem(CuboidPackingItem original, Cloner cloner)
    4550      : base(original, cloner) {
    46         this.Weight = original.Weight;
    47         this.Material = original.Material;
     51      this.Weight = original.Weight;
     52      this.Material = original.Material;
     53      this.TargetBin = cloner.Clone(TargetBin);
    4854    }
    4955    public override IDeepCloneable Clone(Cloner cloner) {
    5056      return new CuboidPackingItem(this, cloner);
    5157    }
    52     public CuboidPackingItem() : base() {
     58    public CuboidPackingItem()
     59      : base() {
    5360    }
    5461
    55     public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin, double weight, int material) : this(width, height, depth, targetBin) { this.Weight = weight; this.Material = material; }
    56     public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin) : base(width, height, depth) { this.TargetBin = new CuboidPackingBin(targetBin.Width, targetBin.Height, targetBin.Depth); }
     62    public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin, double weight, int material)
     63      : this(width, height, depth, targetBin) {
     64      this.Weight = weight;
     65      this.Material = material;
     66    }
     67
     68    public CuboidPackingItem(int width, int height, int depth, CuboidPackingBin targetBin)
     69      : base(width, height, depth) {
     70      this.TargetBin = (CuboidPackingBin)targetBin.Clone();
     71    }
    5772
    5873    public void AddTargetBinMeasures(int[] targetBinMeasures) {
     
    6176
    6277    public override string ToString() {
    63       return String.Format("CuboidPackingItem ({0}, {1}, {2}; w={3}, m={4})", this.Width, this.Height, this.Depth, this.Weight,this.Material);
     78      return String.Format("CuboidPackingItem ({0}, {1}, {2}; w={3}, m={4})", this.Width, this.Height, this.Depth, this.Weight, this.Material);
    6479    }
    6580  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingItem/RectangularPackingItem.cs

    r13461 r13497  
    3333  public class RectangularPackingItem : RectangularPackingShape, IPackingItem {
    3434
     35    [Storable]
    3536    public RectangularPackingBin TargetBin { get; set; }
     37
     38    [Storable]
    3639    public double Weight { get; set; }
     40
     41    [Storable]
    3742    public int Material { get; set; }
     43
    3844    public bool SupportsStacking(IPackingItem other) {
    3945      return ((other.Material < this.Material) || (other.Material.Equals(this.Material) && other.Weight <= this.Weight));
     
    4652      this.Weight = original.Weight;
    4753      this.Material = original.Material;
     54      this.TargetBin = cloner.Clone(TargetBin);
    4855    }
    4956    public override IDeepCloneable Clone(Cloner cloner) {
     
    5461    }
    5562
    56     public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin) : base(width, height) { this.TargetBin = new RectangularPackingBin(targetBin.Width, targetBin.Height); }
     63    public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin)
     64      : base(width, height) {
     65      this.TargetBin = (RectangularPackingBin)targetBin.Clone();
     66    }
    5767
    5868    public void AddTargetBinMeasures(int[] targetBinMeasures) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/CuboidPackingShape.cs

    r13461 r13497  
    2121
    2222using System;
     23using System.Diagnostics;
    2324using HeuristicLab.Problems.BinPacking.Interfaces;
    2425using HeuristicLab.Core;
     
    148149
    149150    public int CompareTo(object obj) {
    150       if (obj.GetType() == this.GetType())
    151         return this.CompareTo((CuboidPackingShape)obj);
    152       else return 0;
     151      var other = (CuboidPackingShape)obj;
     152      if (other != null) return CompareTo(other);
     153      else throw new ArgumentException(string.Format("Cannot compare with object {0}", obj), "obj");
    153154    }
    154155
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/PackingShape.cs

    r13461 r13497  
    3030  [Item("PackingShape", "Represents an abstract shape to describe the measures and the positioning of objects related to bin-packing problems.")]
    3131  [StorableClass]
    32   public abstract class PackingShape<D> : Item, IPackingShape
    33     where D : class, IPackingDimensions {
     32  public abstract class PackingShape<T> : Item, IPackingShape
     33    where T : class, IPackingDimensions {
    3434    public static Type PositionType {
    35       get { return typeof(D); }
     35      get { return typeof(T); }
    3636    }
    3737
    38     public abstract bool EnclosesPoint(D myPosition, D checkedPoint);
    39     public abstract bool Encloses(D checkedPosition, PackingShape<D> checkedShape);
    40     public abstract bool Overlaps(D myPosition, D checkedPosition, PackingShape<D> checkedShape);
     38    public abstract bool EnclosesPoint(T myPosition, T checkedPoint);
     39    public abstract bool Encloses(T checkedPosition, PackingShape<T> checkedShape);
     40    public abstract bool Overlaps(T myPosition, T checkedPosition, PackingShape<T> checkedShape);
    4141    public abstract void InitializeFromMeasures(int[] measures);
    4242    public abstract int[] ToArray();
    4343    public abstract int MultipliedMeasures { get; }
    44     public abstract D Origin { get; }
     44    public abstract T Origin { get; }
    4545
    4646    protected PackingShape(int[] measures) {
     
    5353    [StorableConstructor]
    5454    protected PackingShape(bool deserializing) : base(deserializing) { }
    55     protected PackingShape(PackingShape<D> original, Cloner cloner)
     55    protected PackingShape(PackingShape<T> original, Cloner cloner)
    5656      : base(original, cloner) {
    5757    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs

    r13032 r13497  
    3333  public abstract class RectangularPackingShape : PackingShape<TwoDimensionalPacking>, IRegularPackingShape, IComparable<RectangularPackingShape> {
    3434    #region Properties
    35     /// <summary>
    36     /// Describes the size on the Y-axis
    37     /// </summary>
    3835    [Storable]
    3936    public int Height { get; set; }
    40     /// <summary>
    41     /// Describes the size on the X-axis
    42     /// </summary> 
     37
    4338    [Storable]
    4439    public int Width { get; set; }
     
    6055    private bool Encloses(TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {
    6156      return Encloses(new RectangleDiagonal(this), new RectangleDiagonal(checkedPosition, checkedShape));
    62     }       
     57    }
    6358    private bool Encloses(RectangleDiagonal r1, RectangleDiagonal r2) {
    64       return  ( r1.x1 <= r2.x1 &&
     59      return (r1.x1 <= r2.x1 &&
    6560                r1.x2 >= r2.x2 &&
    6661                r1.y1 <= r2.y1 &&
     
    7166      return Overlaps(myPosition, checkedPosition, (RectangularPackingShape)checkedShape);
    7267    }
    73     private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {   
    74       return Overlaps(new RectangleDiagonal (myPosition, this),new RectangleDiagonal (checkedPosition, checkedShape));
     68    private bool Overlaps(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPosition, RectangularPackingShape checkedShape) {
     69      return Overlaps(new RectangleDiagonal(myPosition, this), new RectangleDiagonal(checkedPosition, checkedShape));
    7570    }
    7671    private bool Overlaps(RectangleDiagonal r1, RectangleDiagonal r2) {
     
    9085    #endregion
    9186
    92     public RectangularPackingShape(int width, int height) : base () {
     87    protected RectangularPackingShape() : base() { }
     88    protected RectangularPackingShape(int width, int height)
     89      : base() {
    9390      this.Height = height;
    9491      this.Width = width;
     
    10198      this.Height = measures[1];
    10299    }
    103     public override int[] ToArray() {
    104       return new int[] { Width, Height };
    105     }
     100
    106101
    107102    [StorableConstructor]
     
    112107      this.Height = original.Height;
    113108    }
    114     public RectangularPackingShape() : base() {}
    115109
    116110    public override string ToString() {
     
    124118      if (result == 0) {
    125119        result = this.Width.CompareTo(other.Width);
    126         if (result == 0) 
     120        if (result == 0)
    127121          result = this.Height.CompareTo(other.Height);
    128122      }
     
    131125
    132126    public int CompareTo(object obj) {
    133       if (obj.GetType().Equals(this.GetType()))
    134         return this.CompareTo((RectangularPackingShape)obj);
    135       else return 0;
     127      var other = obj as RectangularPackingShape;
     128      if (other != null) return CompareTo(other);
     129      else throw new ArgumentException(string.Format("Cannot compare to object {0}", obj), "obj");
    136130    }
    137131
    138132    #endregion
     133
     134    public override int[] ToArray() {
     135      return new int[] { Width, Height };
     136    }
    139137
    140138    private struct RectangleDiagonal {
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/CenteredContainer2D.cs

    r13477 r13497  
    3131    private float yScaling;
    3232    private readonly List<PackingItem> packingItems = new List<PackingItem>();
    33 
    34     //public Vector2 ContainerCenter {
    35     //  get { return new Vector2(controlSize.X / 2, controlSize.Y / 2); }
    36     //}
    3733
    3834    private struct PackingItem {
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/2D/PackingPlan2D.cs

    r13477 r13497  
    3333namespace PackingPlanVisualizations {
    3434  public partial class PackingPlan2D : UserControl {
    35     WindowRenderTarget wndRender = null;
    36     Factory2D1 factory = new Factory2D1(FactoryType2D1.SingleThreaded);
    37     SharpDX.DirectWrite.Factory dwFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);
    38     RenderTargetProperties rndTargProperties = new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied));
    39     HwndRenderTargetProperties hwndProperties = new HwndRenderTargetProperties();
     35    private WindowRenderTarget wndRender;
     36    private readonly Factory2D1 factory = new Factory2D1(FactoryType2D1.SingleThreaded);
     37    private readonly SharpDX.DirectWrite.Factory dwFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);
     38    private readonly RenderTargetProperties rndTargProperties = new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied));
     39    private HwndRenderTargetProperties hwndProperties;
    4040
    4141
    42     #region Packing members BEGIN
    43     SolidColorBrush containerBrush;
    44     SolidColorBrush containerFillingBrush;
    45     SolidColorBrush itemBrush;
    46     SolidColorBrush itemFillingBrush;
    47     SolidColorBrush labelBrush;
    48     TextFormat textFormat;
     42    private SolidColorBrush containerBrush;
     43    private SolidColorBrush containerFillingBrush;
     44    private SolidColorBrush itemBrush;
     45    private SolidColorBrush itemFillingBrush;
     46    private SolidColorBrush labelBrush;
     47    private TextFormat textFormat;
    4948
    50     CenteredContainer2D container;
    51     #endregion
    52 
    53     //Initialization-Methods
     49    private CenteredContainer2D container;
    5450
    5551    public PackingPlan2D() {
    5652      InitializeComponent();
    57       this.SetStyle(
    58         ControlStyles.ResizeRedraw, true);
     53      this.SetStyle(ControlStyles.ResizeRedraw, true);
    5954    }
    6055
     
    7469    }
    7570
    76 
    77 
    78 
    79 
    80     //Packing-Methods
    8171    public void InitializeContainer(float width, float height) {
    8272      container = new CenteredContainer2D(new Vector2(Math.Max(this.Width - 12, 1), Math.Max(this.Height - 12, 1)), new Vector2(width, height));
     
    8676      container.AddItem(new Vector2(width, height), new Vector2(x, y), label);
    8777    }
    88 
    89     //Event-Listeners
    9078
    9179    private void PackingPlan2D_Load(object sender, EventArgs e) {
     
    119107        wndRender.Resize(new Size2(this.Width, this.Height));
    120108    }
    121 
    122109  }
    123110}
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/BasicCuboidShape.cs

    r13465 r13497  
    2727
    2828  public class BasicCuboidShape {
    29     //Basic information
    30     private readonly Vector3 shapeSize;
    31     public Vector3 ShapeSize { get { return shapeSize; } }
    32     private readonly Vector3 shapePosition;
    33     public Vector3 ShapePosition { get { return shapePosition; } }
    34     private readonly int shapeID;
    35     public int ShapeID { get { return shapeID; } }
    36     public int Material { get; set; }
     29    public Vector3 ShapeSize { get; private set; }
     30    public Vector3 ShapePosition { get; private set; }
     31    public int ShapeID { get; private set; }
     32    public int Material { get; private set; }
    3733
    3834
    39     //Vertices
    4035    private VertexPositionColorNormal[] shapeTriangleVertices;
    4136    private VertexPositionColorNormal[] shapeLineVertices;
    4237
    4338    public BasicCuboidShape(Vector3 size, Vector3 position, int shapeNr, int material) {
    44       shapeSize = size;
    45       shapePosition = position;
    46       shapeID = shapeNr;
    47       this.Material = material;
     39      ShapeSize = size;
     40      ShapePosition = position;
     41      ShapeID = shapeNr;
     42      Material = material;
    4843    }
    4944    public BasicCuboidShape(Vector3 size, int shapeNr) : this(size, new Vector3(0, 0, 0), shapeNr, 0) { }
     
    5348    }
    5449    public void RenderShapeLines(GraphicsDevice device, Color color) {
    55       shapeLineVertices = (new CuboidShapePreparations(shapeSize, shapePosition, color)).CreateVertexDefinitionsForEdgeLines();
    56       Buffer<VertexPositionColorNormal> shapeLineBuffer = Buffer.Vertex.New(
    57           device,
    58           shapeLineVertices);
    59       VertexInputLayout inputLayoutLine = VertexInputLayout.FromBuffer(0, shapeLineBuffer);
     50      shapeLineVertices =
     51        new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForEdgeLines();
     52      var shapeLineBuffer = Buffer.Vertex.New(device, shapeLineVertices);
     53      var inputLayoutLine = VertexInputLayout.FromBuffer(0, shapeLineBuffer);
    6054
    6155      device.SetVertexBuffer(shapeLineBuffer);
     
    6963
    7064    public void RenderShapeTriangles(GraphicsDevice device, Color color) {
    71       shapeTriangleVertices = (new CuboidShapePreparations(shapeSize, shapePosition, color)).CreateVertexDefinitionsForTriangles();
    72       Buffer<VertexPositionColorNormal> shapeTriangleBuffer = Buffer.Vertex.New(
    73           device,
    74           shapeTriangleVertices);
    75       VertexInputLayout inputLayoutTriangles = VertexInputLayout.FromBuffer(0, shapeTriangleBuffer);
     65      shapeTriangleVertices =
     66        new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForTriangles();
     67      var shapeTriangleBuffer = Buffer.Vertex.New(device, shapeTriangleVertices);
     68      var inputLayoutTriangles = VertexInputLayout.FromBuffer(0, shapeTriangleBuffer);
    7669
    7770      device.SetVertexBuffer(shapeTriangleBuffer);
     
    8679
    8780    public Vector3 CalculatePositionRelativeToBottomLeftBackCorner(Vector3 itemSize, Vector3 itemPosition) {
    88       Vector3 newPosition = itemPosition - (shapeSize / 2 - itemSize / 2);
     81      Vector3 newPosition = itemPosition - (ShapeSize / 2 - itemSize / 2);
    8982      return newPosition;
    9083    }
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/CenteredContainer.cs

    r13465 r13497  
    2727
    2828  public class CenteredContainer {
    29     private readonly BasicCuboidShape container;
    30     private readonly List<BasicCuboidShape> packingItems;
     29    public BasicCuboidShape Container { get; private set; }
     30    public List<BasicCuboidShape> PackingItems { get; private set; }
     31
    3132    private readonly float normalizingFactor;
    3233
    3334    public CenteredContainer(BasicCuboidShape container) {
    3435      normalizingFactor = CalculateNormalizingFactor(container);
    35       this.container = Normalize (container);
    36       packingItems = new List<BasicCuboidShape>();
     36      Container = Normalize(container);
     37      PackingItems = new List<BasicCuboidShape>();
    3738    }
    3839
     
    4546    }
    4647
    47 
    48 
    49     public BasicCuboidShape Container {
    50       get { return container; }
    51     }
    52     public List<BasicCuboidShape> PackingItems {
    53       get { return packingItems; }
    54     }
    55 
    56 
    5748    public void AddPackingItem(Vector3 size, Vector3 position, int index, int material) {
    58       Vector3 itemSize = size * normalizingFactor;
    59       Vector3 itemPosition = position * normalizingFactor;
    60       Vector3 actualPosition = container.CalculatePositionRelativeToBottomLeftBackCorner(itemSize, itemPosition);
    61       BasicCuboidShape itemShape = new BasicCuboidShape(itemSize, actualPosition, index, material);
    62       packingItems.Add(itemShape);
     49      var itemSize = size * normalizingFactor;
     50      var itemPosition = position * normalizingFactor;
     51      var actualPosition = Container.CalculatePositionRelativeToBottomLeftBackCorner(itemSize, itemPosition);
     52      var itemShape = new BasicCuboidShape(itemSize, actualPosition, index, material);
     53      PackingItems.Add(itemShape);
    6354    }
    6455  }
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/CuboidShapePreparations.cs

    r13496 r13497  
    2525  public class CuboidShapePreparations {
    2626
    27     #region Private Members 
     27    #region Private Members
    2828    //Define the shape in a way so that the position is in the center of the shape.
    2929    //Define the 8 defining points of the cube
    30     Vector3 topLeftFront;
    31     Vector3 bottomLeftFront;
    32     Vector3 topRightFront;
    33     Vector3 bottomRightFront;
    34     Vector3 topLeftBack;
    35     Vector3 topRightBack;
    36     Vector3 bottomLeftBack;
    37     Vector3 bottomRightBack;
     30    private readonly Vector3 topLeftFront;
     31    private readonly Vector3 bottomLeftFront;
     32    private readonly Vector3 topRightFront;
     33    private readonly Vector3 bottomRightFront;
     34    private readonly Vector3 topLeftBack;
     35    private readonly Vector3 topRightBack;
     36    private readonly Vector3 bottomLeftBack;
     37    private readonly Vector3 bottomRightBack;
    3838
    3939    //Define normal vectors of the 6 surfaces
    40     Vector3 frontNormal;
    41     Vector3 backNormal;
    42     Vector3 topNormal;
    43     Vector3 bottomNormal;
    44     Vector3 leftNormal;
    45     Vector3 rightNormal;
     40    private readonly Vector3 frontNormal;
     41    private readonly Vector3 backNormal;
     42    private readonly Vector3 topNormal;
     43    private readonly Vector3 bottomNormal;
     44    private readonly Vector3 leftNormal;
     45    private readonly Vector3 rightNormal;
    4646
    4747    //Define colors of the 6 surfaces
    48     Color frontColor = Color.Black;
    49     Color backColor = Color.Black;
    50     Color topColor = Color.Black;
    51     Color bottomColor = Color.Black;
    52     Color leftColor = Color.Black;
    53     Color rightColor = Color.Black;
     48    private readonly Color frontColor = Color.Black;
     49    private readonly Color backColor = Color.Black;
     50    private readonly Color topColor = Color.Black;
     51    private readonly Color bottomColor = Color.Black;
     52    private readonly Color leftColor = Color.Black;
     53    private readonly Color rightColor = Color.Black;
    5454
    5555    #endregion Private Members
    5656
    5757
    58     public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition) : this (shapeSize, shapePosition, Color.Black) { }
     58    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition) : this(shapeSize, shapePosition, Color.Black) { }
    5959    public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition, Color color) {
    6060      var halfShapeSize = shapeSize / 2;
     
    8585      leftColor = color;
    8686      rightColor = color;
    87 
    88     }
    89 
    90     public VertexPositionColorNormal[] CreateVertexDefinitionsForTriangles () {
     87    }
     88
     89    public VertexPositionColorNormal[] CreateVertexDefinitionsForTriangles() {
    9190      //Definition of the actual triangles
    9291      VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[36];
     
    160159    public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines(Color color) {
    161160      //Definition of the actual lines
    162       VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[48];
    163 
    164       Vector3 topRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
    165       Vector3 topRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
    166       Vector3 topLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
    167       Vector3 topLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
    168       Vector3 bottomRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
    169       Vector3 bottomRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
    170       Vector3 bottomLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
    171       Vector3 bottomLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
     161      var shapeVertices = new VertexPositionColorNormal[48];
     162
     163      var topRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
     164      var topRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
     165      var topLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
     166      var topLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
     167      var bottomRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3;
     168      var bottomRightBackNormal = (topNormal + rightNormal + backNormal) / 3;
     169      var bottomLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3;
     170      var bottomLeftBackNormal = (topNormal + leftNormal + backNormal) / 3;
    172171
    173172      shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal);
     
    227226      return shapeVertices;
    228227    }
    229 
    230 
    231228  }
    232229}
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/PackingGame.cs

    r13478 r13497  
    2222using System;
    2323using System.Drawing.Printing;
     24using System.Windows.Forms;
    2425using SharpDX;
    2526using SharpDX.Direct3D11;
     
    6566      graphicsDeviceManager.PreparingDeviceSettings +=
    6667        (object sender, PreparingDeviceSettingsEventArgs e) => {
    67           e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = MSAALevel.X4;
     68          e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = MSAALevel.X4;         
    6869          return;
    6970        };
    70       var controlColor = Color.White;//System.Drawing.SystemColors.Control;
     71      var controlColor = Color.White; // System.Drawing.SystemColors.Control;
    7172      backgroundColor = new Color(controlColor.R, controlColor.G, controlColor.B, controlColor.A);
    7273
     
    103104    protected override void Initialize() {
    104105      base.Initialize();
    105       initializeWorld();
     106      InitializeWorld();
    106107      previousMouseState = Mouse.GetState();
    107108      Console.WriteLine("Initial bounds:" + Window.ClientBounds);
    108109      this.Window.IsMouseVisible = true;
    109110    }
    110     private void initializeWorld() {
     111    private void InitializeWorld() {
    111112      #region Matrix-Initialization
    112113      worldMatrix = Matrix.Identity;
     
    233234
    234235    protected override void Update(GameTime gameTime) {
    235       computeMouseHandling();
     236      ComputeMouseHandling();
    236237      base.Update(gameTime);
    237238    }
     
    242243    private Vector2 currentViewAngle = new Vector2(0, 0);
    243244    #endregion Mouse-Handling Variables
    244     private void computeMouseHandling() {
     245    private void ComputeMouseHandling() {
    245246      MouseState mouseState = Mouse.GetState();
    246247
    247       computeLeftMouseBtnHandling(mouseState);
    248       computeMouseWheelHandling(mouseState);
     248      ComputeLeftMouseBtnHandling(mouseState);
     249      ComputeMouseWheelHandling(mouseState);
    249250
    250251      previousMouseState = mouseState;
    251252    }
    252     private void computeLeftMouseBtnHandling(MouseState mouseState) {
     253    private void ComputeLeftMouseBtnHandling(MouseState mouseState) {
    253254      //Left btn pressed
    254255      if (mouseState.LeftButton.Down && (previousMouseState.LeftButton.Pressed || previousMouseState.LeftButton.Down)) {
     
    268269      }
    269270    }
    270     private void computeMouseWheelHandling(MouseState mouseState) {
     271    private void ComputeMouseWheelHandling(MouseState mouseState) {
    271272      int curr = mouseState.WheelDelta;
    272273      if (curr < 0 && zoom > 1) {
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/PackingPlan3D.cs

    r13465 r13497  
    2323using System.Windows.Forms;
    2424using System.Threading;
     25using SharpDX.Toolkit;
     26using SharpDX.Windows;
    2527
    2628
    2729namespace PackingPlanVisualizations {
    2830  public partial class PackingPlan3D : UserControl {
    29     private PackingGame game;
     31    private readonly PackingGame game;
    3032    private Thread gameLoopThread;
     33    private RenderForm renderForm;
    3134
    3235    public PackingPlan3D() {
    3336      InitializeComponent();
    34       if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
     37
     38      using (var proc = System.Diagnostics.Process.GetCurrentProcess()) {
     39        if (proc.ProcessName == "devenv") return;
    3540        game = new PackingGame(this);
    3641      }
     
    3944
    4045    public void StartRendering() {
    41       if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
     46      using (var proc = System.Diagnostics.Process.GetCurrentProcess()) {
     47        if (proc.ProcessName == "devenv") return;
    4248        if (!game.IsRunning)
    4349          StartGameLoop();
     
    5561                new MethodInvoker(
    5662                  () => {
    57                     game.Run(this);
     63                    var renderForm = new RenderForm("bla");
     64                    var gameContext = new GameContext(renderForm);
     65                    gameContext.UseApplicationDoEvents = false;
     66                    game.Run(gameContext);
    5867                  }
    5968                )
     
    95104    private void PackingPlan3D_Resize(object sender, EventArgs e) {
    96105      //this.Refresh();                                         
    97       if (!(System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")) {
     106      using (var proc = System.Diagnostics.Process.GetCurrentProcess()) {
     107        if (proc.ProcessName == "devenv") return;
    98108        game.SetSize(this.Width, this.Height);
    99109      }
    100110    }
     111
     112    private void PackingPlan3D_MouseEnter(object sender, EventArgs e) {
     113    }
     114
     115    private void PackingPlan3D_MouseLeave(object sender, EventArgs e) {
     116
     117    }
    101118  }
    102119}
  • branches/HeuristicLab.BinPacking/PackingPlanVisualizations/PackingPlanVisualizations.csproj

    r13465 r13497  
    8787    <Compile Include="3D\BasicCuboidShape.cs" />
    8888    <Compile Include="3D\CenteredContainer.cs" />
    89     <Compile Include="3D\CuboidShapePreperations.cs" />
     89    <Compile Include="3D\CuboidShapePreparations.cs" />
    9090    <Compile Include="3D\PackingGame.cs" />
    9191    <Compile Include="3D\PackingPlan3D.cs">
Note: See TracChangeset for help on using the changeset viewer.