Skip to content

Commit f1fc418

Browse files
authored
Subgridplots (#2)
Work with vectors of grid data and functions in order to support subgrid plots in GridVisualize.
1 parent 5225576 commit f1fc418

File tree

11 files changed

+366
-309
lines changed

11 files changed

+366
-309
lines changed

.JuliaFormatter.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
style = "sciml"
2+
always_for_in = false
3+
separate_kwargs_with_semicolon = true
4+
margin = 132

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GridVisualizeTools"
22
uuid = "5573ae12-3b76-41d9-b48c-81d0b6e61cc5"
33
authors = ["Jürgen Fuhrmann <[email protected]>"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

docs/make.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
using Documenter, GridVisualizeTools, ColorTypes
22

33
function mkdocs()
4-
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive=true)
5-
makedocs(sitename="GridVisualizeTools.jl",
4+
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
5+
makedocs(; sitename = "GridVisualizeTools.jl",
66
modules = [GridVisualizeTools],
7-
clean = false,
7+
clean = false,
88
doctest = true,
99
authors = "J. Fuhrmann",
10-
repo="https://github.com/j-fu/GridVisualizeTools.jl",
11-
pages=[
12-
"Home"=>"index.md"
10+
repo = "https://github.com/j-fu/GridVisualizeTools.jl",
11+
pages = [
12+
"Home" => "index.md",
1313
])
1414
if !isinteractive()
15-
deploydocs(repo = "github.com/j-fu/GridVisualizeTools.jl.git", devbranch = "main")
15+
deploydocs(; repo = "github.com/j-fu/GridVisualizeTools.jl.git", devbranch = "main")
1616
end
17-
1817
end
1918

2019
mkdocs()
21-

docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ makeisolevels
9797

9898
```jldoctest
9999
using GridVisualizeTools
100-
makeisolevels(0:0.1:10, 1, (-1,1),3)
100+
makeisolevels(collect(0:0.1:10), 1, (-1,1),3)
101101
# output
102102
([-1.0, 0.0, 1.0], (-1, 1), [-1.0, 0.0, 1.0])
103103
```
104104

105105
```jldoctest
106106
using GridVisualizeTools
107-
makeisolevels(0:0.1:10, 1, (1,-1),3)
107+
makeisolevels(collect(0:0.1:10), 1, (1,-1),3)
108108
# output
109109
([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0])
110110
```
111111

112112
```jldoctest
113113
using GridVisualizeTools
114-
makeisolevels(0:0.1:10, 1, (1,-1),nothing)
114+
makeisolevels(collect(0:0.1:10), 1, (1,-1),nothing)
115115
# output
116116
([0.0, 5.0, 10.0], (0.0, 10.0), [0.0, 5.0, 10.0])
117117
```

src/GridVisualizeTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ include("markerpoints.jl")
1717
export markerpoints
1818

1919
include("planeslevels.jl")
20-
export makeplanes,makeisolevels
20+
export makeplanes, makeisolevels
2121

2222
end # module GridVisualizeTools

src/colors.jl

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,62 @@ $(SIGNATURES)
44
Create customized distinguishable colormap for interior regions.
55
For this we use a kind of pastel colors.
66
"""
7-
region_cmap(n)=distinguishable_colors(max(5,n),
8-
[RGB(0.85,0.6,0.6), RGB(0.6,0.85,0.6),RGB(0.6,0.6,0.85)],
9-
lchoices = range(70, stop=80, length=5),
10-
cchoices = range(25, stop=65, length=15),
11-
hchoices = range(20, stop=360, length=15)
12-
)
7+
function region_cmap(n)
8+
distinguishable_colors(max(5, n),
9+
[RGB(0.85, 0.6, 0.6), RGB(0.6, 0.85, 0.6), RGB(0.6, 0.6, 0.85)];
10+
lchoices = range(70; stop = 80, length = 5),
11+
cchoices = range(25; stop = 65, length = 15),
12+
hchoices = range(20; stop = 360, length = 15))
13+
end
1314

1415
"""
1516
$(SIGNATURES)
1617
1718
Create customized distinguishable colormap for boundary regions.
1819
These use fully saturated colors.
1920
"""
20-
bregion_cmap(n)=distinguishable_colors(max(5,n),
21-
[RGB(1.0,0.0,0.0), RGB(0.0,1.0,0.0), RGB(0.0,0.0,1.0)],
22-
lchoices = range(50, stop=75, length=10),
23-
cchoices = range(75, stop=100, length=10),
24-
hchoices = range(20, stop=360, length=30)
25-
)
26-
27-
21+
function bregion_cmap(n)
22+
distinguishable_colors(max(5, n),
23+
[RGB(1.0, 0.0, 0.0), RGB(0.0, 1.0, 0.0), RGB(0.0, 0.0, 1.0)];
24+
lchoices = range(50; stop = 75, length = 10),
25+
cchoices = range(75; stop = 100, length = 10),
26+
hchoices = range(20; stop = 360, length = 30))
27+
end
2828

2929
"""
3030
$(SIGNATURES)
3131
3232
Create RGB color from color name string.
3333
"""
3434
function Colors.RGB(c::String)
35-
c64=Colors.color_names[c]
36-
RGB(c64[1]/255,c64[2]/255, c64[3]/255)
35+
c64 = Colors.color_names[c]
36+
RGB(c64[1] / 255, c64[2] / 255, c64[3] / 255)
3737
end
3838

39-
4039
"""
4140
$(SIGNATURES)
4241
4342
Create RGB color from color name symbol.
4443
"""
45-
Colors.RGB(c::Symbol)=Colors.RGB(String(c))
44+
Colors.RGB(c::Symbol) = Colors.RGB(String(c))
4645

4746
"""
4847
$(SIGNATURES)
4948
5049
Create RGB color from tuple
5150
"""
52-
Colors.RGB(c::Tuple)=Colors.RGB(c...)
53-
51+
Colors.RGB(c::Tuple) = Colors.RGB(c...)
5452

5553
"""
5654
$(SIGNATURES)
5755
5856
Create color tuple from color description (e.g. string)
5957
"""
60-
rgbtuple(c)=rgbtuple(Colors.RGB(c))
61-
58+
rgbtuple(c) = rgbtuple(Colors.RGB(c))
6259

6360
"""
6461
$(SIGNATURES)
6562
6663
Create color tuple from RGB color.
6764
"""
68-
rgbtuple(c::RGB)=(red(c),green(c),blue(c))
69-
65+
rgbtuple(c::RGB) = (red(c), green(c), blue(c))

src/extraction.jl

Lines changed: 72 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,59 @@ Extract visible tetrahedra - those intersecting with the planes
77
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
88
or trisurf (pyplot)
99
"""
10-
function extract_visible_cells3D(coord,cellnodes,cellregions,nregions,xyzcut;
11-
primepoints=zeros(0,0),Tp=SVector{3,Float32},Tf=SVector{3,Int32})
12-
all_lt=ones(Bool,3)
13-
all_gt=ones(Bool,3)
10+
function extract_visible_cells3D(coord, cellnodes, cellregions, nregions, xyzcut;
11+
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
12+
all_lt = ones(Bool, 3)
13+
all_gt = ones(Bool, 3)
1414

15-
function take(coord,simplex,xyzcut,all_lt,all_gt)
16-
for idim=1:3
17-
all_lt[idim]=true
18-
all_gt[idim]=true
19-
for inode=1:4
20-
c=coord[idim,simplex[inode]]-xyzcut[idim]
21-
all_lt[idim]=all_lt[idim] && (c<0.0)
22-
all_gt[idim]=all_gt[idim] && (c>0.0)
15+
function take(coord, simplex, xyzcut, all_lt, all_gt)
16+
for idim = 1:3
17+
all_lt[idim] = true
18+
all_gt[idim] = true
19+
for inode = 1:4
20+
c = coord[idim, simplex[inode]] - xyzcut[idim]
21+
all_lt[idim] = all_lt[idim] && (c < 0.0)
22+
all_gt[idim] = all_gt[idim] && (c > 0.0)
2323
end
2424
end
25-
tke=false
26-
tke=tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3])
27-
tke=tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3])
28-
tke=tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
25+
tke = false
26+
tke = tke || (!all_lt[1]) && (!all_gt[1]) && (!all_gt[2]) && (!all_gt[3])
27+
tke = tke || (!all_lt[2]) && (!all_gt[2]) && (!all_gt[1]) && (!all_gt[3])
28+
tke = tke || (!all_lt[3]) && (!all_gt[3]) && (!all_gt[1]) && (!all_gt[2])
2929
end
3030

