Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showsegments support for vizgridfallback! #1056

Merged
merged 9 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 66 additions & 44 deletions ext/geometryset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

function Makie.plot!(plot::Viz{<:Tuple{GeometrySet}})
gset = plot[:object]
color = plot[:color]
alpha = plot[:alpha]
colormap = plot[:colormap]
colorrange = plot[:colorrange]

# process color spec into colorant
colorant = Makie.@lift process($color, $colormap, $colorrange, $alpha)

# get geometries
geoms = Makie.@lift parent($gset)

# get geometry types
types = Makie.@lift unique(typeof.($geoms))

for G in types[]
inds = Makie.@lift findall(g -> g isa G, $geoms)
gvec = Makie.@lift collect(G, $geoms[$inds])
colors = Makie.@lift $colorant isa AbstractVector ? $colorant[$inds] : $colorant
M = Makie.@lift manifold(first($gvec))
pdim = Makie.@lift paramdim(first($gvec))
edim = Makie.@lift embeddim(first($gvec))
vizgset!(plot, M[], Val(pdim[]), Val(edim[]), gvec, colors)
end
end
Makie.plot!(plot::Viz{<:Tuple{GeometrySet}}) = vizgeoms!(plot)

const ObservableVector{T} = Makie.Observable{<:AbstractVector{T}}

Expand All @@ -52,14 +27,20 @@
end

function vizgset!(plot, ::Type{<:𝔼}, ::Val{1}, ::Val, geoms, colorant)
showpoints = plot[:showpoints]

Check warning on line 30 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L30

Added line #L30 was not covered by tests

meshes = Makie.@lift discretize.($geoms)
vizmany!(plot, meshes, colorant)
showfacets1D!(plot, geoms)

if showpoints[]
eliascarv marked this conversation as resolved.
Show resolved Hide resolved
vizfacets!(plot, geoms)

Check warning on line 36 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L35-L36

Added lines #L35 - L36 were not covered by tests
end
end

function vizgset!(plot, ::Type{<:𝔼}, ::Val{1}, ::Val, geoms::ObservableVector{<:Ray}, colorant)
rset = plot[:object]
segmentsize = plot[:segmentsize]
showpoints = plot[:showpoints]

Check warning on line 43 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L43

Added line #L43 was not covered by tests

Dim = embeddim(rset[])

Expand All @@ -71,13 +52,20 @@
size = Makie.@lift 0.1 * $segmentsize
Makie.arrows!(plot, orig, dirs, color=colorant, arrowsize=size)

showfacets1D!(plot, geoms)
if showpoints[]
vizfacets!(plot, geoms)

Check warning on line 56 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L55-L56

Added lines #L55 - L56 were not covered by tests
end
end

function vizgset!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val, geoms, colorant)
showsegments = plot[:showsegments]

meshes = Makie.@lift discretize.($geoms)
vizmany!(plot, meshes, colorant)
showfacets2D!(plot, geoms)

if showsegments[]
vizfacets!(plot, geoms)

Check warning on line 67 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L67

Added line #L67 was not covered by tests
end
end

const PolygonLike = Union{Polygon,MultiPolygon}
Expand All @@ -104,29 +92,63 @@
vizmany!(plot, meshes, colorant)
end

function showfacets1D!(plot, geoms)
showpoints = plot[:showpoints]
vizfacets!(plot::Viz{<:Tuple{GeometrySet}}) = vizgeoms!(plot, facets=false)

Check warning on line 95 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L95

Added line #L95 was not covered by tests

function vizfacets!(plot::Viz{<:Tuple{GeometrySet}}, geoms)
M = Makie.@lift manifold(first($geoms))
pdim = Makie.@lift paramdim(first($geoms))
edim = Makie.@lift embeddim(first($geoms))
vizgsetfacets!(plot, M[], Val(pdim[]), Val(edim[]), geoms)

Check warning on line 101 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L97-L101

Added lines #L97 - L101 were not covered by tests
end

function vizgsetfacets!(plot, ::Type, ::Val{1}, ::Val, geoms)

Check warning on line 104 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L104

Added line #L104 was not covered by tests
pointmarker = plot[:pointmarker]
pointcolor = plot[:pointcolor]
pointsize = plot[:pointsize]

if showpoints[]
# all boundaries are points or multipoints
points = Makie.@lift filter(!isnothing, boundary.($geoms))
pset = Makie.@lift GeometrySet($points)
viz!(plot, pset, color=pointcolor, pointmarker=pointmarker, pointsize=pointsize)
end
# all boundaries are points or multipoints
points = Makie.@lift filter(!isnothing, boundary.($geoms))
pset = Makie.@lift GeometrySet($points)
viz!(plot, pset, color=pointcolor, pointmarker=pointmarker, pointsize=pointsize)

Check warning on line 112 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L110-L112

Added lines #L110 - L112 were not covered by tests
end

function showfacets2D!(plot, geoms)
showsegments = plot[:showsegments]
function vizgsetfacets!(plot, ::Type, ::Val{2}, ::Val, geoms)

