Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with smooth voronoi diagrams


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Kaptein   Prime Members   -  Reputation: 2059

Like
0Likes
Like

Posted 02 November 2012 - 09:27 PM

[source lang="vb"]sub vor_gradient cdecl(px as f32_t, pz as f32_t, weights as integer, vret as vor_return ptr) dim as integer x = int(px), z = int(pz) dim as vvalue pmin(WEIGHTS-1) dim as vpoint ptr p2 dim as f32_t dist, mindist(WEIGHTS-1) for i as integer = 0 to WEIGHTS-1 mindist(i) = 10 '' set to out of bounds distance next for dx as Integer = x-2 to x+2 for dz as integer = z-2 to z+2 p2 = @vor_points( dx and (VORONOI_TABLESIZE-1), dz and (VORONOI_TABLESIZE-1) ) dist = VOR_EUCLIDIAN( px, pz, dx + 0.5, dz + 0.5 ) for i as integer = 0 to WEIGHTS-1 if dist <= mindist(i) then for j as integer = WEIGHTS-1 to i+1 step -1 '' set N-closest pmin(j) = pmin(j-1) mindist(j) = mindist(j-1) next '' set closest pmin(i).value = p2->value mindist(i) = dist exit for endif next next next '' find max distance #define length mindist(WEIGHTS-1) #define weight(i) mindist(i) '' inverse distance and recount weights dist = 0.0 for i as integer = 0 to WEIGHTS-1 weight(i) = 1.0 - mindist(i) / length dist += weight(i) next dim as uinteger cl = 0 '' finalize weights and create final color using N-vector for i as integer = 0 to WEIGHTS-1 weight(i) /= dist cl = adduint32(cl, pmin(i).value, weight(i)) next '' return final composite vret->v = cl end sub[/source]
I am trying to blend the nearby weights of voronoi cells
in this example all cell centers are at 0.5, 0.5 for simplicity's sake, and to show the error more clearly
I have tried for a day now to figure out what mistake I'm making, but i just dont understand what I'm doing wrong here

First: I find the N closest points (determined by WEIGHTS)
then I use the longest distance as the "normalizing value" all the way to the end
finally i divide by the total length of the inverted distances (so that the closest point has the strongest weight)
by listening to my brain, this should be working, but it doesn't seem like it's working alright.. :S
Please help!
Note: if you want me to recreate the function in C, that can be arranged since it's not an issue for me..

Here are some example images for 3,4 and 9 weights, first with center at (0.5, 0.5) then with centers at the respective cells for a total of 6 images:

http://art.fwsnet.net/vor/w3c.png
http://art.fwsnet.net/vor/w4c.png
http://art.fwsnet.net/vor/w9c.png

http://art.fwsnet.net/vor/w3.png
http://art.fwsnet.net/vor/w4.png
http://art.fwsnet.net/vor/w9.png

Edited by Kaptein, 02 November 2012 - 09:29 PM.


Sponsor:

#2 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 03 November 2012 - 04:47 AM

When you rasterize a colored Voronoï diagram, you can determine the winning (nearest) node for each pixel, and paint the pixel with the color of the winning node. It's computationnally huge, but it's pixel-accurate and easy to implement.

But it wouldn't produce a 'smoothed' Voronoï diagram .... is it possible to explain what does this smooth represent ?

Posted Image

#3 Kaptein   Prime Members   -  Reputation: 2059

Like
0Likes
Like

Posted 03 November 2012 - 05:28 AM

I've already shown in the previous images sort-of what i want, but the keywords are: transitions with continuity Posted Image
or crossfade, if you will
here is my best effort so far:
http://fbcraft.fwsnet.net/gonzonoi.png
and my conclusion is: it can't be done
it can be done "pretty well", but anything short of 100% success is worthless to me
i need total control over ramps and curves, and my example image is one that already has discontinuities using best-match trial and error
googling around for anything like voronoi diagrams and weights only shows each diagram being assigned a weight that determines its control exertion
i guess i'll yet again just have to look for something completely different to solve my problem Posted Image

Edited by Kaptein, 03 November 2012 - 05:29 AM.


#4 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 03 November 2012 - 05:56 AM

I think it can be done as you wish, as an extention of the algorithm I gave above, but instead of saying " this node is the closest", you can take into account the distances of all nodes, expressed as probabilities. Then you blend the nodes colors accordingly to these probabilities to get the final pixel color.

#5 Kaptein   Prime Members   -  Reputation: 2059

Like
0Likes
Like

Posted 03 November 2012 - 06:52 AM

this isn't a finite set, it's infinite
i can only grab WEIGHTS amount of nodes around me, or the algorithm will never finish
regardless, i think i figured out in the end, that determining the weights for the nearest points at any point in space is easy enough
but it was impossible to do this in a way that made the image continous
the more weights i grab, the more it will look like a soup of colors anyways
the final result where i gave up was where i had set a minimum distance that gave 100% weight to one color, and anything under that was distributed as evenly as i could
it wasn't all that bad, but it was insufficient for the purpose of what i need it for

i hope i haven't wasted anyones time with this..
seeing the complete lack of information on voronoi diagrams with weights AND id's, i'll just have to assume that it can't be done properly
you just arent able to determine the correct weights as you go (and keep in mind, the nodes aren't centered on a grid in the final result, only when testing)

Edited by Kaptein, 03 November 2012 - 06:54 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS