Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

BrianGun/issue257 #264

Merged
merged 26 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7784b97
Tessellation tools: clusters
BrianGun Aug 5, 2021
a4c0aef
see previous commit
BrianGun Aug 5, 2021
f2bb9fc
started working on lattice clusters
BrianGun Aug 5, 2021
c32fb5b
Tessellation tools: clusters
BrianGun Aug 6, 2021
f044b63
Tessellation tools: clusters
BrianGun Aug 6, 2021
a1eecaf
added another cluster shape hexRGBW()
BrianGun Aug 7, 2021
e114b3d
Tessellation tools: clusters
BrianGun Aug 8, 2021
1aa6e9c
Tessellation tools: clusters
BrianGun Aug 9, 2021
a8676df
Tessellation tools: clusters
BrianGun Aug 10, 2021
b31a412
Merge branch 'main' into BrianGun/issue257
BrianGun Aug 10, 2021
2e322d4
Tessellation tools: clusters
BrianGun Aug 10, 2021
2c5057c
hex12RGB function appears to be working. Changed drawing functions fo…
BrianGun Aug 10, 2021
c02d0e0
Tessellation tools: clusters
BrianGun Aug 11, 2021
a477032
deleted include of Projections.jl since file is deleted
BrianGun Aug 11, 2021
f75e69a
Merge branch 'main' into BrianGun/issue257
BrianGun Aug 11, 2021
c9818fa
Tessellation tools: clusters
BrianGun Aug 11, 2021
b67e96d
added license header
BrianGun Aug 11, 2021
5bbd2e2
Tessellation tools: clusters
BrianGun Aug 12, 2021
953c924
fixed bug in hexrectcells. Was returning Vector{Tuple} code had chang…
BrianGun Aug 12, 2021
aa49478
updated all examples in repeatin_structure_examples.jl to work with c…
BrianGun Aug 12, 2021
e2481d4
fixed bug in tests. Had incorrect name for hexdrawneighbors().
BrianGun Aug 12, 2021
d4b2ad0
Tessellation tools: clusters
BrianGun Aug 13, 2021
d181eb4
modifying get_shapes to use lattice functions better
BrianGun Aug 14, 2021
ddda1e0
Tessellation tools: clusters
BrianGun Aug 14, 2021
168c23e
changed keyword radius to size for consistency
BrianGun Aug 14, 2021
6cff034
finished modifying get_shapes
BrianGun Aug 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Examples/Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Luxor

include("docs_examples.jl")
include("other_examples.jl")
include("repeating_structure_examples.jl.jl")
include("repeating_structure_examples.jl")

end #module Examples
export Examples
107 changes: 107 additions & 0 deletions src/Examples/repeating_structure_examples.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# MIT license
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE in the project root for full license information.



#############################################################################
drawrectlattice() = Vis.drawcells(Repeat.RectangularBasis(),50.0,SMatrix{2,4,Int64}(0,0,0,1,1,0,1,1))
export drawrectlattice

"""draw the 2 ring neighbors of the hex cell at coordinates (0,0)"""
drawhexneighbors() = Vis.drawcells(Repeat.HexBasis1(),50,Repeat.neighbors(Repeat.HexBasis1,(0,0),2))
export drawneighbors

"""draw hex cell at coordinates (0,0) and the 1 and 2 ring neighbors"""
drawhexregion() = Vis.drawcells(Repeat.HexBasis1(),50,Repeat.region(Repeat.HexBasis1,(0,0),2))
export drawhexregion

"""draw hex cells that fit within a rectangular box centered at coordinates (0,0). Use fill color yellow."""
function drawhexrect()
cells = Repeat.hexcellsinbox(2,2)
Vis.drawcells(Repeat.HexBasis1(),50,cells,color = repeat(["yellow"],length(cells)))
end
export drawhexrect

"""draw hex cells that fit within a rectangular box centered at coordinates (0,0). Use random fill colors selected for maximum distinguishability."""
function drawhexrectcolors()
cells = Repeat.hexcellsinbox(4,4)
Vis.drawcells(Repeat.HexBasis1(),30,cells)
end
export drawhexrectcolors

