kneemesh
Generate B-rep geometry of knee structures from a segmentation LabelMap, and mesh it with high-quality elements. The meniscus is supported now; lateral and medial tibial, femoral, and patellar cartilage and the bones are planned. For the meniscus:
- B-rep from segmentation labels. Reads a LabelMap (
.nii,.nrrd, or.mhd), fits a centerline through the labeled meniscus, slices its smoothed surface into cross-section contours, and lofts them into a solid B-spline B-rep (.brep) with planar or smooth end caps. - Tetrahedral meshing with linear 4-node or quadratic 10-node tetrahedra.
- Hexahedral meshing with block-structured 8-node, 20-node, or 27-node hexahedra. The solid is split into a butterfly (O-grid) of five blocks, so elements stay well shaped at the meniscus's sharp corners. Optional node optimization (
--optimize true) then raises the scaled Jacobians further, roughly doubling the worst element's on the real test menisci.
Meshes are written in any format gmsh infers from the file extension, such as .msh, .vtk, or .inp.
Documentation: https://comporthobiomech.github.io/kneemesh/
Installation
pip install kneemesh
Usage
The command-line pipelines take a JSON configuration, --option value overrides, or both. kneemesh-brep builds every structure named in the segmentation, and kneemesh-mesh every structure named in --breps; the names, such as lateral_meniscus, pick each structure's pipeline. Outputs are written as <structure><output>, where --output is a suffix such as _hex8.msh. Run kneemesh-brep --help to list every option and its default.
kneemesh-assemble --label-maps '{"lateral_meniscus": "lateral.nii", "medial_meniscus": "medial.nii"}' --output knee.nrrd
kneemesh-brep --label-map knee.nrrd --labels "$(cat knee_labels.json)"
kneemesh-brep --label-map meniscus.nii --labels '{"medial_meniscus": 1}' --meniscus.cap planar
kneemesh-mesh --breps '{"medial_meniscus": "medial_meniscus.brep"}' --element-type tet10 --meniscus.max-size 1.0
A multilabel LabelMap takes --labels naming its values, such as --labels '{"lateral_meniscus": 2, "medial_meniscus": 3}'; values it does not name are ignored. kneemesh-assemble resamples separate single-label LabelMaps onto one grid and writes the multilabel LabelMap with its labels in <stem>_labels.json. kneemesh-brep can also take --label-maps directly and assemble them within the run. Example configurations are in examples/. See the documentation's usage page.
Each run saves the configuration it used, so it can be repeated with --config. Without --config it is saved as settings<timestamp>.json in the working directory. With --config and overrides, the changed configuration is saved beside the original as <name>_modified.json.
Element types
| Elements | B-rep options | Mesh options |
|---|---|---|
| 4-node tetrahedra | --element-type tet4 (the default) |
|
| 10-node tetrahedra | --element-type tet10 |
|
| 8-node hexahedra | --meniscus.hex-blocks true --meniscus.points-per-slice 10 |
--element-type hex8 |
| 20-node hexahedra | --meniscus.hex-blocks true --meniscus.points-per-slice 10 |
--element-type hex20 |
| 27-node hexahedra | --meniscus.hex-blocks true --meniscus.points-per-slice 10 |
--element-type hex27 |
Development
Requires uv.
uv sync
uv run pytest
Build the documentation into docs/_build/html:
uv run --group docs sphinx-build -W -b html docs docs/_build/html
License
Licensed under the Apache License 2.0.
Metadata
Release files for kneemesh 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kneemesh-0.1.1.tar.gz | 46.1 kB | With provenance | Details for kneemesh-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kneemesh-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for kneemesh-0.1.1-py3-none-any.whl |
Total release size: 100.0 kB
Release files / kneemesh-0.1.1.tar.gz
| Download URL | kneemesh-0.1.1.tar.gz |
|---|---|
| Size | 46.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2c614661ddcd20ade29b5d5c8995e2934d548d401dff5c8080fdbebfbd4cbf1
|
|
BLAKE2b-256 checksum How to use checksums |
3ac2d2bf653e2780cc2d895786bc65d52f48f0150eed6afbc26dc8ab68c3b927
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / kneemesh-0.1.1-py3-none-any.whl
| Download URL | kneemesh-0.1.1-py3-none-any.whl |
|---|---|
| Size | 53.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07491e7f62e62bd0f89d2d80267ef4df3c36348c14b41df32782cbb998120f18
|
|
BLAKE2b-256 checksum How to use checksums |
7133b1b566a0de2034a5b753d9a90ef3c52141bc8853cef982ceeae9ec3fdf3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for kneemesh 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for kneemesh-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.