Is there a C ++ source for lib 2D packaging with a rectangular bin (not square) and rotation?

As mentioned in the title, I need C / C ++ source code or a library that I can use to solve the problem with Bin Packing with two-dimensional rectangular shapes, where the cell is also rectangular and the rectangles also rotate at 90 ยฐ to fit better . I already have all the necessary values, so I do not need an online packaging algorithm.

I found only lib that deals with a square box and without rotation, which is not very effective for my needs.

I would really appreciate that C / C ++ handles a rectangular basket and rotation.

Thanks.

PS: The required time for calculation is not important, only the result.

PPS: it must be C or C ++, and I did not find anything useful to search for stackoverflow ...

+7
source share
2 answers

http://clb.demon.fi/files/RectangleBinPack.pdf is the key. This is a link to 2d bin packaging.

You may be able to modify one of the algorithms there to suit your needs. I doubt that rotation is necessary, the algorithms are pretty advanced, as it is.

This ( https://github.com/Lalaland/PixelPacker/blob/master/src/algoMaxRects.cpp ) is an example of how to implement the MaxRects algorithm.

The modification you probably should do is at the top of the algorithm when choosing the next rectangle to use. Just have a look at the different orientations of the rectangles along with the cyclic movement throughout the list.

+11
source

I found this thread a few weeks ago, after I read the PDF file in response and walked around with the authors code, I did a rewrite that was more suited to my needs (packing texture atlas)

If anyone else is interested ... https://github.com/chris-stones/BinPack2D

  • Allow the user to associate the data structure with the presented rectangles (name of the source file, etc.)
  • Package of several boxes (for atlas 2d array - GL_EXT_texture_array)

In addition, instead of tracking the splitting and combining of free rectangles, I track and sort the upper left corners. I found it much easier to implement, with equally good results.

No documentation, see ExampleProgram () at the top of the header file.

+4
source

All Articles