# Implementing LBG algorithm

**URL:** <https://discourse.julialang.org/t/implementing-lbg-algorithm/115066>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [June 1, 2024, 6:20pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066 "2024-06-01T18:20:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manasa\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manasa_s/32/209514_2.png) [@Manasa\_S](https://discourse.julialang.org/u/Manasa_S)\
**Post date:** [June 1, 2024, 6:20pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066/1 "2024-06-01T18:20:03Z")

</div>

Hi, I’m new to Julia and wondering how to loop through the generated voronoi cells to implement the MLBG algorithm.

```module

using GLMakie
using DelaunayTriangulation
using Interpolations
using Plots

function perform_computations(axis, time_range, mean_data, std_data, mean_color, fig)
    # band!(time_range, mean_data - std_data, mean_data + std_data, color=GLMakie.RGBA(mean_color, 0.6), label="Error")

    lines!(axis, time_range, mean_data, color=GLMakie.RGBA(mean_color, 1.0), label="Mean")
    # xlims!(axis, [0, 50])
    time_range_dense = range(1, stop=length(time_range), length=length(time_range) * 20)

    itp_mean = interpolate((time_range,), mean_data, Gridded(Linear()))

    itp_lower = interpolate((time_range,), mean_data - std_data, Gridded(Linear()))
    itp_upper = interpolate((time_range,), mean_data + std_data, Gridded(Linear()))

    plot_ys_mean = [itp_mean(t) for t in time_range_dense]
    plot_ys_lower = [itp_lower(t) for t in time_range_dense]
    plot_ys_upper = [itp_upper(t) for t in time_range_dense]
    ax = Axis(fig[1, 2])

    GLMakie.scatter!(axis, time_range_dense, plot_ys_mean, color=:blue, label="Interpolation", markersize=3)

    error_ranges = plot_ys_upper .- plot_ys_lower

    tri = DelaunayTriangulation.triangulate(points; rng)

    vorn = voronoi(tri)

end

end

```

I need to loop through each of voronoi cells check if the density is lesser and update

```julia
stippleList ← initialize stipple list repeat
vd ← computeVoronoiDiagram(stippleList) newStippleList ← empty list
for all Voronoi cell vc ∈ vd do
density ← vc.sumDensity if density < Tl then
// remove point
else if density < Tu then
// keep point
newStippleList.add(vc.centroid)
else
// split point
splitPoints ← splitCell(vc) newStippleList.add(splitPoints)
end if end for
stippleList ← newStippleList until no splitting or merging
endfunction

```

Can anyone help me with this

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [June 1, 2024, 7:18pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066/2 "2024-06-01T19:18:51Z")

</div>

What is the MLBG algorithm? It’s not clear to me what you want to do exactly. And P.S. NaturalNeighbours.jl might be a more natural choice for your interpolation (if I’m reading your code right?) since it’s directly built on top of DelaunayTriangulation.jl.

---

<div class="post-metadata">

**Author:** ![Manasa\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manasa_s/32/209514_2.png) [@Manasa\_S](https://discourse.julialang.org/u/Manasa_S)\
**Post date:** [June 1, 2024, 7:35pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066/3 "2024-06-01T19:35:47Z")

</div>

MLBG is [LindeBuzoGrayStippling Algorithm]. I’m trying to create stipples for the error bands using voronoi cells in order to avoid overlap when there are multiple time series data. Do you know How i can loop through the voronoi cells?

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [June 1, 2024, 7:36pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066/4 "2024-06-01T19:36:41Z")

</div>

The documentation has examples of iterating over the Voronoi cells: [Voronoi Tessellations · DelaunayTriangulation.jl](https://juliageometry.github.io/DelaunayTriangulation.jl/dev/tutorials/voronoi/#Iterating-over-polygon-and-polygon-vertices). If anything there is unclear feel free to let me know and I’ll also update the documentation to address it.

---

<div class="post-metadata">

**Author:** ![Manasa\_S](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manasa_s/32/209514_2.png) [@Manasa\_S](https://discourse.julialang.org/u/Manasa_S)\
**Post date:** [June 1, 2024, 7:37pm UTC](https://discourse.julialang.org/t/implementing-lbg-algorithm/115066/5 "2024-06-01T19:37:59Z")

</div>

@DanielVandH thank you very much!
