For my mesh i have a element’s color matrix . This code can be used to create vertex colors when our data don’t have color for vertex. It takes vertex color as average of colors in adjacent elements.
vertex_color = Float64[]
for i in 1:nelements(g)
el= element(g,i)
bd = Boundary{3,0}(topology(g))(i) #Ntuple of vertex ids of i-th element
for id in bd
adels= Coboundary{0,3}(topology(g))(id) #Ntuple of element ids adjacent to this vertex
clct = collect(Element_color[(elem2cart(topology(g),idx))...] for idx in adels) #position of i-th element in grid
push!(vertex_color, sum(clct)/length(clct))
end
@inline viz!(el, color =vertex_color, alpha=0.2)
#@show clr
end
Can you tell more efficient version of this code? Thanks.