Closed software6ptk closed 1 year ago
Hi, can you please provide your dxf files ? It is strange behavior indeed
Sure, here are my dxf files. Inside the zip are the three files i use:
I have to say though, that i use an underlying structure to take the points from a dxf parser, then i pass the points to your library by converting them to your svgpoint
I fixed dxf sheets loader, and maybe that would be enough for your purposes. P.S. In order to load your DXF files, I converted them using LibreCAD to the DXF 2007 format
First of all i thank you for keeping this lib active and updated.
BUT
I'm really sorry to tell you the issue is still present
it presents itself only when i'm using different types of shapes to nest into the container though (like before) so maybe that's why you didn't notice, if you tested only with one.
It seems to be somehow better though, had to set spacing to a very low value to make it REALLY visible like in the figure, with a higher spacing value the issue is less visible but still a big problem.
PS: after today i'll be on vacation for a while, and won't be able to test the fixes, so take all the time you need
it presents itself only when i'm using different types of shapes to nest into the container though (like before) so maybe that's why you didn't notice, if you tested only with one.
Unlikely. It seems work fine with multiple shapes . I think the reason is something else
ok so this seems to be a problem on my side, maybe i'm missing some steps?
could you maybe help me find the problem? This is what i do:
NestingContext context = new NestingContext();
objects = _objects;
NFP sheetnfp = new NFP();
SvgPoint[] sheetpoints = new SvgPoint[container.Geometries[0].Vertices.Count];
int j = 0;
foreach (Point3D point in container.Geometries[0].Vertices)
{
sheetpoints[j] = new SvgPoint(point.X, point.Y);
j++;
}
sheetnfp.Points = sheetpoints;
context.Sheets.Add(sheetnfp);
foreach (ptk_Object obj in objects)
{
foreach (Geometry3D geo in obj.Geometries)
{
NFP shapenfp = new NFP();
SvgPoint[] shapepoints = new SvgPoint[geo.Vertices.Count];
j = 0;
foreach (Point3D point in geo.Vertices)
{
shapepoints[j] = new SvgPoint(point.X, point.Y);
j++;
}
shapenfp.Points = shapepoints;
context.Polygons.Add(shapenfp);
}
}
SvgNest.Config.spacing = spacing;
context.ReorderSheets();
context.StartNest();
Stopwatch sw = Stopwatch.StartNew();
while (true)
{
context.NestIterate();
if (sw.ElapsedMilliseconds > runTime)
{
break;
}
}
sw.Stop();
objects.Clear();
foreach (var item in context.Polygons.Union(context.Sheets))
{
if (!context.Sheets.Contains(item))
{
if (!item.fitted) continue;
}
var m = new Matrix();
m.Translate((float)item.x, (float)item.y);
m.Rotate(item.rotation);
PointF[] pp = item.Points.Select(z => new PointF((float)z.x, (float)z.y)).ToArray();
m.TransformPoints(pp);
var pointz = pp.Select(z => new SvgPoint(z.X, z.Y)).ToArray();
Geometry3D geo = new Geometry3D();
foreach (var p in pointz)
{
geo.Vertices.Add(new Point3D(p.x, p.y));
}
List<Geometry3D> list = new List<Geometry3D>();
list.Add(geo);
objects.Add(new ptk_Object(list));
}
Could you also provide your geometric data (points) as well (any format is ok) ?
i literally just load the files i've given you with a simple parser and put them into my object/geometry type, then create multiple instances/clones of the objects when i have to pass them to the nesting algorithm.
anyway these are for the big star:
X = 208,64500427246094, Y = 123,68599700927734, Z = 0 X = 158,05479431152344, Y = 73,22959899902344, Z = 0 X = 171,8231964111328, Y = 3,818000078201294, Z = 0 X = 107,18250274658203, Y = 35,33829879760742, Z = 0 X = 44,018798828125, Y = 1,0671000480651855, Z = 0 X = 54,65879821777344, Y = 71,00409698486328, Z = 0 X = 1,853100061416626, Y = 119,23490142822266, Z = 0 X = 73,0697021484375, Y = 130,93809509277344, Z = 0 X = 103,59760284423828, Y = 195,01759338378906, Z = 0 X = 136,9718017578125, Y = 132,3135986328125, Z = 0
these are for the little star X = 27,398521423339844, Y = 46,759700775146484, Z = 0 X = 31,113996505737305, Y = 31,009069442749023, Z = 0 X = 46,195343017578125, Y = 25,14052963256836, Z = 0 X = 32,3637580871582, Y = 16,73969078063965, Z = 0 X = 31,44283103942871, Y = 0,5830000042915344, Z = 0 X = 19,178964614868164, Y = 11,141619682312012, Z = 0 X = 3,5284528732299805, Y = 7,024779796600342, Z = 0 X = 9,780553817749023, Y = 21,951200485229492, Z = 0 X = 1,028931975364685, Y = 35,56354904174805, Z = 0 X = 17,156810760498047, Y = 34,22996139526367, Z = 0
and these are for the square X = 1,4612550735473633, Y = 35,80072021484375, Z = 0 X = 40,91512680053711, Y = 35,80072021484375, Z = 0 X = 40,91512680053711, Y = 1,0959240198135376, Z = 0 X = 1,4612550735473633, Y = 1,0959240198135376, Z = 0
hope i understood what you asked for XD
Probably, your shapes are not closed. You should copy the first point of each NFP and add it to the end of the points list. The first and last points must be equal. Anyway, I'll check it out too.
I tried to do as suggested, the problem persists.
Thank you for your time though
I added a Console.Core project, so you can run task1.xml (it contains your raw geometric data)
It should produce next output svg file:
Image output (generated via Inkscape from svg):
PS: If this doesn't help, please give me your whole project (.csproj), in order to reproduce your bug on my side
Hi, i'm finally back from vacation and taking a look at what you did.
Right now i'm trying to understand how you take the points from the file, since i'm thinking that my problem resides in how i give the points to the nester.
Unfortunately i can't share the whole project with you, so i'll just try and make it work with what i have. I'll be back with updates on my progress once i manage to do something.
Thank you again for your time
EDIT:
Seems i managed to resolve the issue by adding the source ( context.GetNextSource() ) to the polygons
Hi, sorry if i bother you but i'm not that experienced of a programmer.
As for the title, when i try nesting multiple different shapes, i get a strange behavior. Shapes overlap one with another.
This is not a spacing problem, as it works perfectly when i use only multiple copies of the same shape.
Here's an example of what i mean
Is this an error on my side? What can i do to fix this?
EDIT: Also, sometimes the shapes go outside of the container (happens more when using different shapes, but sometimes happens with single shapes too) This also is represented in the example i posted, with the square on the left that overlaps its bottom left corner with the container.