31-
32-
faces=[Vector{Tf}(undef,0) for iregion=1:nregions]
33-
points=[Vector{Tp}(undef,0) for iregion=1:nregions]
34-
35-
for iregion=1:nregions
36-
for iprime=1:size(primepoints,2)
37-
@views push!(points[iregion],Tp(primepoints[:,iprime]))
31+
faces = [Vector{Tf}(undef, 0) for iregion = 1:nregions]
32+
points = [Vector{Tp}(undef, 0) for iregion = 1:nregions]
33+
34+
for iregion = 1:nregions
35+
for iprime = 1:size(primepoints, 2)
36+
@views push!(points[iregion], Tp(primepoints[:, iprime]))
3837
end
3938
end
40-
tet=zeros(Int32,4)
41-
42-
for itet=1:size(cellnodes,2)
43-
iregion=cellregions[itet]
44-
for i=1:4
45-
tet[i]=cellnodes[i,itet]
39+
tet = zeros(Int32, 4)
40+
41+
for itet = 1:size(cellnodes, 2)
42+
iregion = cellregions[itet]
43+
for i = 1:4
44+
tet[i] = cellnodes[i, itet]
4645
end
47-
if take(coord,tet,xyzcut,all_lt,all_gt)
48-
npts=size(points[iregion],1)
46+
if take(coord, tet, xyzcut, all_lt, all_gt)
47+
npts = size(points[iregion], 1)
4948
@views begin
50-
push!(points[iregion],coord[:,cellnodes[1,itet]])
51-
push!(points[iregion],coord[:,cellnodes[2,itet]])
52-
push!(points[iregion],coord[:,cellnodes[3,itet]])
53-
push!(points[iregion],coord[:,cellnodes[4,itet]])
54-
push!(faces[iregion],(npts+1,npts+2,npts+3))
55-
push!(faces[iregion],(npts+1,npts+2,npts+4))
56-
push!(faces[iregion],(npts+2,npts+3,npts+4))
57-
push!(faces[iregion],(npts+3,npts+1,npts+4))
49+
push!(points[iregion], coord[:, cellnodes[1, itet]])
50+
push!(points[iregion], coord[:, cellnodes[2, itet]])
51+
push!(points[iregion], coord[:, cellnodes[3, itet]])
52+
push!(points[iregion], coord[:, cellnodes[4, itet]])
53+
push!(faces[iregion], (npts + 1, npts + 2, npts + 3))
54+
push!(faces[iregion], (npts + 1, npts + 2, npts + 4))
55+
push!(faces[iregion], (npts + 2, npts + 3, npts + 4))
56+
push!(faces[iregion], (npts + 3, npts + 1, npts + 4))
5857
end
5958
end
6059
end
61-
points,faces
60+
points, faces
6261
end
6362

