tamasmeszaros / libnest2d

2D irregular bin packaging and nesting library written in modern C++
GNU Lesser General Public License v3.0
315 stars 104 forks source link

running the simple example... no output #12

Open markfink opened 4 years ago

markfink commented 4 years ago

I just found libnest2d and it looks awesome. thank you for sharing your code!

I am running the simple example code and it does nothing. I guess it is related to this part of the code.

    // Retrieve resulting geometries
    for(Item& r : input) {
        auto polygon = r.transformedShape();
        // render polygon...
    }

Could you please share the version of the example that renders the beautifull 38 green objects. I assume this was generated using your lib.

I managed to doctor in some code from your other example (very ugly compared to your output). image

#include <iostream>
#include <string>
#include <fstream>
#include <cstdint>

#include <libnest2d/libnest2d.hpp>

#include "../tools/printer_parts.hpp"
#include "../tools/svgtools.hpp"

// Here we include the libnest2d library
#include <libnest2d/libnest2d.hpp>

int main(int argc, const char* argv[]) {
    using namespace libnest2d;

    // Example polygons 
    std::vector<Item> input1(23,
    {
        {-5000000, 8954050},
        {5000000, 8954050},
        {5000000, -45949},
        {4972609, -568550},
        {3500000, -8954050},
        {-3500000, -8954050},
        {-4972609, -568550},
        {-5000000, -45949},
        {-5000000, 8954050},
    });
    std::vector<Item> input2(15,
    {
       {-11750000, 13057900},
       {-9807860, 15000000},
       {4392139, 24000000},
       {11750000, 24000000},
       {11750000, -24000000},
       {4392139, -24000000},
       {-9807860, -15000000},
       {-11750000, -13057900},
       {-11750000, 13057900},
    });

    std::vector<Item> input;
    input.insert(input.end(), input1.begin(), input1.end());
    input.insert(input.end(), input2.begin(), input2.end());

    // Perform the nesting with a box shaped bin
    size_t bins = nest(input, Box(150000000, 150000000));

    PackGroup pgrp(bins);

    for (Item &itm : input) {
        if (itm.binId() >= 0) pgrp[size_t(itm.binId())].emplace_back(itm);
    }

    using SVGWriter = libnest2d::svg::SVGWriter<PolygonImpl>;
    SVGWriter::Config conf;
    conf.mm_in_coord_units = mm();
    SVGWriter svgw(conf);
    svgw.setSize(Box(mm(250), mm(210)));
    svgw.writePackGroup(pgrp);
    svgw.save("out");

    return EXIT_SUCCESS;
}
samsonsite1 commented 4 years ago

I also found that Box() takes a center parameter if you want to push the entire bin in positve space. Otherwise the bin gets centered at (0,0), and gets clipped in negative space.

size_t s = 150000000; size_t bins = nest(input, Box(s,s, {s/2, s/2} ));

tamasmeszaros commented 4 years ago

Hello @markfink. I believe @samsonsite1 is right. The green color for the output polygons are made by hand in Inkscape, the SWGWriter is too dummy for that.

BTW, thank you for nest2d, it's awesome to see libnest2d being used in this way.

markfink commented 4 years ago

@tamasmeszaros it was a pleasure! Thanks really belongs to the pybind11 developers. The bindings are brand new (shame, I did not even write a blog post about it) and it is not clear where to go with it. Would you be interested to move the binding code to your repo?