vector optimizing math/logic?
Moderators: Víctor Paredes, Belgarath, slowtiger
- spasmodic_cheese
- Posts: 330
- Joined: Wed Aug 04, 2004 2:02 am
vector optimizing math/logic?
Hey, I was wondering if anyone had any ideas on the best way to go about creating script that optimizes vector curves.
I think many people(including myself) would benefit from something like this whom import vectors and want to minimize the amount of points moho creates during the conversion.
But I can't really think of how to go about it...
at the moment im looking at
http://potrace.sourceforge.net/potrace.pdf
--- EDIT
Okay i read that.... and im drowning in symbols!
im reading this now
http://www.jarno.demon.nl/polygon.htm
and getting a better idea of what needs to be done.
I think i'll just tackle polygon simplification...then if i compelte that someone else can do curve approximation...
or help me understand it =P
I think many people(including myself) would benefit from something like this whom import vectors and want to minimize the amount of points moho creates during the conversion.
But I can't really think of how to go about it...
at the moment im looking at
http://potrace.sourceforge.net/potrace.pdf
--- EDIT
Okay i read that.... and im drowning in symbols!
im reading this now
http://www.jarno.demon.nl/polygon.htm
and getting a better idea of what needs to be done.
I think i'll just tackle polygon simplification...then if i compelte that someone else can do curve approximation...
or help me understand it =P
My basic idea was to use a hack of the Freehand tool script, using the angleTolerance bit's to filter out the points that aren't making much of a difference to the vector. I'd rather make the pixelTolerance variable translate to something that wasn't so screen resution specific, but I don't program much and I'm having a hard time getting my head around the flexibility of the Lua data/function structure. I think if someone would set up a script based on that concept to eliminate points that were under a certrain angle threshhold that would simplify imported vectors enourmously
I've put up an extremely naive and simple first draft of a point-reduction script at http://www-personal.monash.edu.au/~myle ... index.html
How it works: if a point is "close enough" to the previous point on a curve, and not part of another curve, and "not particularly pointy", it will get deleted.
Well, actually, at the moment the points only get selected, and you can hit the Delete key if you like the look of the points selected - you can uncomment out the point deletion code if you really want to.
The definition of "close enough" and "not particularly pointy" are up to you to set numerically. "Pointy" is generally in the range 0.1 or less, normal smoothness is around 0.3, and "close enough" can be anything from 0.001 to 0.1 or more.
Brian (7feet), is that close enough for starters ?
The script has a tendency to wipe out fine detail and leave a deformed but simplified version of the initial shapes, which is probably not what you wanted.
Because I want to keep some very small ellipses in a test file, I've also added a "keep every second point" checkbox - otherwise every single point on the ellipse was both close enough and not particularly pointy, so the whole (very small, 8-point) ellipse was getting deleted.
Well, I've put it up for laughs - don't expect anything sophisticated out of it - but maybe some of the Moho-related code will be useful for people who have a decent point-reduction algorithm to replace this silly one.
Result of running it on Lost Marble's Lenny character, using default settings:
Better than I expected but, as you can see, the pupils have been completely deleted and the eyebrows are reduced to almost uselessness.
Regards, Myles.
How it works: if a point is "close enough" to the previous point on a curve, and not part of another curve, and "not particularly pointy", it will get deleted.
Well, actually, at the moment the points only get selected, and you can hit the Delete key if you like the look of the points selected - you can uncomment out the point deletion code if you really want to.
The definition of "close enough" and "not particularly pointy" are up to you to set numerically. "Pointy" is generally in the range 0.1 or less, normal smoothness is around 0.3, and "close enough" can be anything from 0.001 to 0.1 or more.
Brian (7feet), is that close enough for starters ?
The script has a tendency to wipe out fine detail and leave a deformed but simplified version of the initial shapes, which is probably not what you wanted.
Because I want to keep some very small ellipses in a test file, I've also added a "keep every second point" checkbox - otherwise every single point on the ellipse was both close enough and not particularly pointy, so the whole (very small, 8-point) ellipse was getting deleted.
Well, I've put it up for laughs - don't expect anything sophisticated out of it - but maybe some of the Moho-related code will be useful for people who have a decent point-reduction algorithm to replace this silly one.
Result of running it on Lost Marble's Lenny character, using default settings:
Better than I expected but, as you can see, the pupils have been completely deleted and the eyebrows are reduced to almost uselessness.
Regards, Myles.
Last edited by myles on Mon Oct 04, 2004 9:21 am, edited 1 time in total.
- spasmodic_cheese
- Posts: 330
- Joined: Wed Aug 04, 2004 2:02 am
- spasmodic_cheese
- Posts: 330
- Joined: Wed Aug 04, 2004 2:02 am
point-reduction script
[quote="myles"]I've put up an extremely naive and simple first draft of a point-reduction script at http://www-personal.monash.edu.au/~myle ... index.html
Thanks Myles
it worked reeeeaaaal nice
Cheers
Benvindo
Thanks Myles
it worked reeeeaaaal nice
Cheers
Benvindo
Re: point-reduction script
You're welcome Benvindo - I'm glad to hear it is of some use.Benvindo wrote:Thanks Myles
it worked reeeeaaaal nice
Regards, Myles.
Ack! Scripting! My brain hurts!
Thanks for putting that script up, Myles. It inspired my to whack my head against it for a while. I added some code (that I hacked out of the Freehand script) that detects the angle that a point forms relative to it's 2 adjacent points with a user specified angle threshold. It even seems to be working. I tweaked the every second point bit so it's a little more like "never pick consecutive points". Per suggestions, I also slapped in a checkbox to never select an entire curve, as well as allowing you to set the minimum number of points a curve must have before it'll be affected. The latter was because initially I was seeing short , 3-4 point open curves going right to straight lines and it was annoying me. I also made it so it will never select the existing endpoints of an open curve.
One of the main reasons that I put in the point angle analysis is that it also allows you use the simplifications on drawings done inside of Moho. With it you can unload a lot of points (especially from Freehand drawings) without killing sharp corners, even though the vertex's pointiness might be set above the scripts curvature threshhold.
That was kinda fun, in a long, somewhat exasperating sort of way. Its been a Loooong time since I've tried any coding.
Oh, yeah, before I forget, here's my version. Not so elegant, but it seems to be doin' the trick. Anybody finds anything dopey with the logic or has any suggestions for improvement, let me know.
Now if I can just get the Auto-weld script to work the way I want...
--Brian
Thanks for putting that script up, Myles. It inspired my to whack my head against it for a while. I added some code (that I hacked out of the Freehand script) that detects the angle that a point forms relative to it's 2 adjacent points with a user specified angle threshold. It even seems to be working. I tweaked the every second point bit so it's a little more like "never pick consecutive points". Per suggestions, I also slapped in a checkbox to never select an entire curve, as well as allowing you to set the minimum number of points a curve must have before it'll be affected. The latter was because initially I was seeing short , 3-4 point open curves going right to straight lines and it was annoying me. I also made it so it will never select the existing endpoints of an open curve.
One of the main reasons that I put in the point angle analysis is that it also allows you use the simplifications on drawings done inside of Moho. With it you can unload a lot of points (especially from Freehand drawings) without killing sharp corners, even though the vertex's pointiness might be set above the scripts curvature threshhold.
That was kinda fun, in a long, somewhat exasperating sort of way. Its been a Loooong time since I've tried any coding.
Oh, yeah, before I forget, here's my version. Not so elegant, but it seems to be doin' the trick. Anybody finds anything dopey with the logic or has any suggestions for improvement, let me know.
Now if I can just get the Auto-weld script to work the way I want...
--Brian
Well, on the Autoweld. I had a few .AI's I'd exported from Wings3D. They were pretty complex mechanical images, and the Illistrator files had an awful lot of points. Many of these points were so close together (on the order of 7 or 8 vertexes) that you had to zoom in a lot to see that they were distinguishable. I've tried playing a bit with the parameter (it's 100 in the script) that determines if a point is close enough to another to weld them. On simpler images I seem to remember it working okay. But if there a a lot of points in a very small area for some reason it doesn't weld them together. Perhaps it's because they are on separate curves.
On that note, the section of the script which is supposed to weld dead-end points into the nearest point of the nearest curve has been commented out since the first beta. Really, besides the simplification of points welding clusters together would give, it's the fact that points that seem to be welded to a curve yet aren't really bolloxes up creating filled shapes out of imported vectors. I've looked at it a little, but haven't really had a chance to figure out the logic..
I don't want to clutter up the basic interface, but I can already see that I'm going to be adding a lot more parameters to a lot of the tools for my own use ( or anyone else who wants them.). Good defaults are cool, but given the opportunity to set it up I'm gonna arrange things so I can twaek like crazy.
On use, because the curvature on a point in my version is basically a check to verify if you should even look at the angle between adjacent points, you could still end up with a sharp point, with point's very nearby under the distance threshold, that don't really contribute much to the image. Haveta make it smarter, but I'm just getting the structure of Lua down in my head, didn't want to bust out something too kludgy I'd need to fix later. For real usefulness, I think that I made the default angle tolerance too low. I'm also not sure if my translation of the algorithm from the freehand script is quite right, but at least it seems to avoing the angular, defining curves like I wanted. Also, I just now thought that in addition to having a minimum distance between points, a maximum to keep broad curves that cover a lot of angular distance from being mucked up would be a good thing as well.
'Kay, now I have to put the adjustable Origin for the Rotate Points thingy I said I would do earlier into effect. Anyone has some other script modification ideas, throw 'em out. Knowing myself, I won't be happy 'til I can think in Lua. Hope it doesn't keep me from animating...
--Brian
SevenFeetDesign
On that note, the section of the script which is supposed to weld dead-end points into the nearest point of the nearest curve has been commented out since the first beta. Really, besides the simplification of points welding clusters together would give, it's the fact that points that seem to be welded to a curve yet aren't really bolloxes up creating filled shapes out of imported vectors. I've looked at it a little, but haven't really had a chance to figure out the logic..
I don't want to clutter up the basic interface, but I can already see that I'm going to be adding a lot more parameters to a lot of the tools for my own use ( or anyone else who wants them.). Good defaults are cool, but given the opportunity to set it up I'm gonna arrange things so I can twaek like crazy.
On use, because the curvature on a point in my version is basically a check to verify if you should even look at the angle between adjacent points, you could still end up with a sharp point, with point's very nearby under the distance threshold, that don't really contribute much to the image. Haveta make it smarter, but I'm just getting the structure of Lua down in my head, didn't want to bust out something too kludgy I'd need to fix later. For real usefulness, I think that I made the default angle tolerance too low. I'm also not sure if my translation of the algorithm from the freehand script is quite right, but at least it seems to avoing the angular, defining curves like I wanted. Also, I just now thought that in addition to having a minimum distance between points, a maximum to keep broad curves that cover a lot of angular distance from being mucked up would be a good thing as well.
'Kay, now I have to put the adjustable Origin for the Rotate Points thingy I said I would do earlier into effect. Anyone has some other script modification ideas, throw 'em out. Knowing myself, I won't be happy 'til I can think in Lua. Hope it doesn't keep me from animating...
--Brian
SevenFeetDesign
"Think in Lua", eh? I don't know ... it's not that it's a hard language, obviously it goes to great lengths to make things easy ... but somehow that makes it hard. I'm used to declaring and defining everything, and knowing exactly how many bytes there are in an array at all times. Using something like Lua will be counterintuitive for me because there's so much trusting involved.
-Keith
- spasmodic_cheese
- Posts: 330
- Joined: Wed Aug 04, 2004 2:02 am
Yeah, well, that comment was a little facetious, but it was the first programming (as little as it is) I'd done in almost 17 years. I was kinda amazed it did about what I wanted. In some ways I'd rather it were a little more explicitly typed, since you can put just about anything inside a variable and quite possibly get all turned around if you're a neo-novice like me. Think I have ti sit down and read Programming in Lua another time or 2.
--Brian
--Brian