""" Create a LatticeCluser with three elements at (0,0),(-1,0),(-1,1) coordinates in the HexBasis1 lattice"""
function hex3cluster()
clusterelts = SVector((0,0),(-1,0),(-1,1))
eltlattice = HexBasis1()
clusterbasis = LatticeBasis(( -1,2),(2,-1))
return LatticeCluster(clusterbasis,eltlattice,clusterelts)
end
export hex3cluster

""" Create a ClusterWithProperties with three types of elements, R,G,B """
function hex3RGB()
clusterelements = SVector((0,0),(-1,0),(-1,1))
colors = [color("red"),color("green"),color("blue")]
names = ["R","G","B"]
eltlattice = HexBasis1()
clusterbasis = LatticeBasis(( -1,2),(2,-1))
lattice = LatticeCluster(clusterbasis,eltlattice,clusterelements)
properties = DataFrame(Color = colors, Name = names)
return ClusterWithProperties(lattice,properties)
end
export hex3RGB

""" Create a ClusterWithProperties with four types of elements, R,G,B,W """
function hexRGBW()
clusterelements = SVector((0,0),(-1,0),(-1,1),(0,-1))
colors = [color("red"),color("green"),color("blue"),color("white")]
names = ["R","G","B","W"]
eltlattice = HexBasis1()
clusterbasis = LatticeBasis((0,2),(2,-2))
lattice = LatticeCluster(clusterbasis,eltlattice,clusterelements)
properties = DataFrame(Color = colors, Name = names)
return ClusterWithProperties(lattice,properties)
end
export hexRGBW

function hex12RGB()
clusterelements = SVector(
(-1,1),(0,1),
(-1,0),(0,0),(1,0),
(-1,-1),(0,-1),(1,-1),(2,-1),
(0,-2),(1,-2),(2,-2)
)
red = color("red")
grn = color("green")
blu = color("blue")
colors = [
grn,blu,
blu,red,grn,
red,grn,blu,red,
blu,red,grn
]
names = [
"G3","B0",
"B2","R1","G2",
"R0","G1","B1","R3",
"B3","R2","G0"
]
eltlattice = HexBasis3()
clusterbasis = LatticeBasis((2,2),(-3,2))
lattice = LatticeCluster(clusterbasis,eltlattice,clusterelements)
properties = DataFrame(Color = colors, Name = names)
return ClusterWithProperties(lattice,properties)
end
export hex12RGB

""" draw 3 repeats of hex3RGB cluster """
drawhex3RGB() = Vis.draw(hex3RGB(),[0 1 0; 0 0 1])
export drawhex3RGB

""" draw 3 repeats of hex12RGB cluster """
drawhex12RGB() = Vis.draw(hex12RGB(),[0 1 0; 0 0 1])
export drawhex12RGB



23 changes: 0 additions & 23 deletions src/Examples/repeating_structure_examples.jl.jl

This file was deleted.

112 changes: 30 additions & 82 deletions src/Optical/ParaxialAnalysis/HeadEyeModel/Arrangement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,107 +10,55 @@ struct Shape{N, T} <: ArrangementConvexShape{N, T}
_points::Vector{SVector{N, T}}
_coordinates::Tuple{Int,Int}

function Shape(center::SVector{N, T}, points::Vector{SVector{N, T}}, coordinates::Tuple{Int,Int}) where {N, T<:Real}
function Shape(center::SVector{N, T}, points::AbstractVector{SVector{N, T}}, coordinates::Tuple{Int,Int}) where {N, T<:Real}
return new{N, T}(center, points, coordinates)
end

"""convenience function to make Shape constructor more compatible with functions in Repeat module, which use SMatrix{N1,N2} to represent vertices rather than Vector{SVector}"""
function Shape(center::SVector{N, T}, points::SMatrix{N,N2,T}, coordinates::Tuple{Int,Int}) where {N, N2, T<:Real}
return new{N,T}(center, Vector{SVector{N,T}}([points[:,i] for i in 1:N2]),coordinates)
end
end

center(h::Shape) = h._center
points(h::Shape) = h._points
coordinates(h::Shape) = h._coordinates

