Geometry

Geometry

Bases: BaseModel

Shared geometry wrapper for gdsfactory Component.

This class wraps a gdsfactory Component and provides computed properties that are useful for simulation setup (bounds, ports, etc.).

Attributes:

  • component (Any) –

    The wrapped gdsfactory Component

Example
from gdsfactory.components import straight
c = straight(length=100)
geom = Geometry(component=c)
print(geom.bounds)
(0.0, -0.25, 100.0, 0.25)

GeometryModel dataclass

GeometryModel(
    prisms: dict[str, list[Prism]],
    bbox: tuple[tuple[float, float, float], tuple[float, float, float]],
    layer_bboxes: dict[
        str, tuple[tuple[float, float, float], tuple[float, float, float]]
    ] = dict(),
    layer_mesh_orders: dict[str, int] = dict(),
)

Complete 3D geometry: layers of prisms, ready for visualization.

Attributes:

Prism dataclass

Prism(
    vertices: ndarray,
    z_base: float,
    z_top: float,
    layer_name: str = "",
    material: str = "",
    sidewall_angle: float = 0.0,
    original_polygon: Any = None,
)

A 2D polygon extruded in z. No solver dependency.

Attributes:

  • vertices (ndarray) –

    (N, 2) numpy array of xy coordinates defining the polygon.

  • z_base (float) –

    Bottom z coordinate of the extrusion.

  • z_top (float) –

    Top z coordinate of the extrusion.

  • layer_name (str) –

    Name of the layer this prism belongs to.

  • material (str) –

    Name of the material assigned to this prism.

  • sidewall_angle (float) –

    Sidewall taper angle in degrees (gdsfactory convention).

  • original_polygon (Any) –

    Optional reference to the source Shapely polygon.

extract_geometry_model

extract_geometry_model(layered_component: LayeredComponentBase) -> GeometryModel

Convert a LayeredComponentBase into a GeometryModel with generic Prisms.

For each geometry layer (sorted by mesh_order): 1. Retrieve the merged Shapely polygon from layered_component.polygons. 2. Compute z_base / z_top from get_layer_bbox. 3. Iterate sub-polygons for MultiPolygon geometries. 4. Handle polygons with holes via Delaunay triangulation. 5. Produce Prism objects with (N, 2) numpy vertex arrays.

Parameters:

  • layered_component (LayeredComponentBase) –

    A LayeredComponentBase (or subclass) instance that provides polygons, geometry_layers, and get_layer_bbox.

Returns:

Stack

LayerStack

Bases: BaseModel

Complete layer stack for Palace simulation.

Layer

Bases: BaseModel

Layer information for Palace simulation.

Visualization

plot_prisms_3d

plot_prisms_3d(
    geometry_model: GeometryModel,
    *,
    show_edges: bool = True,
    opacity: float = 0.8,
    color_by_layer: bool = True,
    show_simulation_box: bool = True,
    camera_position: str | None = "isometric",
    notebook: bool = True,
    theme: str = "default",
    **kwargs: Any,
) -> Any | None

Create interactive 3D visualisation of prisms using PyVista.

Parameters:

  • geometry_model (GeometryModel) –

    A GeometryModel with prisms and bbox.

  • show_edges (bool, default: True ) –

    Whether to show edges of the prisms.

  • opacity (float, default: 0.8 ) –

    Base opacity (0.0-1.0). Core layer forced opaque.

  • color_by_layer (bool, default: True ) –

    Colour by layer name.

  • show_simulation_box (bool, default: True ) –

    Draw the simulation bounding box.

  • camera_position (str | None, default: 'isometric' ) –

    "isometric", "xy", "xz", "yz", or custom tuple.

  • notebook (bool, default: True ) –

    Whether running inside Jupyter.

  • theme (str, default: 'default' ) –

    PyVista theme ("default", "dark", "document").

  • **kwargs (Any, default: {} ) –

    Extra args forwarded to pv.Plotter.

Returns:

  • Any | None

    PyVista plotter object for further customisation.

plot_prism_slices

plot_prism_slices(
    geometry_model: GeometryModel,
    x: float | str | None = None,
    y: float | str | None = None,
    z: float | str = "core",
    ax: Axes | None = None,
    legend: bool = True,
    slices: str = "z",
    *,
    overlay: Any | None = None,
) -> Axes | None

Plot cross sections of a GeometryModel with multi-view support.

Parameters:

  • geometry_model (GeometryModel) –

    GeometryModel with prisms and bbox.

  • x (float | str | None, default: None ) –

    X-coordinate (or layer name) for the slice plane.

  • y (float | str | None, default: None ) –

    Y-coordinate (or layer name) for the slice plane.

  • z (float | str, default: 'core' ) –

    Z-coordinate (or layer name) for the slice plane.

  • ax (Axes | None, default: None ) –

    Axes to draw on. If None, a new figure is created.

  • legend (bool, default: True ) –

    Whether to show the legend.

  • slices (str, default: 'z' ) –

    Which slice(s) to plot -- "x", "y", "z", or combinations like "xy", "xz", "yz", "xyz".

  • overlay (Any | None, default: None ) –

    Optional SimOverlay with sim cell / PML / port metadata.

Returns:

  • Axes | None

    plt.Axes when ax was provided, otherwise None

  • Axes | None

    (the figure is shown directly).

create_web_export

create_web_export(
    geometry_model: GeometryModel,
    filename: str = "geometry_3d.html",
    title: str = "3D Geometry Visualization",
) -> str

Export 3D visualisation as standalone HTML (via PyVista).

export_3d_mesh

export_3d_mesh(geometry_model: GeometryModel, filename: str, fmt: str = 'auto') -> None

Export 3D geometry to mesh file (STL, PLY, OBJ, VTK, glTF).