Skip to content

Commit

Permalink
Subgridplots (#2)
Browse files Browse the repository at this point in the history
Work with vectors of grid data and functions in order to support subgrid plots in GridVisualize.
  • Loading branch information
j-fu authored Feb 4, 2023
1 parent 5225576 commit f1fc418
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 309 deletions.
4 changes: 4 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
style = "sciml"
always_for_in = false
separate_kwargs_with_semicolon = true
margin = 132
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GridVisualizeTools"
uuid = "5573ae12-3b76-41d9-b48c-81d0b6e61cc5"
authors = ["Jürgen Fuhrmann <[email protected]>"]
version = "0.2.1"
version = "0.3.0"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
16 changes: 7 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -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()

6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
```
2 changes: 1 addition & 1 deletion src/GridVisualizeTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ include("markerpoints.jl")
export markerpoints

include("planeslevels.jl")
export makeplanes,makeisolevels
export makeplanes, makeisolevels

end # module GridVisualizeTools
44 changes: 20 additions & 24 deletions src/colors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,62 @@ $(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)
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)
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))
151 changes: 72 additions & 79 deletions src/extraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -72,57 +69,53 @@ 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
end
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
Loading

2 comments on commit f1fc418

@j-fu
Copy link
Member Author

@j-fu j-fu commented on f1fc418 Feb 4, 2023

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

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

Please sign in to comment.