Skip to content
This repository was archived by the owner on Apr 28, 2021. It is now read-only.

Commit d60db9a

Browse files
committed
cleaning up
1 parent b748bef commit d60db9a

File tree

15 files changed

+190
-9
lines changed

15 files changed

+190
-9
lines changed

docs/new/3dlines.png

1.23 MB
Loading

docs/new/surface_mesh.png

111 KB
Loading

examples/3dlines.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using GLAbstraction, Colors, Images
2+
# The number of points per line
3+
N = 300
4+
5+
# The scalar parameter for each line
6+
TL = linspace(-2f0 * pi, 2f0 * pi, N)
7+
8+
# We create a list of positions and connections, each describing a line.
9+
# We will collapse them in one array before plotting.
10+
xyz = Point3f0[]
11+
s = RGBA{Float32}[]
12+
13+
# The index of the current point in the total amount of points
14+
nloops = 50
15+
base_colors1 = distinguishable_colors(nloops, RGB{Float64}(1,0,0))
16+
base_colors2 = distinguishable_colors(nloops, RGB{Float64}(1,1,0))
17+
# Create each line one after the other in a loop
18+
for i=1:nloops
19+
append!(xyz, [Point3f0(sin(t), cos((2 + .02 * i) * t), cos((3 + .02 * i) * t)) for t in TL])
20+
unique_colors = base_colors1[i]
21+
hsv = HSV(unique_colors)
22+
println(hsv, " ", unique_colors)
23+
a = sequential_palette(hsv.h, N, s=hsv.s)
24+
color_palette = map(x->RGBA{Float32}(x, 1.0), a)
25+
append!(s, color_palette)
26+
end
27+
28+
using GLVisualize, Reactive
29+
w, r = glscreen()
30+
buff = GLBuffer(s)
31+
x = map(p->p[1], xyz)
32+
y = map(p->p[2], xyz)
33+
z = map(p->p[3], xyz)
34+
view(visualize(x,y,z, :surface), method=:perspective)
35+
r()

examples/dirac_belt.jl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using GeometryTypes, Quaternions, GLVisualize, Reactive, GLAbstraction
2+
function quaternion_belt_trick()
3+
4+
rad1 = 1f0 # outer circle
5+
rad2 = 0.2f0 # inner circle
6+
7+
center1 = Point(rad1,rad1) # left
8+
center2 = Point(rad1+2f0,rad1) # right
9+
10+
u1234 = Quaternion(0.,0.,1.,0.) # gets rotated
11+
axis = Quaternion(0.,0.,0.,1.) # axis of qrotationdd
12+
mi = 80
13+
mj = 10
14+
rxs = zeros(Float32, mi+1,mj+1)
15+
rys = zeros(Float32, mi+1,mj+1)
16+
rzs = zeros(Float32, mi+1,mj+1)
17+
18+
max_frames = 96
19+
dphi = 2*pi/(max_frames-1) # include both ends
20+
w, r = glscreen()
21+
22+
u1234_s = foldp(u1234, bounce(1:max_frames)) do v0, _
23+
qrotation(axis, v0, dphi)
24+
end
25+
xyz = const_lift(plot_belts, rxs, rys, rzs, u1234_s, center1, center2, rad1, rad2)
26+
x = const_lift(getindex, xyz, 1)
27+
view(visualize(
28+
x, const_lift(getindex, xyz, 2), const_lift(getindex, xyz, 3), :surface
29+
))
30+
31+
r()
32+
end
33+
34+
35+
#------------------------------------
36+
37+
function plot_circles(center1, center2, rad1, rad2)
38+
mi = 100
39+
iis = 1:(mi+1)
40+
thetas = 2*pi*(iis-1)/mi
41+
als = cos(thetas)
42+
bls = sin(thetas)
43+
44+
for ii=2:(mi+1)
45+
#plot(center1[1]+rad1*[als[ii-1],als[ii]],center1[2]+rad1*[bls[ii-1],bls[ii]]) # left one
46+
#plot(center1[1]+rad2*[als[ii-1],als[ii]],center1[2]+rad2*[bls[ii-1],bls[ii]])
47+
#plot(center2[1]+rad1*[als[ii-1],als[ii]],center2[2]+rad1*[bls[ii-1],bls[ii]]) # right one
48+
#plot(center2[1]+rad2*[als[ii-1],als[ii]],center2[2]+rad2*[bls[ii-1],bls[ii]])
49+
end
50+
end
51+
#------------------------------------
52+
53+
function plot_belts(rxs, rys, rzs, u1234, center1, center2, rad1, rad2)
54+
mi = 80
55+
mj = 10
56+
iis = 1:(mi+1)
57+
rs = rad1-((rad1-rad2)*(iis-1)/mi)
58+
for ii=1:(mi+1)
59+
jjs = 1:(mj+1)
60+
xs = (rad2/mj)*((jjs-1)-(mj/2))
61+
ys = sqrt(rs[ii]*rs[ii]-xs.*xs)
62+
theta = 2*pi*(ii-1)/mi
63+
64+
for jj=1:(mj+1)
65+
efgh = Quaternion(0., xs[jj], ys[jj], 0.)
66+
wxyz = qrotation(efgh, u1234, theta)
67+
rxs[ii,jj] = center1[1]+wxyz.v1
68+
rys[ii,jj] = center1[2]+wxyz.v2
69+
rzs[ii,jj] = wxyz.v3
70+
end
71+
#plot1(rxs-0.1*rzs, +rys, rzs, center1[1], center1[2], rad2) # left one
72+
#plot1(center2[1]+rxs+0.1*rzs, center2[2]+rys, rzs, center2[1], center2[2], rad2) # right one
73+
end
74+
rxs, rys, rzs
75+
end
76+
77+
#------------------------------------
78+
79+
function plot1(sxs, sys, szs, xc, yc, rad2)
80+
hidz = (szs<0)
81+
txs = sxs-xc
82+
tys = sys-yc
83+
hidr = (((txs.*txs)+(tys.*tys))<(rad2*rad2))
84+
hid = hidr&hidz
85+
sxs[hid] = NaN
86+
sys[hid] = NaN
87+
#plot(sxs,sys) # left one
88+
end
89+
quaternion_belt_trick()
90+
91+
#------------------------------------

