1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using SharpDX;
|
---|
25 |
|
---|
26 | namespace PackingPlanVisualizations {
|
---|
27 |
|
---|
28 | public class CenteredContainer {
|
---|
29 | private BasicCuboidShape container;
|
---|
30 | private List<BasicCuboidShape> packingItems;
|
---|
31 | private float normalizingFactor;
|
---|
32 |
|
---|
33 | public CenteredContainer(BasicCuboidShape container) {
|
---|
34 | normalizingFactor = CalculateNormalizingFactor(container);
|
---|
35 | this.container = Normalize (container);
|
---|
36 | packingItems = new List<BasicCuboidShape>();
|
---|
37 | }
|
---|
38 |
|
---|
39 | private float CalculateNormalizingFactor(BasicCuboidShape shape) {
|
---|
40 | float longestEdge = Math.Max(Math.Max(shape.ShapeSize.X, shape.ShapeSize.Y), shape.ShapeSize.Z);
|
---|
41 | return 1 / (longestEdge / 30);
|
---|
42 | }
|
---|
43 | private BasicCuboidShape Normalize(BasicCuboidShape shape) {
|
---|
44 | return new BasicCuboidShape(shape.ShapeSize * normalizingFactor, shape.ShapePosition * normalizingFactor, shape.ShapeID, shape.Material);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | public BasicCuboidShape Container {
|
---|
50 | get { return container; }
|
---|
51 | }
|
---|
52 | public List<BasicCuboidShape> PackingItems {
|
---|
53 | get { return packingItems; }
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | public void AddPackingItem(Vector3 size, Vector3 position, int index, int material) {
|
---|
58 | Vector3 itemSize = size * normalizingFactor;
|
---|
59 | Vector3 itemPosition = position * normalizingFactor;
|
---|
60 | //Apply rotation = swap X and Y size
|
---|
61 | //if (rotated) {
|
---|
62 | // float aux = itemSize.X;
|
---|
63 | // itemSize.X = itemSize.Y;
|
---|
64 | // itemSize.Y = aux;
|
---|
65 | //}
|
---|
66 | Vector3 actualPosition = container.CalculatePositionRelativeToBottomLeftBackCorner(itemSize, itemPosition);
|
---|
67 | BasicCuboidShape itemShape = new BasicCuboidShape(itemSize, actualPosition, index, material);
|
---|
68 | packingItems.Add(itemShape);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | } |
---|