-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
splines are not rendering all the control points #366
Comments
Can you attach or link to an example DXF file that shows the problem? |
Hi, Thanks for following up the case and many thanks for making CAMotics! I already used it to carve a pirate dagger for my son with his name on it and he was very happy! :-D |
I finally managed to get the rendering right in dxf_tpl.zip |
Two things that I should fix are:
|
I removes the zSafe and identified what I need to do to access the spline flags that contain the |
I started implementing some similar changes when you first opened this issue. I'll have to merge your changes with mine at some point. |
In theory my change just misses adding the same point twice at the beginning and end of the segments split to create the open splines and understanding why that division by two is necessary, but if you want to implement it yourself, feel free to go for it! |
I believe the rendering is wrong in the first place. The code treats the data as if it work a series of Bezier curves. But it's actually a B-spline which is something else. I think this is why the adjustment is needed. I've done some tests with the "stretching cat" demo and this new code does not work at all. "stretching cat" is made of of 3-degree B-splines. Previously it just connected the control points, which is pretty dumb but it worked in this case. I think we need to implement De Boor's algorithm to render the B-splines correctly. There are many improvements that could be made to the DXF library. It was something I just whipped up to get a job done. I've been studying your changes. The help is much appreciated. |
Ah! Thanks for the clarification! I implement a https://en.m.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull%E2%80%93Rom_spline because I saw that it had to pass through the control points and because the bezier evaluators were already in place. |
Where did you get the idea to average the point computation result with the second control point. It seems to work but I don't understand why. |
I started with a 3 points spline, rendering the p0-p1 and p1-p2 lines together with the spline and I noticed that it kind of looked twice as big compared to the LibreCAD rendering, so I halved the coordinates. Then it looked offsetted from p1 so I added p1, but then it went too much the other way, so I added half p1 instead and it looked exactly like in LibreCAD. So it was a dirty hack based on observation. It would indeed be good to understand why it's needed... |
I read the Autodesk specs and the splines in dxf are NURBS: https://en.m.wikipedia.org/wiki/Non-uniform_rational_B-spline |
I found something that should work: https://github.com/caadxyz/DeBoorAlgorithmNurbs/blob/master/src/DeBoorAlgorithmNurbs.py It's the deBorr you mentioned above, but adapted to work with NURBS. Porting it to the And we indeed need to export the spline flags into the JavaScript code since it needs a couple of them. |
Most of the DXF splines are uniform and non-rational. Uniform splines have equal spacing between knots and non-rational splines have no weights. All the examples, I have looked at are like this. However, it would be great to also implement rational and non-uniform splines. In order to do this, we need to also load the weights from the DXF, if there are any, and look at the other flags. As you noted before, there are closed and unclosed splines. In addition, there are periodic and non-periodic splines. I don't know if closed non-periodic splines are likely to occur in a DXF. I didn't understand most of this when I first wrote the code. I've been doing some reading. Here's an possible implementation in Javascript: https://github.com/thibauts/b-spline/blob/master/index.js |
I ported the javascript implementation that you pointed at in #367 and it works well (only assumes open nurbs for now). |
Thanks for the code review! |
Either way is fine by me. |
After my last change to #367 it looks like closed nurbs can be rendered correctly. (sorry for hardcoding |
Finally I managed to use my ubuntu machine :-) |
Awesome. Thanks for doing all that. |
No problem! This was fun to implement :-) |
I have my own coding style which I should document. All of the C++ and Javascript code should already be in my style. So you can try to copy the other code. Otherwise, I'll just make a pass over it when your done to bring it in to compliance. So fix the style if you want to. I'll do a through code review when you're done. Awesome work! One of the next big things I'd like to implemented, related to this DXF work, is to add an UI interface for opening DXF files and configuring the layers to be cut using different operations such as offsetting and pocketing. You would open a DXF file and get a list of its layers and/or it's polygons. Then for each one you could select the CAM operation and parameters such as which tool, the depth, offset amount, etc. This UI would just produce a bit of JSON data that a TPL program would read and execute the correct CAM operations. There would be a function like |
I committed the final optimization for splines rendering and I added the Z interpolation because, why not? Then I created an unruly mess of shapes in LibreCAD and checked if they matched the CAMotics rendering. Splines worked well, opened or closed. Ellipses gave a warning about not being implemented (I can do that in another GitHub issues). However, when I added even a single polyline, the polyline was always rendered closed and it was messing the closed splines data. I then added one more commit to pass the isClosed flag of the polylines down to the json, but it looks like the flags won't appear in the json. It does appear with the correct value if I move it in the vertices list, inside the x,y,z dictionary :-| About opening the dxf files with a dialog, I think it's a great idea. I indeed almost discarded CAMotics as broken the first time I tried it because it didn't show me the dxf rendered when I tried to open it directly :-D Good thing that I later found out about the tpl files in another tutorial. I also like the idea of configuring each layer independently. My workflow is to have a layer with the figure's details and a layer with the figure's silhouette to cut it off of the plywood. I woul configure the tpl to do the details layer first in a single pass and then to cut the silhouette with multiple passes, depending on how deep the drillbit can cut and on how thick is the plywood. |
I figured out the last bug after looking at a simpler example where I noticed that the control points are inverted when the bug happens: I forgot to modify the element_flips for splines and polylines :-) |
Great, the last bug is fixed (it was actually 2 or 3 of them) and #367 is ready to merge after your code review! |
Hi @jcoffland |
I'll do this soon. |
I haven't forgotten about this but I'm still trying to find time to review it. |
I made a branch from your PR, added some of my own changes and then made a new PR. See #370. I reviewed my own PR. Please take a look at my review comments when you have a chance. I'm mostly happy with this code but I'm not convinced it's 100% yet. Regardless, it's way better than what we had. |
Thanks for reviewing! |
I left some comments. |
Hi,
I just noticed that when I make a drawing in LibreCAD and read it in CAMotics, only the first bit of the spline is rendered, so I started digging into dxf.tpl and found that it's not running the Catmull-Rom 2D on all the control points.
The quick hack below makes the shapes appear more or less in the right place, but there are some gaps.
I'll try to find some time to fix the spline rendering and submit a change :-)
The text was updated successfully, but these errors were encountered: