Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #351 from JuliaPlots/sd/geometrybasics
Browse files Browse the repository at this point in the history
switch to geometrybasics
  • Loading branch information
SimonDanisch authored Apr 9, 2020
2 parents bb99b60 + 9edc07b commit d460a60
Show file tree
Hide file tree
Showing 24 changed files with 492 additions and 415 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test:
- apt-get install -y cmake xorg-dev mesa-utils # glfw
script:
- mkdir -p $JULIA_DEPOT_PATH # Pkg.jl#325
- julia --project -e 'using Pkg; pkg"add GLMakie#master"; Pkg.test(; coverage=true)'
- julia --project -e 'using Pkg; pkg"add Packing#master MeshIO#master FreeTypeAbstraction#master https://github.com/SimonDanisch/GridLayoutBase.jl.git#sd/geometrybasics GLMakie#sd/geometrybasics StatsMakie#sd/geometrybasics MakieGallery#master; build"; Pkg.test(; coverage=true)'
after_script:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit_local(process_folder(), ".")'
artifacts:
Expand Down
16 changes: 9 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AbstractPlotting"
uuid = "537997a7-5e4e-5d89-9595-2241ea00577e"
version = "0.9.27"
version = "0.10.0"

[deps]
AbstractNumbers = "85c772de-338a-5e7f-b815-41e76c26ac1f"
Expand All @@ -15,7 +15,7 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9"
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -45,21 +45,23 @@ DocStringExtensions = "0.8"
FFMPEG = "0.2, 0.3"
FileIO = "1.1"
FixedPointNumbers = "0.6, 0.7, 0.8"
FreeType = "2.1, 3.0"
FreeTypeAbstraction = "0.6"
GeometryTypes = "0.8.1"
FreeType = "3.0"
FreeTypeAbstraction = "0.6, 0.7"
GLMakie = "0.18, 0.1"
GeometryBasics = "0.2.2"
ImageMagick = "0.7, 1.0"
IntervalSets = "0.3, 0.4"
MakieGallery = "0.2"
MeshIO = "0.3, 0.4"
Observables = "0.3.1"
Packing = "0.3"
Packing = "0.3, 0.4"
PlotUtils = "^0.6.2"
Showoff = "0.3"
SignedDistanceFields = "0.4"
StaticArrays = "0.12"
StructArrays = "0.3.0, 0.4"
UnicodeFun = "0.4"
julia = "1.0"
MakieGallery = "0.1.9"

[extras]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
11 changes: 7 additions & 4 deletions src/AbstractPlotting.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module AbstractPlotting

using Random
using FFMPEG # get FFMPEG on any system!
using Observables, GeometryTypes, StaticArrays, IntervalSets, PlotUtils
using Observables, GeometryBasics, StaticArrays, IntervalSets, PlotUtils
using ColorBrewer, ColorTypes, Colors, ColorSchemes
using FixedPointNumbers, Packing, SignedDistanceFields
using Markdown, DocStringExtensions # documentation
using Serialization # serialize events
using StructArrays
# conflicting identifiers
using GeometryBasics: widths, positive_widths

# Text related packages
using FreeType, FreeTypeAbstraction, UnicodeFun
using LinearAlgebra, Statistics
Expand Down Expand Up @@ -39,6 +43,8 @@ include("utilities/texture_atlas.jl")
include("interaction/nodes.jl")
include("interaction/liftmacro.jl")

include("colorsampler.jl")

# Basic scene/plot/recipe interfaces + types
include("scenes.jl")
include("theming.jl")
Expand Down Expand Up @@ -159,8 +165,6 @@ export (..), GLNormalUVMesh
# Exports of units
export px

# conflicting identifiers
using GeometryTypes: widths, positive_widths
export widths, decompose

# building blocks for series recipes
Expand All @@ -176,7 +180,6 @@ export save
# colormap stuff from PlotUtils, and showlibrary, showgradients
export clibraries, cgradients, clibrary, showlibrary, showgradients