function get_shapes(basis::Basis{2,T},cells::AbstractMatrix{Int}, radius::T) where{T}
basic_tile = Repeat.tilevertices(basis) * radius
cols = Base.size(cells)[2]
res = Vector{Shape{2, T}}(undef, 0)

get_shapes(type::Type{Any};) = @error "Unknown Type [$type] - available types are :hexagon, :rectangle"

# function get_shapes(type::Symbol; resolution::Tuple{Int,Int}=(2,2), size=1.5)::Vector{Shape{2, Float64}}
# if (type == :hexagon)
# return get_hexagons(resolution, size)
# elseif (type == :rectangle)
# return get_rectangles(resolution, size)
# else
# @error "Unknown Type [$type] - available types are :hexagon, :rectangle"
# return nothing
# end
# end

function get_shapes(::Type{Hexagon}; resolution::Tuple{Int,Int}=(2,2), radius=1.5)::Vector{Shape{2, Float64}}
cells = Repeat.hexcellsinbox(resolution[1],resolution[2])
hexbasis = Repeat.HexBasis1()
basic_tile = Repeat.tilevertices(hexbasis) * radius

res = Vector{Shape{2, Float64}}(undef, 0)
for c in cells
center = SVector(hexbasis[c[1], c[2]]) * radius
points = [(SVector(p...) + center) for p in eachrow(basic_tile)]
for i in 1:cols
cell = cells[:,i]
center = SVector(basis[cell[1], cell[2]]) * radius
points = [(SVector(p) + center) for p in eachcol(basic_tile)]
center = center
push!(res, Shape(center, points, c))
push!(res, Shape(center, points, (cell[1],cell[2])))
end
return res
end

function get_shapes(::Type{Rectangle}; resolution::Tuple{Int,Int}=(2,2), size=1.5)::Vector{Shape{2, Float64}}
if (typeof(size) == Float64)
w = h = size
elseif (typeof(size) == Tuple{Float64, Float64})
w, h = size
else
@error "Unsupported size format [$size] - can be either a Float64 for a square or (Float64, Float64) for a rectangle"
end
get_shapes(type::Type{Any};) = @error "Unknown Type [$type] - available types are Hexagon, Rectangle"

cells = [[c for c in Iterators.product(-resolution[1]:resolution[1], -resolution[2]:resolution[2])]...]
# hexbasis = Repeat.HexBasis1()
# basic_tile = Repeat.tilevertices(hexbasis) * radius
basic_tile = [w h; w -h; -w -h; -w h]
function get_shapes(basis::HexBasis1{2,T};resolution::Tuple{Int,Int}=(2,2), size=1.5) where{T}
println(typeof(Repeat.hexcellsinbox(resolution[1],resolution[2])))
return get_shapes(basis,Repeat.hexcellsinbox(resolution[1],resolution[2]),size)
end

res = Vector{Shape{2, Float64}}(undef, 0)
for c in cells
center = SVector(Float64(c[1])*w*2.0, Float64(c[2])*h*2.0)
points = [(SVector(p...) + center) for p in eachrow(basic_tile)]
center = center
push!(res, Shape(center, points, c))
function get_shapes(basis::RectangularBasis{2,T};resolution::Tuple{Int,Int}=(2,2), size=1.5) where{T}
temp = collect(Iterators.product(-resolution[1]:resolution[1], -resolution[2]:resolution[2]))
cells = reshape(temp,length(temp))
result = Matrix{Int64}(undef,2,length(temp))

for i in 1:length(cells)
result[1,i] = cells[i][1]
result[2,i] = cells[i][2]
end
return res

get_shapes(basis,result,size)
end

# function get_hexagons(resolution::Tuple{Int,Int}=(2,2), radius=1.5)::Vector{Shape{2, Float64}}
# cells = Repeat.hexcellsinbox(resolution[1],resolution[2])
# hexbasis = Repeat.HexBasis1()
# basic_tile = Repeat.tilevertices(hexbasis) * radius

# res = Vector{Shape{2, Float64}}(undef, 0)
# for c in cells
# center = SVector(hexbasis[c[1], c[2]]) * radius
# points = [(SVector(p...) + center) for p in eachrow(basic_tile)]
# center = center
# push!(res, Shape(center, points, c))
# end
# return res
# end

