From f1fc4188d0d03638865ac333713585a3a892e498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Sat, 4 Feb 2023 23:38:56 +0100 Subject: [PATCH] Subgridplots (#2) Work with vectors of grid data and functions in order to support subgrid plots in GridVisualize. --- .JuliaFormatter.toml | 4 + Project.toml | 2 +- docs/make.jl | 16 +- docs/src/index.md | 6 +- src/GridVisualizeTools.jl | 2 +- src/colors.jl | 44 +++--- src/extraction.jl | 151 +++++++++--------- src/marching.jl | 321 +++++++++++++++++++++++--------------- src/markerpoints.jl | 50 +++--- src/planeslevels.jl | 75 ++++----- test/runtests.jl | 4 +- 11 files changed, 366 insertions(+), 309 deletions(-) create mode 100644 .JuliaFormatter.toml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..95edb89 --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1,4 @@ +style = "sciml" +always_for_in = false +separate_kwargs_with_semicolon = true +margin = 132 \ No newline at end of file diff --git a/Project.toml b/Project.toml index 34aac03..1afa06c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GridVisualizeTools" uuid = "5573ae12-3b76-41d9-b48c-81d0b6e61cc5" authors = ["Jürgen Fuhrmann "] -version = "0.2.1" +version = "0.3.0" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" diff --git a/docs/make.jl b/docs/make.jl index d57419f..06b6d6b 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,21 +1,19 @@ using Documenter, GridVisualizeTools, ColorTypes function mkdocs() - DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive=true) - makedocs(sitename="GridVisualizeTools.jl", + DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true) + makedocs(; sitename = "GridVisualizeTools.jl", modules = [GridVisualizeTools], - clean = false, + clean = false, doctest = true, authors = "J. Fuhrmann", - repo="https://github.com/j-fu/GridVisualizeTools.jl", - pages=[ - "Home"=>"index.md" + repo = "https://github.com/j-fu/GridVisualizeTools.jl", + pages = [ + "Home" => "index.md", ]) if !isinteractive() - deploydocs(repo = "github.com/j-fu/GridVisualizeTools.jl.git", devbranch = "main") + deploydocs(; repo = "github.com/j-fu/GridVisualizeTools.jl.git", devbranch = "main") end - end mkdocs() - diff --git a/docs/src/index.md b/docs/src/index.md index 02e2667..b1e9696 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -97,21 +97,21 @@ makeisolevels ```jldoctest using GridVisualizeTools -makeisolevels(0:0.1:10, 1, (-1,1),3) +makeisolevels(collect(0:0.1:10), 1, (-1,1),3) # output ([-1.0, 0.0, 1.0], (-1, 1), [-1.0, 0.0, 1.0]) ``` ```jldoctest using GridVisualizeTools -makeisolevels(0:0.1:10, 1, (1,-1),3) +makeisolevels(collect(0:0.1:10), 1, (1,-1),3) # output ([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0]) ``` ```jldoctest using GridVisualizeTools -makeisolevels(0:0.1:10, 1, (1,-1),nothing) +makeisolevels(collect(0:0.1:10), 1, (1,-1),nothing) # output ([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0]) ``` diff --git a/src/GridVisualizeTools.jl b/src/GridVisualizeTools.jl index 5442036..beacff2 100644 --- a/src/GridVisualizeTools.jl +++ b/src/GridVisualizeTools.jl @@ -17,6 +17,6 @@ include("markerpoints.jl") export markerpoints include("planeslevels.jl") -export makeplanes,makeisolevels +export makeplanes, makeisolevels end # module GridVisualizeTools diff --git a/src/colors.jl b/src/colors.jl index 5beef47..10635b6 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -4,12 +4,13 @@ $(SIGNATURES) Create customized distinguishable colormap for interior regions. For this we use a kind of pastel colors. """ -region_cmap(n)=distinguishable_colors(max(5,n), - [RGB(0.85,0.6,0.6), RGB(0.6,0.85,0.6),RGB(0.6,0.6,0.85)], - lchoices = range(70, stop=80, length=5), - cchoices = range(25, stop=65, length=15), - hchoices = range(20, stop=360, length=15) - ) +function region_cmap(n) + distinguishable_colors(max(5, n), + [RGB(0.85, 0.6, 0.6), RGB(0.6, 0.85, 0.6), RGB(0.6, 0.6, 0.85)]; + lchoices = range(70; stop = 80, length = 5), + cchoices = range(25; stop = 65, length = 15), + hchoices = range(20; stop = 360, length = 15)) +end """ $(SIGNATURES) @@ -17,14 +18,13 @@ $(SIGNATURES) Create customized distinguishable colormap for boundary regions. These use fully saturated colors. """ -bregion_cmap(n)=distinguishable_colors(max(5,n), - [RGB(1.0,0.0,0.0), RGB(0.0,1.0,0.0), RGB(0.0,0.0,1.0)], - lchoices = range(50, stop=75, length=10), - cchoices = range(75, stop=100, length=10), - hchoices = range(20, stop=360, length=30) - ) - - +function bregion_cmap(n) + distinguishable_colors(max(5, n), + [RGB(1.0, 0.0, 0.0), RGB(0.0, 1.0, 0.0), RGB(0.0, 0.0, 1.0)]; + lchoices = range(50; stop = 75, length = 10), + cchoices = range(75; stop = 100, length = 10), + hchoices = range(20; stop = 360, length = 30)) +end """ $(SIGNATURES) @@ -32,38 +32,34 @@ $(SIGNATURES) Create RGB color from color name string. """ function Colors.RGB(c::String) - c64=Colors.color_names[c] - RGB(c64[1]/255,c64[2]/255, c64[3]/255) + c64 = Colors.color_names[c] + RGB(c64[1] / 255, c64[2] / 255, c64[3] / 255) end - """ $(SIGNATURES) Create RGB color from color name symbol. """ -Colors.RGB(c::Symbol)=Colors.RGB(String(c)) +Colors.RGB(c::Symbol) = Colors.RGB(String(c)) """ $(SIGNATURES) Create RGB color from tuple """ -Colors.RGB(c::Tuple)=Colors.RGB(c...) - +Colors.RGB(c::Tuple) = Colors.RGB(c...) """ $(SIGNATURES) Create color tuple from color description (e.g. string) """ -rgbtuple(c)=rgbtuple(Colors.RGB(c)) - +rgbtuple(c) = rgbtuple(Colors.RGB(c)) """ $(SIGNATURES) Create color tuple from RGB color. """ -rgbtuple(c::RGB)=(red(c),green(c),blue(c)) - +rgbtuple(c::RGB) = (red(c), green(c), blue(c)) diff --git a/src/extraction.jl b/src/extraction.jl index 2fdfbf1..4601ff1 100644 --- a/src/extraction.jl +++ b/src/extraction.jl @@ -7,62 +7,59 @@ Extract visible tetrahedra - those intersecting with the planes Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat) or trisurf (pyplot) """ -function extract_visible_cells3D(coord,cellnodes,cellregions,nregions,xyzcut; - primepoints=zeros(0,0),Tp=SVector{3,Float32},Tf=SVector{3,Int32}) - all_lt=ones(Bool,3) - all_gt=ones(Bool,3) +function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut; + primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}) + all_lt = ones(Bool, 3) + all_gt = ones(Bool, 3) - function take(coord,simplex,xyzcut,all_lt,all_gt) - for idim=1:3 - all_lt[idim]=true - all_gt[idim]=true - for inode=1:4 - c=coord[idim,simplex[inode]]-xyzcut[idim] - all_lt[idim]=all_lt[idim] && (c<0.0) - all_gt[idim]=all_gt[idim] && (c>0.0) + function take(coord, simplex, xyzcut, all_lt, all_gt) + for idim = 1:3 + all_lt[idim] = true + all_gt[idim] = true + for inode = 1:4 + c = coord[idim, simplex[inode]] - xyzcut[idim] + all_lt[idim] = all_lt[idim] && (c < 0.0) + all_gt[idim] = all_gt[idim] && (c > 0.0) end end - tke=false - tke=tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3]) - tke=tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3]) - tke=tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2]) + tke = false + tke = tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3]) + tke = tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3]) + tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2]) end - - faces=[Vector{Tf}(undef,0) for iregion=1:nregions] - points=[Vector{Tp}(undef,0) for iregion=1:nregions] - - for iregion=1:nregions - for iprime=1:size(primepoints,2) - @views push!(points[iregion],Tp(primepoints[:,iprime])) + faces = [Vector{Tf}(undef, 0) for iregion = 1:nregions] + points = [Vector{Tp}(undef, 0) for iregion = 1:nregions] + + for iregion = 1:nregions + for iprime = 1:size(primepoints, 2) + @views push!(points[iregion], Tp(primepoints[:, iprime])) end end - tet=zeros(Int32,4) - - for itet=1:size(cellnodes,2) - iregion=cellregions[itet] - for i=1:4 - tet[i]=cellnodes[i,itet] + tet = zeros(Int32, 4) + + for itet = 1:size(cellnodes, 2) + iregion = cellregions[itet] + for i = 1:4 + tet[i] = cellnodes[i, itet] end - if take(coord,tet,xyzcut,all_lt,all_gt) - npts=size(points[iregion],1) + if take(coord, tet, xyzcut, all_lt, all_gt) + npts = size(points[iregion], 1) @views begin - push!(points[iregion],coord[:,cellnodes[1,itet]]) - push!(points[iregion],coord[:,cellnodes[2,itet]]) - push!(points[iregion],coord[:,cellnodes[3,itet]]) - push!(points[iregion],coord[:,cellnodes[4,itet]]) - push!(faces[iregion],(npts+1,npts+2,npts+3)) - push!(faces[iregion],(npts+1,npts+2,npts+4)) - push!(faces[iregion],(npts+2,npts+3,npts+4)) - push!(faces[iregion],(npts+3,npts+1,npts+4)) + push!(points[iregion], coord[:, cellnodes[1, itet]]) + push!(points[iregion], coord[:, cellnodes[2, itet]]) + push!(points[iregion], coord[:, cellnodes[3, itet]]) + push!(points[iregion], coord[:, cellnodes[4, itet]]) + push!(faces[iregion], (npts + 1, npts + 2, npts + 3)) + push!(faces[iregion], (npts + 1, npts + 2, npts + 4)) + push!(faces[iregion], (npts + 2, npts + 3, npts + 4)) + push!(faces[iregion], (npts + 3, npts + 1, npts + 4)) end end end - points,faces + points, faces end - - """ $(SIGNATURES) @@ -72,19 +69,17 @@ Extract visible boundary faces - those not cut off by the planes Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat) or trisurf (pyplot) """ -function extract_visible_bfaces3D(coord,bfacenodes,bfaceregions, nbregions, xyzcut; - primepoints=zeros(0,0), Tp=SVector{3,Float32},Tf=SVector{3,Int32}) +function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xyzcut; + primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32}) + nbfaces = size(bfacenodes, 2) + cutcoord = zeros(3) - - nbfaces=size(bfacenodes,2) - cutcoord=zeros(3) - - function take(coord,simplex,xyzcut) - for idim=1:3 - all_gt=true - for inode=1:3 - c=coord[idim,simplex[inode]]-xyzcut[idim] - all_gt= all_gt && c>0 + function take(coord, simplex, xyzcut) + for idim = 1:3 + all_gt = true + for inode = 1:3 + c = coord[idim, simplex[inode]] - xyzcut[idim] + all_gt = all_gt && c > 0 end if all_gt return false @@ -92,37 +87,35 @@ function extract_visible_bfaces3D(coord,bfacenodes,bfaceregions, nbregions, xyzc end return true end - - Tc=SVector{3,eltype(coord)} - xcoord=reinterpret(Tc,reshape(coord,(length(coord),))) - - - faces=[Vector{Tf}(undef,0) for iregion=1:nbregions] - points=[Vector{Tp}(undef,0) for iregion=1:nbregions] - for iregion=1:nbregions - for iprime=1:size(primepoints,2) - @views push!(points[iregion],Tp(primepoints[:,iprime])) + Tc = SVector{3, eltype(coord)} + xcoord = reinterpret(Tc, reshape(coord, (length(coord),))) + + faces = [Vector{Tf}(undef, 0) for iregion = 1:nbregions] + points = [Vector{Tp}(undef, 0) for iregion = 1:nbregions] + for iregion = 1:nbregions + for iprime = 1:size(primepoints, 2) + @views push!(points[iregion], Tp(primepoints[:, iprime])) end end # remove some type instability here - function collct(points,faces) - trinodes=[1,2,3] - for i=1:nbfaces - iregion=bfaceregions[i] - trinodes[1]=bfacenodes[1,i] - trinodes[2]=bfacenodes[2,i] - trinodes[3]=bfacenodes[3,i] - if take(coord,trinodes,xyzcut) - npts=size(points[iregion],1) - @views push!(points[iregion],xcoord[trinodes[1]]) - @views push!(points[iregion],xcoord[trinodes[2]]) - @views push!(points[iregion],xcoord[trinodes[3]]) - @views push!(faces[iregion],(npts+1,npts+2,npts+3)) + function collct(points, faces) + trinodes = [1, 2, 3] + for i = 1:nbfaces + iregion = bfaceregions[i] + trinodes[1] = bfacenodes[1, i] + trinodes[2] = bfacenodes[2, i] + trinodes[3] = bfacenodes[3, i] + if take(coord, trinodes, xyzcut) + npts = size(points[iregion], 1) + @views push!(points[iregion], xcoord[trinodes[1]]) + @views push!(points[iregion], xcoord[trinodes[2]]) + @views push!(points[iregion], xcoord[trinodes[3]]) + @views push!(faces[iregion], (npts + 1, npts + 2, npts + 3)) end end end - collct(points,faces) - points,faces + collct(points, faces) + points, faces end diff --git a/src/marching.jl b/src/marching.jl index 27e8d15..b2279b9 100644 --- a/src/marching.jl +++ b/src/marching.jl @@ -25,33 +25,40 @@ This method can be used both for the evaluation of plane sections and for the evaluation of function isosurfaces. """ -function tet_x_plane!(ixcoord,ixvalues,pointlist,node_indices,planeq_values,function_values; tol=0.0) +function tet_x_plane!(ixcoord, + ixvalues, + pointlist, + node_indices, + planeq_values, + function_values; + tol = 0.0) # If all nodes lie on one side of the plane, no intersection - @fastmath if (mapreduce(a->a< -tol,*,planeq_values) || mapreduce(a->a>tol,*,planeq_values)) + @fastmath if (mapreduce(a -> a < -tol, *, planeq_values) || + mapreduce(a -> a > tol, *, planeq_values)) return 0 end # Interpolate coordinates and function_values according to # evaluation of the plane equation - nxs=0 - @inbounds @simd for n1=1:3 - N1=node_indices[n1] - @inbounds @fastmath @simd for n2=n1+1:4 - N2=node_indices[n2] - if planeq_values[n1]!=planeq_values[n2] && planeq_values[n1]*planeq_values[n2]=3 - last_i=length(all_ixvalues) - for is=1:ns - @views push!(all_ixcoord,ixcoord[:,is]) - push!(all_ixvalues,ixvalues[is]) # todo consider nan_replacement here + if ns >= 3 + last_i = length(all_ixvalues) + for is = 1:ns + @views push!(all_ixcoord, ixcoord[:, is]) + push!(all_ixvalues, ixvalues[is]) # todo consider nan_replacement here end - push!(all_ixfaces,(last_i+1,last_i+2,last_i+3)) - if ns==4 - push!(all_ixfaces,(last_i+3,last_i+2,last_i+4)) + push!(all_ixfaces, (last_i + 1, last_i + 2, last_i + 3)) + if ns == 4 + push!(all_ixfaces, (last_i + 3, last_i + 2, last_i + 4)) end end end - function calcxs() - @inbounds for itet=1:ntet - node_indices[1]=cellnodes[1,itet] - node_indices[2]=cellnodes[2,itet] - node_indices[3]=cellnodes[3,itet] - node_indices[4]=cellnodes[4,itet] - planeq[1]=all_planeq[node_indices[1]] - planeq[2]=all_planeq[node_indices[2]] - planeq[3]=all_planeq[node_indices[3]] - planeq[4]=all_planeq[node_indices[4]] - nxs=tet_x_plane!(ixcoord,ixvalues,coord,node_indices,planeq,func,tol=tol) - pushtris(nxs,ixcoord,ixvalues) + for igrid = 1:length(allcoords) + coord = allcoords[igrid] + cellnodes = allcellnodes[igrid] + func = allfuncs[igrid] + nnodes = size(coord, 2) + ntet = size(cellnodes, 2) + all_planeq = Vector{Float32}(undef, nnodes) + + function calcxs() + @inbounds for itet = 1:ntet + node_indices[1] = cellnodes[1, itet] + node_indices[2] = cellnodes[2, itet] + node_indices[3] = cellnodes[3, itet] + node_indices[4] = cellnodes[4, itet] + planeq[1] = all_planeq[node_indices[1]] + planeq[2] = all_planeq[node_indices[2]] + planeq[3] = all_planeq[node_indices[3]] + planeq[4] = all_planeq[node_indices[4]] + nxs = tet_x_plane!(ixcoord, + ixvalues, + coord, + node_indices, + planeq, + func; + tol = tol) + pushtris(nxs, ixcoord, ixvalues) + end + end + + @inbounds for iplane = 1:nplanes + @views @inbounds map!(inode -> plane_equation(planes[iplane], coord[:, inode]), + all_planeq, + 1:nnodes) + calcxs() + end + + # allocation free (besides push!) + @inbounds for ilevel = 1:nlevels + @views @inbounds @fastmath map!(inode -> (func[inode] - flevels[ilevel]), + all_planeq, + 1:nnodes) + calcxs() end end - - @inbounds for iplane=1:nplanes - @views @inbounds map!(inode->plane_equation(planes[iplane],coord[:,inode]),all_planeq,1:nnodes) - calcxs() - end - - # allocation free (besides push!) - @inbounds for ilevel=1:nlevels - @views @inbounds @fastmath map!(inode->(func[inode]-flevels[ilevel]),all_planeq,1:nnodes) - calcxs() - end - all_ixcoord, all_ixfaces, all_ixvalues end - """ $(SIGNATURES) Collect isoline snippets on triangles ready for linesegments! """ -function marching_triangles(coord,cellnodes,func,levels; Tc=Float32, Tp=SVector{2,Tc}) - points=Vector{Tp}(undef,0) - function isect(nodes) - (i1,i2,i3)=(1,2,3) - - f=(func[nodes[1]],func[nodes[2]],func[nodes[3]]) - - f[1] <= f[2] ? (i1,i2) = (1,2) : (i1,i2) = (2,1) - f[i2] <= f[3] ? i3=3 : (i2,i3) = (3,i2) - f[i1] > f[i2] ? (i1,i2) = (i2,i1) : nothing - - (n1,n2,n3)=(nodes[i1],nodes[i2],nodes[i3]) - - dx31=coord[1,n3]-coord[1,n1] - dx21=coord[1,n2]-coord[1,n1] - dx32=coord[1,n3]-coord[1,n2] - - dy31=coord[2,n3]-coord[2,n1] - dy21=coord[2,n2]-coord[2,n1] - dy32=coord[2,n3]-coord[2,n2] - - df31 = f[i3]!=f[i1] ? 1/(f[i3]-f[i1]) : 0.0 - df21 = f[i2]!=f[i1] ? 1/(f[i2]-f[i1]) : 0.0 - df32 = f[i3]!=f[i2] ? 1/(f[i3]-f[i2]) : 0.0 - - for level ∈ levels - if (f[i1]<=level) && (level f[i2] ? (i1, i2) = (i2, i1) : nothing + + (n1, n2, n3) = (nodes[i1], nodes[i2], nodes[i3]) + + dx31 = coord[1, n3] - coord[1, n1] + dx21 = coord[1, n2] - coord[1, n1] + dx32 = coord[1, n3] - coord[1, n2] + + dy31 = coord[2, n3] - coord[2, n1] + dy21 = coord[2, n2] - coord[2, n1] + dy32 = coord[2, n3] - coord[2, n2] + + df31 = f[i3] != f[i1] ? 1 / (f[i3] - f[i1]) : 0.0 + df21 = f[i2] != f[i1] ? 1 / (f[i2] - f[i1]) : 0.0 + df32 = f[i3] != f[i2] ? 1 / (f[i3] - f[i2]) : 0.0 + + for level ∈ levels + if (f[i1] <= level) && (level < f[i3]) + α = (level - f[i1]) * df31 + x1 = coord[1, n1] + α * dx31 + y1 = coord[2, n1] + α * dy31 + + if (level < f[i2]) + α = (level - f[i1]) * df21 + x2 = coord[1, n1] + α * dx21 + y2 = coord[2, n1] + α * dy21 + else + α = (level - f[i2]) * df32 + x2 = coord[1, n2] + α * dx32 + y2 = coord[2, n2] + α * dy32 + end + push!(points, SVector{2, Tc}((x1, y1))) + push!(points, SVector{2, Tc}((x2, y2))) end - push!(points,SVector{2,Tc}((x1,y1))) - push!(points,SVector{2,Tc}((x2,y2))) end end - end - - for itri=1:size(cellnodes,2) - @views isect(cellnodes[:,itri]) + + for itri = 1:size(cellnodes[igrid], 2) + @views isect(cellnodes[igrid][:, itri]) + end end points -end +end diff --git a/src/markerpoints.jl b/src/markerpoints.jl index 4d27d7e..2ebfde7 100644 --- a/src/markerpoints.jl +++ b/src/markerpoints.jl @@ -7,34 +7,34 @@ Place `nmarkers` equidistant markers at the polyline, under the assumption that the points are transformed via the transformation matrix M vor visualization. """ -function markerpoints(points,nmarkers,transform) - dist(p1,p2)=norm(transform*(p1-p2)) - - llen=0.0 - for i=2:length(points) - llen+=dist(points[i],points[i-1]) +function markerpoints(points, nmarkers, transform) + dist(p1, p2) = norm(transform * (p1 - p2)) + + llen = 0.0 + for i = 2:length(points) + llen += dist(points[i], points[i - 1]) end - mdist=llen/(nmarkers-1) - - mpoints=[points[1]] - - i=2 - l=0.0 - lnext=l+mdist - while ixyzmin[1] && x xyzmin[1] && x < xyzmax[1] && push!(planes, [1, 0, 0, -x]) end - - for i=1:length(Y) - y=Y[i] - y>xyzmin[2] && y xyzmin[2] && y < xyzmax[2] && push!(planes, [0, 1, 0, -y]) end - - for i=1:length(Z) - z=Z[i] - z>xyzmin[3] && z xyzmin[3] && z < xyzmax[3] && push!(planes, [0, 0, 1, -z]) end planes end @@ -51,23 +51,26 @@ Update levels, limits, colorbartics based on vector given in func. - if colorbarticks is `nothing` replace it with levels, otherwise, if it is a number, replace it with a linear range of corresponding length """ -function makeisolevels(func,levels,limits, colorbarticks) - - if limits[1]>limits[2] - limits=extrema(func) +function makeisolevels(func::Vector{T}, levels, limits, colorbarticks) where {T <: Number} + makeisolevels([func], levels, limits, colorbarticks) +end + +function makeisolevels(funcs::Vector{Vector{T}}, levels, limits, colorbarticks) where {T <: Number} + if limits[1] > limits[2] + ext = extrema.(funcs) + limits = (minimum(first.(ext)), maximum(last.(ext))) end - - if isa(levels,Number) - levels=collect(LinRange(limits[1],limits[2],levels+2)) + + if isa(levels, Number) + levels = collect(LinRange(limits[1], limits[2], levels + 2)) end - + if colorbarticks == nothing colorbarticks = levels - elseif isa(colorbarticks,Number) - colorbarticks = collect(limits[1]:(limits[2]-limits[1])/(colorbarticks-1):limits[2]) + elseif isa(colorbarticks, Number) + colorbarticks = collect(limits[1]:((limits[2] - limits[1]) / (colorbarticks - 1)):limits[2]) end - - # map(t->round(t,sigdigits=4),levels),limits,map(t->round(t,sigdigits=4),colorbarticks) - levels,limits,colorbarticks + # map(t->round(t,sigdigits=4),levels),limits,map(t->round(t,sigdigits=4),colorbarticks) + levels, limits, colorbarticks end diff --git a/test/runtests.jl b/test/runtests.jl index 3dd52d1..f18bd33 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,4 @@ using Test, Documenter, GridVisualizeTools, ColorTypes - -DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes); recursive=true) +DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes); recursive = true) doctest(GridVisualizeTools) -