Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ jobs:
name: cibw-sdist
path: dist/*.tar.gz

# Plugins (Python/tigre/plugins, MATLAB/Plugins) are not in the wheels and
# not built on pull requests, because building takes long. This checks at
# each release that every compiled plugin still builds and imports. It does
# not block the release: a broken plugin shows here as a failed job.
plugins:
name: Build and import the plugins
needs: check_version
runs-on: ubuntu-latest
container: nvidia/cuda:12.8.1-devel-ubuntu24.04
env:
TIGRE_PLUGINS: all
# No GPU here, so compile for one architecture only (much faster).
TIGRE_CUDA_ARCH: "75"
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.3.3
with:
version: 0.13.10
- name: Build and install TIGRE with every plugin
run: |
uv venv --python 3.14
uv pip install --python .venv/bin/python .
- name: Import the plugins
run: .venv/bin/python -c "import tigre.plugins.pct as pct; print('proton CT plugin built, intercepts', pct.INTERCEPTS)"

# TIGRE is not published to PyPI: the `tigre` name there belongs to an
# unrelated project. Wheels and the sdist are attached to the GitHub Release.
github_release:
Expand Down
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ MATLAB and Python on top of shared CUDA code.
`Python/demos/`.
- `MATLAB/`: the MATLAB toolbox (`Algorithms/`, `Utilities/`, `Demos/`,
`Tests/`). `Compile.m` builds the MEX files.
- Plugins (optional parts, outside the core): `Python/tigre/plugins/<name>/`,
`MATLAB/Plugins/<Name>/`, CUDA in `Common/CUDA/plugins/<Name>/`. Compiled
plugins are not built by default (`TIGRE_PLUGINS=<name>|all`,
`Compile <Name>` / `Compile all`). How to add one:
https://cern.github.io/TIGRE/user-guide/plugins.html
- `docs/`: the website (Sphinx, MyST Markdown), https://cern.github.io/TIGRE/.
- `changelog.md`, `CITATION.cff`, `pyproject.toml`: release notes, citation and
version.
Expand Down
36 changes: 36 additions & 0 deletions MATLAB/Utilities/TIGRE.bib
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,40 @@ @article{https://doi.org/10.1002/mp.17002
url = {https://aapm.onlinelibrary.wiley.com/doi/abs/10.1002/mp.17002},
eprint = {https://aapm.onlinelibrary.wiley.com/doi/pdf/10.1002/mp.17002},

pCTCubicSpline

S. Kaser, T. Bergauer, A. Biguri, W. Birkfellner, S. Hatamikia, A. Hirtl, C. Irmler, B. Kirchmayer and F. Ulrich-Pur.
Extension of the open-source TIGRE toolbox for proton imaging.
Zeitschrift fur Medizinische Physik, 33(4):552-566, 2023.
DOI: 10.1016/j.zemedi.2022.08.005

@article{pCT_TIGRE,
author={Kaser, Stefanie and Bergauer, Thomas and Biguri, Ander and Birkfellner, Wolfgang and Hatamikia, Sepideh and Hirtl, Albert and Irmler, Christian and Kirchmayer, Benjamin and Ulrich-Pur, Felix},
title={Extension of the open-source {TIGRE} toolbox for proton imaging},
journal={Zeitschrift f{\"u}r Medizinische Physik},
volume={33},
number={4},
pages={552--566},
year={2023},
doi={10.1016/j.zemedi.2022.08.005}
}

pCTCubicSpline_method

C.-A. Collins-Fekete, S. Brousmiche, S. K. N. Portillo, L. Beaulieu and J. Seco.
A maximum likelihood method for high resolution proton radiography/proton CT.
Physics in Medicine and Biology, 61(23):8232, 2016.
DOI: 10.1088/0031-9155/61/23/8232

@article{pCT_cubic_spline,
author={Collins-Fekete, Charles-Antoine and Brousmiche, S{\'e}bastien and Portillo, Stephen K. N. and Beaulieu, Luc and Seco, Joao},
title={A maximum likelihood method for high resolution proton radiography/proton {CT}},
journal={Physics in Medicine and Biology},
volume={61},
number={23},
pages={8232},
year={2016},
doi={10.1088/0031-9155/61/23/8232}
}

End of Bib (leave this here)
36 changes: 36 additions & 0 deletions Python/tigre/utilities/TIGRE.bib
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,40 @@ @article{sun2010fasks
publisher={IOP Publishing}
}

pCTCubicSpline

S. Kaser, T. Bergauer, A. Biguri, W. Birkfellner, S. Hatamikia, A. Hirtl, C. Irmler, B. Kirchmayer and F. Ulrich-Pur.
Extension of the open-source TIGRE toolbox for proton imaging.
Zeitschrift fur Medizinische Physik, 33(4):552-566, 2023.
DOI: 10.1016/j.zemedi.2022.08.005

@article{pCT_TIGRE,
author={Kaser, Stefanie and Bergauer, Thomas and Biguri, Ander and Birkfellner, Wolfgang and Hatamikia, Sepideh and Hirtl, Albert and Irmler, Christian and Kirchmayer, Benjamin and Ulrich-Pur, Felix},
title={Extension of the open-source {TIGRE} toolbox for proton imaging},
journal={Zeitschrift f{\"u}r Medizinische Physik},
volume={33},
number={4},
pages={552--566},
year={2023},
doi={10.1016/j.zemedi.2022.08.005}
}

pCTCubicSpline_method

C.-A. Collins-Fekete, S. Brousmiche, S. K. N. Portillo, L. Beaulieu and J. Seco.
A maximum likelihood method for high resolution proton radiography/proton CT.
Physics in Medicine and Biology, 61(23):8232, 2016.
DOI: 10.1088/0031-9155/61/23/8232

@article{pCT_cubic_spline,
author={Collins-Fekete, Charles-Antoine and Brousmiche, S{\'e}bastien and Portillo, Stephen K. N. and Beaulieu, Luc and Seco, Joao},
title={A maximum likelihood method for high resolution proton radiography/proton {CT}},
journal={Physics in Medicine and Biology},
volume={61},
number={23},
pages={8232},
year={2016},
doi={10.1088/0031-9155/61/23/8232}
}

End of Bib (leave this here)
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ thank you.
them directly, e.g. `from _minTV import minTV`, now needs `from tigre.utilities.cuda_interface._minTV import minTV`.

### Added
- Docs: a Plugins section in the user guide (what plugins are, how to build them, how to add one) and the proton CT
plugin in the Python and MATLAB API reference. Its papers are in `TIGRE.bib` (`citeme('pCTCubicSpline')` in MATLAB).
- Python proton CT: `tigre.plugins.pct.pCTCubicSpline`, the optimised proton radiographies MATLAB already had.
Not built by default: install with `TIGRE_PLUGINS=pct pip install .` (or `TIGRE_PLUGINS=all`); intercept vector
lengths with `TIGRE_PCT_PIXEL` / `TIGRE_PCT_INTERCEPTS`. Demo: `Python/demos/pRad_demo.py`.
Expand Down
1 change: 1 addition & 0 deletions docs/_ext/tigre_matlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"Utilities/IO/DXChange/DXChangeDataLoader.m",
"Utilities/IO/Dicom/dicomDataLoader.m",
],
"plugins": ["Plugins/pCT/pCTCubicSpline.m"],
}

# Families for a group's page, in order, as on the Python API page and in the
Expand Down
1 change: 1 addition & 0 deletions docs/api/matlab/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Geometry <geometry>
Algorithms <algorithms>
Utilities <utilities>
Scanner data loaders <io>
Plugins <plugins>
```
15 changes: 15 additions & 0 deletions docs/api/matlab/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
og:description: "MATLAB reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies."
myst:
html_meta:
description: "MATLAB reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies."
---

# MATLAB plugins

Optional parts of TIGRE in `MATLAB/Plugins`; compiled plugins must be built
first (see {doc}`/user-guide/plugins`). Proton CT: `Compile pCT`, see
{doc}`/user-guide/proton-ct`.

```{include} ../../_generated/matlab/plugins.md
```
1 change: 1 addition & 0 deletions docs/api/python/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Algorithms <algorithms>
Utilities <utilities>
Scanner data loaders <io>
Plotting <plotting>
Plugins <plugins>
```
20 changes: 20 additions & 0 deletions docs/api/python/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
og:description: "Python reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies."
myst:
html_meta:
description: "Python reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies."
---

# Python plugins

Optional parts of TIGRE; compiled plugins must be built first (see
{doc}`/user-guide/plugins`).

```{eval-rst}
Proton CT
---------

Built with ``TIGRE_PLUGINS=pct``. See :doc:`/user-guide/proton-ct`.

.. autofunction:: tigre.plugins.pct.pCTCubicSpline
```
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _version_from_cff():
autodoc_mock_imports = [
*("tigre.utilities.cuda_interface." + m for m in (
"_Ax", "_Atb", "_AwminTV", "_minTV", "_minPICCS", "_tv_proximal", "_gpuUtils", "_RandomNumberGenerator")),
"tigre.plugins.pct._pct",
"h5py", "tqdm", "torch",
]
autodoc_typehints = "none"
Expand Down
14 changes: 14 additions & 0 deletions docs/user-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ from loading to the final image.
[](performance-tuning.md)
: Source-level changes for a little more speed.

## Plugins

Optional parts of TIGRE, outside the core toolbox.

[](plugins.md)
: What plugins are, how to build them, and how to add one.

[](proton-ct.md)
: The proton CT plugin: optimised proton radiographies.

Expand Down Expand Up @@ -154,6 +161,13 @@ real-data-tutorial
interoperability
troubleshooting
performance-tuning
```

```{toctree}
:hidden:
:caption: Plugins

plugins
proton-ct
```

Expand Down
115 changes: 115 additions & 0 deletions docs/user-guide/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
og:description: "TIGRE plugins: optional parts of TIGRE outside the core toolbox, how to build them in Python and MATLAB, and how to add a new one."
myst:
html_meta:
description: "TIGRE plugins: optional parts of TIGRE outside the core toolbox, how to build them in Python and MATLAB, and how to add a new one."
---

# Plugins

Plugins are optional parts of TIGRE that live outside the core toolbox. They
are for methods that only some users need, such as a different imaging
modality, so that core TIGRE stays small and quick to build. A plugin works in
both Python and MATLAB, with the same function names, like the rest of TIGRE.

| Plugin | What it does | Compiled | Page |
|---|---|---|---|
| `pct` (Python), `pCT` (MATLAB) | Optimised proton radiographies from single-proton data | Yes (CUDA, NVIDIA GPUs) | [](proton-ct.md) |

## Building plugins

Plugins with compiled code are **not built by default**: building TIGRE as
usual gives core TIGRE only. Ask for the plugins you want when you build.
Plugins written only in Python or MATLAB need no build and are always there.

::::{tab-set}
:sync-group: lang

:::{tab-item} Python
:sync: python
Set `TIGRE_PLUGINS` to a comma-separated list of plugins, or `all`, when
installing TIGRE from its source folder:

```bash
TIGRE_PLUGINS=pct pip install .
TIGRE_PLUGINS=all pip install .
```

In Windows cmd, set the variable first:

```bat
set TIGRE_PLUGINS=pct
pip install .
```

Plugins are imported from `tigre.plugins`, for example
`from tigre.plugins.pct import pCTCubicSpline`. Importing a plugin that was
not built raises an `ImportError` that says how to build it. The release
wheels do not include compiled plugins: build TIGRE from source to use them.
:::

:::{tab-item} MATLAB
:sync: matlab
From TIGRE's `MATLAB` folder:

```matlab
Compile % core TIGRE only, as always
Compile pCT % only the proton CT plugin (compile core TIGRE first)
Compile all % core TIGRE and every plugin
```

`InitTIGRE` puts every plugin folder (`MATLAB/Plugins/<name>`) on the path,
with its demos and, once compiled, its MEX files.
:::
::::

A plugin can have its own build options; see its page.

## Where plugins live

| | Python | MATLAB | Shared CUDA code |
|---|---|---|---|
| Code | `Python/tigre/plugins/<name>/` | `MATLAB/Plugins/<Name>/` | `Common/CUDA/plugins/<Name>/` |
| Demos | `Python/demos/` | `MATLAB/Plugins/<Name>/Demos/` | |
| Tests | `Python/tests/test_<name>_plugin.py` | `MATLAB/Tests/test_<Name>_plugin.m` | |

Data a plugin's demos need stays in the source folder (for proton CT,
`MATLAB/Plugins/pCT/data/`) and is not installed.

## Adding a plugin

For contributors. A plugin follows the same rules as the rest of TIGRE (see
[`AGENTS.md`](https://github.com/CERN/TIGRE/blob/master/AGENTS.md) and
[`contributing.md`](https://github.com/CERN/TIGRE/blob/master/contributing.md)):
the same function names and arguments in Python and MATLAB, a line in
`changelog.md`, and few, small tests.

1. **Code.** Put it in the folders above. Shared CUDA code goes in
`Common/CUDA/plugins/<Name>/` and includes `../../TIGRE_common.hpp` (not
`mex.h`), so both languages can build it. If the C++ wrapper includes a
header with device code, keep the `__device__` and `__global__`
declarations under `#ifdef __CUDACC__`.
2. **MATLAB build** (compiled plugins). In `MATLAB/Compile.m`, add the name to
`all_plugins` and a `case` that calls a local `compile_<name>` function.
Write the MEX files to `MATLAB/Plugins/<Name>/Mex_files/<arch>`, where
`InitTIGRE` finds them.
3. **Python build** (compiled plugins). In `setup.py`, add the name to
`PLUGINS` and an `Extension` named `tigre.plugins.<name>._<name>` in the
loop that builds `plugin_exts`. In the package's `__init__.py`, import the
compiled module inside `try`/`except ImportError` and re-raise an
`ImportError` that says how to build it. Add the generated `.cpp` to
`.gitignore` (already covered for `Python/tigre/plugins/*/*.cpp`) and the
`.pyx` to `[tool.setuptools.package-data]` in `pyproject.toml`.
4. **Tests.** One small test per language. A compiled plugin's Python test
must skip when the plugin is not built: import it in `try`/`except
ImportError` and call `pytest.skip(..., allow_module_level=True)`.
`pytest.importorskip` is not enough, because from pytest 9 it only skips
a missing module, not the plugin's own `ImportError`. Mark tests that need
a GPU with `pytest.mark.gpu`.
5. **Docs.** A user-guide page for the plugin, linked from the table at the
top of this page and from the user guide's index; its functions in the
API reference (add the compiled module to `autodoc_mock_imports` in
`docs/conf.py`); and its demos in `docs/_ext/tigre_demos.py`, where a
MATLAB demo in a plugin folder is given relative to `MATLAB/` (for example
`Plugins/pCT/Demos/pRad_demo.m`). Add a Python demo that needs a compiled
plugin to `NOT_RUN`.
12 changes: 10 additions & 2 deletions docs/user-guide/proton-ct.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ The radiographies can then be reconstructed with TIGRE's usual algorithms to
give a full proton CT image, or used on their own.

The plugin lives in `Python/tigre/plugins/pct` and `MATLAB/Plugins/pCT`, with
its CUDA code in `Common/CUDA/plugins/pCT`. It is not compiled with the rest of
TIGRE.
its CUDA code in `Common/CUDA/plugins/pCT`. Like other compiled
[plugins](plugins.md), it is not compiled with the rest of TIGRE. The method
and its validation are described in
[Kaser et al. (2023)](https://doi.org/10.1016/j.zemedi.2022.08.005); cite it
if you use the plugin. The function reference is in the API pages
([Python](../api/python/plugins.md), [MATLAB](../api/matlab/plugins.md)).

The radiographies are computed for parallel-beam protons (`geo.mode =
'parallel'`), as in the demo and the paper. A `'cone'` mode exists in the code
but has not been checked since the plugin moved out of core TIGRE.

## Building the plugin

Expand Down
Loading