Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running the simple example... no output #12

Open
markfink opened this issue Dec 23, 2019 · 3 comments
Open

running the simple example... no output #12

markfink opened this issue Dec 23, 2019 · 3 comments

Comments

@markfink
Copy link

markfink commented Dec 23, 2019

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
Copy link

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
Copy link
Owner

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
Copy link
Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants