We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Can't think of an elegant algorithm for this
Page Index Toggle Pages: 1
Can't think of an elegant algorithm for this (Read 545 times)
Can't think of an elegant algorithm for this
Feb 7th, 2008, 10:39pm
 
Hello, sorry the topic does not summarise the question as it is not easy to explain in a simple sentence.

Suppose I have a 3D array holding x y values and a state variable which is either 1 or 0.

Some function updates this array and another function draws it to the screen. A for loop iterates through x,y pairs and draws a point if state variable is 1 and draws a black(bg color) point if it is 0. So an array like this:

Code:

00000000000000100000000
00000000000011100000000
00000000000001111110000
00000000001111111100000
00000001111111001111110
01111111111110000110000
00011111111111111111100
00000011111000011100000
00000001110000001000000
00000000100000000000000
00000000000000000000000


You'd be seeing the 1's on the screen and 0's would be black.

What I want to do with this data is:
I want to see the outlines of the closed shapes in a curved manner. As you can see, the shape I've shown has a weird form with a hole in it. I want to take this data and visualise its outlines smoothly(a parameter like "how smooth?" would be nice).

I just can't think of a way to do it. Any help yielding to the direction of a solution would be greatly appreciated.

Thanks
Re: Can't think of an elegant algorithm for this
Reply #1 - Feb 8th, 2008, 1:50am
 
I can think of a couple of ways to get the result you're looking for.

a: create a PImage the same size as your data, fill it black/white depending on state, and then resize to screen size and in P3D/OpenGL mode it'll automatically blur/smooth the image

b: alternatively, you could do something similar to something I did in the past for an online game I play:
http://www.hardcorepawn.com/CitiesMap/foo.pdf
The code to generate which is available here:
http://www.hardcorepawn.com/CitiesMap/CitiesNETunnelsVector.pde

and
http://www.hardcorepawn.com/CitiesMap/square.pde
Re: Can't think of an elegant algorithm for this
Reply #2 - Feb 9th, 2008, 9:43pm
 
What exactly do you mean by "smoothly"?

It seems like you could build some sort of vector image so you can reproduce the figure using bezier curves instead of a bitmap so you can control the "smoothness factor".

I believe that would be pretty hard to do, specially if you include figures with "holes" (non-manifold figures I believe).

The solution JohnG points out seems easier to do. Apply some kind of blur filter to the image, maybe even to the outer edges only, so you can take the outline of the image 3-5 pixels deep and blur/smooth only those, kind of like Photoshop's "feather" radius.
Page Index Toggle Pages: 1