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

dual_energy (Python), DualEnergy (MATLAB)

Virtual monoenergetic images from dual-energy CBCT

No

Dual-energy CBCT

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.

Set TIGRE_PLUGINS to a comma-separated list of plugins, or all, when installing TIGRE from its source folder:

TIGRE_PLUGINS=pct pip install .
TIGRE_PLUGINS=all pip install .

In Windows cmd, set the variable first:

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.

From TIGRE’s MATLAB folder:

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. Data the plugin itself needs at run time goes in Common/data/, read by both languages; setup.py copies it into the Python package (as for the dual-energy plugin’s calibration tables).

Adding a plugin#

For contributors. A plugin follows the same rules as the rest of TIGRE (see AGENTS.md and 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.