# default icon for Makie
function icon()
path = joinpath(dirname(pathof(AbstractPlotting)), "..", "assets", "icons")
Expand Down
11 changes: 2 additions & 9 deletions src/basic_recipes/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ default_labels(x::AbstractVector{<: AbstractString}, ranges, formatter::Function
default_labels(x::AbstractVector{<: AbstractString}, ranges::AbstractVector, formatter::Function) = x

function convert_arguments(::Type{<: Axis2D}, limits::Rect)
e = (minimum(limits), maximum(limits))
e = extrema(limits)
(((e[1][1], e[2][1]), (e[1][2], e[2][2])),)
end

Expand Down Expand Up @@ -332,7 +332,7 @@ function draw_frame(

mini = minimum.(limits)
maxi = maximum.(limits)
rect = HyperRectangle(Vec(mini), Vec(maxi .- mini))
rect = Rect(Vec(mini), Vec(maxi .- mini))
origin = Vec{N}(0.0)
if (origin in rect) && axis_position == :origin
for i = 1:N
Expand Down Expand Up @@ -592,13 +592,6 @@ function labelposition(ranges, dim, dir, tgap, origin::StaticVector{N}) where N
origin .+ (halfaxis .+ (normalize(dir) * tgap))
end


function GeometryTypes.widths(x::AbstractRange)
mini, maxi = Float32.(extrema(x))
maxi - mini
end


_widths(x::Tuple{<: Number, <: Number}) = x[2] - x[1]
_widths(x) = Float32(maximum(x) - minimum(x))

Expand Down
44 changes: 25 additions & 19 deletions src/basic_recipes/basic_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Plots a polygon based on the arguments given.
When vertices and indices are given, it functions similarly to `mesh`.
When points are given, it draws one polygon that connects all the points in order.
When a shape is given (essentially anything decomposable by `GeometryTypes`), it will plot `decompose(shape)`.
When a shape is given (essentially anything decomposable by `GeometryBasics`), it will plot `decompose(shape)`.
poly(coordinates, connectivity; kwargs...)
Expand Down Expand Up @@ -40,11 +40,10 @@ end
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: AbstractMesh}) = (v,)
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: VecTypes}) = (v,)
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: AbstractVector{<: VecTypes}}) = (v,)
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: Union{Circle, Rectangle, HyperRectangle}}) = (v,)
convert_arguments(::Type{<: Poly}, v::AbstractVector{<: Union{Circle, Rect}}) = (v,)
convert_arguments(::Type{<: Poly}, args...) = ([convert_arguments(Scatter, args...)[1]],)
convert_arguments(::Type{<: Poly}, vertices::AbstractArray, indices::AbstractArray) = convert_arguments(Mesh, vertices, indices)


function plot!(plot::Poly{<: Tuple{Union{AbstractMesh, GeometryPrimitive}}})
mesh!(
plot, plot[1],
Expand All @@ -57,8 +56,9 @@ function plot!(plot::Poly{<: Tuple{Union{AbstractMesh, GeometryPrimitive}}})
linewidth = plot[:strokewidth], visible = plot[:visible], overdraw = plot[:overdraw]
)
end

# Poly conversion
poly_convert(geometries) = GLNormalMesh.(geometries)
poly_convert(geometries) = triangle_mesh.(geometries)
poly_convert(meshes::AbstractVector{<:AbstractMesh}) = meshes

function poly_convert(polygon::AbstractVector{<: VecTypes})
Expand All @@ -68,10 +68,10 @@ end
function poly_convert(polygons::AbstractVector{<: AbstractVector{<: VecTypes}})
polys = Vector{Point2f0}[]
for poly in polygons
s = GeometryTypes.split_intersections(poly)
s = GeometryBasics.split_intersections(poly)
append!(polys, s)
end
return GLNormalMesh.(polys)
return triangle_mesh.(polys)
end

function to_line_segments(meshes)
Expand All @@ -94,7 +94,7 @@ function to_line_segments(polygon::AbstractVector{<: VecTypes})
return result
end

const PolyElements = Union{Circle, Rectangle, HyperRectangle, AbstractMesh, VecTypes, AbstractVector{<:VecTypes}}
const PolyElements = Union{Circle, Rect, AbstractMesh, VecTypes, AbstractVector{<:VecTypes}}

function plot!(plot::Poly{<: Tuple{<: AbstractVector{<: PolyElements}}})
geometries = plot[1]
Expand Down Expand Up @@ -128,20 +128,26 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: AbstractMe

