Shape Database Tutorial (Part B): Generating 2D images and meshes
In Part A you created a new entry in the Shape database and built your first mesh from a simple photonic-crystal style pattern. In this part we focus on how those 2D images are generated in the first place, and how they are converted into useful 3D structures for ray tracing and device simulations.
The Shape database is intended for geometries that are hard to describe with simple analytic functions: AFM images, rough interfaces, complex tilings and meshes, as well as imported CAD parts. All of these are handled consistently by starting from a 2D image and then extruding it into 3D.
1. The 2D Image ribbon
Open the Shape editor for any entry in the database (for example the demo shape
from Part A) and switch to the 2D Image ribbon. You should see a toolbar
similar to the one in
??.
Each button generates a new grayscale height map in the right-hand panel of the Shape editor: a honeycomb, a photonic crystal (labelled Generate Xtal), a lens-like profile, a Gaussian spot, a saw wave, a checkerboard pattern or a Perlin-noise rough surface. Every time you click on a button the image is regenerated with the current configuration.
Each generator also has a small arrow beneath it. Clicking this opens a Configure window specific to that pattern. We will look at some concrete examples below.
You are not restricted to synthetic images. The Image button on the left allows you to import true AFM data or any other bitmap. The discretiser interprets the image as a height map: white pixels correspond to maximum height, black pixels to minimum height, and intermediate greys produce intermediate heights. For best results AFM data should be converted to a linear grayscale colour scale; coloured “heat map” palettes are not suitable because the brightness no longer encodes height in a simple way.
Finally, if you left-click with the mouse on the right-hand image you can “paint” pixels black to remove material. This is an easy way to clip unwanted regions or cut out apertures without having to regenerate the entire pattern.
2. Example: Honeycomb contact patterns
Honeycomb structures are useful as transparent contacts, flexible conductive meshes or mechanical supports. To generate one, click Generate Honeycomb. The right-hand panel will update to a hexagonal lattice. When you click Build Mesh, the pattern is extruded into a 3D structure as shown in ??.
The configuration window allows you to change the characteristic spacing in the x and y directions, shift the pattern relative to the underlying grid, set the linewidth and rotate the pattern. Small adjustments here can make a large difference to how the mesh fits into a device structure, so it is worth experimenting a little.
Once you are happy with the 2D pattern, press Build Mesh again to update the 3D view. If the mesh looks overly complicated you can click Edit mesh and reduce the number of triangles. The aim is always to use the fewest triangles that still capture the geometry faithfully: every extra triangle increases the cost of the ray tracing, and in practice the slowdown is usually super-linear rather than linear.
3. Example: AFM-like roughness from Perlin noise
Real interfaces are often rough, and it is useful to be able to generate “fake AFM” surfaces with similar statistics for quick optical experiments. OghmaNano uses Perlin noise, a smooth random field commonly used in computer graphics (see Wikipedia), to mimic this behaviour.
Click Perlin noise in the 2D Image ribbon. A grayscale noise pattern will appear in the right-hand panel. You can adjust the noise parameters via the drop-down configuration menu and click the icon again to regenerate until you obtain the type of roughness you want.
After you have chosen a pattern, press Build Mesh to create the 3D surface. For AFM-like structures it is often better to use a regular mesh rather than the default node-reduction algorithm. A regular grid gives more uniform sampling of the surface height and makes it easier to control the total triangle count. You can switch between these options in the Edit mesh dialog and experiment with different triangle resolutions until you reach a good compromise between fidelity and speed.
4. Post-processing with Filters
Once a 2D image has been generated, you can refine it further using the Filters ribbon, shown in ??. These tools act directly on the right-hand image, before meshing.
The Blur filter smooths sharp steps and corners; the Normalize options rescale the height distribution to a controlled range; Threshold can turn a grayscale pattern into a binary structure; and Boundary can add a solid border around the pattern. All of these operate on the underlying image, so you can combine them freely and then press Build Mesh to see the effect on the 3D surface.
As a concrete example, start from a saw-wave pattern generated with the Saw wave button. After building the mesh you might see something similar to ??. Applying a blur filter softens the edges and produces the smoother surface in ??.
The general strategy is always the same: generate or import a 2D image, apply any filters you need, and then rebuild the mesh. If the resulting mesh still feels too heavy, use Edit mesh to reduce the triangle count while keeping the key features of the surface intact.
5. Importing CAD files (Wavefront OBJ)
As well as image-based shapes, OghmaNano can import simple CAD models via the Wavefront OBJ format (Wikipedia link). This is useful if you already have mechanical designs or lens geometries defined in an external CAD package.
To import a CAD model, click Import CAD file at the top-left of the Shape editor and select an OBJ file. The parser supports the plain text version of the format, consisting mainly of vertex and face definitions. Other CAD formats are not currently recognised.
When importing CAD geometry it is particularly important to keep the triangle count under control. A highly detailed OBJ with tens of thousands of triangles may be perfectly fine for visualisation, but for ray tracing it will be painfully slow and can easily dominate the runtime of an entire simulation. If possible, simplify or decimate the mesh in your CAD tool before bringing it into OghmaNano.
6. A note on closed surfaces
Regardless of whether a shape comes from a 2D image or an imported CAD file, all shapes used by OghmaNano are treated as closed surfaces. Informally, a surface is closed if it completely encloses a volume with no holes or gaps. In mesh terms, every edge in the mesh should belong to exactly two triangles.
The reason for this requirement is that the optical solver needs to know unambiguously when a ray is “inside” or “outside” a structure. If a mesh has open edges, missing faces or self-intersections, rays can leak through the gaps or become trapped in ill-defined regions. This can lead to numerical artefacts or even cause the ray tracer to fail.
Meshes generated from 2D images are always closed by construction: the base plane and side walls are added automatically. CAD imports, however, are only as good as the original file. If you run into problems with a CAD-derived shape, it is worth checking in a CAD viewer whether the object really forms a sealed shell and repairing it if necessary before using it in OghmaNano.