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

why merge function throw GeometryException ? #31

Open
gloryXmj opened this issue Mar 11, 2021 · 9 comments
Open

why merge function throw GeometryException ? #31

gloryXmj opened this issue Mar 11, 2021 · 9 comments

Comments

@gloryXmj
Copy link

I followed the code given in the case and tested it with my own data. An exception was thrown in the place of the meger function. Why?

@tamasmeszaros
Copy link
Owner

If you followed the code, you can see that it throws if clipper.AddPath return false. Ask clipper why he does that.
On the other hand, it may be an overly strict approach to throw, the geometry failing to be added could just be ignored. But then, you would wonder why you don't get the result you expect from the merge...

@gloryXmj
Copy link
Author

If you followed the code, you can see that it throws if clipper.AddPath return false. Ask clipper why he does that.
On the other hand, it may be an overly strict approach to throw, the geometry failing to be added could just be ignored. But then, you would wonder why you don't get the result you expect from the merge...

如果遵循该代码,则如果clipper.AddPath返回false,则可以看到它抛出。问快船为什么会那样做。
另一方面,它可能是一种过于严格的抛出方法,未能添加的几何形状可以忽略不计。但是然后,您会想知道为什么无法从合并中获得预期的结果...

Thanks for your reply, I have solved this problem, but the graphics obtained after typesetting are not what I hoped.

The first picture is my original graphic, and the dashed part in the second picture is obtained through typesetting. In the second picture, I set the center of the box. In the third picture, I did not specify the center of the picture. You can see that the picture is displayed outside the box.
1
2
3

Even if I set the center of the Box, I cannot get satisfactory results. I hope the graphics are typeset from the bottom left corner of the Box.

What other parameters should I set, I hope I can get your help, thank you again.

@gloryXmj
Copy link
Author

This is my typesetting implementation part

int Length = 1500;
int Width = 1500;
size_t bins = nest(input,
libnest2d::Box(Length,Width/,{Length/2,Width/2}/)
,10,{},
ProgressFunction{[](unsigned cnt) {
std::cout << "parts left: " << cnt << std::endl;
}});

        for(Item&r : input) {
            auto polygon = r.transformedShape();
            ClipperLib::Path path = polygon.Contour;   /// Get the offset contour
            NCPolyline *polyline = new  NCPolyline();
            for(int i =0; i < int(path.size());i++)
            {
                polyline->Insert(new NCPoint(path.at(i).X,path.at(i).Y));
                polyline->SetSelected(true);
            }
            g_pShapeSetList.at(r.binId())->Push(polyline);  //Push shape then show graphics

@tamasmeszaros
Copy link
Owner

Hi! I did a quick check with my tests for the library when the bin box has been specified with a center. It should work, I'm sorry to say but I don't know what the issue might be for your case.

@tamasmeszaros
Copy link
Owner

tamasmeszaros commented Mar 25, 2021

Ou, I see now what your problem is. You where expecting the boxes to be aligned beside each other and not in that tetris shape.
For that you would need to change the object-function of the nesting. See NfpPConfig in the nfpplacer.hpp header. This can be passed with the NestConfig parameter for the nest() function. But finding the right object function is not trivial. You can also try the BottomLeftPlacer algorithm, although I've not tested that very extensively.

The library is not specially intended for aligning a few parts nicely, but to fit many (potentially different) parts into the specified region as tightly as possible.

@gloryXmj
Copy link
Author

Ou, I see now what your problem is. You where expecting the boxes to be aligned beside each other and not in that tetris shape.
For that you would need to change the object-function of the nesting. See NfpPConfig in the nfpplacer.hpp header. This can be passed with the NestConfig parameter for the nest() function. But finding the right object function is not trivial. You can also try the BottomLeftPlacer algorithm, although I've not tested that very extensively.

The library is not specially intended for aligning a few parts nicely, but to fit many (potentially different) parts into the specified region as tightly as possible.

Thank you very much, according to your guidance, I successfully obtained my expected layout graphics.

@gloryXmj
Copy link
Author

Hi, I found a problem when using it, when I set the item
There is no problem with binId(id) (for example: 0,1,2,3). However, after calling nest, I will get binId and then all binIds obtained are 0. Why is this?

@tamasmeszaros
Copy link
Owner

This is intentional. In general, the packed items may not fit into a single bin only. If this happens, more virtual bins are allocated and the nesting continues in the new bins. The binId is an output property after the nesting and tells you the virtual bin index in which the Item is positioned. Zero means that the item is in the first bin. If the binId() returns less than zero, it means the item could not be nested for some reason (e. g. it was too big to fit into a bin).

It may be confusing that this property can be written before the packing. I guess there is no use for that currently, and should be made read only. I will consider that.

@gloryXmj
Copy link
Author

Okay, I understand what you mean. But when I used it again, I found that NestConfig<BottomLeftPlacer, FirstFitSelection> cfg;
The rotation value used for the result obtained by configuring the nest is 0, and in time I configured cfg.placer_config.allow_rotations = true; the rotation angle obtained is also 0.
How is this going? For this, I specially modified the allow_rotations value to be true by default, which is useless. Is this value useless?

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

2 participants