Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smoothing a path: a better algorithm
#1
Among my plugins there are two rather similar ones which can be used to smooth a (straight-edge) path: the simple plugin

https://www.gimp-forum.net/Thread-Smooth...ple-plugin

and the better algorithm

https://www.gimp-forum.net/Thread-Making...uous-paths

which makes very smooth paths (continuous curvature).

It came to my mind that some people may miss the better plugin just because it is called "G2-continuity" and hardly anybody knows what that means. So, just to draw peoples' attention to the plugin, I made this new thread where the title contains the words "smoothing" and "better". I hope this is not against any netiquette or forum rules. The two plugins are found at:

http://kmarkku.arkku.net/Path_modify_fil...aster.html

under the names "Simple smooth" and "G2-continuity". The sites above contain some instructions and discussion.
Reply
#2
(04-21-2022, 01:31 PM)Ottia Tuota Wrote: Among my plugins there are two rather similar ones which can be used to smooth a (straight-edge) path: the simple plugin

https://www.gimp-forum.net/Thread-Smooth...ple-plugin

and the better algorithm

https://www.gimp-forum.net/Thread-Making...uous-paths

which makes very smooth paths (continuous curvature).

It came to my mind that some people may miss the better plugin just because it is called "G2-continuity" and hardly anybody knows what that means. So, just to draw peoples' attention to the plugin, I made this new thread where the title contains the words "smoothing" and "better". I hope this is not against any netiquette or forum rules. The two plugins are found at:

http://kmarkku.arkku.net/Path_modify_fil...aster.html

under the names "Simple smooth" and "G2-continuity". The sites above contain some instructions and discussion.

At that point you could combine them in  a single plugin with either two entry points or a dialog that lets the user select one or the other.
Reply
#3
Well, I would rather just delete the simple plugin. I feel that the point in the plugin "G2-continuity" is just that it creates G2-continuous paths (continuous curvature), so there is not much point in offering there an option to make paths that are not G2-continuous, however simple the algorithm is.

The point in the simple plugin, on the other hand, was precisely that it was simple and quick to make. I also put there an option to remove superfluous anchors, and the better plugin does not have that feature. So I think I shall delete nothing and keep both plugins.

Instead, now I tell you a story: How it happened that I wanted to have paths with continuous curvature. You may recall that I made a plugin "Replicate path along circle" and I put there two distortion methods that I called "polar coordinates" and "exponential". The former is what everybody probably finds more natural. The latter is based on a property of the complex exponential function which makes it very natural for the job since we are dealing with a circle. I could draw a nice picture about that property but I skip that now.

Then I made another plugin "Replicate path along another path", and there I made distortion with the same idea as in "polar coordinates". Then I got some reason to think that it might be good to have "exponential" distortion in this plugin as well. Here we have a path instead of a circle but one could do the distortion locally by using circles of curvature. You note that the notion of "curvature" sneaked in. I made such a plugin, but it appeared to give bad results. To get better results the curvature should be continuous.

So, we need paths with continuous curvature. The idea now was to make a plugin that (1) takes a path; (2) smooths it to have continuous curvature (that is, to be G2-continuous); (3) does the replication job with locally exponential distortion. And I indeed made such a plugin and I got it working to such extent that I could look at what it produced. The results were not so very wonderful to justify publication. In addition, the replicated paths had faults here and there, hence the plugin would still require extra work. At that point I decided to give up.

So, that was a dead end. But in the course of the work I had got code for making a path G2-continuous. I took that code and developed it further to a plugin and published it.

What I want to say with this story is that the plugin "G2-continuity" is not only about smoothing a path: it is about making a path with that special property, G2-continuity. Even if this effort of mine failed, it may happen that some day somebody has a need for paths with continuous curvature. And now we have such a plugin. Therefore I feel that it is better to keep it as such, without putting there an option for that simple algorithm. Thanks for the suggestion anyway.
Reply
#4
@Ottia Tuota
I plan to port your G2 Continuity plugin to python3 / Gimp3.
After reading your code, I suggest that you split the code in 2 files for easier maintenance and reuse :
- one python module to handle everything related to mathematical stuff (like g2continuity.py)
- one python script for the gimp plugin (like g2continuity-plugin.py)

Since every gimp plug-in needs a dedicated folder, you simply have to put the 2 files into the zip archive.
Reply
#5
(04-23-2022, 04:02 PM)tmanni Wrote: @Ottia Tuota
I plan to port your G2 Continuity plugin to python3 / Gimp3.
After reading your code, I suggest that you split the code in 2 files for easier maintenance and reuse :
- one python module to handle everything related to mathematical stuff (like g2continuity.py)
- one python script for the gimp plugin (like g2continuity-plugin.py)

Since every gimp plug-in needs a dedicated folder, you simply have to put the 2 files into the zip archive.

