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 |
|---|---|---|---|
|
Optimised proton radiographies from single-proton data |
Yes (CUDA, NVIDIA GPUs) |
|
|
Virtual monoenergetic images from dual-energy CBCT |
No |
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 |
|
|
|
Demos |
|
|
|
Tests |
|
|
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.
Code. Put it in the folders above. Shared CUDA code goes in
Common/CUDA/plugins/<Name>/and includes../../TIGRE_common.hpp(notmex.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__.MATLAB build (compiled plugins). In
MATLAB/Compile.m, add the name toall_pluginsand acasethat calls a localcompile_<name>function. Write the MEX files toMATLAB/Plugins/<Name>/Mex_files/<arch>, whereInitTIGREfinds them.Python build (compiled plugins). In
setup.py, add the name toPLUGINSand anExtensionnamedtigre.plugins.<name>._<name>in the loop that buildsplugin_exts. In the package’s__init__.py, import the compiled module insidetry/except ImportErrorand re-raise anImportErrorthat says how to build it. Add the generated.cppto.gitignore(already covered forPython/tigre/plugins/*/*.cpp) and the.pyxto[tool.setuptools.package-data]inpyproject.toml.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 ImportErrorand callpytest.skip(..., allow_module_level=True).pytest.importorskipis not enough, because from pytest 9 it only skips a missing module, not the plugin’s ownImportError. Mark tests that need a GPU withpytest.mark.gpu.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_importsindocs/conf.py); and its demos indocs/_ext/tigre_demos.py, where a MATLAB demo in a plugin folder is given relative toMATLAB/(for examplePlugins/pCT/Demos/pRad_demo.m). Add a Python demo that needs a compiled plugin toNOT_RUN.