Skip to content

Commit

Permalink
Edges and Faces
Browse files Browse the repository at this point in the history
  • Loading branch information
paurierap committed Jul 5, 2021
1 parent 3ddfea9 commit bcadf31
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/GridapMakie.jl
Expand Up @@ -8,6 +8,10 @@ using Gridap.Visualization
import Makie
import GeometryBasics

include("Makie_conversion.jl")
include("conversions.jl")

include("faces.jl")

include("edges.jl")

end #module
12 changes: 10 additions & 2 deletions src/Makie_conversion.jl → src/conversions.jl
@@ -1,5 +1,6 @@

Makie.convert_arguments(::Makie.PlotFunc, grid::Grid) = ( grid |> to_plot_mesh, )
Makie.convert_arguments(::Type{<:Makie.Mesh}, grid::Grid) = ( grid |> to_plot_mesh, )
Makie.convert_arguments(::Type{<:Makie.Wireframe}, grid::Grid) = ( grid |> to_plot_mesh, )
#Makie.convert_arguments(::Makie.PlotFunc, grid::Grid) = ( grid |> to_plot_mesh, )

function to_plot_mesh(grid::Grid)
grid |> UnstructuredGrid |> to_plot_mesh
Expand Down Expand Up @@ -51,6 +52,13 @@ function to_mesh(grid::UnstructuredGrid)
GeometryBasics.Mesh(GeometryBasics.connect(ps,fs))
end

function to_edge_grid(grid::UnstructuredGrid)
topo = GridTopology(grid)
labels = FaceLabeling(topo)
model = DiscreteModel(grid,topo,labels)
Grid(ReferenceFE{1},model)
end

#=function Makie.wireframe(grid::CartesianGrid; kw...)
ls = GeometryBasics.Point2f0[]
cns = get_cell_node_ids(grid)
Expand Down
31 changes: 31 additions & 0 deletions src/edges.jl
@@ -0,0 +1,31 @@

# Create recipe:

@Makie.recipe(Edges, grid) do scene
#Makie.default_theme(scene, Makie.LineSegments)
Makie.Attributes(;
# generic attributes
colormap = Makie.theme(scene, :colormap),
color = Makie.theme(scene, :linecolor),
linewidth = Makie.theme(scene, :linewidth),

# new attributes
fieldstyle = :nodes
)
end

# Plot! especialization:

function Makie.plot!(plot::Edges{<:Tuple{Grid}})

grid = plot[:grid][]
color = plot[:color][]
linewidth = plot[:linewidth][]

faces!(plot, grid |> to_edge_grid,
color = color,
linewidth = linewidth,
colormap = plot[:colormap]
)

end
56 changes: 56 additions & 0 deletions src/faces.jl
@@ -0,0 +1,56 @@

# Create recipe:

@Makie.recipe(Faces, grid) do scene
#Makie.default_theme(scene, Makie.Mesh)
Makie.Attributes(;
# generic attributes
colormap = Makie.theme(scene, :colormap),
color = Makie.theme(scene, :linecolor),
linewidth = Makie.theme(scene, :linewidth),

# new attributes
fieldstyle = :nodes
)
end

# Plot! especialization:

function Makie.plot!(plot::Faces{<:Tuple{Grid}})

grid = plot[:grid][]
color = plot[:color][]
linewidth = plot[:linewidth][]

Dc = num_cell_dims(grid)

if Dc == 1
if color isa AbstractVector
Makie.wireframe!(plot, grid,
color = color,
linewidth = linewidth,
colormap = plot[:colormap]
)
else
Makie.wireframe!(plot, grid,
color = color,
linewidth = linewidth,
colormap = plot[:colormap]
)
end

else
if color isa AbstractVector
Makie.mesh!(plot, grid,
color = color,
colormap = plot[:colormap]
)
else
Makie.mesh!(plot, grid,
color = color,
colormap = plot[:colormap]
)
end
end

end
6 changes: 5 additions & 1 deletion test/runtests.jl
Expand Up @@ -40,6 +40,10 @@ end

@testset "GridapMakieTests" begin
@test savefig("mesh_2d") do
fig, scene = faces(grid_2D,color=:blue)
edges!(scene,grid_2D,linewidth=4)
end
#=@test savefig("mesh_2d") do
mesh(grid_2D, color=:purple)
end
@test savefig("mesh_2d_colormap&bar") do
Expand All @@ -65,7 +69,7 @@ end
end
@test savefig("wireframe_3d") do
fig, = wireframe(grid_3D; color=:blue, linewidth=.5)
end
end=#
end

end #module

0 comments on commit bcadf31

Please sign in to comment.