# function get_rectangles(resolution::Tuple{Int,Int}=(2,2), size=1.5)::Vector{Shape{2, Float64}}

# if (typeof(size) == Float64)
# w = h = size
# elseif (typeof(size) == Tuple{Float64, Float64})
# w, h = size
# else
# @error "Unsupported size format [$size] - can be either a Float64 for a square or (Float64, Float64) for a rectangle"
# end

# cells = [[c for c in Iterators.product(-resolution[1]:resolution[1], -resolution[2]:resolution[2])]...]
# # hexbasis = Repeat.HexBasis1()
# # basic_tile = Repeat.tilevertices(hexbasis) * radius
# basic_tile = [w h; w -h; -w -h; -w h]

# res = Vector{Shape{2, Float64}}(undef, 0)
# for c in cells
# center = SVector(Float64(c[1])*w*2.0, Float64(c[2])*h*2.0)
# points = [(SVector(p...) + center) for p in eachrow(basic_tile)]
# center = center
# push!(res, Shape(center, points, c))
# end
# return res
# end


function project(shapes::Vector{Shape{2, T}}, csg::OpticSim.CSGTree{T})::Vector{Shape{3, T}} where {T<:Real}
Expand Down
19 changes: 13 additions & 6 deletions src/Optical/ParaxialAnalysis/HeadEyeModel/Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ using StaticArrays
using Colors
import Makie


emitterarray(emitters, transform = identitytransform()) = Emitters.Sources.CompositeSource(transform, emitters)

function example1()

t = identitytransform()
Expand All @@ -36,11 +39,12 @@ function example1()
# Vis.draw!(eli, transparency=true, color=RGBA(1.0, 0.2, 0.2, 0.4))

csg = HeadEye.csg_sphere(radius=20.0)
csg = HeadEye.csg_cylinder(radius = 20.0, added_rotation = rotationX(π/2.0))
# csg = HeadEye.csg_cylinder(radius = 20.0, added_rotation = rotationX(π/2.0))
# csg = HeadEye.csg_plane()

# shapes_2d = HeadEye.get_shapes(HeadEye.Hexagon, resolution=(8,5), radius=1.0)
shapes_2d = HeadEye.get_shapes(HeadEye.Rectangle, resolution=(5,5), size=1.0)
# shapes_2d = HeadEye.get_shapes(HexBasis1(), resolution=(8,5), size=1.0)

shapes_2d = HeadEye.get_shapes(RectangularBasis(), resolution=(5,5), size=1.0)

shapes_3d = HeadEye.project(shapes_2d, csg)

Expand Down Expand Up @@ -71,11 +75,11 @@ function example1()
end

mla = LensAssembly(paraxial_lenses...)
display = Emitters.Sources.CompositeSource(identitytransform(), emitters)
display = emitterarray(emitters)

pupil = HeadEye.pupil(HeadEye.eye(h, :left))
pupil_tr = HeadEye.tr(h, :left_pupil)
detector = Circle(HeadEye.size(pupil) / 2.0, forward(pupil_tr), origin(pupil_tr), interface = opaqueinterface())
detector = Circle(HeadEye.pupilsize(pupil) / 2.0, forward(pupil_tr), origin(pupil_tr), interface = opaqueinterface())
sys = CSGOpticalSystem(mla, detector)


Expand All @@ -89,11 +93,14 @@ function example1()
Vis.drawtracerays(sys; raygenerator=display, trackallrays = true, colorbynhits = true, test = true, numdivisions = 100, drawgen = false)
# Vis.draw!(sys)

Vis.draw!(h, draw_head=true)
Vis.draw!(h, draw_head=false)

Vis.draw!(display, debug=false)
end
end
export example1




end # module Test
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

tr(p::Pupil) = p._tr
text(p::Pupil) = p._size
size(p::Pupil) = p._size
pupilsize(p::Pupil) = p._size


# --------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/Optical/ParaxialAnalysis/HeadEyeModel/HeadEyeModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using ..OpticSim
using ..OpticSim.Geometry
using ..OpticSim.Repeat
using ..OpticSim.Emitters
using ..OpticSim.Repeat

using Colors
using StaticArrays, Statistics
Expand Down
Loading