@@ -71,36 +71,39 @@ function vizmesh!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val)
71
71
elems = elements (topo)
72
72
73
73
# coordinates of vertices
74
- coords = map (p -> ustrip .( to (p)) , verts)
74
+ coords = map (asmakie , verts)
75
75
76
76
# fan triangulation (assume convexity)
77
- tris4elem = map (elems) do elem
77
+ ntris = sum (e -> nvertices (pltype (e)) - 2 , elems)
78
+ tris = Vector {GB.TriangleFace{Int}} (undef, ntris)
79
+ tind = 0
80
+ for elem in elems
78
81
I = indices (elem)
79
- [[I[1 ], I[i], I[i + 1 ]] for i in 2 : (length (I) - 1 )]
82
+ for i in 2 : (length (I) - 1 )
83
+ tind += 1
84
+ tris[tind] = GB. TriangleFace (I[1 ], I[i], I[i + 1 ])
85
+ end
80
86
end
81
87
82
- # flatten vector of triangles
83
- tris = [tri for tris in tris4elem for tri in tris]
84
-
85
88
# element vs. vertex coloring
86
89
if $ colorant isa AbstractVector
87
90
ncolor = length ($ colorant)
88
91
if ncolor == nelem # element coloring
89
92
# duplicate vertices and adjust
90
93
# connectivities to avoid linear
91
94
# interpolation of colors
92
- nt = 0
95
+ tind = 0
93
96
elem4tri = Dict {Int,Int} ()
94
- for e in 1 : nelem
95
- Δs = tris4elem[e]
96
- for _ in 1 : length (Δs )
97
- nt += 1
98
- elem4tri[nt ] = e
97
+ sizehint! (elem4tri, ntris)
98
+ for (eind, e) in enumerate (elems)
99
+ for _ in 1 : ( nvertices ( pltype (e)) - 2 )
100
+ tind += 1
101
+ elem4tri[tind ] = eind
99
102
end
100
103
end
101
- nv = 3 nt
104
+ nv = 3 ntris
102
105
tcoords = [coords[i] for tri in tris for i in tri]
103
- tconnec = [collect (I ) for I in Iterators . partition ( 1 : nv, 3 )]
106
+ tconnec = [GB . TriangleFace (i, i + 1 , i + 2 ) for i in range (start = 1 , step = 3 , length = ntris )]
104
107
tcolors = map (1 : nv) do i
105
108
t = ceil (Int, i / 3 )
106
109
e = elem4tri[t]
@@ -126,22 +129,23 @@ function vizmesh!(plot, ::Type{<:𝔼}, ::Val{2}, ::Val)
126
129
tcolors = $ colorant
127
130
end
128
131
129
- # convert connectivities to matrix format
130
- tmatrix = reduce (hcat, tconnec) |> transpose
131
-
132
132
# enable shading in 3D
133
133
tshading = dim == 3 ? Makie. FastShading : Makie. NoShading
134
134
135
- tcoords, tmatrix , tcolors, tshading
135
+ tcoords, tconnec , tcolors, tshading
136
136
end
137
137
138
138
# unpack observable of parameters
139
139
tcoords = Makie. @lift $ tparams[1 ]
140
- tmatrix = Makie. @lift $ tparams[2 ]
140
+ tconnec = Makie. @lift $ tparams[2 ]
141
141
tcolors = Makie. @lift $ tparams[3 ]
142
142
tshading = Makie. @lift $ tparams[4 ]
143
143
144
- Makie. mesh! (plot, tcoords, tmatrix, color= tcolors, shading= tshading)
144
+ # Makie's triangle mesh
145
+ mkemesh = Makie. @lift GB. Mesh ($ tcoords, $ tconnec)
146
+
147
+ # main visualization
148
+ Makie. mesh! (plot, mkemesh, color= tcolors, shading= tshading)
145
149
146
150
if showsegments[]
147
151
# retrieve coordinates parameters
0 commit comments