-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathgeometryset.jl
184 lines (144 loc) ยท 5.57 KB
/
geometryset.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------
Makie.plot!(plot::Viz{<:Tuple{GeometrySet}}) = vizgeoms!(plot)
const ObservableVector{T} = Makie.Observable{<:AbstractVector{T}}
function vizgset!(plot, ::Type{<:๐}, pdim::Val, edim::Val, geoms, colorant)
vizgset!(plot, ๐ผ, pdim, edim, geoms, colorant)
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{0}, ::Val, geoms, colorant)
points = Makie.@lift pointify.($geoms)
vizmany!(plot, points, colorant)
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{0}, ::Val, geoms::ObservableVector{<:Point}, colorant)
pointmarker = plot[:pointmarker]
pointsize = plot[:pointsize]
# get raw Cartesian coordinates of points
coords = Makie.@lift map(p -> ustrip.(to(p)), $geoms)
# visualize points with given marker and size
Makie.scatter!(plot, coords, color=colorant, marker=pointmarker, markersize=pointsize, overdraw=true)
end
function vizgset!(plot, ::Type{<:๐}, ::Val{1}, ::Val, geoms, colorant)
showpoints = plot[:showpoints]
meshes = Makie.@lift begin
T = numtype(Meshes.lentype(first($geoms)))
method = MaxLengthDiscretization(T(1000) * u"km")
[discretize(g, method) for g in $geoms]
end
vizmany!(plot, meshes, colorant)
if showpoints[]
vizfacets!(plot, geoms)
end
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{1}, ::Val, geoms, colorant)
showpoints = plot[:showpoints]
meshes = Makie.@lift discretize.($geoms)
vizmany!(plot, meshes, colorant)
if showpoints[]
vizfacets!(plot, geoms)
end
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{1}, ::Val, geoms::ObservableVector{<:Ray}, colorant)
rset = plot[:object]
segmentsize = plot[:segmentsize]
showpoints = plot[:showpoints]
Dim = embeddim(rset[])
Dim โ (2, 3) || error("not implemented")
# visualize as built-in arrows
orig = Makie.@lift [asmakie(ray(0)) for ray in $geoms]
dirs = Makie.@lift [asmakie(ray(1) - ray(0)) for ray in $geoms]
size = Makie.@lift 0.1 * $segmentsize
Makie.arrows!(plot, orig, dirs, color=colorant, arrowsize=size)
if showpoints[]
vizfacets!(plot, geoms)
end
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{2}, ::Val, geoms, colorant)
showsegments = plot[:showsegments]
meshes = Makie.@lift discretize.($geoms)
vizmany!(plot, meshes, colorant)
if showsegments[]
vizfacets!(plot, geoms)
end
end
const PolygonLike = Union{Polygon,MultiPolygon}
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{2}, ::Val{2}, geoms::ObservableVector{<:PolygonLike}, colorant)
showsegments = plot[:showsegments]
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]
# repeat colors if necessary
colors = Makie.@lift mayberepeat($colorant, $geoms)
# visualize as built-in poly
polys = Makie.@lift asmakie($geoms)
if showsegments[]
Makie.poly!(plot, polys, color=colors, strokecolor=segmentcolor, strokewidth=segmentsize)
else
Makie.poly!(plot, polys, color=colors)
end
end
function vizgset!(plot, ::Type{<:๐}, ::Val{2}, ::Val, geoms::ObservableVector{<:Box}, colorant)
showsegments = plot[:showsegments]
meshes = Makie.@lift begin
T = numtype(Meshes.lentype(first($geoms)))
method = MaxLengthDiscretization(T(100) * u"km")
[discretize(g, method) for g in $geoms]
end
vizmany!(plot, meshes, colorant)
if showsegments[]
vizfacets!(plot, geoms)
end
end
function vizgset!(plot, ::Type{<:๐ผ}, ::Val{3}, ::Val, geoms, colorant)
meshes = Makie.@lift discretize.(boundary.($geoms))
vizmany!(plot, meshes, colorant)
end
vizfacets!(plot::Viz{<:Tuple{GeometrySet}}) = vizgeoms!(plot, facets=false)
function vizfacets!(plot::Viz{<:Tuple{GeometrySet}}, geoms)
M = Makie.@lift manifold(first($geoms))
pdim = Makie.@lift paramdim(first($geoms))
edim = Makie.@lift embeddim(first($geoms))
vizgsetfacets!(plot, M[], Val(pdim[]), Val(edim[]), geoms)
end
function vizgsetfacets!(plot, ::Type, ::Val{1}, ::Val, geoms)
pointmarker = plot[:pointmarker]
pointcolor = plot[:pointcolor]
pointsize = plot[:pointsize]
# all boundaries are points or multipoints
points = Makie.@lift filter(!isnothing, boundary.($geoms))
pset = Makie.@lift GeometrySet($points)
viz!(plot, pset, color=pointcolor, pointmarker=pointmarker, pointsize=pointsize)
end
function vizgsetfacets!(plot, ::Type, ::Val{2}, ::Val, geoms)
segmentcolor = plot[:segmentcolor]
segmentsize = plot[:segmentsize]
# all boundaries are 1D geometries
bounds = Makie.@lift filter(!isnothing, boundary.($geoms))
bset = Makie.@lift GeometrySet($bounds)
viz!(plot, bset, color=segmentcolor, segmentsize=segmentsize)
end
function vizgeoms!(plot; facets=false)
gset = plot[:object]
color = plot[:color]
alpha = plot[:alpha]
colormap = plot[:colormap]
colorrange = plot[:colorrange]
# process color spec into colorant
colorant = facets ? nothing : Makie.@lift(process($color, $colormap, $colorrange, $alpha))
# get geometries
geoms = Makie.@lift parent($gset)
# get geometry types
types = Makie.@lift unique(typeof.($geoms))
for G in types[]
inds = Makie.@lift findall(g -> g isa G, $geoms)
gvec = Makie.@lift collect(G, $geoms[$inds])
M = Makie.@lift manifold(first($gvec))
pdim = Makie.@lift paramdim(first($gvec))
edim = Makie.@lift embeddim(first($gvec))
if facets
vizgsetfacets!(plot, M[], Val(pdim[]), Val(edim[]), gvec)
else
cvec = Makie.@lift $colorant isa AbstractVector ? $colorant[$inds] : $colorant
vizgset!(plot, M[], Val(pdim[]), Val(edim[]), gvec, cvec)
end
end
end