64-
65-
6663
"""
6764
$(SIGNATURES)
6865
@@ -72,57 +69,53 @@ Extract visible boundary faces - those not cut off by the planes
7269
Return corresponding points and facets for each region for drawing as mesh (Makie,MeshCat)
7370
or trisurf (pyplot)
7471
"""
75-
function extract_visible_bfaces3D(coord,bfacenodes,bfaceregions, nbregions, xyzcut;
76-
primepoints=zeros(0,0), Tp=SVector{3,Float32},Tf=SVector{3,Int32})
72+
function extract_visible_bfaces3D(coord, bfacenodes, bfaceregions, nbregions, xyzcut;
73+
primepoints = zeros(0, 0), Tp = SVector{3, Float32}, Tf = SVector{3, Int32})
74+
nbfaces = size(bfacenodes, 2)
75+
cutcoord = zeros(3)
7776

78-
79-
nbfaces=size(bfacenodes,2)
80-
cutcoord=zeros(3)
81-
82-
function take(coord,simplex,xyzcut)
83-
for idim=1:3
84-
all_gt=true
85-
for inode=1:3
86-
c=coord[idim,simplex[inode]]-xyzcut[idim]
87-
all_gt= all_gt && c>0
77+
function take(coord, simplex, xyzcut)
78+
for idim = 1:3
79+
all_gt = true
80+
for inode = 1:3
81+
c = coord[idim, simplex[inode]] - xyzcut[idim]
82+
all_gt = all_gt && c > 0
8883
end
8984
if all_gt
9085
return false
9186
end
9287
end
9388
return true
9489
end
95-
9690