I am no coder and my code is usually quite messy. Maintaining would be a nightmare. I am not sure I understand what you actually mean by splitting it to mathematical stuff and Gimp plugin. The mathematics concerning G2-continuity is a very small part in the code and isolated to one routine (plus the matrix inversion code). The mathematics concerning Bezier curves (paths) uses my own data structure (class) BCurve, and it is used all over the code. I don't see how the splitting could be done, except for putting that one routine and the matrix inversion code in one module. Is that what you mean?

If that is what you mean, and if you think it worth-while to do even if the module will be so very small, I can try it. Could you please give detailed instructions. This is all new to me.
  1. I take that one routine and the matrix inversion code out and make them into a new file g2continuity.py.
  2. The rest is made into a file g2continuity_plugin.py.
  3. In the file g2continuity_plugin.py I write "from g2continuity import *"?
  4. Then I make a .zip file from those two files? Or should I make one folder from those two files and a .zip from that?
  5. Then what? When I share the plugin, that .zip file is what I share?
  6. And the user unzippes it and places the contents in Gimp's plug-ins folder?
  7. From where does that "dedicated folder" of the plugin come?
Please clarify.

But to help in another way anybody else to re-use the ideas, I attach here a pdf that contains the mathematics. There you find the formulas and how they are derived. I wrote it for my own use to record it all in a better form, just in case I would later need it. Before it was all just hand-written notes on paper. Don't let the appearance of the text frighten you. It looks like a mathematics paper, but it is not and will never be published anywhere. I just like to use the style I am accustomed with.

.pdf   G2_continuity.pdf (Size: 195.39 KB / Downloads: 323)

If you want to port the plugin to Gimp3, that is great. I am a little scared of the thought what to do with all my other plugins. I hope porting to Gimp3 is not too difficult.
Reply
#6
Quote:I am no coder and my code is usually quite messy.

Your code is not bad, a bit messy I admit, but your detailed comments throughout the code make it really easy to understand and to refactor.

Quote:Maintaining would be a nightmare.
Quote:
  1. I take that one routine and the matrix inversion code out and make them into a new file g2continuity.py.
  2. The rest is made into a file g2continuity_plugin.py.
  3. In the file g2continuity_plugin.py I write "from g2continuity import *"?

The reason of my suggestion; my previous post was bad; forget the "mathematical stuff", think RE-USABLE code: you have written several plug-ins related to bezier curves handling and if I'm not wrong (I don't have ridden your other plug-ins code), lots of code is shared between all these plug-ins. So, putting in a python module all RE-USABLE code (like the g2continuity  BCurve classes) would make your plug-ins easier and faster to develop and easier to maintain.

Quote:
  1. Then I make a .zip file from those two files? Or should I make one folder from those two files and a .zip from that?
  2. Then what? When I share the plugin, that .zip file is what I share?
  3. And the user unzippes it and places the contents in Gimp's plug-ins folder?
  4. From where does that "dedicated folder" of the plugin come?

In gimp 2.10.x, when you install a plug-in, you simply have to  copy a file in the plug-ins directory:
C:\Users\<user>\AppData\Roaming\GIMP\2.10\plug-ins\G2_continuity.py

In gimp 3 (but you can also do it in 2.10.x), every plug-in need to be put in a dedicated folder, inside the plug-ins directory:
C:\Users\<user>\AppData\Roaming\GIMP\2.10\plug-ins\G2_continuity\G2_continuity.py

So you can provide a plug-in with one python script and several others files like python modules, images, brushes, gradients, ... all you plug-in needs:
C:\Users\<user>\AppData\Roaming\GIMP\2.10\plug-ins\G2_continuity\G2_continuity-plug-in.py
C:\Users\<user>\AppData\Roaming\GIMP\2.10\plug-ins\G2_continuity\reusable-code-module.py

And to distribute your plug-in, simply put all these files in your zip archive.

Anyway, your g2continuity is a must have. My port to 2.99 is almost finished (already usable) but several things in the gimp api needs to be fixed/improved.
With your permission, I will make this plug-in a core gimp plug-in in the future gimp 2.99.x/3.0 release.
Reply
#7
(04-25-2022, 09:49 PM)tmanni Wrote: ...
The reason of my suggestion; my previous post was bad; forget the "mathematical stuff", think RE-USABLE code: you have written several plug-ins related to bezier curves handling and if I'm not wrong (I don't have ridden your other plug-ins code), lots of code is shared between all these plug-ins. So, putting in a python module all RE-USABLE code (like the g2continuity  BCurve classes) would make your plug-ins easier and faster to develop and easier to maintain.
...

For my own use, I have an unorganized collection of small Python functions, each written for some special problem at hand. But they are not so well designed or tested, so probably they are buggy, therefore bound to be changed every now and then. Making a module from every small function is not reasonable.

But that class BCurve is a different matter. There I agree with you. I use it in almost every plugin of mine, so it could well be made into a module. And, different plugins would each contain its own copy of the class BCurve, in its dedicated folder. And if I should later make changes in BCurve, different plugins could each have a different version of BCurve, and each plugin would work all right since there are no imports between them.