bigmesh = if color_node[] isa AbstractVector && length(color_node[]) == length(meshes[])
# One color per mesh
real_colors = Observable(RGBAf0[])
attributes[:color] = real_colors
lift(meshes, color_node, attributes.colormap, attributes.colorrange) do meshes, colors, cmap, crange
# Color are reals, so we need to transform it to colors first
real_colors = if colors isa AbstractVector{<:Number}
single_colors = if colors isa AbstractVector{<:Number}
interpolated_getindex.((to_colormap(cmap),), colors, (crange,))
else
to_color.(colors)
end
meshes = GeometryTypes.add_attribute.(GLNormalMesh.(meshes), real_colors)
# Map one single color per mesh to each vertex
for (mesh, color) in zip(meshes, single_colors)
append!(real_colors[], Iterators.repeated(RGBAf0(color), length(coordinates(mesh))))
end
real_colors[] = real_colors[]
return merge(meshes)
end
else
attributes[:color] = color_node
lift(meshes) do meshes
return merge(GLPlainMesh.(meshes))
return merge(triangle_mesh.(meshes))
end
end
mesh!(plot, attributes, bigmesh)
Expand Down Expand Up @@ -256,8 +262,8 @@ function plot!(plot::Wireframe{<: Tuple{<: Any, <: Any, <: AbstractMatrix}})
points = vec(Point3f0.(xvector(x, M), yvector(y, N), z))
# Connect the vetices with faces, as one would use for a 2D Rectangle
# grid with M,N grid points
faces = decompose(Face{2, GLIndex}, SimpleRectangle(0, 0, 1, 1), (M, N))
view(points, faces)
faces = decompose(LineFace{GLIndex}, Rect2D(0, 0, 1, 1), (M, N))
connect(points, faces)
end
linesegments!(plot, Theme(plot), points_faces)
end
Expand All @@ -266,9 +272,9 @@ end
function plot!(plot::Wireframe{Tuple{T}}) where T
points = lift(plot[1]) do g
# get the point representation of the geometry
indices = decompose(Face{2, GLIndex}, g)
indices = decompose(LineFace{GLIndex}, g)
points = decompose(Point3f0, g)
view(points, indices)
return connect(points, indices)
end
linesegments!(plot, Theme(plot), points)
end
Expand Down Expand Up @@ -323,7 +329,6 @@ end
# linesegments!(plot, Theme(plot), lines)
# end