Check warning on line 115 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L115

Added line #L115 was not covered by tests
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

if showsegments[]
# all boundaries are 1D geometries
bounds = Makie.@lift filter(!isnothing, boundary.($geoms))
bset = Makie.@lift GeometrySet($bounds)
viz!(plot, bset, color=segmentcolor, segmentsize=segmentsize)
# all boundaries are 1D geometries
bounds = Makie.@lift filter(!isnothing, boundary.($geoms))
bset = Makie.@lift GeometrySet($bounds)
viz!(plot, bset, color=segmentcolor, segmentsize=segmentsize)

Check warning on line 122 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L120-L122

Added lines #L120 - L122 were not covered by tests
end

function vizgeoms!(plot; facets=false)
gset = plot[:object]
color = plot[:color]
alpha = plot[:alpha]
colormap = plot[:colormap]
colorrange = plot[:colorrange]

# process color spec into colorant
colorant = facets ? nothing : Makie.@lift(process($color, $colormap, $colorrange, $alpha))

# get geometries
geoms = Makie.@lift parent($gset)

# get geometry types
types = Makie.@lift unique(typeof.($geoms))

for G in types[]
inds = Makie.@lift findall(g -> g isa G, $geoms)
gvec = Makie.@lift collect(G, $geoms[$inds])
M = Makie.@lift manifold(first($gvec))
pdim = Makie.@lift paramdim(first($gvec))
edim = Makie.@lift embeddim(first($gvec))
if facets
vizgsetfacets!(plot, M[], Val(pdim[]), Val(edim[]), gvec)

Check warning on line 148 in ext/geometryset.jl

View check run for this annotation

Codecov / codecov/patch

ext/geometryset.jl#L148

Added line #L148 was not covered by tests
else
cvec = Makie.@lift $colorant isa AbstractVector ? $colorant[$inds] : $colorant
vizgset!(plot, M[], Val(pdim[]), Val(edim[]), gvec, cvec)
end
end
end
20 changes: 18 additions & 2 deletions ext/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

vizgrid!(plot, M::Type{<:𝔼}, pdim::Val, edim::Val) = vizgridfallback!(plot, M, pdim, edim)

function vizfacets!(plot::Viz{<:Tuple{Grid}})
grid = plot[:object]
M = Makie.@lift manifold($grid)
pdim = Makie.@lift paramdim($grid)
edim = Makie.@lift embeddim($grid)
vizgridfacets!(plot, M[], Val(pdim[]), Val(edim[]))
end

vizgridfacets!(plot, M::Type, pdim::Val, edim::Val) = vizmeshfacets!(plot, M, pdim, edim)

Check warning on line 27 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L27

Added line #L27 was not covered by tests

# ----------------
# SPECIALIZATIONS
# ----------------
Expand All @@ -35,6 +45,7 @@
alpha = plot[:alpha]
colormap = plot[:colormap]
colorrange = plot[:colorrange]
showsegments = plot[:showsegments]

Check warning on line 48 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L48

Added line #L48 was not covered by tests

if pdim == Val(2) # visualize quadrangle mesh with texture using uv coords
# decide whether or not to reverse connectivity list
Expand All @@ -50,23 +61,28 @@
ncolor = Makie.@lift $colorant isa AbstractVector ? length($colorant) : 1

dims = Makie.@lift size($grid)
vdims = Makie.@lift Meshes.vsize($grid)

Check warning on line 64 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L64

Added line #L64 was not covered by tests
texture = if ncolor[] == 1
Makie.@lift fill($colorant, $dims)
elseif ncolor[] == nquads[]
Makie.@lift reshape($colorant, $dims)
elseif ncolor[] == nverts[]
Makie.@lift reshape($colorant, $dims .+ 1)
Makie.@lift reshape($colorant, $vdims)

Check warning on line 70 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L70

Added line #L70 was not covered by tests
else
throw(ArgumentError("invalid number of colors"))
end

uv = Makie.@lift [Makie.Vec2f(v, 1 - u) for v in range(0, 1, $dims[2] + 1) for u in range(0, 1, $dims[1] + 1)]
uv = Makie.@lift [Makie.Vec2f(v, 1 - u) for v in range(0, 1, $vdims[2]) for u in range(0, 1, $vdims[1])]

Check warning on line 75 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L75

Added line #L75 was not covered by tests

mesh = Makie.@lift GB.Mesh(Makie.meta($verts, uv=$uv), $quads)

shading = edim == Val(3) ? Makie.FastShading : Makie.NoShading

Makie.mesh!(plot, mesh, color=texture, shading=shading)

if showsegments[]
vizfacets!(plot)

Check warning on line 84 in ext/grid.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid.jl#L83-L84

Added lines #L83 - L84 were not covered by tests
end
else # fallback to triangle mesh visualization
vizmesh!(plot, M, pdim, edim)
end
Expand Down
37 changes: 25 additions & 12 deletions ext/grid/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
viz!(plot, bbox, color=colorant)

