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

Commit

Permalink
Merge branch 'main' into update-version
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianGun authored Apr 7, 2021
2 parents c3e0274 + d68caf3 commit 04db58d
Show file tree
Hide file tree
Showing 9 changed files with 1,436 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Format = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
ImageView = "86fae568-95e7-573e-a6b2-d8a6b900c9ef"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
Expand All @@ -30,6 +32,8 @@ Optim = "429524aa-4258-5aef-a3af-852621145aeb"
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -38,6 +42,7 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StringEncodings = "69024149-9ee7-55f6-a4c4-859efe599b68"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

Expand All @@ -48,7 +53,7 @@ ColorTypes = "0.10"
Colors = "0.12"
DataFrames = "0.22"
Distributions = "0.24"
FileIO = "1.6"
FileIO = "1.4"
ForwardDiff = "0.10"
HTTP = "0.8, 0.9"
ImageView = "0.10"
Expand All @@ -62,6 +67,8 @@ NLopt = "0.6"
Optim = "1.2"
PackageCompiler = "1.2"
Plots = "1.10"
Pluto = "0.12"
PlutoUI = "0.7"
Polynomials = "2.0"
ReverseDiff = "1.7"
StaticArrays = "1.0"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ makedocs(
"Optical" => [
"Systems" => "systems.md",
"Emitters" => "emitters.md",
"Emitters (NEW)" => "emitters_new.md",
"Interfaces" => "interfaces.md",
"Lenses" => "lenses.md"
],
Expand Down
13 changes: 13 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Examples

## Pluto Notebooks

The [`OpticSim`](index.html) package comes with several [`Pluto`](https://github.com/fonsp/Pluto.jl) notebooks (code snippets are coming soon) that allow the user to change and run sample code and view the results in real-time. We highly recommend for you to try these out.
The notebooks are located in the **samples** folder, and you can try them by running:

```julia
import OpticSim.NotebooksUtils as NB # the **as** option was added in Julia v1.6

NB.run_sample("EmittersIntro.jl")
```

The **run_sample** method will **copy** the notebook to your current folder (if it does not exist) and launch Pluto to run the notebook in the browser.

## Cooke Triplet

```@example
Expand Down
264 changes: 264 additions & 0 deletions samples/notebooks/BasicCSG.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
### A Pluto.jl notebook ###
# v0.12.21

using Markdown
using InteractiveUtils

# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
el
end
end

# ╔═╡ 3f2e9c20-974c-11eb-3e97-757b3e0255f4
begin
init_notebook = true
using OpticSim, OpticSim.Geometry, OpticSim.Emitters
import OpticSim.NotebooksUtils as NB

NB.InitNotebook()
end

# ╔═╡ d6c83680-879e-11eb-31d4-7dbda7e93e48
begin
init_notebook

import PlutoUI

using Makie
using AbstractPlotting
using AbstractPlotting.MakieLayout

defs = OpticSim.NotebooksUtils.Defs("ran")

NB.DefsClearHTML(defs)

# this function is needed to allow the visualization scene to be displayed inside a pluto notebook
function Makie.display(obj)
#@info "RG: $obj"
return obj
end

#text of this cell to appear in the notebook
NB.DefsAddHTML(defs, NB.HTMLFromObj(md"Basic Initialization (code)"))

PlutoUI.Show(MIME"text/html"(), NB.DefsHTML(defs))
end

# ╔═╡ 576fb1c0-8ba3-11eb-1c10-fdb51172e2c9
md"# Basic CSG (more to come soon)"

# ╔═╡ aa47f750-8c1f-11eb-21d7-d3a969fb1f6d
begin
csg1_top_surface_caption = "Top Surface"
csg1_bottom_surface_caption = "Bottom Surface"
csg1_cylinder_surface_caption = "Cylinder"
csg1_result_surface_caption = "Intersection Result"
csg1_surfaces = [
csg1_top_surface_caption,
csg1_bottom_surface_caption,
csg1_cylinder_surface_caption,
csg1_result_surface_caption,
]

NB.DefsClearHTML(defs)

csg1_selected_surfaces_info = NB.GetVarInfo(@bind csg1_selected_surfaces PlutoUI.MultiSelect(csg1_surfaces, default=csg1_surfaces))

cyl_rot_x_info = NB.GetVarInfo(@bind cyl_rot_x NB.UISlider(0:30, 0))
cyl_rot_y_info = NB.GetVarInfo(@bind cyl_rot_y NB.UISlider(0:30, 0))
cyl_rot_z_info = NB.GetVarInfo(@bind cyl_rot_z NB.UISlider(0:30, 0))

NB.DefsAddHTML(defs,
"<div>" * csg1_selected_surfaces_info.html *"</div>" *
"Rotation: (x, y, z):" * cyl_rot_x_info.html *
cyl_rot_y_info.html *
cyl_rot_z_info.html
)

PlutoUI.Show(MIME"text/html"(), NB.DefsHTML(defs))
end

# ╔═╡ 5cc45e60-8c1f-11eb-3e4a-17c26a3214f6
begin
function beziersurface()
points = map(
x -> collect(x),
[
(0.0, 0.0, 0.0) (0.0, 0.33, 0.0) (0.0, 0.66, 0.0) (0.0, 1.0, 0.0)
(0.33, 0.0, 0.0) (0.33, 0.33, 1.0) (0.33, 0.66, 1.0) (0.33, 1.0, 0.0)
(0.66, 0.0, 0.0) (0.66, 0.33, 1.0) (0.66, 0.66, 1.0) (0.66, 1.0, 0.0)
(1.0, 0.0, 0.0) (1.0, 0.33, 0.0) (1.0, 0.66, 0.0) (1.0, 1.0, 0.0)
],
)
return BezierSurface{OpticSim.Euclidean,Float64,3,3}(points)
end

# canonic bezier surface
csg1_surf1 = AcceleratedParametricSurface(beziersurface(), 25);

# two transformed copies of the canonic bezier surface
csg1_surf2 = leaf(csg1_surf1, OpticSim.translation(-0.5, -0.5, 0.0))
csg1_surf3 = leaf(csg1_surf1, Transform{Float64}(0.0, Float64(π), 0.0, 0.5, -0.5, 0.0))

# transformed cilinder
csg1_surf4_1 = leaf(Cylinder(0.3, 1.0), OpticSim.translation(0.0, 0.0, 0.0))
csg1_surf4 = leaf(csg1_surf4_1, OpticSim.rotation(deg2rad(cyl_rot_x), deg2rad(cyl_rot_y), deg2rad(cyl_rot_z)))

# intersection result
csg1_surf5 = OpticSim.csgintersection(csg1_surf2,csgintersection(csg1_surf4, csg1_surf3))()

md"## Define Surfaces and Perform CSG Optrations (code)"
end


# ╔═╡ 5f77cfd0-8854-11eb-377c-ef975f9abf63
md"## Initialization Stuff - Can be ignored"

# ╔═╡ 68e9b210-87ad-11eb-0f3a-5bb2dbf7d86c
begin
NB.DefsClearHTML(defs)

default_resolution_info = NB.GetVarInfo(
@bind default_resolution PlutoUI.Select(["Small", "Medium", "Large"], default="Medium")
)
makie_backend_info = NB.GetVarInfo(
@bind makie_backend PlutoUI.Select(["Static", "Web"], default="Static")
)
show_toc_info = NB.GetVarInfo(
@bind show_toc PlutoUI.CheckBox(default=true)
)

fb3_items = [
"Options",
"@ Drawings Size $(default_resolution_info.html)",
"Document Options",
"@ $(show_toc_info.html) Show Table Of Content",
"@ Makie Backend $(makie_backend_info.html) <i><b>(Leave as Static for now)</b></i>",
]

NB.DefsAddHTML(defs,
NB.HTMLFloatingBox(
fb3_items,
name="plutoui-docmenu",
header="Document Menu",
width="25%",
top="45%",
)
)

# wide document layout
NB.DefsAddHTML(defs, NB.HTMLNewDocLayout())

# add TOC
NB.DefsAddHTML(defs,
NB.HTMLFromObj(
PlutoUI.TableOfContents(title = "Document Table of Content", depth = 4)
)*
NB.HTMLFixTOC()
)


#text of this cell to appear in the notebook
NB.DefsAddHTML(defs, NB.HTMLFromObj(md"Define Floating Menu, TOC and New Layout (code)"))

PlutoUI.Show(MIME"text/html"(), NB.DefsHTML(defs))
end


# ╔═╡ 3a5d3ba0-87ae-11eb-1717-93be0b802cab
begin
drawing = 1
OpticSim.NotebooksUtils.SetBackend(defs, makie_backend)
md"Set Makie backend"
end

# ╔═╡ 8ba2f700-8c1f-11eb-209f-b76b9713b576
begin
drawing # notebook only - create dependency on drawing backend - comment if running in REPL

Vis.draw(OpticSim.SVector(0.0, 0.0, 0.0), markersize=0)

if (csg1_top_surface_caption in csg1_selected_surfaces)
Vis.draw!(
csg1_surf2;
wireframe=true,
linewidth=1,
color=:orange,
shaded=false,
normals=false,
numdivisions=50
)
end
if (csg1_bottom_surface_caption in csg1_selected_surfaces)
Vis.draw!(
csg1_surf3;
wireframe=true,
linewidth=1,
color=:blue,
shaded=false,
normals=false,
numdivisions=50
)
end
if (csg1_cylinder_surface_caption in csg1_selected_surfaces)
Vis.draw!(
csg1_surf4;
wireframe=true,
linewidth=1,
color=:red,
shaded=false,
normals=false,
numdivisions=50
)
end
if (csg1_result_surface_caption in csg1_selected_surfaces)
Vis.draw!(
csg1_surf5;
wireframe=true,
linewidth=1,
color=:green,
shaded=true,
normals=false,
numdivisions=50
)
end
Vis.current_main_scene
end

# ╔═╡ 96e423a0-885a-11eb-02a3-8704e8dbdab6
begin
function Vis.scene(resolution = (1000, 1000))
# @info "RG: Vis.Scene Replacement"
scene, layout = MakieLayout.layoutscene(resolution = resolution)
Vis.set_current_main_scene(scene)
lscene = layout[1, 1] = MakieLayout.LScene(scene, scenekw = (camera = Makie.cam3d_cad!, axis_type = Makie.axis3d!, raw = false))
Vis.set_current_3d_scene(lscene)
return scene, lscene
end

function resolution()
if (default_resolution == "Small")
return (300, 300)
elseif (default_resolution == "Medium")
return (500, 500)
else
return (1000, 1000)
end
end
end

# ╔═╡ Cell order:
# ╟─576fb1c0-8ba3-11eb-1c10-fdb51172e2c9
# ╟─5cc45e60-8c1f-11eb-3e4a-17c26a3214f6
# ╟─aa47f750-8c1f-11eb-21d7-d3a969fb1f6d
# ╠═8ba2f700-8c1f-11eb-209f-b76b9713b576
# ╟─5f77cfd0-8854-11eb-377c-ef975f9abf63
# ╠═3f2e9c20-974c-11eb-3e97-757b3e0255f4
# ╠═d6c83680-879e-11eb-31d4-7dbda7e93e48
# ╟─68e9b210-87ad-11eb-0f3a-5bb2dbf7d86c
# ╟─3a5d3ba0-87ae-11eb-1717-93be0b802cab
# ╟─96e423a0-885a-11eb-02a3-8704e8dbdab6
Loading

0 comments on commit 04db58d

Please sign in to comment.