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

Switch to new emitter code #140

Merged
merged 24 commits into from
Apr 27, 2021
Merged

Switch to new emitter code #140

merged 24 commits into from
Apr 27, 2021

Conversation

alfredclwong
Copy link
Collaborator

@alfredclwong alfredclwong commented Apr 22, 2021

Examples preview

Changes

  • Update to v0.5.0-DEV (pending detector changes for full v0.5.0 release)
  • Remove old Emitter.jl and emitters.md (fixes #127)
    • Rename emitters_new.md to emitters.md
    • Retain RayGenerator types in new file RayGenerator.jl
  • Rework examples to use new emitters
    • Split Examples.jl into docs.jl and other.jl to clearly see which examples are used in the docs
    • Use CodeTracking macro @code_string to avoid duplicated code between docs and examples (fixes #144)
  • Update tests to use new emitters
  • Update Vis to use new emitters
    • Update raygenerator default arg
    • Remove origingen-related draw functions
  • Add Maybe and MaybeVector types to OpticSim
  • Add a more convenient constructor to Directions.Constant

@alfredclwong alfredclwong added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 22, 2021
BrianGun and others added 6 commits April 22, 2021 12:44
modified Examples.jl drawSchmidth to use new emitters.
renamed Emitter.jl to OldEmitter.jl to find all places where old Emitter code is used.
moved AbstractRayGenerator types from Emitter.jl to RayGenerator.jl
fixed Examples.drawSchmidt so it draws correctly using the new emitter classes.

merge with AbstractOpticalSystem changes
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2021

Codecov Report

Merging #140 (518f0ac) into main (de68aa7) will increase coverage by 1.44%.
The diff coverage is 0.86%.

❗ Current head 518f0ac differs from pull request most recent head 31774b5. Consider uploading reports for the commit 31774b5 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #140      +/-   ##
==========================================
+ Coverage   48.37%   49.81%   +1.44%     
==========================================
  Files          65       64       -1     
  Lines        6667     6424     -243     
==========================================
- Hits         3225     3200      -25     
+ Misses       3442     3224     -218     
Impacted Files Coverage Δ
src/Examples/docs.jl 0.00% <0.00%> (ø)
src/OpticSim.jl 88.88% <ø> (+8.88%) ⬆️
src/Optical/Emitters/Directions.jl 5.47% <0.00%> (+5.47%) ⬆️
src/Vis/Visualization.jl 6.11% <0.00%> (+0.36%) ⬆️
src/Examples/other.jl 1.62% <1.62%> (ø)
src/Optical/Emitters/Emitters.jl 0.00% <0.00%> (-20.00%) ⬇️
src/Geometry/Primitives/Qtype.jl 75.00% <0.00%> (-8.34%) ⬇️
src/Optical/LensAssembly.jl 48.22% <0.00%> (-7.33%) ⬇️
src/Optical/OpticalInterface.jl 63.23% <0.00%> (-4.30%) ⬇️
src/Geometry/CSG/Intersection.jl 48.57% <0.00%> (-2.14%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de68aa7...31774b5. Read the comment docs.

@BrianGun
Copy link
Contributor

@alfredclwong this looks great. Is it ready to go from draft to regular PR? I'm seeing changes you have made that I have also made on another branch and would like to merge your PR into main as soon as possible so I can sync with your version.

@alfredclwong
Copy link
Collaborator Author

@alfredclwong this looks great. Is it ready to go from draft to regular PR? I'm seeing changes you have made that I have also made on another branch and would like to merge your PR into main as soon as possible so I can sync with your version.

Thanks! It's pretty much ready to go, I just wanted to have a crack at syntax highlighting and to get some feedback on the new docs using @code_string. What are the duplicate changes? I agree with the sentiment - merges can be painful.

@friggog
Copy link
Collaborator

friggog commented Apr 24, 2021

Yeah looks great @alfredclwong! Syntax highlighting would be nice as you say, but already this makes life a lot easier - let's make sure to remove all commented code before merging

src/Vis/Visualization.jl Outdated Show resolved Hide resolved
@friggog
Copy link
Collaborator

friggog commented Apr 24, 2021

It would be nice to be able to colour the source surfaces, and perhaps have the default be something different from the ordinary default surface colour so they are distinct? Can't quite follow where/how these are actually getting drawn now with all the diffs and comments

docs/make.jl Outdated Show resolved Hide resolved
@alfredclwong
Copy link
Collaborator Author

It would be nice to be able to colour the source surfaces, and perhaps have the default be something different from the ordinary default surface colour so they are distinct? Can't quite follow where/how these are actually getting drawn now with all the diffs and comments

I looked into colouring surfaces a while back because I was working with waveguides which kept being drawn out in very distracting rainbow-like patterns! We had a discussion about how to implement it, and I think Ran wrote some code, but I can't remember it being added to the main project. I'll revisit it later.

@alfredclwong
Copy link
Collaborator Author

Syntax highlighting is working! See the @setup ... block in examples.md.

The code still needs reshuffling to follow a single convention (see #144, I agree with Charlie). I'm pretty busy this weekend so it'll be a while until I can sit down and code - should be quite easy work though so anyone can do it if you have the time.

@BrianGun
Copy link
Contributor

@alfredclwong this looks great. Is it ready to go from draft to regular PR? I'm seeing changes you have made that I have also made on another branch and would like to merge your PR into main as soon as possible so I can sync with your version.

Thanks! It's pretty much ready to go, I just wanted to have a crack at syntax highlighting and to get some feedback on the new docs using @code_string. What are the duplicate changes? I agree with the sentiment - merges can be painful.

The duplicate code (there's not much) is on the optimization branch.

@alfredclwong alfredclwong force-pushed the new-emitter branch 2 times, most recently from aa30b60 to a787732 Compare April 27, 2021 10:14
this means that all we need to do in examples.md is show the
(syntax-highlighted) code_string and then call the corresponding draw_*
function in an @example block

also consolidated the usage of Maybe{T} and MaybeVector{T} within
OpticSim by definining them within OpticSim.jl (sources.jl still has to
define it separately because it is included directly in deps/build.jl)

fixes #144
@alfredclwong alfredclwong marked this pull request as ready for review April 27, 2021 12:16
@alfredclwong alfredclwong changed the title [WIP] Switch to new emitter code Switch to new emitter code Apr 27, 2021
@@ -18,7 +19,8 @@ using Revise
import GLMakie
import Makie.AbstractPlotting

unzip(a) = map(x -> getfield.(a, x), fieldnames(eltype(a)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this ok to remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anywhere else in the code so ok to remove.

Comment on lines +34 to +37
function Constant(dirx::T,diry::T,dirz::T) where{T<:Real}
return new{T}(Vec3(dirx,diry,dirz))
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrianGun this is copied this from the optimization branch so there shouldn't be any merge conflicts.

@@ -236,6 +236,7 @@ function save(path::String)
AbstractPlotting.resize!(current_main_scene, size)
display(current_main_scene)
end
function save(::Nothing) end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for convenience (instead of checking if isnothing(filename))

Comment on lines -519 to -592
"""
draw!(scene::MakieLayout.LScene, origingenerator::RayOriginGenerator; kwargs...)

Draw the surface representing `origingenerator`.
"""
function draw!(scene::MakieLayout.LScene, origingenerator::Union{RandomRectOriginPoints{T},GridRectOriginPoints{T}}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), color = :white, kwargs...) where {T<:Real}
draw!(scene, Rectangle(Plane(origingenerator.direction, origingenerator.position + position), origingenerator.halfsizeu, origingenerator.halfsizev, origingenerator.uvec, origingenerator.vvec); color = color)
end

function draw!(scene::MakieLayout.LScene, origingenerator::Union{HexapolarOriginPoints{T},RandomEllipseOriginPoints{T}}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), color = :white, kwargs...) where {T<:Real}
draw!(scene, Ellipse(Plane(origingenerator.direction, origingenerator.position + position), origingenerator.halfsizeu, origingenerator.halfsizev, origingenerator.uvec, origingenerator.vvec); color = color)
end

function draw!(scene::MakieLayout.LScene, origingenerator::OriginPoint{T}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), color = :white, kwargs...) where {T<:Real}
draw!(scene, origingenerator.position + position; color = color)
end

"""
draw!(scene::MakieLayout.LScene, raygen::OpticalRayGenerator, norays::Bool = false; kwargs...)

Draw the surface representing `raygen`, as well as some sample [`OpticalRay`](@ref)s eminating from it (providing `norays` is false).
"""
function draw!(scene::MakieLayout.LScene, raygen::OpticalRayGenerator{T}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), norays::Bool = false, kwargs...) where {T<:Real}
if !norays
for r in raygen
draw!(scene, OpticalRay(origin(r) + position, direction(r), power(r), wavelength(r), opl = pathlength(r), nhits = nhits(r), sourcenum = sourcenum(r)); kwargs...)
end
end
if hasproperty(raygen, :sourcenum)
col = indexedcolor(raygen.sourcenum)
else
col = :white
end
if !(nothing === origingen(raygen))
draw!(scene, origingen(raygen), position = position, color = col)
end
end

"""
draw!(scene::MakieLayout.LScene, raygen::GeometricRayGenerator, norays::Bool = false; kwargs...)

Draw the surface representing `raygen`, as well as some sample [`Ray`](@ref)s eminating from it (providing `norays` is false).
"""
function draw!(scene::MakieLayout.LScene, raygen::GeometricRayGenerator{T}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), norays::Bool = false, kwargs...) where {T<:Real}
if !norays
for r in raygen
draw!(scene, Ray(origin(r) + position, direction(r)); kwargs...)
end
end
draw!(scene, origingen(raygen), position = position, color = :white)
end

function draw!(scene::MakieLayout.LScene, pixel::PixelSource{T,C}; kwargs...) where {T<:Real,C}
for (i, raygen) in enumerate(pixel.subpixels)
draw!(scene, raygen; kwargs...)
end
end

function draw!(scene::MakieLayout.LScene, display::BasicDisplayPanel{T,C}; kwargs...) where {T<:Real,C}
draw!(scene, display.generator; kwargs...)
end

function draw!(scene::MakieLayout.LScene, arr::OpticalSourceArray{T}; position::SVector{3,T} = SVector{3,T}(0, 0, 0), kwargs...) where {T<:Real}
for pos in arr.positions
draw!(scene, arr.generator; kwargs..., position = pos + position)
end
end

function draw!(scene::MakieLayout.LScene, arr::OpticalSourceGroup{T}; kwargs...) where {T<:Real}
for gen in arr.generators
draw!(scene, gen; kwargs...)
end
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to remove these?

Comment on lines -8 to +9
rays = RayListSource([OpticalRay([0.0,0.0,0.0],[0.0,0.0,1.0],1.0,.78) for _ in 1:100])
trace(conv,rays)
rays = Emitters.Sources.CompositeSource(translation(-unitZ3()), repeat([Emitters.Sources.Source()], 100))
trace(conv, rays)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still fulfil the original purpose of this test?

using OpticSim, StaticArrays # hide
Vis.draw(CosineOpticalSource(RandomSource(OriginPoint{Float64}(200, direction = SVector(0.0, 0.0, 1.0))), 1.0, 0.45))
Vis.save("assets/source3.png") # hide
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
Copy link
Contributor

@BrianGun BrianGun Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this new example do the same thing as the old one? It doesn't matter so long as the new text matches the new example.

@BrianGun BrianGun merged commit 9595f11 into main Apr 27, 2021
@BrianGun BrianGun deleted the new-emitter branch April 27, 2021 22:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate example/test/doc code Switch to new emitter code
4 participants