Skip to content

Commit

Permalink
Viz: Refactor conversion code (#666)
Browse files Browse the repository at this point in the history
* Viz: Convert all 'Mesh' types to 'SimpleMesh' except 'SimpleMesh' and 'CartesianGrid'

* Apply suggestions

* Apply suggestions

* Apply suggestions
  • Loading branch information
eliascarv authored Dec 21, 2023
1 parent 8deba9f commit c9cfd52
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ext/MeshesMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ include("utils.jl")
# viz recipes
include("simplemesh.jl")
include("cartesiangrid.jl")
include("subcartesiangrid.jl")
include("geometryset.jl")
include("fallbacks.jl")
include("optimized.jl")

end
2 changes: 0 additions & 2 deletions ext/cartesiangrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

Makie.plottype(::CartesianGrid) = Viz{<:Tuple{CartesianGrid}}

function Makie.plot!(plot::Viz{<:Tuple{CartesianGrid}})
# retrieve parameters
grid = plot[:object]
Expand Down
36 changes: 12 additions & 24 deletions ext/fallbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

Makie.plottype(::AbstractVector{<:Geometry}) = Viz{<:Tuple{AbstractVector{<:Geometry}}}

Makie.convert_arguments(P::Type{<:Viz}, geoms::AbstractVector{<:Geometry}) =
Makie.convert_arguments(P, GeometrySet(geoms))

Makie.plottype(::Geometry) = Viz{<:Tuple{Geometry}}

Makie.convert_arguments(P::Type{<:Viz}, geom::Geometry) = Makie.convert_arguments(P, GeometrySet([geom]))

Makie.plottype(::Domain) = Viz{<:Tuple{Domain}}

function Makie.plot!(plot::Viz{<:Tuple{Domain}})
# retrieve domain object
domain = plot[:object]
Makie.convert_arguments(::Type{<:Viz}, geom::Geometry) = (GeometrySet([geom]),)
Makie.convert_arguments(::Type{<:Viz}, domain::Domain) = (GeometrySet(collect(domain)),)
Makie.convert_arguments(::Type{<:Viz}, mesh::Mesh) = (convert(SimpleMesh, mesh),)

# skip conversion for these types
Makie.convert_arguments(::Type{<:Viz}, gset::GeometrySet) = (gset,)
Makie.convert_arguments(::Type{<:Viz}, mesh::SimpleMesh) = (mesh,)
Makie.convert_arguments(::Type{<:Viz}, grid::CartesianGrid) = (grid,)
Makie.convert_arguments(::Type{<:Viz}, grid::SubCartesianGrid) = (grid,)

# fallback to vector recipe
viz!(
plot,
(Makie.@lift collect($domain)),
color=plot[:color],
alpha=plot[:alpha],
colorscheme=plot[:colorscheme],
pointsize=plot[:pointsize],
segmentsize=plot[:segmentsize],
showfacets=plot[:showfacets],
facetcolor=plot[:facetcolor]
)
end
# vector of geometries for convenience
Makie.plottype(::AbstractVector{<:Geometry}) = Viz{<:Tuple{AbstractVector{<:Geometry}}}
Makie.convert_arguments(::Type{<:Viz}, geoms::AbstractVector{<:Geometry}) = (GeometrySet(geoms),)
4 changes: 0 additions & 4 deletions ext/geometryset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

Makie.plottype(::GeometrySet) = Viz{<:Tuple{GeometrySet}}

function Makie.plot!(plot::Viz{<:Tuple{GeometrySet}})
gset = plot[:object]
color = plot[:color]
Expand Down Expand Up @@ -69,8 +67,6 @@ function Makie.plot!(plot::Viz{<:Tuple{GeometrySet}})
end
end

Makie.plottype(::PointSet) = Viz{<:Tuple{PointSet}}

function Makie.plot!(plot::Viz{<:Tuple{PointSet}})
pset = plot[:object]
color = plot[:color]
Expand Down
2 changes: 0 additions & 2 deletions ext/simplemesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

Makie.plottype(::SimpleMesh) = Viz{<:Tuple{SimpleMesh}}

function Makie.plot!(plot::Viz{<:Tuple{SimpleMesh}})
# retrieve mesh and rank
mesh = plot[:object][]
Expand Down
22 changes: 0 additions & 22 deletions ext/optimized.jl → ext/subcartesiangrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,8 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

# ----------------
# RectilinearGrid
# ----------------

Makie.plottype(::RectilinearGrid) = Viz{<:Tuple{RectilinearGrid}}

Makie.convert_arguments(P::Type{<:Viz}, grid::RectilinearGrid) = Makie.convert_arguments(P, convert(SimpleMesh, grid))

# ---------------
# StructuredGrid
# ---------------

Makie.plottype(::StructuredGrid) = Viz{<:Tuple{StructuredGrid}}

Makie.convert_arguments(P::Type{<:Viz}, grid::StructuredGrid) = Makie.convert_arguments(P, convert(SimpleMesh, grid))

# -----------------
# SubCartesianGrid
# -----------------

const SubCartesianGrid{Dim,T} = Meshes.SubDomain{Dim,T,<:CartesianGrid{Dim,T}}

Makie.plottype(::SubCartesianGrid) = Viz{<:Tuple{SubCartesianGrid}}

function Makie.plot!(plot::Viz{<:Tuple{SubCartesianGrid}})
subgrid = plot[:object]
color = plot[:color]
Expand Down

0 comments on commit c9cfd52

Please sign in to comment.