Skip to content

Commit d3e136e

Browse files
eliascarvjuliohm
andauthored
Add a heuristic to use uv coords in vizgridfallback! (#1057)
* Add a heuristic to use uv coords in 'vizgridfallback!' * Apply suggestions from code review --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent 6624d79 commit d3e136e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ext/grid.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,30 @@ function vizgridfallback!(plot, M, pdim, edim)
4747
colorrange = plot[:colorrange]
4848
showsegments = plot[:showsegments]
4949

50-
if pdim == Val(2) # visualize quadrangle mesh with texture using uv coords
50+
# process color spec into colorant
51+
colorant = Makie.@lift process($color, $colormap, $colorrange, $alpha)
52+
53+
# number of vertices, elements and colors
54+
nverts = Makie.@lift nvertices($grid)
55+
nelems = Makie.@lift nelements($grid)
56+
ncolor = Makie.@lift $colorant isa AbstractVector ? length($colorant) : 1
57+
58+
# visualize quadrangle mesh with texture using uv coords
59+
# plots with uv coords are always interpolated,
60+
# so it is only used in the case ncolor == nverts
61+
# or when there is a large number of elements
62+
if pdim == Val(2) && (ncolor[] == 1 || ncolor[] == nverts[] || nelems[] 1000)
5163
# decide whether or not to reverse connectivity list
5264
rfunc = Makie.@lift _reverse(crs($grid))
5365

5466
verts = Makie.@lift map(asmakie, vertices($grid))
5567
quads = Makie.@lift [GB.QuadFace($rfunc(indices(e))) for e in elements(topology($grid))]
5668

57-
colorant = Makie.@lift process($color, $colormap, $colorrange, $alpha)
58-
59-
nverts = Makie.@lift length($verts)
60-
nquads = Makie.@lift length($quads)
61-
ncolor = Makie.@lift $colorant isa AbstractVector ? length($colorant) : 1
62-
6369
dims = Makie.@lift size($grid)
6470
vdims = Makie.@lift Meshes.vsize($grid)
6571
texture = if ncolor[] == 1
6672
Makie.@lift fill($colorant, $dims)
67-
elseif ncolor[] == nquads[]
73+
elseif ncolor[] == nelems[]
6874
Makie.@lift reshape($colorant, $dims)
6975
elseif ncolor[] == nverts[]
7076
Makie.@lift reshape($colorant, $vdims)

0 commit comments

Comments
 (0)