"""
Series - ?
Expand Down Expand Up @@ -563,6 +568,7 @@ $(ATTRIBUTES)
@recipe(Band, lowerpoints, upperpoints) do scene
Theme(;
default_theme(scene, Mesh)...,
colorrange = automatic,
color = RGBAf0(0.0,0,0,0.2)
)
end
Expand All @@ -572,7 +578,7 @@ convert_arguments(::Type{<: Band}, x, ylower, yupper) = (Point2f0.(x, ylower), P
function band_connect(n)
ns = 1:n-1
ns2 = n+1:2n-1
[GLTriangle.(ns, ns .+ 1, ns2); GLTriangle.(ns .+ 1, ns2 .+ 1, ns2)]
[GLTriangleFace.(ns, ns .+ 1, ns2); GLTriangleFace.(ns .+ 1, ns2 .+ 1, ns2)]
end

function plot!(plot::Band)
Expand Down Expand Up @@ -627,6 +633,7 @@ $(ATTRIBUTES)
colorrange = AbstractPlotting.automatic,
levels = 5,
linewidth = 1.0,
alpha = 1.0,
fillrange = false,
)
end
Expand All @@ -643,7 +650,6 @@ $(ATTRIBUTES)
default_theme(scene, Contour)
end


function contourlines(::Type{<: Contour}, contours, cols)
result = Point2f0[]
colors = RGBA{Float32}[]
Expand Down Expand Up @@ -672,19 +678,19 @@ function contourlines(::Type{<: Contour3d}, contours, cols)
result, colors
end


to_levels(x::AbstractVector{<: Number}, cnorm) = x

function to_levels(n::Integer, cnorm)
zmin, zmax = cnorm
dz = (zmax - zmin) / (n + 1)
range(zmin + dz; step = dz, length = n)
end

conversion_trait(::Type{<: Contour3d}) = SurfaceLike()
conversion_trait(::Type{<: Contour}) = SurfaceLike()
conversion_trait(::Type{<: Contour{<: Tuple{X, Y, Z, Vol}}}) where {X, Y, Z, Vol} = VolumeLike()
conversion_trait(::Type{<: Contour{<: Tuple{<: AbstractArray{T, 3}}}}) where T = VolumeLike()


function plot!(plot::Contour{<: Tuple{X, Y, Z, Vol}}) where {X, Y, Z, Vol}
x, y, z, volume = plot[1:4]
@extract plot (colormap, levels, linewidth, alpha)
Expand Down
9 changes: 4 additions & 5 deletions src/basic_recipes/legend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ function plot!(plot::ColorLegend)
)
)
vertices = Point3f0[(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)]
mesh = GLNormalUVMesh(
vertices = copy(vertices),
faces = GLTriangle[(1, 2, 3), (3, 4, 1)],
texturecoordinates = UV{Float32}[(0, 1), (0, 0), (0, 0), (0, 1)]
mesh = GeometryBasics.Mesh(
meta(vertices, uv=Vec2f0[(0, 1), (0, 0), (0, 0), (0, 1)]),
GLTriangleFace[(1, 2, 3), (3, 4, 1)],
)

cmap_node = lift(colormap) do cmap
Expand Down Expand Up @@ -242,7 +241,7 @@ function plot!(plot::ColorLegend)
rect
end
meshnode = lift(width, padding, textsize) do w, pad, ts
mesh.vertices .= broadcast(vertices) do v
mesh.position .= broadcast(vertices) do v
Point3f0(((Point2f0(v[1], v[2]) .* Point2f0(w)) .+ Point2f0(0, ts/2) .+ pad)..., 0.0)
end
mesh
Expand Down
2 changes: 1 addition & 1 deletion src/camera/camera2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ end



function add_restriction!(cam, window, rarea::SimpleRectangle, minwidths::Vec)
function add_restriction!(cam, window, rarea::Rect2D, minwidths::Vec)
area_ref = Base.RefValue(cam[Area])
restrict_action = paused_action(1.0) do t
o = lerp(origin(area_ref[]), origin(cam[Area]), t)
Expand Down
12 changes: 5 additions & 7 deletions src/camera/projection_math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ end
projection ratio in terms of the rectangular view size `rect` rather
than the aspect ratio.
"""
function perspectiveprojection(wh::SimpleRectangle, fov::T, near::T, far::T) where T
function perspectiveprojection(wh::Rect2D, fov::T, near::T, far::T) where T
perspectiveprojection(fov, T(wh.w/wh.h), near, far)
end
function perspectiveprojection(
::Type{T}, wh::SimpleRectangle, fov::Number, near::Number, far::Number
::Type{T}, wh::Rect2D, fov::Number, near::Number, far::Number
) where T
perspectiveprojection(T(fov), T(wh.w/wh.h), T(near), T(far))
end
Expand Down Expand Up @@ -141,11 +141,11 @@ end
function lookat(::Type{T}, eyePos::Vec{3}, lookAt::Vec{3}, up::Vec{3}) where T
lookat(Vec{3,T}(eyePos), Vec{3,T}(lookAt), Vec{3,T}(up))
end
function orthographicprojection(wh::SimpleRectangle, near::T, far::T) where T
function orthographicprojection(wh::Rect2D, near::T, far::T) where T
orthographicprojection(zero(T), T(wh.w), zero(T), T(wh.h), near, far)
end
function orthographicprojection(
::Type{T}, wh::SimpleRectangle, near::Number, far::Number
::Type{T}, wh::Rect2D, near::Number, far::Number
) where T
orthographicprojection(wh, T(near), T(far))
end
Expand Down Expand Up @@ -176,8 +176,6 @@ function orthographicprojection(::Type{T},
)
end



mutable struct Pivot{T}
origin ::Vec{3, T}
xaxis ::Vec{3, T}
Expand All @@ -188,7 +186,7 @@ mutable struct Pivot{T}
scale ::Vec{3, T}
end

GeometryTypes.origin(p::Pivot) = p.origin
GeometryBasics.origin(p::Pivot) = p.origin

rotationmatrix4(q::Quaternion{T}) where {T} = Mat4{T}(q)

Expand Down
Loading

2 comments on commit d460a60

@SimonDanisch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/12673

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" d460a605cc830af097c66cddc08c430ca35ff747
git push origin v0.10.0

Please sign in to comment.