if showsegments[]
xyz = Makie.@lift map(x -> ustrip.(x), Meshes.xyz($grid))
tup = Makie.@lift xysegments($xyz...)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)
vizfacets!(plot)
end
else
if nc[] == nv[]
Expand All @@ -48,9 +45,7 @@
end

if showsegments[]
tup = Makie.@lift xysegments(0:$sz[1], 0:$sz[2])
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)
vizfacets!(plot)

Check warning on line 48 in ext/grid/cartesian.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/cartesian.jl#L48

Added line #L48 was not covered by tests
end

# adjust spacing and origin
Expand All @@ -69,8 +64,6 @@
colormap = plot[:colormap]
colorrange = plot[:colorrange]
showsegments = plot[:showsegments]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

# process color spec into colorant
colorant = Makie.@lift process($color, $colormap, $colorrange, $alpha)
Expand Down Expand Up @@ -103,8 +96,28 @@
end

if showsegments[]
tup = Makie.@lift xyzsegments($xyz...)
x, y, z = Makie.@lift($tup[1]), Makie.@lift($tup[2]), Makie.@lift($tup[3])
Makie.lines!(plot, x, y, z, color=segmentcolor, linewidth=segmentsize)
vizfacets!(plot)

Check warning on line 99 in ext/grid/cartesian.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/cartesian.jl#L99

Added line #L99 was not covered by tests
end
end

function vizgridfacets!(plot::Viz{<:Tuple{CartesianGrid}}, ::Type{<:𝔼}, ::Val{2}, ::Val{2})
grid = plot[:object]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

xyz = Makie.@lift map(x -> ustrip.(x), Meshes.xyz($grid))
tup = Makie.@lift xysegments($xyz...)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)
end

function vizgridfacets!(plot::Viz{<:Tuple{CartesianGrid}}, ::Type{<:𝔼}, ::Val{3}, ::Val{3})
grid = plot[:object]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

Check warning on line 117 in ext/grid/cartesian.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/cartesian.jl#L114-L117

Added lines #L114 - L117 were not covered by tests

xyz = Makie.@lift map(x -> ustrip.(x), Meshes.xyz($grid))
tup = Makie.@lift xyzsegments($xyz...)
x, y, z = Makie.@lift($tup[1]), Makie.@lift($tup[2]), Makie.@lift($tup[3])
Makie.lines!(plot, x, y, z, color=segmentcolor, linewidth=segmentsize)

Check warning on line 122 in ext/grid/cartesian.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/cartesian.jl#L119-L122

Added lines #L119 - L122 were not covered by tests
end
15 changes: 12 additions & 3 deletions ext/grid/rectilinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@
end

if showsegments[]
tup = Makie.@lift xysegments($xs, $ys)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)
vizfacets!(plot)

Check warning on line 47 in ext/grid/rectilinear.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/rectilinear.jl#L47

Added line #L47 was not covered by tests
end
else
vizgridfallback!(plot, M, pdim, edim)
end
end

function vizgridfacets!(plot::Viz{<:Tuple{RectilinearGrid}}, ::Type{<:𝔼}, ::Val{2}, ::Val{2})
grid = plot[:object]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

Check warning on line 57 in ext/grid/rectilinear.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/rectilinear.jl#L54-L57

Added lines #L54 - L57 were not covered by tests

xyz = Makie.@lift map(x -> ustrip.(x), Meshes.xyz($grid))
tup = Makie.@lift xysegments($xyz...)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)

Check warning on line 62 in ext/grid/rectilinear.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/rectilinear.jl#L59-L62

Added lines #L59 - L62 were not covered by tests
end
14 changes: 11 additions & 3 deletions ext/grid/structured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
Makie.surface!(plot, X, Y, color=C)

if showsegments[]
tup = Makie.@lift structuredsegments($grid)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)
vizfacets!(plot)

Check warning on line 35 in ext/grid/structured.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/structured.jl#L35

Added line #L35 was not covered by tests
end
else
vizmesh!(plot, M, pdim, edim)
Expand All @@ -44,6 +42,16 @@
end
end

function vizgridfacets!(plot::Viz{<:Tuple{StructuredGrid}}, ::Type{<:𝔼}, ::Val{2}, ::Val{2})
grid = plot[:object]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]

Check warning on line 48 in ext/grid/structured.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/structured.jl#L45-L48

Added lines #L45 - L48 were not covered by tests

tup = Makie.@lift structuredsegments($grid)
x, y = Makie.@lift($tup[1]), Makie.@lift($tup[2])
Makie.lines!(plot, x, y, color=segmentcolor, linewidth=segmentsize)

Check warning on line 52 in ext/grid/structured.jl

View check run for this annotation

Codecov / codecov/patch

ext/grid/structured.jl#L50-L52

Added lines #L50 - L52 were not covered by tests
end

function structuredsegments(grid)
cinds = CartesianIndices(size(grid) .+ 1)
coords = []
Expand Down
Loading
Loading