# Help with smooth voronoi diagrams

This topic is 1906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

[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
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
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

##### Share on other sites
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 ?

##### Share on other sites
I've already shown in the previous images sort-of what i want, but the keywords are: transitions with continuity
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 Edited by Kaptein

##### Share on other sites
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.

##### Share on other sites
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