Skip to content

Commit

Permalink
add makeplanes to common.jl, next steps for plutovista backend
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Sep 16, 2021
1 parent 2e44b22 commit fea51c3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridVisualize"
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
authors = ["Juergen Fuhrmann <[email protected]>"]
version = "0.2.17"
version = "0.2.18"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
43 changes: 43 additions & 0 deletions examples/plutovista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,42 @@ testgridplot2d(PyPlot)
# ╔═╡ 1388c246-be49-4757-a2cc-a685642b6b37
testgridplot2d(PlutoVista)

# ╔═╡ 5eee8f1d-49ca-4e95-bd14-fe415b0c15e5
md"""
## 3D Scalar plot
"""

# ╔═╡ 0c99daca-f9a8-4116-867b-e13461c3e754
function grid3d(;n=15)
X=collect(0:1/n:1)
g=simplexgrid(X,X,X)
end

# ╔═╡ 82ccfd24-0053-4399-9bc8-b2e4010bbc92
function func3d(;n=15)
g=grid3d(n=n)
g, map((x,y,z)->sinpi(2*x)*sinpi(3.5*y)*sinpi(1.5*z),g)
end

# ╔═╡ 8b20f720-5470-4da7-bbb6-b746e887046e
g3,f3=func3d(n=49)

# ╔═╡ c0a0ea34-6fc3-4409-934e-086a1a36f94e
p3d=PlutoVista.tetcontour(resolution=(500,500))

# ╔═╡ 35be5ef4-0664-4196-8f10-cf71ec7cb371
md"""
f: $(@bind flevel Slider(0:0.01:1,show_value=true,default=0.45))
x: $(@bind xplane Slider(0:0.01:1,show_value=true,default=0.45))
y: $(@bind yplane Slider(0:0.01:1,show_value=true,default=0.45))
z: $(@bind zplane Slider(0:0.01:1,show_value=true,default=0.45))
"""

# ╔═╡ ecd941a0-85b7-4bb7-a903-b19a500198e1
tetcontour!(p3d,g3[Coordinates],g3[CellNodes],f3;flevel=flevel,
xplane=xplane,yplane=yplane,zplane=zplane)

# ╔═╡ Cell order:
# ╠═6df3beed-24a7-4b26-a315-0520f4863190
# ╠═9701cbe0-d048-11eb-151b-67dda7b72b71
Expand Down Expand Up @@ -253,3 +289,10 @@ testgridplot2d(PlutoVista)
# ╠═2b3cb0f4-0656-4981-bec6-48785caf2994
# ╠═db488643-2e6b-40d6-ba81-126c752953c5
# ╠═1388c246-be49-4757-a2cc-a685642b6b37
# ╟─5eee8f1d-49ca-4e95-bd14-fe415b0c15e5
# ╠═0c99daca-f9a8-4116-867b-e13461c3e754
# ╠═82ccfd24-0053-4399-9bc8-b2e4010bbc92
# ╠═8b20f720-5470-4da7-bbb6-b746e887046e
# ╠═c0a0ea34-6fc3-4409-934e-086a1a36f94e
# ╟─35be5ef4-0664-4196-8f10-cf71ec7cb371
# ╠═ecd941a0-85b7-4bb7-a903-b19a500198e1
10 changes: 10 additions & 0 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,13 @@ function markerpoints(points,nmarkers,transform)
end
push!(mpoints,points[end])
end



function makeplanes(xyzmin,xyzmax,x,y,z)
planes=Vector{Vector{Float64}}(undef,0)
x>xyzmin[1] && x<xyzmax[1] && push!(planes,[1,0,0,-x])
y>xyzmin[2] && y<xyzmax[2] && push!(planes,[0,1,0,-y])
z>xyzmin[3] && z<xyzmax[3] && push!(planes,[0,0,1,-z])
planes
end
9 changes: 1 addition & 8 deletions src/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,6 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid , func)
adjust_planes()


function makeplanes(x,y,z)
planes=Vector{Vector{Float64}}(undef,0)
x>xyzmin[1] && x<xyzmax[1] && push!(planes,[1,0,0,-x])
y>xyzmin[2] && y<xyzmax[2] && push!(planes,[0,1,0,-y])
z>xyzmin[3] && z<xyzmax[3] && push!(planes,[0,0,1,-z])
planes
end

if !haskey(ctx,:scene)

Expand Down Expand Up @@ -898,7 +891,7 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid , func)

f=d->make_mesh(marching_tetrahedra(d.g,
d.f,
makeplanes(d.x,d.y,d.z),
makeplanes(xyzmin,xyzmax,d.x,d.y,d.z),
[d.l],
primepoints=hcat(xyzmin,xyzmax),
primevalues=fminmax,
Expand Down
22 changes: 19 additions & 3 deletions src/plutovista.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,25 @@ function scalarplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{2}}, grid,func)
end

gridplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{3}}, grid)=nothing
scalarplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{3}}, grid,func)=nothing



function scalarplot!(ctx, TP::Type{PlutoVistaType}, ::Type{Val{3}}, grid,func)
PlutoVista=ctx[:Plotter]
pts=grid[Coordinates]
tris=grid[CellNodes]

isolines=ctx[:isolines]
fmin,fmax=ctx[:flimits]

if fmin<fmax
isolines=collect(range(fmin,fmax,length=isolines))
end
PlutoVista.backend!(ctx[:figure],backend=ctx[:backend],datadim=3)
PlutoVista.tetcontour!(ctx[:figure],pts,tris,func,
colormap=ctx[:colormap],
flevel=ctx[:flevel],
xplane=ctx[:xplane],
yplane=ctx[:yplane],
zplane=ctx[:zplane],
)
reveal(ctx,TP)
end
6 changes: 1 addition & 5 deletions src/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,7 @@ function scalarplot!(ctx, TP::Type{PyPlotType}, ::Type{Val{3}},grid,func)
ctx[:zplane]=max(xyzmin[3],min(xyzmax[3],ctx[:zplane]) )
ctx[:flevel]=max(fminmax[1],min(fminmax[2],ctx[:flevel]))

makeplanes(x,y,z)=[[1,0,0,-x],
[0,1,0,-y],
[0,0,1,-z]]

ccoord0,faces0,values=marching_tetrahedra(grid,func,makeplanes(ctx[:xplane],ctx[:yplane],ctx[:zplane]),[ctx[:flevel]])
ccoord0,faces0,values=marching_tetrahedra(grid,func,makeplanes(xyzmin,xyzmax,ctx[:xplane],ctx[:yplane],ctx[:zplane]),[ctx[:flevel]])

faces=reshape(reinterpret(Int32,faces0),(3,length(faces0)))
ccoord=reshape(reinterpret(Float32,ccoord0),(3,length(ccoord0)))
Expand Down

2 comments on commit fea51c3

@j-fu
Copy link
Member Author

@j-fu j-fu commented on fea51c3 Sep 16, 2021

Choose a reason for hiding this comment

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

@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/44994

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.2.18 -m "<description of version>" fea51c31bbf04e5bd52da031cf5655c5a2b872d2
git push origin v0.2.18

Please sign in to comment.