SeeMorton1 / 2D-packing-problem

This project produces a simple bin packing solver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2D packing problem

This project demonstrates a solver for 2D packing problem.
We utilize this algorithm.

BinPacking

Getting Started

Prerequisties

C++ is required to build.

Installation

Just download/clone all .h/.cpp files.

Example

Same example is shown in main.cpp.

To pack multiple images, use "ImagePacker" class,

#include "imagePacker.h"
...
ImagePacker packer(1024, 1024);

and call "insert" method.

Image img;
... setting img color, width/height

int id = 0;
if (packer.insert(image, id))
{
    ...
}

"insert" method returns true and assign id when success to insert.

Once success to insert an image to the packer, you can access a node with ID.

auto* nodePtr = packer.getNode(id);

Finally, to save the atlas image, call "save()" method.

packer.save("result.bmp");

Author

nossey

License

This project uses CImg library for image process.
CImg is distributed under CeCILL License

(If you want to use your own image library, please modify "Image" class and related functions. (e.g. Image.getWidth(), fillPixel(), ...))

Disclaimer

This project is free for use.
But we do not take any responsibilities for any risks and damages by using this project codes.

About

This project produces a simple bin packing solver.


Languages

Language:C++ 100.0%Language:C 0.0%