examples/image_processing.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ using FileIO, Images, GLVisualize, Reactive, ColorTypes, GLAbstraction, Geometry
22

33
w, r = glscreen()
44
slider_s, slider = vizzedit(1f0:0.1f0:20f0, w.inputs)
5-
6-
img = restrict(map(RGBA{Float32}, load(joinpath(homedir(), "julia.png"))))
5+
# if link is broken, you can just use any path to an arbitrary file on your disk
6+
julia_logo = download("https://camo.githubusercontent.com/e1ae5c7f6fe275a50134d5889a68f0acdd09ada8/687474703a2f2f6a756c69616c616e672e6f72672f696d616765732f6c6f676f5f68697265732e706e67")
7+
img = restrict(map(RGBA{Float32}, load(julia_logo)))
78

89
function myfilter(img, sigma)
910
img = imfilter_gaussian(img, [sigma, sigma])

examples/juliaset.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Calculate the Julia set on a grid
2+
x = [Float32(i)*im for i=-1.5:0.5:500]
3+
y = [Float32(i)*im for i=-1:1:500]
4+
println(size(x))
5+
println(size(y))
6+
z = x + 1im * y
7+
8+
julia = zeros(Float32, size(z))
9+
10+
for i=1:50
11+
z = z^2 - 0.70176 - 0.3842im
12+
julia += 1 / 2f0 + i) * (z * conj(z) > 4)
13+
end
14+
15+
# Display it
16+
view(visualize(julia))
17+
18+
# A view into the "Canyon"
19+
view(65, 27, 322, [30., -13.7, 136])
20+
show()
21+

examples/mesh.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# taken from http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html#mayavi.mlab.mesh
2+
dphi, dtheta = pi/250.0f0, pi/250.0f0
3+
function mgrid(dim1, dim2)
4+
X = [i for i in dim1, j in dim2]
5+
Y = [j for i in dim1, j in dim2]
6+
return X,Y
7+
end
8+
phi,theta = mgrid(0f0:dphi:(pi+dphi*1.5f0), 0f0:dtheta:(2f0*pi+dtheta*1.5f0))
9+
m0 = 4f0; m1 = 3f0; m2 = 2f0; m3 = 3f0; m4 = 6f0; m5 = 2f0; m6 = 6f0; m7 = 4f0;
10+
a = sin(m0*phi).^m1
11+
b = cos(m2*phi).^m3
12+
c = sin(m4*theta).^m5
13+
d = cos(m6*theta).^m7
14+
r = a + b + c + d
15+
x = r.*sin(phi).*cos(theta)
16+
y = r.*cos(phi)
17+
z = r.*sin(phi).*sin(theta)
18+
19+
using GLVisualize, GLAbstraction
20+
w,r = glscreen()
21+
view(visualize(x,y,z, :surface))
22+
r()

