Rendering components and systems
Optical components are rendered by drawing their shape. Example renderings of the individual components can be found in the Mirrors, Lenses, Beamsplitters and Polarizers sections.
Components
The generic methods below cover every BeamletOptics.AbstractObject and every group of components such as an ObjectGroup, whose members are rendered one after another.
BeamletOptics.render! Method
render!(ax, object; material = nothing, edges = nothing, show_bounding_sphere = false, kwargs...)Renders the object into the specified axis. Additional kwargs can be piped through to the backend.
Look
Each object is rendered with the material preset of its component class, e.g. clear glass for lenses and prisms or silver for mirrors. The parts of composite objects (e.g. the prisms and the coating of a CubeBeamsplitter) are rendered with the class of each part. Explicit kwargs like color, alpha or transparency override the preset, for all parts of the object.
material = nothing: one of:refractive,:reflective,:coating,:polarizer,:detector,:mechanicsand:interface, overrides the component classedges = nothing: draws the feature edges of the object, i.e. the sharp edges and the boundary of open surfaces, as thin dark lines. By default in the:cadlook for all materials except:mechanics, in the:modernlook as faint silhouettes of the glass (:refractive,:coatingand:interface) only, seeset_render_look
The cemented interfaces of doublet and triplet lenses are rendered as thin amber surfaces. See also studio_lighting! for the lighting of the scene.
Debugging
show_bounding_sphere = false: also draws the bounding sphere of the shape of the object as a magenta wireframe, for an object of several parts one sphere per part, seerender_bounding_sphere!. A shape without a bounding sphere (e.g. a mesh) gets none. Withlive_render!the spheres follow the object. Callrender_bounding_sphere!directly to change the color or the line width
Examples
It is recommended to use the following snippet in order to generate plots:
using GLMakie, BeamletOptics
fig = Figure()
ax = LScene(fig[1,1]) # or Axis3
render!(ax, my_BMO_obj; color=:white)Additional keyword arguments can be passed. Refer to the Makie and BeamletOptics documentation for supported options for each object.
BeamletOptics.render! Method
render!(ax, group::AbstractObjectGroup; edges = nothing, show_bounding_sphere = false, kwargs...)Renders all objects of the group, merged like the parts of a MultiShape object, see _render_parts!. Nested groups are merged into the meshes of the outermost group. The kwargs, e.g. material or color, and an explicit edges apply to all objects. show_bounding_sphere is consumed by the outermost group, which draws the spheres of all its objects, see render_bounding_sphere!.
Materials
The color, opacity and shading of a component follow its material class, e.g. clear glass for lenses or metallic silver for mirrors, in the active look (:modern or :cad). The materials, feature edges and lighting are described on the Look page. Each default can be overridden with the corresponding keyword argument, e.g. render!(ax, lens; color=:orange), render!(ax, mirror; transparency=true) or render!(ax, mount; material=:mechanics).
Polarizing filters
BeamletOptics.render! Method
render!(ax, pf::PolarizationFilter; kwargs...)Renders the PolarizationFilter pf into the specified ax, optionally with its transmission axis.
Keyword args
show_transmission_axis = true: draws thetransmission_axisas a line on the filteraxis_color = :black: color of the transmission axis lineaxis_linewidth = 2: line width of the transmission axis lineshow_bounding_sphere = false: draws the bounding sphere of the shape, seerender_bounding_sphere!
Remaining kwargs are passed on to the Makie mesh plot.
sourceBeamletOptics.render! Method
render!(ax, lipo::LinearPolarizer; kwargs...)Renders the LinearPolarizer lipo into the specified ax, optionally with its transmission axis. The two substrate halves render like refractive optics, the filter film with the polarizer material of the render look; explicit kwargs (e.g. material, edges) apply to all parts.
Keyword args
show_transmission_axis = true: draws thetransmission_axisas a line on the filteraxis_color = :black: color of the transmission axis lineaxis_linewidth = 2: line width of the transmission axis lineshow_bounding_sphere = false: draws the bounding spheres of the parts, seerender_bounding_sphere!
Remaining kwargs are passed on to the Makie mesh plots of the substrate halves.
sourceSystems
BeamletOptics.render! Method
render!(ax::_RenderEnv, sys::AbstractSystem; kwargs...)Render all objects contained in the system. The kwargs are passed on to render! of each object, e.g. show_bounding_sphere = true to draw the bounding spheres of all shapes.
Bounding spheres
A shape can state a sphere that encloses it, see BeamletOptics.bounding_sphere_of. The solver then skips the shape for every ray that misses the sphere. The spheres are drawn as magenta wireframes, either along with the components via the keyword show_bounding_sphere of render!, or on their own via render_bounding_sphere!, which also takes a single shape or a sphere value. This is a debugging aid, e.g. to check that the sphere of a custom shape encloses the shape and is tight. An object that consists of several parts, e.g. a doublet lens, and an object group show one sphere per part and, in orange (keyword main_color), the main sphere around all parts, which the solver tests first. A shape or object without a sphere (NoBoundingSphere), e.g. a NonInteractableObject, shows none.
using GLMakie, BeamletOptics
lens = SphericalLens(50e-3, -50e-3, 10e-3, 25.4e-3)
mirror = RoundPlanoMirror(25.4e-3, 5e-3)
translate3d!(mirror, [0, 50e-3, 0])
system = System([lens, mirror])
fig = Figure()
ax = LScene(fig[1, 1])
render!(ax, system; show_bounding_sphere = true)
# or separately, e.g. in another color
render!(ax, system)
render_bounding_sphere!(ax, system; color = :orange, linewidth = 2)With live_render! and show_bounding_sphere = true, the spheres follow the components when they are moved, see Live rendering.
BeamletOptics.render_bounding_sphere! Function
render_bounding_sphere!(ax, sphere; color = :magenta, linewidth = 1, kwargs...)
render_bounding_sphere!(ax, shape; color = :magenta, linewidth = 1, kwargs...)
render_bounding_sphere!(ax, object; color = :magenta, main_color = :orange, linewidth = 1, kwargs...)
render_bounding_sphere!(ax, system; color = :magenta, main_color = :orange, linewidth = 1, kwargs...)Draws the bounding sphere of an AbstractShape into ax (an LScene or Axis3), if a suitable backend is loaded: the sphere of BeamletOptics.bounding_sphere_of in world coordinates, for the current position and orientation of the shape, as a wireframe of three great circles (parallel to the xy-, yz- and zx-plane of the world frame) in one lines plot. The solver skips a shape for every ray that misses this sphere, hence the function shows what the solver tests, e.g. to check the bounding_sphere_of method of an own shape type: the sphere must enclose the whole shape and should be tight.
sphere: a
SingleBoundingSphereorMultiBoundingSphereis drawn as it is, aNoBoundingSpheregives no plotshape: one plot, or none if the shape has no bounding sphere
object: the sphere of its shape, or, if it consists of several parts (e.g. a doublet lens, a cube beamsplitter), the sphere of each part, since the solver tests each part on its own, and the main sphere around all parts in
main_color. The solver tests a ray against the main sphere first. An object without a main sphere, because a part has none, gets none. An object without a sphere, e.g. aNonInteractableObject, gets no plot.object group (
ObjectGroup): like an object of several parts, the spheres of its objects and then the main sphere of the groupsystem: the spheres of all its objects
Keyword args
color = :magenta: color of the linesmain_color = :orange: color of the main spheres of objects with several parts and of groups, also those nested in a group. Not passed to the plot.linewidth = 1: line width in screen units
All other kwargs are passed on to the lines plot of Makie. Returns nothing. The spheres are drawn once and do not follow an object that is moved afterwards. For spheres that follow, use the show_bounding_sphere option of render! for objects with live_render!.
render!(ax, system)
render_bounding_sphere!(ax, system)
# or in one call
render!(ax, system; show_bounding_sphere = true)If no suitable backend is loaded, a MissingBackendError will be thrown.
Shapes (advanced)
The following methods render the shapes that components are built from. They are mainly of interest when writing custom components, see the Signed Distance Functions (SDFs) and Meshes pages of the API documentation. A BeamletOptics.UnionSDF or BeamletOptics.DifferenceSDF is rendered as one mesh, which is merged from the analytical meshes of its SDFs if all of them have one, and otherwise sampled via marching cubes. The spherical, aspherical and acylindrical lens surfaces have dedicated analytical renderers that are used automatically when a lens is rendered.
BeamletOptics.render! Method
Render the surface of the sdf into the specified axis. Shapes with an analytic tessellation (see _tessellate) are rendered as a single mesh. Other shapes are rendered based on the marching cubes algorithm, with a resolution of x_resolution, y_resolution and z_resolution samples per axis (defaults: a voxel size of 1/100 of the largest bounding box width, at most 150 samples per axis).
Additional kwargs can be passed into the mesh plot.
sourceBeamletOptics.render! Method
Analytical mesh renderer for a BeamletOptics.ConicSDF. Renders the concave/convex conic front reflective face in color, the cylindrical substrate side wall and the flat rear substrate base in grey into ax.
BeamletOptics.render! Method
render!(ax, d::DifferenceSDF{T, <:ConicSDF}; color=:silver, kwargs...)Analytical mesh renderer for a BeamletOptics.ConicSDF with an axial cylindrical bore (e.g. Cassegrain, Ritchey-Chrétien, or OAP with :collimated through-hole). Other tools are cut from the mesh of the BeamletOptics.ConicSDF, see _difference.
BeamletOptics.render! Method
render!(axis, mesh; kwargs...)Renders the mesh into the specified axis.
Keyword args
show_normals = false: shows a small lineshow_normals_length = 0.01:
Makie kwargs
source