Render methods
DeviceLayout.render!
— Functionrender!(c::Cell, p::Polygon, meta::GDSMeta=GDSMeta())
Render a polygon p
to cell c
, defaulting to plain styling. If p
has more than 8190 (set by DeviceLayout's GDS_POLYGON_MAX
constant), then it is partitioned into smaller polygons which are then rendered. Environment variable ENV["GDS_POLYGON_MAX"]
will override this constant. The partitioning algorithm implements guillotine cutting, that goes through at least one existing vertex and in manhattan directions. Cuts are selected by ad hoc optimzation for "nice" partitions.
render!(c::CoordinateSystem, ent, meta)
Synonym for place!
.
render!(cell::Cell{S}, cs::GeometryStructure;
memoized_cells=Dict{CoordinateSystem, Cell}(),
map_meta = identity,
kwargs...) where {S}
Render a geometry structure (e.g., CoordinateSystem
) to a cell.
Passes each element and its metadata (mapped by map_meta
if a method is supplied) to render!(::Cell, element, ::Meta)
, traversing the references such that if a CoordinateSystem is referred to in multiple places, it will become a single cell referred to in multiple places.
Rendering a GeometryEntity
to a Cell
uses the optional keyword arguments
map_meta
, a function that takes aMeta
object and returns anotherMeta
object (ornothing
, in which case rendering is skipped)
Usage note: calling this function with non-empty dictionary memoized_cells = Dict{CoordinateSystem, Cell}(cs => cell)
is effectively a manual override that forces cs
to render as cell
.
render!(sm::SolidModel, cs::AbstractCoordinateSystem{T}; map_meta=layer, postrender_ops=[], zmap=(_) -> zero(T), kwargs...) where {T}
Render cs
to sm
.
Keywords
map_meta
: Function (m::SemanticMeta) -> name ofPhysicalGroup
(asString
orSymbol
; may also returnnothing
to skip renderingm
)postrender_ops
: Vector of Tuples(destination, op, args, op_kwargs...)
specifying "postrendering" ofPhysicalGroup
s executed after entities have been rendered to tosm
. Each operationop
creates a newPhysicalGroup
defined assm[destination] = op(sm, args...; op_kwargs...)
. That is,args
are the arguments toop
(following the first argument, which is always the modelsm
being rendered to). For most operations, these arguments include the names and dimensions of groups being operated on, andop_kwargs
are the keyword arguments passed toop
. For example,("base", difference_geom!, ("writeable_area", "base_negative"), :remove_object => true, :remove_tool => true)
defines a postrendering step that subtracts thePhysicalGroup
named"base_negative"
from"writeable_area"
(by default using dimension 2 for each group) to define a new group called"base"
. The keyword pairs:remove_object=>true
and:remove_tool=>true
mean that the "object" (first argument) group"writeable_area"
and the "tool" (second argument) group"base_negative"
are both removed when"base"
is created.zmap
: Function (m::SemanticMeta) ->z
coordinate of corresponding elements. Default: Map all metadata to zero.meshing_parameters
:MeshingParameters
allows customization of the top level meshing parameters when calling Gmsh.
Available postrendering operations are translate!
, extrude_z!
, revolve!
, union_geom!
, intersect_geom!
, difference_geom!
, fragment_geom!
, and box_selection
. (The geometric Boolean operations are only available for models using the OpenCASCADE kernel.)
Additional keyword arguments are passed to SolidModels.to_primitives
(which falls back to to_polygons
) and may be used for certain entity types to control how entities of cs
are converted to primitives and added to sm
.
render!(cs::AbstractCoordinateSystem, obj::GeometryEntity, meta::DeviceLayout.Meta,
target::LayoutTarget; kwargs...)
Render obj
to cs
, with metadata mapped to layers and rendering options by target
.
render!(cs::AbstractCoordinateSystem, cs2::GeometryStructure, target::LayoutTarget; kwargs...)
Render cs2
to cs
, with metadata mapped to layers and rendering options by target
.
See LayoutTarget
documentation for details.
render!(
cs::AbstractCoordinateSystem,
sch::Schematic,
target::LayoutTarget;
strict=:error,
kwargs...
)
Run build!(sch, target)
and render the resulting geometry to cs
using target
's rendering options.
The strict
keyword should be :error
, :warn
, or :no
.
The strict=:error
keyword option causes render!
to throw an error if any errors were logged while building component geometries or while rendering geometries to cs
. This is enabled by default, but can be disabled with strict=:no
, in which case any component which was not successfully built will have an empty geometry, and any non-fatal rendering errors will be ignored as usual. Using strict=:no
is recommended only for debugging purposes.
The strict=:warn
keyword option causes render!
to throw an error if any warnings were logged. This is disabled by default. Using strict=:warn
is suggested for use in automated pipelines, where warnings may require human review.
render!(sm::SolidModel, sch::Schematic, target::Target; strict=:error, kwargs...)
Render sch
to sm
, using rendering settings from target
.
The strict
keyword should be :error
, :warn
, or :no
.
The strict=:error
keyword option causes render!
to throw an error if any errors were logged while building component geometries or while rendering geometries to cs
. This is enabled by default, but can be disabled with strict=:no
, in which case any component which was not successfully built will have an empty geometry, and any non-fatal rendering errors will be ignored as usual. Using strict=:no
is recommended only for debugging purposes.
The strict=:warn
keyword option causes render!
to throw an error if any warnings were logged. This is disabled by default. Using strict=:warn
is suggested for use in automated pipelines, where warnings may require human review.
Additional keyword arguments may be used for certain entity types for controlling how geometry entities are converted to primitives and added to sm
.
Rendering arbitrary paths
A Segment
and Style
together define one or more closed curves in the plane. The job of rendering is to approximate these curves by closed polygons. To enable rendering of styles along generic paths in the plane, an adaptive algorithm is used when no other method is available:
DeviceLayout.adapted_grid
— Functionadapted_grid(f, anchors;
max_recursions::Real = 7, max_change = 5°, rand_factor::Real = 0.05,
grid_step = 1.0μm)
Computes a resampled grid
given anchor points so that f.(grid)
is sufficiently smooth. The method used is to create an initial grid around the anchor points and refine intervals. When an interval becomes "straight enough" it is no longer divided. Adapted from a contribution to PlotUtils.jl from Kristoffer Carlsson.
max_recursions
: how many times each interval is allowed to be refined.max_change
: specifies acceptable change between evaluations off
on subsequent grid points, as estimated by the derivative times the distance between grid points. Typically,f
is the angle of a path in the plane, so this is often an angle threshold. This condition is approximately valid in the end result, but may be weakly violated. This condition may be grossly violated ifmax_recursions
is too low.rand_factor
: between anchor points,adapted_grid
will wiggle initial grid points a bit to prevent aliasing. The wiggling is sampled uniformly from the interval:[-rand_factor, rand_factor]
, times the distance between three grid points (e.g.i+1
andi-1
). A random number generator is given a fixed seed every timeadapted_grid
is called, so the rendered results are deterministic.grid_step
: Step size for initial grid points. If you set this to be larger than the maximum anchor point, then the lowest resolution consistent withmax_change
is used (unlessf
has some fast variations that the algorithm might miss).
In some cases, custom rendering methods are implemented when it would improve performance for simple structures or when special attention is required. The rendering methods can specialize on either the Segment
or Style
types, or both.