GUI¶
kneemesh-gui runs every stage of the pipeline interactively in a browser: import labels, configure and build each structure’s geometry, mesh it, and view the results in 3D. It is a trame app with an optional dependency:
pip install "kneemesh[gui]"
kneemesh-gui # opens a browser tab
kneemesh-gui --server --port 8080 # serves without opening one
kneemesh-gui --config examples/knee_brep_hex.json # starts from a configuration
kneemesh-gui --view-ratio 2 # renders the 3D view at twice the screen's pixels
The 3D view is rendered on the server at the size it takes on screen in CSS pixels, so on a high-density display it looks soft. --view-ratio renders it at that many pixels per CSS pixel, with its scalar bar and lines scaled to match. Rendering cost grows with the ratio’s square. A ratio of 2.4 showed no image in testing, though 1.5, 2, and 3 work.
The server runs the pipeline on its own machine, and the file dialogs browse that machine’s files, so paths in exported configurations are paths there. Relative paths are relative to the directory the GUI was started in, as for the command-line pipelines. When the server runs elsewhere, the file dialog’s Upload to this directory copies files from your computer into the directory it shows, such as a .mhd with its .raw, selecting the one to open; its Download button saves the selected file to your computer, and the toolbar’s download button saves every file the session has written, geometry, meshes, and exported configurations, as one zip. Anyone who can reach the server can read and write the files its user can, so serve it only where that is acceptable.
Layout¶
The drawer on the left holds a tree above a settings panel; drag the bar between them to resize them. The view on the right shows the structures, with the log of running jobs beneath it.
Settings holds what applies to every structure: the output directory, the B-rep suffix (
output), how several label files are assembled (interpolator,padding), where to write the composed segmentation (assembled_label_map), the overclosure settings (overclosure: whether building every structure also resolves overclosures, theclearance, and thepriority, reordered with each row’s arrows), the default mesh element type, the mesh suffix, andassembled_mesh.Labels lists the imported labels. Add Label opens a file dialog for a
.nii,.nrrd, or.mhdLabelMap. Each value in the file becomes a branch with a Structure Name, a Label Value, and an Include Label checkbox. A file holding one value takes the next label value not yet used, so single-label files of value 1 are numbered 1, 2, 3, … as they are added; the values of a multilabel file keep their own where free. Structures are picked from a<stem>_labels.jsonbeside the file, aswrite_segmentation()writes, or from a file named for its structure, such astibia.nii.Structures lists the nine structures, each with Geometry and Mesh. Selecting one shows its settings below, with a button to build or mesh that structure alone. A structure’s settings are its configuration section, so the two menisci share theirs, as do the tibial and patellar cartilage, and the panel says which structures share them. Own settings gives one of them a section of its own, such as
lateral_meniscus, starting from the shared values; turning it off shares them again and keeps its own values for next time. A mesh page also sets the structure’s own element type (element_types) and the geometry file it meshes, by default the one the geometry step writes. The icons beside a structure show whether its geometry and mesh are built, the target shows it alone in the view until clicked again, and the eye hides it.
Every field’s tooltip is its description from LabelMapBrep or BrepMesh, and invalid values are flagged as they are typed. Empty optional fields, shown as auto or none, take the pipeline’s default.
Running¶
The toolbar builds the geometry of every included structure, meshes every structure whose geometry exists, or shows geometry already written. Building composes the included labels into one segmentation: labels from one file are relabelled in place, keeping its grid, and labels from several files are assembled onto one grid as kneemesh-assemble does. A cartilage needs its bone among the included labels, though building the cartilage alone does not rebuild the bone.
Each job runs in a separate process, so the GUI stays responsive, the toolbar’s stop button cancels it, and a crash in gmsh ends only the job. Outputs are written as the command-line pipelines write them. The view shows each structure’s latest stage, its label, geometry, or mesh, or one stage for all of them, as the toolbar’s selector says. Surfaces are shaded smoothly with point normals, split where faces meet at more than 30 degrees, as ParaView’s Generate Surface Normals makes them, and the faces of second-order elements are subdivided twice, with their edges drawn along their curves. The cutter button clips everything by a plane, keeping the cells beyond it and those it crosses whole (a crinkle clip), so a mesh’s inner elements show as they are. Unpinned, the default, the plane faces the viewer through the camera’s focal point and turns with the view; the pin freezes it where it is, so it turns with the geometry. The slider moves it toward or away from the viewer. The palette selector colors the meshes shown by a quality metric, with a scalar bar spanning their values: each element’s scaled Jacobian or Frobenius aspect ratio, drawn on its outer faces, or each quadrilateral face’s warp (see element_quality()). The metrics are those the meshing step computed and wrote into the mesh: an element’s scaled Jacobian is its smallest at any point it is sampled at, its corners and, if high-order, its Gauss points. Metrics of one element shape, such as tetrahedra’s minimum dihedral angle, leave meshes of other shapes in their structure colors.
Resolve overclosures, on the toolbar and in Settings, moves every structure with geometry apart where they overlap, as kneemesh-brep does with overclosure.enabled (see Overclosure in Pipeline), and rewrites the moved files. Building every structure with Enabled on resolves them right after. A cartilage or meniscus moves only if this session built its file, since moving it needs what it was built from (its sheet, or its contours and the settings they were lofted with), which the session keeps in its temporary directory and removes on exit; geometry built elsewhere stays in place, though structures below it still move out of it. Bones always can move. Moved geometry leaves its mesh out of date, so it is cleared from the view.
Configurations¶
The toolbar imports a kneemesh-brep, kneemesh-mesh, or kneemesh-assemble JSON configuration, telling which by the fields it holds, and exports the settings as configurations for kneemesh-brep and kneemesh-mesh. A geometry configuration names the labels as kneemesh-brep reads them: label_map and labels when they all come from one file at their own values, or label_maps when each is the only value of its own file (kneemesh-brep then numbers them 1, 2, … in order). Any other labels are written as the segmentation they compose, <name>_segmentation.nrrd beside the configuration, for it to read. A mesh configuration’s breps are the geometry files of the included structures and of any structure given its own file.