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

Commit

Permalink
Upgrade to a new version of Makie, GLMakie and WGLMakie (#228)
Browse files Browse the repository at this point in the history
* First set of changes to remove explicit references to the AbstractPlotting and Makie Layout modules inside makie as they are removed since Makie version 0.13.
Still need to change the samples but I want to check it agains the new makie version to see the effect.

* removed AbstractPlotting and MakieLAyout from the example notebooks.

* missed a reference to MakieLayout - fixed.

* fix the makie references in the sample notebooks.

* Upgrade: [email protected], [email protected], [email protected]
Added some utility functions for the documentation - currently added them in NotebooksUtilities as they are very similar to the utility functions to support Pluto.
Removed support for older version of Makie due to the fact that we are limiting the version in the project.toml
Seems that the new Makie draw arrows in figures a bit differently than previous versions which cause some changes in some debug features in the Emitters module and a few function in the Vis module.
Changed the support for the 3D, 2Dx and 2Dy buttons in the Makie figures - need to be checked well.
Added first try at producing documentation figures that are interactable - currently just in the Emitters documentation page for 3D drawings.

* a cleaner support for documentation generation - removed the need to override the Makie and Vis functions by adding a mode (:docs) to support the required behavior.
The next step is to support the Pluto notebooks in the same way and remove the function override altogether.
  • Loading branch information
galran authored Jul 13, 2021
1 parent e2e6ae2 commit eae00a8
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 204 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ Distributions = "0.24, 0.25"
FileIO = "1.4"
Format = "1.3"
ForwardDiff = "0.10"
GLMakie = "0.1, 0.2"
HTTP = "0.8, 0.9"
ImageView = "0.10"
Images = "0.23, 0.24"
Ipopt = "0.6"
JSServe = "1"
JuMP = "0.21"
Luxor = "2.10"
Makie = "0.12"
MeshIO = "0.4"
NLopt = "0.6"
Optim = "1.2"
Expand All @@ -85,7 +83,9 @@ Revise = "3.1"
StaticArrays = "1.0"
StringEncodings = "0.3"
Unitful = "1.6"
WGLMakie = "0.3"
ZipFile = "0.9"
Zygote = "0.6"
julia = "1.5.2"
Makie = "0.14"
GLMakie = "0.4"
WGLMakie = "0.4"
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
OpticSim = "24114763-4efb-45e7-af0e-cde916beb153"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
5 changes: 5 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

using Documenter
using OpticSim
import Makie

# override certain functions to allow production of interactive figures
OpticSim.Vis.set_current_mode(:docs)


makedocs(
sitename = "OpticSim.jl",
Expand Down
175 changes: 20 additions & 155 deletions docs/src/emitters.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ The [`OpticSim`](index.html) package comes with various implementations of each

**Note**: All of the examples on this page assume that the following statement was executed:

```@example
dummy = "switching to WGLMakie in order to produce interactive figures with Makie" # hide
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
OpticSim.NotebooksUtils.SetDocsBackend("Web") # hide
```

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters
```
Expand All @@ -49,22 +55,7 @@ Emitters.pointemitter
```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
pt = Emitters.pointemitter([0.0,0.0,.5],.3)
Vis.draw(pt, debug=true)
Vis.save("assets/emitters_example_pointemitter.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_pointemitter.png">
<img width="250" src="../assets/emitters_example_pointemitter.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of a standard point emitter
</td>
</tr></table>
Vis.draw(pt, debug=true, resolution = (800, 600))
```

```@docs
Expand All @@ -74,131 +65,45 @@ Emitters.collimatedemitter
```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
pt = Emitters.collimatedemitter([0.0,0.0,1.0],.5)
Vis.draw(pt, debug=true)
Vis.save("assets/emitters_example_collimatedemitter.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_collimatedemitter.png">
<img width="250" src="../assets/emitters_example_collimatedemitter.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of a standard collimated emitter
</td>
</tr></table>
Vis.draw(pt, debug=true, resolution = (800, 600))
```

### Point origin with various Direction distributions
```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
src = Sources.Source(origins=Origins.Point(), directions=Directions.RectGrid(π/4, π/4, 15, 15))
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_rect_grid.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_rect_grid.png">
<img width="250" src="../assets/emitters_example_rect_grid.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>RectGrid</b> Direction Distribution
</td>
</tr></table>
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
src = Sources.Source(origins=Origins.Point(), directions=Directions.UniformCone(π/6, 1000))
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_uniform_cone.png") # hide
nothing #hide
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_uniform_cone.png">
<img width="250" src="../assets/emitters_example_uniform_cone.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>UniformCone</b> Direction Distribution with 1000 sampled directions
</td>
</tr></table>
```

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
src = Sources.Source(origins=Origins.Point(), directions=Directions.HexapolarCone(π/6, 10))
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_hexapolar_cone.png") # hide
nothing #hide
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_hexapolar_cone.png">
<img width="250" src="../assets/emitters_example_hexapolar_cone.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>HexapolarCone</b> Direction Distribution
</td>
</tr></table>
```

### Various origins distributions

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
src = Sources.Source(origins=Origins.RectGrid(1.0, 1.0, 10, 10), directions=Directions.Constant())
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_origin_rectgrid.png") # hide
nothing #hide
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_origin_rectgrid.png">
<img width="250" src="../assets/emitters_example_origin_rectgrid.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>RectGrid</b> origin distribution
</td>
</tr></table>
```

```@example
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
src = Sources.Source(origins=Origins.Hexapolar(5, 1.0, 2.0), directions=Directions.Constant())
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_origin_hexapolar.png") # hide
nothing #hide
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_origin_hexapolar.png">
<img width="250" src="../assets/emitters_example_origin_hexapolar.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>Hexapolar</b> origin distribution
</td>
</tr></table>
```

### Examples of Angular Power Distribution

Expand All @@ -211,22 +116,7 @@ src = Sources.Source(
directions=Directions.RectGrid(π/6, π/6, 15, 15), # RectGrid Directions
power=AngularPower.Cosine(10.0) # Cosine Angular Power
)
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_angular1.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_angular1.png">
<img width="250" src="../assets/emitters_example_angular1.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>Cosine</b> angular power distribution
</td>
</tr></table>
Vis.draw(src, debug=true, resolution = (800, 600))
```

```@example
Expand All @@ -236,22 +126,7 @@ src = Sources.Source(
directions=Directions.HexapolarCone(π/6, 10), # HexapolarCone Directions
power=AngularPower.Gaussian(2.0, 2.0) # Gaussian Angular Power
)
Vis.draw(src, debug=true)
Vis.save("assets/emitters_example_angular2.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_angular2.png">
<img width="250" src="../assets/emitters_example_angular2.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
An example of <b>Gaussian</b> angular power distribution
</td>
</tr></table>
Vis.draw(src, debug=true, resolution = (800, 600))
```

### Composite Sources - Display Example
Expand Down Expand Up @@ -291,24 +166,14 @@ my_display = Sources.CompositeSource(Tr, pixels)
Vis.draw(my_display) # render the display - nothing but the origins primitives
rays = AbstractArray{OpticalRay{Float64, 3}}(collect(my_display)) # collect the rays generated by the display
Vis.draw!(rays) # render the rays
Vis.save("assets/emitters_example_composite_display.png") # hide
nothing #hide
```

```@raw html
<table><tr>
<td>
<a target="_blank" href="../assets/emitters_example_composite_display.png">
<img width="500" src="../assets/emitters_example_composite_display.png" style="max-width:100%;">
</a>
</td>
<td valign="middle">
A display example using composite sources.
</td>
</tr></table>
```

```@example
dummy = "switching Back to the GLMakie to allow the rest of the pages to work with static figures" # hide
using OpticSim, OpticSim.Geometry, OpticSim.Emitters # hide
OpticSim.NotebooksUtils.SetDocsBackend("Static") # hide
```


## [Spectrum](@id spectrum)
Expand Down
4 changes: 0 additions & 4 deletions docs/src/vis.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,3 @@ Here is a full list of the available drawing function and their associated optio
```@docs
OpticSim.Vis.draw!
```

## Known Issues

If the Makie plot is printing to the console rather than showing properly in a separate window then call `Vis.AbstractPlotting.__init__()`. This will only occur when using a system image including the OpticSim package.
42 changes: 27 additions & 15 deletions src/NotebooksUtils/NotebooksUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module NotebooksUtils

import ...OpticSim

# import Pluto
import PlutoUI
# import Markdown
Expand All @@ -12,6 +14,7 @@ import Format
import Makie
import WGLMakie
import GLMakie
import JSServe

mutable struct Defs
authors::String # authors
Expand Down Expand Up @@ -248,28 +251,37 @@ function SetBackend(defs::Defs, be::String)
if (be == "Web")
@info "Makie backend set to WEB (WGLMakie)"
WGLMakie.activate!()
# this try and catch is for Makie versions below 0.13 (where Abstract Plotting was removed and renamed to Makie)
# the display stack used to get shuffled around such that the Makie display did not take priority.
# with Makie v0.13 and above is should not be nececery but i didn't find a clean way to test for the Makie version
try
Makie.AbstractPlotting.__init__()
Makie.AbstractPlotting.inline!(true)
catch e
Makie.inline!(true) # for version 0.13 and above
end
Makie.inline!(true) # for version 0.13 and above
else
@info "Makie backend set to STATIC (GLMakie)"
GLMakie.activate!()
try
Makie.AbstractPlotting.__init__()
Makie.AbstractPlotting.inline!(true)
catch e
Makie.inline!(true) # for version 0.13 and above
end
Makie.inline!(true) # for version 0.13 and above
end

end

"""
function SetDocsBackend(be::String)
Sets the backend for documantation images.
"""
function SetDocsBackend(be::String)
if (be == "Web")
WGLMakie.activate!()
Makie.__init__();
Makie.inline!(true)

return JSServe.Page(exportable=true, offline=true)
else
GLMakie.activate!()
Makie.__init__();
Makie.inline!(false)
return nothing
end
end



"""
InitNotebook(; port=8449)
Expand Down
8 changes: 0 additions & 8 deletions src/OpticSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ function __init__()
# this call is to try and keep the original behevior of Makie's default backend after adding the WGLMakie backend to the package
try
GLMakie.activate!()
# this try and catch is for Makie versions below 0.13 (where Abstract Plotting was removed and renamed to Makie)
# the display stack used to get shuffled around such that the Makie display did not take priority.
# with Makie v0.13 and above is should not be nececery but i didn't find a clean way to test for the Makie version
try
Makie.AbstractPlotting.__init__()
catch e
# do nothing
end
catch e
@warn "Unable to activate! the GLMakie backend\n$e"
end
Expand Down
Loading

0 comments on commit eae00a8

Please sign in to comment.