Beispiel #1
0
        /// <summary>
        /// Deep copy.
        /// </summary>
        /// <returns></returns>
        public OTree Copy()
        {
            OTree ot = new OTree();
            ot.moduleSequence = new List<int>(moduleSequence);
            ot.dfsSequence = new List<Bit>(dfsSequence);

            return ot;
        }
Beispiel #2
0
        /// <summary>
        /// Deep copy.
        /// </summary>
        /// <returns></returns>
        public OTree Copy()
        {
            OTree ot = new OTree();

            ot.moduleSequence = new List <int>(moduleSequence);
            ot.dfsSequence    = new List <Bit>(dfsSequence);

            return(ot);
        }
Beispiel #3
0
        /// <summary>
        /// Greedy algorithm.
        /// </summary>
        /// <param name="_modules">List of modules that represent the images that need to be inserted into the sprite.</param>
        /// <returns>Near optimal placement.</returns>
        public static Placement Greedy(List <Module> _modules)
        {
            //Empty O-Tree code.
            OTree oTree   = new OTree();
            OT    finalOT = null;
            //Empty list of modules.
            List <Module> moduleList = new List <Module>();

            //For each module which needs to be inserted.
            foreach (Module module in _modules)
            {
                OTree bestOTree = null;
                //Add module to the list of already packed modules.
                moduleList.Add(module);
                //Set the minimum perimeter of the placement to high.
                int minPerimeter = Int32.MaxValue;

                //Try all insertation point.
                foreach (int insertationPoint in oTree.InsertationPoints())
                {
                    OTree ot = oTree.Copy();
                    ot.Insert(module.Name, insertationPoint);
                    OT        oT = new OT(ot, moduleList);
                    Placement pm = oT.Placement;

                    //Choose the one with the minimum perimeter.
                    if (pm.Perimeter < minPerimeter)
                    {
                        finalOT      = oT;
                        bestOTree    = ot;
                        minPerimeter = pm.Perimeter;
                    }
                }
                oTree = bestOTree;
            }

            return(finalOT.Placement);
        }
Beispiel #4
0
        /// <summary>
        /// Greedy algorithm.
        /// </summary>
        /// <param name="_modules">List of modules that represent the images that need to be inserted into the sprite.</param>
        /// <returns>Near optimal placement.</returns>
        public static Placement Greedy(List<Module> _modules)
        {
            //Empty O-Tree code.
            OTree oTree = new OTree();
            OT finalOT = null;
            //Empty list of modules.
            List<Module> moduleList = new List<Module>();

            //For each module which needs to be inserted.
            foreach (Module module in _modules)
            {
                OTree bestOTree = null;
                //Add module to the list of already packed modules.
                moduleList.Add(module);
                //Set the minimum perimeter of the placement to high.
                int minPerimeter = Int32.MaxValue;

                //Try all insertation point.
                foreach (int insertationPoint in oTree.InsertationPoints())
                {
                    OTree ot = oTree.Copy();
                    ot.Insert(module.Name, insertationPoint);
                    OT oT = new OT(ot, moduleList);
                    Placement pm = oT.Placement;

                    //Choose the one with the minimum perimeter.
					if (pm.Perimeter < minPerimeter && pm.Width <= 2048 && pm.Height <= 2048)
                    {
                        finalOT = oT;
                        bestOTree = ot;
                        minPerimeter = pm.Perimeter;
                    }
                }
                oTree = bestOTree;
            }

            return finalOT.Placement;
        }
Beispiel #5
0
 /// <summary>
 /// Algoritms class for O-Tree representation.
 /// </summary>
 /// <param name="ot">The O-tree code which describes the placement.</param>
 /// <param name="_modules">Modules to be packed.</param>
 public OT(OTree ot, List<Module> _modules)
 {
     oTree = ot;
     modules = _modules.ToDictionary(item => item.Name, item => item);
     placement = null;
 }
Beispiel #6
0
 /// <summary>
 /// Algoritms class for O-Tree representation.
 /// </summary>
 /// <param name="ot">The O-tree code which describes the placement.</param>
 /// <param name="_modules">Modules to be packed.</param>
 public OT(OTree ot, List <Module> _modules)
 {
     oTree     = ot;
     modules   = _modules.ToDictionary(item => item.Name, item => item);
     placement = null;
 }