Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- uses: julia-actions/setup-julia@v3
with:
version: ${{ matrix.version }}
Expand All @@ -53,7 +53,7 @@ jobs:
contents: write
statuses: write
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
- uses: julia-actions/setup-julia@v3
with:
version: '1'
Expand Down
33 changes: 17 additions & 16 deletions docs/DocUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ const GLOBAL_USE_PLACEHOLDERS = true

This is a function to speed up compilation time when building the docs locally.
It checks whether the `include` call is made locally or from within the **CI environment**.
In the former case, script evaluation is avoided and a placeholder figure is created for
In the former case, script evaluation is avoided and a placeholder figure is created for
each `save` call within the script.

Evaluation can be forced by setting `use_placeholder = false`. Global evaluation can be forced
by setting `GLOBAL_USE_PLACEHOLDERS = false` in this file (does not apply for CI env.).
"""
function conditional_include(fname::String; use_placeholder::Bool=!haskey(ENV, "CI"))
function conditional_include(fname::String; use_placeholder::Bool = !haskey(ENV, "CI"))
# Check for global flag if not within CI env.
if !haskey(ENV, "CI") && !GLOBAL_USE_PLACEHOLDERS
use_placeholder = false
end
# Check if to run script
if use_placeholder
if use_placeholder
content = read(fname, String)
# match save("filename") but ignore comments, i.e. # save(...)
pattern = Regex("^[ \\t]*save\\(\\s*\"([^\"]+)\"\\s*,\\s*([a-zA-Z_][a-zA-Z0-9_]*)", "m")
pattern = Regex(
"^[ \\t]*save\\(\\s*\"([^\"]+)\"\\s*,\\s*([a-zA-Z_][a-zA-Z0-9_]*)", "m")
for match in eachmatch(pattern, content)
save_name = match.captures[1]
fig_name = match.captures[2]
Expand All @@ -36,22 +37,22 @@ function conditional_include(fname::String; use_placeholder::Bool=!haskey(ENV, "
matches = collect(eachmatch(npattern, prior_content))
if !isempty(matches)
nmatch = last(matches)
_width = parse(Int, nmatch.captures[1])
_width = parse(Int, nmatch.captures[1])
_height = parse(Int, nmatch.captures[2])
else
@info "Using default height for $fig_name"
_width = 600
_width = 600
_height = 300
end
# save placeholder
fig = Figure(size=(_width, _height))
ax = Axis(fig[1,1], backgroundcolor=:gray)
fig = Figure(size = (_width, _height))
ax = Axis(fig[1, 1], backgroundcolor = :gray)
hidedecorations!(ax)
text!(ax, 0, 0;
text="$save_name\n($_width x $_height)",
align=(:center, :center),
color=:white,
fontsize=20
text = "$save_name\n($_width x $_height)",
align = (:center, :center),
color = :white,
fontsize = 20
)
save(save_name, fig)
@info "Saving placeholder for $save_name (Size: $_width x $_height, fig_var_name=$fig_name)"
Expand All @@ -68,7 +69,7 @@ end
function replace_build_with_src(path::String)
clean_path = abspath(path)
build_segment = joinpath("docs", "build")
src_segment = joinpath("docs", "src")
src_segment = joinpath("docs", "src")
src_path = replace(clean_path, build_segment => src_segment)
return src_path
end
Expand All @@ -79,7 +80,7 @@ end
This function runs the build script and places the images within the docs\\src folder when run outside of the CI/CD pipeline.
It is recommended to use this approach when the rendered image is too computationally intensive for the github runner.
If a prerendered image already exists, it has to be **deleted manually** in order to trigger a re-run.

# Arguments

- `fname`: points to the BMO render script
Expand Down Expand Up @@ -120,9 +121,9 @@ function prerender_include(fname::String, cname::String)
save_name = match.captures[1]
path_name = dirname(cname)
@info "Copying $save_name from \\build to \\src"
cp(joinpath(path_name, save_name), joinpath(location, save_name); force=true)
cp(joinpath(path_name, save_name), joinpath(location, save_name); force = true)
end
return nothing
end

end
end
106 changes: 56 additions & 50 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,89 @@ DocMeta.setdocmeta!(
BeamletOptics,
:DocTestSetup,
:(using BeamletOptics);
recursive=true
recursive = true
)

bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib"))

makedocs(;
modules=[BeamletOptics],
authors="Hugo Uittenbosch <hugo.uittenbosch@dlr.de>, Oliver Kliebisch <oliver.kliebisch@dlr.de> and contributors",
sitename="BeamletOptics.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://JuliaPhysics.github.io/BeamletOptics.jl",
edit_link="master",
assets=String[],
size_threshold_ignore=["reference.md"],
sidebar_sitename = false,
modules = [BeamletOptics],
authors = "Hugo Uittenbosch <hugo.uittenbosch@dlr.de>, Oliver Kliebisch <oliver.kliebisch@dlr.de> and contributors",
sitename = "BeamletOptics.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://JuliaPhysics.github.io/BeamletOptics.jl",
edit_link = "master",
assets = String[],
size_threshold_ignore = ["reference.md"],
sidebar_sitename = false
),
pagesonly=true,
pages=[
pagesonly = true,
pages = [
"Home" => "index.md",
"Getting started" => Any[
"Tutorials" => Any[
"Beam expander" => joinpath("tutorials", "expander.md"),
"Miniature microscope" => joinpath("tutorials", "microscope.md"),
"Michelson interferometer" => joinpath("tutorials", "michelson.md"),
"Beam expander" => joinpath("tutorials", "expander.md"),
"Miniature microscope" => joinpath("tutorials", "microscope.md"),
"Michelson interferometer" => joinpath("tutorials", "michelson.md"),
"Wedge trap" => joinpath("tutorials", "wolit_trap.md"),
"Fabry-Pérot cavity" => joinpath("tutorials", "fabry_perot.md")
],
"Examples" => Any[
"Spherical lenses" => joinpath("examples", "spherical_lenses.md"),
"Aspherical lenses" => joinpath("examples", "aspherical_lenses.md"),
"Double Gauss lens" => joinpath("examples", "double_gauss.md"),
"Lens groups" => joinpath("examples", "lens_groups.md"),
"Double slit" => joinpath("examples", "double_slit.md"),
],
"Spherical lenses" => joinpath("examples", "spherical_lenses.md"),
"Aspherical lenses" => joinpath("examples", "aspherical_lenses.md"),
"Double Gauss lens" => joinpath("examples", "double_gauss.md"),
"Lens groups" => joinpath("examples", "lens_groups.md"),
"Double slit" => joinpath("examples", "double_slit.md"),
"Optical coatings" => joinpath("examples", "coatings.md"),
"Polarizing optics" => joinpath("examples", "polarizing_optics.md")
]
],
"Basics" => Any[
"Introduction" => joinpath("basics", "intro.md"),
"Rays" => joinpath("basics", "rays.md"),
"Introduction" => joinpath("basics", "intro.md"),
"Rays" => joinpath("basics", "rays.md"),
"Beams" => Any[
"Basic beam" => joinpath("basics", "beams", "beams.md"),
"Stigmatic Gaussian" => joinpath("basics", "beams", "stigmatic_beam.md"),
"Astigmatic Gaussian" => joinpath("basics", "beams", "astigmatic_beam.md"),
"Beam groups" => joinpath("basics", "beams", "beam_groups.md"),
"Basic beam" => joinpath("basics", "beams", "beams.md"),
"Stigmatic Gaussian" => joinpath("basics", "beams", "stigmatic_beam.md"),
"Astigmatic Gaussian" => joinpath("basics", "beams", "astigmatic_beam.md"),
"Beam groups" => joinpath("basics", "beams", "beam_groups.md")
],
"Optical components" => Any[
"Overview" => joinpath("basics", "components", "components.md"),
"Mirrors" => joinpath("basics", "components", "mirrors.md"),
"Lenses" => joinpath("basics", "components", "lenses.md"),
"Beamsplitters" => joinpath("basics", "components", "beamsplitters.md"),
"Detectors" => joinpath("basics", "components", "detectors.md"),
"Polarizing components" => joinpath("basics", "components", "polarizers.md"),
"Overview" => joinpath("basics", "components", "components.md"),
"Mirrors" => joinpath("basics", "components", "mirrors.md"),
"Lenses" => joinpath("basics", "components", "lenses.md"),
"Beamsplitters" => joinpath("basics", "components", "beamsplitters.md"),
"Detectors" => joinpath("basics", "components", "detectors.md"),
"Polarizing components" => joinpath("basics", "components", "polarizers.md"),
"Coatings" => joinpath("basics", "components", "coatings.md"),
"Materials & Absorption" => joinpath("basics", "components", "materials.md")
],
"Optical systems" => joinpath("basics", "systems.md"),
"Visualization" => joinpath("basics", "render.md"),
"Optical systems" => joinpath("basics", "systems.md"),
"Visualization" => joinpath("basics", "render.md")
],
"Developer Documentation" => Any[
"Developer guide" => Any[
"Contributing" => joinpath("api", "contribute.md"),
"Documentation development" => joinpath("api", "docdev.md"),
"Contributing" => joinpath("api", "contribute.md"),
"Documentation development" => joinpath("api", "docdev.md")
],
"API design" => Any[
"Introduction" => joinpath("api", "api.md"),
"Conventions" => joinpath("api", "conventions.md"),
"Core design" => joinpath("api", "core.md"),
"Introduction" => joinpath("api", "api.md"),
"Conventions" => joinpath("api", "conventions.md"),
"Core design" => joinpath("api", "core.md"),
"Geometry" => Any[
"Geometry representation" => joinpath("api", "geometry.md"),
"Meshes" => joinpath("api", "meshes.md"),
"SDFs" => joinpath("api", "sdfs.md"),
],
],
"Geometry representation" => joinpath("api", "geometry.md"),
"Meshes" => joinpath("api", "meshes.md"),
"SDFs" => joinpath("api", "sdfs.md")
]
]
],
"Reference" => "reference.md"
],
plugins=[bib],
plugins = [bib]
)

deploydocs(;
repo="github.com/JuliaPhysics/BeamletOptics.jl.git",
devbranch="master",
push_preview=false,
repo = "github.com/JuliaPhysics/BeamletOptics.jl.git",
devbranch = "master",
push_preview = false
)
26 changes: 25 additions & 1 deletion docs/src/api/geometry.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,28 @@ An `AbstractObject` can consist of multiple `AbstractShape`s or even multiple su
```@docs; canonical=false
BeamletOptics.SingleShape
BeamletOptics.MultiShape
```
```

---

## Face Partitioning & Coordinate Transformation

When custom components need to apply selective properties (such as coatings or specific surface behaviors) to different parts of their geometry, the **Face Partitioning API** is used.

### Coordinate Transformation

To determine where an intersection occurred relative to the local reference frame of a shape, BMO uses `world_to_local`:

```@docs; canonical=false
BeamletOptics.world_to_local
```

### Face Identification

To partition the surface normal space of a shape into named faces (e.g., `:front`, `:back`, `:side`, or `:hypotenuse`), custom shapes override `face_id`:

```@docs; canonical=false
BeamletOptics.face_id
```

By default, the fallback implementation assumes that the optical axis is aligned with the `y`-axis and partitions normal space into `:front` ($n_y < -0.1$), `:back` ($n_y > 0.1$), and `:side` otherwise. Subtypes representing prisms or custom geometries should implement specialized methods to identify faces (e.g., `RightAnglePrismSDF` maps normals to `:hypotenuse`, `:leg1`, `:leg2`, `:zpos`, `:zneg`).
29 changes: 28 additions & 1 deletion docs/src/api/sdfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,31 @@ BeamletOptics.UnionSDF
```

!!! info
Since two exact SDFs will only yield an exact union during boolean addition, only the `+` operator is defined. Introducing the `-` operator is still under consideration.
Since two exact SDFs will only yield an exact union during boolean addition, only the `+` operator is defined. Introducing the `-` operator is still under consideration.

---

## Developer Guide: Implementing Custom SDFs

When implementing a custom subtype `MySDF <: AbstractSDF`:

1. **Required Interface**:
- `sdf(s::MySDF, point)`: returns the scalar distance to the surface.
- `bounding_sphere(s::MySDF)`: returns `(center, radius)`.

2. **Analytic Normals (`normal3d`)**:
By default, `normal3d(s, pos)` falls back to finite-difference gradient sampling (`normal_fd`).
For maximum ray-tracing performance, overload `normal3d` with an exact analytical vector function whenever possible:
```julia
function normal3d(s::MySDF, pos)
# return normalized normal vector in world coordinates
end
```

3. **Symbolic Surface Tags (`surface_tag`)**:
To support fast face-selective coating matching (e.g. `:front`, `:back`, `:side`, `:top`, `:bottom`), overload `surface_tag`:
```julia
function surface_tag(s::MySDF, point, normal)
# return :front, :back, :side, etc. based on local coordinates
end
```
3 changes: 3 additions & 0 deletions docs/src/basics/beams/stigmatic_beam.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ The [`GaussianBeamlet`](@ref) implements the [`BeamletOptics.AbstractBeam`](@ref
GaussianBeamlet
```

!!! warning "Scalar Nature & Polarization Limitations"
The basic `GaussianBeamlet` is a **scalar** wave approximation. When interacting with optical coatings, it tracks scalar diagonal amplitude transmission ($J_{1,1}$). For optical setups involving polarizing optics (e.g. waveplates, polarizing beamsplitters, or rotated birefringent elements with cross-polarization $J_{1,2} \neq 0$), use [`AstigmaticGaussianBeamlet`](@ref) or [`PolarizedRay`](@ref), which provide full 3D vectorial Jones calculus tracking.

A [`GaussianBeamlet`](@ref) can be constructed via:

```@docs; canonical=false
Expand Down
Loading