# Mirror makie elements

**URL:** <https://discourse.julialang.org/t/mirror-makie-elements/97629>\
**Category:** Visualization\
**Tags:** makie, glmakie\
**Created:** [April 18, 2023, 6:54pm UTC](https://discourse.julialang.org/t/mirror-makie-elements/97629 "2023-04-18T18:54:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 18, 2023, 6:54pm UTC](https://discourse.julialang.org/t/mirror-makie-elements/97629/1 "2023-04-18T18:54:25Z")

</div>

Hey folks, I’m using GLMakie to make some videos with contours, and it would be nice to be able to apply mirroring to a given axis (or two, in my case).

My data is all in one quadrant, and I could make an array four times as big and then copy into it, mirroring the data as needed, and then use `contour!(bigarray)`. However, it seems like a waste since it will need to repeat all the work of identifying the iso-surface, which only takes up a small fraction of the array domain. Is there a way to reflect the contours themselves into the other quadrants? Paraview and Tecplot both have this feature and I use it all the time in visualization.

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [April 19, 2023, 8:20pm UTC](https://discourse.julialang.org/t/mirror-makie-elements/97629/2 "2023-04-19T20:20:00Z")

</div>

Would showing a video improve the interest a little?

[https://global.discourse-cdn.com/julialang/original/3X/7/b/7b70bfe5cba004a4e30d6621c8a93b537e256ff0.mp4](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b70bfe5cba004a4e30d6621c8a93b537e256ff0.mp4)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [April 20, 2023, 2:13pm UTC](https://discourse.julialang.org/t/mirror-makie-elements/97629/3 "2023-04-20T14:13:35Z")

</div>

Hm, it is somewhat possible to copy an OpenGL object and render it a second time, and modify the uniforms to be flipped…  
Sadly, I think the model matrix that does the flipping isn’t 100% implemented correctly for volume, so the flipping causes it to sample incorrectly from the volume:

```julia
using GLMakie

function rewrap(robj::GLMakie.RenderObject{Pre}) where {Pre}
    GLMakie.ShaderAbstractions.switch_context!(robj.context)
    GLMakie.RenderObject{Pre}(
        robj.context,
        copy(robj.uniforms),
        robj.observables,
        robj.vertexarray,
        robj.prerenderfunction,
        robj.postrenderfunction,
        Observable(robj.visible),
        false
    )
end

function copy_plot!(screen::GLMakie.Screen, plot)
    robj = screen.cache[objectid(plot)]
    cpy = rewrap(robj)
    screenid = screen.screen2scene[WeakRef(parent(plot))]
    screen.cache2plot[cpy.id] = plot
    push!(screen.renderlist, (0, screenid, cpy))
    return cpy
end

GLMakie.activate!(float=true)
begin 
    N = 50
    r = LinRange(-1, 1, N)
    r2 = LinRange(0, 1, N)
    cube = Float32[(x .^ 2 + y .^ 2 + z .^ 2) for x = r, y = r, z = r2]
    fig, ax, pl = volume(cube, algorithm=:iso);
    if isdefined(Main, :screen)
        # messing with the internal renderlist will not clean up correctly, so we need to cleanup manually
        screen.renderlist |> empty!
        screen.cache2plot |> empty!
    end
    GLMakie.closeall()
    screen = display(fig)
end

cpy = copy_plot!(scren, pl)
robj = scren.cache[objectid(pl)]
model = Makie.scalematrix(Vec3f(1, -1, -1)) * robj[:model][]
cpy.uniforms[:model] = model
cpy.uniforms[:modelinv] = inv(model)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/a/1/a108e0d30157e0f072c777e0742c4bc00e21f20e.png)

But the correct flip `(1, 1, -1)` doesn’t work -.-
