WildReanimator

packager.h

Nov 23rd, 2012
1,319
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef PACKEGER_H
  2. #define PACKEGER_H
  3.  
  4. #include <QRect>
  5. #include <QList>
  6. #include <QMap>
  7. #include <QColor>
  8.  
  9. class Algorithm
  10. {
  11. public:
  12.     Algorithm(){}
  13.  
  14.     virtual const QList<QRect> pack(const QList<QRect> rects){}
  15.     virtual void setParam(qreal param) {}
  16. };
  17.  
  18. ///////////////////////////////////////////////////////////////////////////////
  19. //  Offline algorithms
  20. ///////////////////////////////////////////////////////////////////////////////
  21. class NFDH: public Algorithm
  22. {
  23. public:
  24.     NFDH(){}
  25.  
  26.     const QList<QRect> pack(const QList<QRect> rects);
  27. };
  28.  
  29. class FFDH: public Algorithm
  30. {
  31. public:
  32.     FFDH(){}
  33.  
  34.     const QList<QRect> pack(const QList<QRect> rects);
  35. };
  36.  
  37. class BFDH: public Algorithm
  38. {
  39. public:
  40.     BFDH(){}
  41.  
  42.     const QList<QRect> pack(const QList<QRect> rects);
  43. };
  44.  
  45. class KP01: public Algorithm
  46. {
  47. public:
  48.     KP01(){}
  49.  
  50.     const QList<QRect> pack(const QList<QRect> rects);
  51. };
  52.  
  53. class SF: public Algorithm
  54. {
  55. public:
  56.     SF(){}
  57.  
  58.     const QList<QRect> pack(const QList<QRect> rects);
  59.  
  60. private:
  61.     typedef struct sf {
  62.         QRect rect;
  63.         qreal scaledWidth;
  64.         bool packedFirst;
  65.     } Sf;
  66. };
  67.  
  68. class JOIN: public Algorithm
  69. {
  70. public:
  71.     JOIN(){_gamma = 0.05;}
  72.  
  73.     const QList<QRect> pack(const QList<QRect> rects);
  74.     void setParam(qreal param) {_gamma = param;}
  75.  
  76. private:
  77.     qreal _gamma;
  78. };
  79.  
  80. class FCNR: public Algorithm
  81. {
  82. public:
  83.     FCNR(){}
  84.  
  85.     const QList<QRect> pack(const QList<QRect> rects);
  86. };
  87.  
  88. class Sleator: public Algorithm
  89. {
  90. public:
  91.     Sleator(){}
  92.  
  93.     const QList<QRect> pack(const QList<QRect> rects);
  94. };
  95.  
  96. class Burke: public Algorithm
  97. {
  98. public:
  99.     Burke(){}
  100.  
  101.     const QList<QRect> pack(const QList<QRect> rects);
  102. };
  103. ///////////////////////////////////////////////////////////////////////////////
  104. //  Online algorithms
  105. ///////////////////////////////////////////////////////////////////////////////
  106. class NFL: public Algorithm
  107. {
  108. public:
  109.     NFL(){}
  110.  
  111.     const QList<QRect> pack(const QList<QRect> rects);
  112. };
  113.  
  114. class FFL: public Algorithm
  115. {
  116. public:
  117.     FFL(){}
  118.  
  119.     const QList<QRect> pack(const QList<QRect> rects);
  120. };
  121.  
  122. class BFL: public Algorithm
  123. {
  124. public:
  125.     BFL(){}
  126.  
  127.     const QList<QRect> pack(const QList<QRect> rects);
  128. };
  129.  
  130. class BiNFL: public Algorithm
  131. {
  132. public:
  133.     BiNFL(){}
  134.  
  135.     const QList<QRect> pack(const QList<QRect> rects);
  136. };
  137.  
  138. class NFS: public Algorithm
  139. {
  140. public:
  141.     NFS(){_base = static_cast<qreal>(0.7);}
  142.  
  143.     const QList<QRect> pack(const QList<QRect> rects);
  144.     void setParam(qreal param) {_base = param;}
  145.  
  146. private:
  147.     qreal _base;
  148. };
  149.  
  150. class FFS: public Algorithm
  151. {
  152. public:
  153.     FFS(){_base = static_cast<qreal>(0.7);}
  154.  
  155.     const QList<QRect> pack(const QList<QRect> rects);
  156.     void setParam(qreal param) {_base = param;}
  157.  
  158. private:
  159.     qreal _base;
  160. };
  161.  
  162. class BFS: public Algorithm
  163. {
  164. public:
  165.     BFS(){_base = static_cast<qreal>(0.7);}
  166.  
  167.     const QList<QRect> pack(const QList<QRect> rects);
  168.     void setParam(qreal param) {_base = param;}
  169.  
  170. private:
  171.     qreal _base;
  172. };
  173.  
  174. class HS: public Algorithm
  175. {
  176. public:
  177.     HS(){_base = static_cast<qreal>(0.7);}
  178.  
  179.     const QList<QRect> pack(const QList<QRect> rects);
  180.     void setParam(qreal param) {_base = param;}
  181.  
  182. private:
  183.     qreal _base;
  184. };
  185.  
  186. class Azar: public Algorithm
  187. {
  188. public:
  189.     Azar(){_gamma = 0.4;}
  190.  
  191.     const QList<QRect> pack(const QList<QRect> rects);
  192.     void setParam(qreal param) {_gamma = param;}
  193.  
  194. private:
  195.     qreal _gamma;
  196. };
  197.  
  198. class CA: public Algorithm
  199. {
  200. public:
  201.     CA(){}
  202.  
  203.     const QList<QRect> pack(const QList<QRect> rects);
  204. };
  205.  
  206. class CPF: public Algorithm
  207. {
  208. public:
  209.     CPF(){}
  210.  
  211.     const QList<QRect> pack(const QList<QRect> rects);
  212. };
  213.  
  214. class CFF: public Algorithm
  215. {
  216. public:
  217.     CFF(){}
  218.  
  219.     const QList<QRect> pack(const QList<QRect> rects);
  220. };
  221.  
  222. class CC: public Algorithm
  223. {
  224. public:
  225.     CC(){}
  226.  
  227.     const QList<QRect> pack(const QList<QRect> rects);
  228. };
  229.  
  230. class OF: public Algorithm
  231. {
  232. public:
  233.     OF(){}
  234.  
  235.     const QList<QRect> pack(const QList<QRect> rects);
  236. private:
  237.     int searchMinGap(const QList<int> gap, int width);
  238.     int _level;
  239. };
  240. ///////////////////////////////////////////////////////
  241. class Packager
  242. {
  243. protected:
  244.     Algorithm* algorithm;
  245.  
  246. private:
  247.     QList<QRect> _rectangles;
  248.  
  249. public:
  250.     Packager(void){}
  251.  
  252.     void init(QString filename);
  253.     int getSize(void);
  254.     void UseAlgorithm(void);
  255.     void SetAlgorithm(Algorithm* a);
  256.     void SetParameter(qreal param) {algorithm->setParam(param);}
  257.  
  258.     QList<QRect> rectangles;
  259.  
  260.     class Level
  261.     {
  262.     public:
  263.         Level(int b, int h, int f=0, int w=0) : bottom(b),
  264.                                                 height(h),
  265.                                                 floor(f),
  266.                                                 initW(w),
  267.                                                 ceiling(0){}
  268.  
  269.         const QRect put(const QRect &rect, bool f=true, bool leftJustified=true);
  270.         bool ceilingFeasible(const QRect &rect, const QList<QRect> existing);
  271.         bool floorFeasible(const QRect &rect);
  272.         int getSpace(bool f=true);
  273.  
  274.         int bottom;
  275.         int height;
  276.         int floor;
  277.         int initW;
  278.         int ceiling;
  279.     };
  280. };
  281. #endif // PACKEGER_H
RAW Paste Data