src/shader/lines.vert

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{GLSL_VERSION}}
22

3-
in vec2 vertex;
3+
{{vertex_type}} vertex;
44
in float lastlen;
55
//in float thickness;
66
{{color_type}} color;
@@ -16,12 +16,15 @@ out float g_thickness;
1616
vec4 getindex(sampler2D tex, int index);
1717
vec4 getindex(sampler1D tex, int index);
1818

19+
vec4 to_vec4(vec3 v){return vec4(v, 1);}
20+
vec4 to_vec4(vec2 v){return vec4(v, 0, 1);}
21+
1922
void main()
2023
{
2124
g_lastlen = lastlen;
2225
int index = gl_VertexID;
2326
g_id = uvec2(objectid, index+1);
2427
//g_thickness = thickness;
2528
g_color = {{color_calculation}};
26-
gl_Position = projectionview*model*vec4(vertex, 0, 1);
29+
gl_Position = projectionview*model*to_vec4(vertex);
2730
}

src/visualize/lines.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
visualize_default{T <: Real}(::Union{Texture{Point{2, T}, 1}, Vector{Point{2, T}}}, s::Style{:lines}, kw_args=Dict()) = Dict(
1+
visualize_default{T <: Real, N}(::Union{Texture{Point{N, T}, 1}, Vector{Point{N, T}}}, s::Style{:lines}, kw_args=Dict()) = Dict(
22
:shape => RECTANGLE,
33
:style => FILLED,
44
:transparent_picking => false,
@@ -8,7 +8,7 @@ visualize_default{T <: Real}(::Union{Texture{Point{2, T}, 1}, Vector{Point{2, T}
88
:dotted => false
99
)
1010

11-
function visualize(locations::Signal{Vector{Point{2, Float32}}}, s::Style{:lines}, customizations=visualize_default(locations.value,s))
11+
function visualize{N}(locations::Signal{Vector{Point{N, Float32}}}, s::Style{:lines}, customizations=visualize_default(locations.value,s))
1212
ll = const_lift(lastlen, locations)
1313
maxlength = const_lift(last, ll)
1414

@@ -27,15 +27,15 @@ function lastlen(points)
2727
end
2828
result
2929
end
30-
function visualize{T}(positions::GLBuffer{Point{2, T}}, ll::GLBuffer{T}, maxlength, s::Style{:lines}, data=visualize_default(positions,s))
30+
function visualize{T <: Point, FT <: AbstractFloat}(positions::GLBuffer{T}, ll::GLBuffer{FT}, maxlength, s::Style{:lines}, data=visualize_default(positions,s))
3131
ps = gpu_data(positions)
3232
data[:vertex] = positions
3333
data[:lastlen] = ll
3434
data[:maxlength] = maxlength
3535
data[:max_primitives] = Cint(length(positions)-4)
3636

3737
program = GLVisualizeShader("util.vert", "lines.vert", "lines.geom", "lines.frag", attributes=data)
38-
std_renderobject(
38+
std_renderobject(
3939
data, program,
4040
Input(AABB{Float32}(ps)), GL_LINE_STRIP_ADJACENCY
4141
)

src/visualize_interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ view(c::Composable, screen=ROOT_SCREEN; kw_args...) = view(extract_renderable(c)
5656

5757
default{T}(::T, s::Style) = default(T, s)
5858
default{T <: Colorant}(::Type{T}, s::Style) = RGBA{Float32}(0.78, 0.01, 0.93, 1.0)
59-
default{T <: Colorant}(::Type{Vector{T}}, s::Style) = map(x->RGBA{U8}(x, 1.0), colormap("Blues"))
59+
default{T <: Colorant}(::Type{Vector{T}}, s::Style) = map(x->RGBA{U8}(x, 1.0), colormap("Blues", 20))

0 commit comments

Comments
 (0)