Skip to content

Commit

Permalink
Rotation kwargs (work only for pyplot)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Dec 9, 2020
1 parent bc83304 commit a342074
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableGrids"
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>"]
version = "0.5.3"
version = "0.5.4"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -11,6 +11,7 @@ ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
ExtendableSparse = "95c220a8-a1cf-11e9-0c77-dbfce5f500b3"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
11 changes: 8 additions & 3 deletions src/ExtendableGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ using ExtendableSparse
using AbstractTrees
using InteractiveUtils

using SparseArrays
using Printf
using Random



# for plotting
using Colors
using GeometryBasics
using Observables
using LinearAlgebra


using SparseArrays
using Printf
using Random

include("adjacency.jl")
export Adjacency,VariableTargetAdjacency,FixedTargetAdjacency
Expand Down
2 changes: 2 additions & 0 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ default_plot_kwargs()=Dict{Any,Pair{Any,String}}(
:xplane => Pair(1.0,"xplane for 3D visualization"),
:yplane => Pair(1.0,"yplane for 3D visualization"),
:zplane => Pair(1.0,"zplane for 3D visualization"),
:azim => Pair(-60,"azimuth angle for 3D visualization (in degrees)"),
:elev => Pair(30,"elevation angle for 3D visualization (in degrees)"),
:elevation_factor => Pair(1.0,"Height factor for elevation"),
:resolution => Pair((500,500),"Plot xy resolution"),
:framepos => Pair(1,"Subplot position in frame (VTKView)"),
Expand Down
8 changes: 8 additions & 0 deletions src/plotters/makie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,16 @@ function plot!(ctx, ::Type{MakieType}, ::Type{Val{3}},grid)
Makie.wireframe!(ctx[:scene],Makie.lift(a->a, ctx[:bsegments][i]) , strokecolor=:black)
end
end

# rect = ctx[:scene]
# azim=ctx[:azim]
# elev=ctx[:elev]
# arr = normalize([cosd(azim/2), 0, sind(azim/2), -sind(azim/2)])
# Makie.rotate!(rect, Makie.Quaternionf0(arr...))

ctx[:fullscene]=Makie.vbox(ctx[:scene],Makie.hbox(ctx[:zslider],ctx[:yslider],ctx[:xslider]))
Makie.display(ctx[:fullscene])

else
if ctx[:interior]
regpoints,regfacets=extract_visible_cells3D(grid,xyzcut)
Expand Down
41 changes: 16 additions & 25 deletions src/plotters/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function plot!(ctx, ::Type{PyPlotType}, ::Type{Val{3}},grid)
# See https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting.html

PyPlot=ctx[:Plotter]

prepare_figure!(ctx)
nregions=num_cellregions(grid)
nbregions=num_bfaceregions(grid)
Expand All @@ -148,42 +148,33 @@ function plot!(ctx, ::Type{PyPlotType}, ::Type{Val{3}},grid)
xyzmax[idim]=maximum(coord[idim,:])
end
xyzcut=[ctx[:xplane],ctx[:yplane],ctx[:zplane]]
regpoints,regfacets=extract_visible_cells3D(grid,xyzcut)
bregpoints,bregfacets=extract_visible_bfaces3D(grid,xyzcut)


PyPlot.xlim(xyzmin[1],xyzmax[1])
PyPlot.ylim(xyzmin[2],xyzmax[2])
PyPlot.zlim(xyzmin[3],xyzmax[3])

for ireg=1:nregions
rgb=frgb(PyPlot,ireg,nregions+nbregions)
if size(regfacets[ireg],2)>0
PyPlot.plot_trisurf(regpoints[ireg][1,:],regpoints[ireg][2,:],transpose(regfacets[ireg].-1),regpoints[ireg][3,:],color=rgb)
if ctx[:interior]
regpoints,regfacets=extract_visible_cells3D(grid,xyzcut)
for ireg=1:nregions
rgb=frgb(PyPlot,ireg,nregions+nbregions)
if size(regfacets[ireg],2)>0
PyPlot.plot_trisurf(regpoints[ireg][1,:],regpoints[ireg][2,:],transpose(regfacets[ireg].-1),regpoints[ireg][3,:],color=rgb)
end
end
end

bregpoints,bregfacets=extract_visible_bfaces3D(grid,xyzcut)
for ireg=1:nbregions
rgb=frgb(PyPlot,nregions+ireg,nregions+nbregions)
if size(bregfacets[ireg],2)>0
PyPlot.plot_trisurf(bregpoints[ireg][1,:],bregpoints[ireg][2,:],transpose(bregfacets[ireg].-1),bregpoints[ireg][3,:],color=rgb)
end
end


# # This is a first raw attempt...
# ncells=size(cellnodes,2)
# cen=local_celledgenodes(Tetrahedron3D)
# for icell=1:ncells
# for iedge=1:6
# in1=cellnodes[cen[1,iedge],icell]
# in2=cellnodes[cen[2,iedge],icell]
# X=[ coord[1,in1],coord[1,in2] ]
# Y=[ coord[2,in1],coord[2,in2] ]
# Z=[ coord[3,in1],coord[3,in2] ]
# PyPlot.plot3D(X,Y,Z,color=:black)
# end
# end
axes=PyPlot.gca()
axes.set_xlim3d(xyzmin[1],xyzmax[1])
axes.set_ylim3d(xyzmin[2],xyzmax[2])
axes.set_zlim3d(xyzmin[3],xyzmax[3])
axes.view_init(ctx[:elev],ctx[:azim])


if ctx[:legend]
PyPlot.legend()
PyPlot.legend(loc=ctx[:legend_location])
Expand Down

2 comments on commit a342074

@j-fu
Copy link
Owner Author

@j-fu j-fu commented on a342074 Dec 9, 2020

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/26120

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

Please sign in to comment.