97-
Tc=SVector{3,eltype(coord)}
98-
xcoord=reinterpret(Tc,reshape(coord,(length(coord),)))
99-
100-
101-
faces=[Vector{Tf}(undef,0) for iregion=1:nbregions]
102-
points=[Vector{Tp}(undef,0) for iregion=1:nbregions]
103-
for iregion=1:nbregions
104-
for iprime=1:size(primepoints,2)
105-
@views push!(points[iregion],Tp(primepoints[:,iprime]))
91+
Tc = SVector{3, eltype(coord)}
92+
xcoord = reinterpret(Tc, reshape(coord, (length(coord),)))
93+
94+
faces = [Vector{Tf}(undef, 0) for iregion = 1:nbregions]
95+
points = [Vector{Tp}(undef, 0) for iregion = 1:nbregions]
96+
for iregion = 1:nbregions
97+
for iprime = 1:size(primepoints, 2)
98+
@views push!(points[iregion], Tp(primepoints[:, iprime]))
10699
end
107100
end
108101

109102
# remove some type instability here
110-
function collct(points,faces)
111-
trinodes=[1,2,3]
112-
for i=1:nbfaces
113-
iregion=bfaceregions[i]
114-
trinodes[1]=bfacenodes[1,i]
115-
trinodes[2]=bfacenodes[2,i]
116-
trinodes[3]=bfacenodes[3,i]
117-
if take(coord,trinodes,xyzcut)
118-
npts=size(points[iregion],1)
119-
@views push!(points[iregion],xcoord[trinodes[1]])
120-
@views push!(points[iregion],xcoord[trinodes[2]])
121-
@views push!(points[iregion],xcoord[trinodes[3]])
122-
@views push!(faces[iregion],(npts+1,npts+2,npts+3))
103+
function collct(points, faces)
104+
trinodes = [1, 2, 3]
105+
for i = 1:nbfaces
106+
iregion = bfaceregions[i]
107+
trinodes[1] = bfacenodes[1, i]
108+
trinodes[2] = bfacenodes[2, i]
109+
trinodes[3] = bfacenodes[3, i]
110+
if take(coord, trinodes, xyzcut)
111+
npts = size(points[iregion], 1)
112+
@views push!(points[iregion], xcoord[trinodes[1]])
113+
@views push!(points[iregion], xcoord[trinodes[2]])
114+
@views push!(points[iregion], xcoord[trinodes[3]])
115+
@views push!(faces[iregion], (npts + 1, npts + 2, npts + 3))
123116
end
124117
end
125118
end
126-
collct(points,faces)
127-
points,faces
119+
collct(points, faces)
120+
points, faces
128121
end

0 commit comments

Comments
 (0)