Right now I don't remember if I have any other such candidates for re-usable modules. But modules might be useful to organize a plugin, so that everything would not be in one big file.

I had some such ideas about modules before, and I first forgot but now remember that two years ago we had a short discussion with Ofnuts:

https://www.gimp-forum.net/Thread-Import...hon-plugin

and at that time I decided to abandon modules and to make each plugin one big file.

Now I made a small experiment of using modules, and succeeded, copying the idea from Ofnuts' example in Modules.zip in:

https://www.gimp-forum.net/Thread-Import...8#pid17158

where the crucial structure is:

Code:
import sys,os,os.path,re,glob,traceback
from gimpfu import *

me=os.path.abspath(sys.argv[0])
mydir=os.path.dirname(me)
sys.path.insert(0,mydir)

import module1,module2,module3

But am I right when I guess that in Gimp3 this trick of Ofnuts will not be needed but everything will be automatically right and only an import clause is needed? (In Gimp2 the trick seems necessary.)

(04-25-2022, 09:49 PM)tmanni Wrote: ...
Anyway, your g2continuity is a must have. My port to 2.99 is almost finished (already usable) but several things in the gimp api needs to be fixed/improved.
With your permission, I will make this plug-in a core gimp plug-in in the future gimp 2.99.x/3.0 release.

By all means, if you think it worth-while and good enough, please go ahead.

But what about maintaining? I have liked to have everything in my own hands, so that whenever I have wanted to make changes in some plugin, I have just made a new version and published it. If now you make it a core gimp plug-in, then how is maintaining done? It is out of my hands? If there is a need for changes, who will do them? And if I want to make changes what is the process?

Anyway, it will be interesting to see what you make from it.
Reply
#8
Quote:But am I right when I guess that in Gimp3 this trick of Ofnuts will not be needed but everything will be automatically right and only an import clause is needed? (In Gimp2 the trick seems necessary.)

Indeed, in Gimp 2.99, the Ofnuts' trick is not longer needed : when running a plug-in, the python interpreter embedded inside gimp automatically add the plug-in directory  into its modules search path.

Quote:But what about maintaining? I have liked to have everything in my own hands, so that whenever I have wanted to make changes in some plugin, I have just made a new version and published it. If now you make it a core gimp plug-in, then how is maintaining done? It is out of my hands? If there is a need for changes, who will do them? And if I want to make changes what is the process?

You could become a gimp contributor and have the responsibility of maintaining this plug-in. But note that core plug-ins do not change often : unless to fix bug or improve time processing, once available into gimp, the plug-in must keep it's arguments and behavior (to not break scripts using it of potential billion users around the world).

So It's up to you. If you're not interested and want to keep the liberty to modify and release at your rhythm, I understand.
I propose this because this plug-in is really useful (particularly to make quick cut out of curvy elements in a photo) and could profit to the whole users community.

Anyway, here is modified version to run with Gimp 2.99. 
.zip   g2continuity-gimp2.99.zip (Size: 9.79 KB / Downloads: 262)

with a big refactoring:
  • classes/methods/functions don't use "gimp" or "Gimp" as a prefix (to avoid confusion with gimp API)
  • classes/methods/functions documentation is put just after their definition
  • more "object oriented" implementation (some functions become methods)
  • some variables names renamed to something more meaningful
  • when possible, lists copies are avoided to work in place (instead of using copy and deepcopy)
  • ...
Reply
#9
(04-29-2022, 06:51 AM)tmanni Wrote: ...
You could become a gimp contributor and have the responsibility of maintaining this plug-in. But note that core plug-ins do not change often : unless to fix bug or improve time processing, once available into gimp, the plug-in must keep it's arguments and behavior (to not break scripts using it of potential billion users around the world).

So It's up to you. If you're not interested and want to keep the liberty to modify and release at your rhythm, I understand.
I propose this because this plug-in is really useful (particularly to make quick cut out of curvy elements in a photo) and could profit to the whole users community.
...

Ok, thanks for explaining. I am what you might call a lonely wolf, without any wish to commit myself to anything, like to long duty of maintaining. Indeed, I want to have my freedom just to drop this hobby whenever I wish and go to do something else. I have now done this for several years and am beginning to feel that it would be time for a change. And I like to have things in my own hands and to make changes in my plugins easily and without restrictions.

So, the way things are right now suits me best. Your suggestion is flattering, but let us not do it after all. I know it is not nice to refuse, now that you did the big work in porting the plugin to Gimp2.99. But I trust that you understand this as you said. And thanks for the suggestion.

The plugin will be available of course though not as a core plugin. And who knows what will happen in the future.

And I looked at what you had done with the code. Frankly, I have much to learn. There is much that I don't even understand. And I noticed a couple of choices I don't like. And the registration part is complicated! I hope in Gimp3 there will also be a simple way to do it, just as there is in Gimp2. Years ago, when I started this hobby, it would never have happened if it would had been so complicated then. I am a mathematician, not a coder.
Reply


Forum Jump: