#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using SharpDX; namespace PackingPlanVisualizations { public class CenteredContainer { private BasicCuboidShape container; private List packingItems; private float normalizingFactor; public CenteredContainer(BasicCuboidShape container) { normalizingFactor = CalculateNormalizingFactor(container); this.container = Normalize (container); packingItems = new List(); } private float CalculateNormalizingFactor(BasicCuboidShape shape) { float longestEdge = Math.Max(Math.Max(shape.ShapeSize.X, shape.ShapeSize.Y), shape.ShapeSize.Z); return 1 / (longestEdge / 30); } private BasicCuboidShape Normalize(BasicCuboidShape shape) { return new BasicCuboidShape(shape.ShapeSize * normalizingFactor, shape.ShapePosition * normalizingFactor, shape.ShapeID, shape.Material); } public BasicCuboidShape Container { get { return container; } } public List PackingItems { get { return packingItems; } } public void AddPackingItem(Vector3 size, Vector3 position, int index, int material) { Vector3 itemSize = size * normalizingFactor; Vector3 itemPosition = position * normalizingFactor; //Apply rotation = swap X and Y size //if (rotated) { // float aux = itemSize.X; // itemSize.X = itemSize.Y; // itemSize.Y = aux; //} Vector3 actualPosition = container.CalculatePositionRelativeToBottomLeftBackCorner(itemSize, itemPosition); BasicCuboidShape itemShape = new BasicCuboidShape(itemSize, actualPosition, index, material); packingItems.Add(itemShape); } } }