Skip to content

Commit

Permalink
Use GRM compatible 'isosurface' method
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Feb 26, 2023
1 parent e886ed2 commit fa63f66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 0 additions & 2 deletions examples/snoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ s = LinRange(-1, 1, 40)
v = 1 .- (s .^ 2 .+ (s .^ 2)' .+ reshape(s,1,1,:) .^ 2) .^ 0.5
isosurface(v, isovalue=0.2)

GR.GR3.terminate()

volume(randn(rng, 50, 50, 50))

N = 1_000_000
Expand Down
26 changes: 20 additions & 6 deletions src/jlgr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function minmax(kind, plt=plt[])
x0, x1 = Extrema64(x)
xmin = min(x0, xmin)
xmax = max(x1, xmax)
elseif kind === :volume
elseif kind === :volume || kind === :isosurface
xmin, xmax = -1, 1
else
xmin, xmax = 0, 1
Expand All @@ -289,7 +289,7 @@ function minmax(kind, plt=plt[])
y0, y1 = Extrema64(y)
ymin = min(y0, ymin)
ymax = max(y1, ymax)
elseif kind === :volume
elseif kind === :volume || kind === :isosurface
ymin, ymax = -1, 1
else
ymin, ymax = 0, 1
Expand All @@ -301,7 +301,7 @@ function minmax(kind, plt=plt[])
z0, z1 = Extrema64(z)
zmin = min(z0, zmin)
zmax = max(z1, zmax)
elseif kind === :volume
elseif kind === :volume || kind === :isosurface
zmin, zmax = -1, 1
else
zmin, zmax = 0, 1
Expand Down Expand Up @@ -1056,9 +1056,22 @@ function plot_iso(V, plt=plt[])
else
color = (0.0, 0.5, 0.8)
end
GR.setwindow3d(-1, 1, -1, 1, -1, 1)
GR.setspace3d(-rotation, tilt, 45, 2.5)
GR.gr3.isosurface(V, isovalue, color)
w, h, ratio = GR.inqvpsize()
GR.selntran(0)
GR.gr3.clear()
vmin, vmax = extrema(V)
data = trunc.(UInt16, (V .- vmin) ./ (vmax - vmin) * 65535)
mesh = GR.gr3.createisosurfacemesh(data, (2 / (nx - 1), 2 / (ny - 1), 2 / (nz - 1)), (-1.0, -1.0, -1.0), trunc(Int64, (isovalue - vmin) / (vmax - vmin) * 65535))
GR.gr3.setbackgroundcolor(1, 1, 1, 0)
GR.gr3.drawmesh(mesh, 1, (0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 0.5, 0.8), (1, 1, 1))
r = 2.5
rotation *= π / 180
tilt *= π / 180
GR.gr3.cameralookat(r * sin(tilt) * sin(rotation), r * cos(tilt), r * sin(tilt) * cos(rotation), 0, 0, 0, 0, 1, 0)
vp = plt.kvs[:viewport]
GR.gr3.drawimage(vp..., trunc(Int, w * ratio), trunc(Int, h * ratio), GR.gr3.DRAWABLE_GKS)
GR.gr3.deletemesh(mesh)
GR.selntran(1)
end

function plot_polar(θ, ρ, plt=plt[])
Expand Down Expand Up @@ -1446,6 +1459,7 @@ function plot_data(flag=true, plt=plt[])
end
draw_axes(kind, 2)
colorbar(0.05)
GR.gr3.terminate()
elseif kind === :volume
algorithm = get(plt.kvs, :algorithm, 0)
w, h, ratio = GR.inqvpsize()
Expand Down

0 comments on commit fa63f66

Please sign in to comment.