Converting Slicer Python code to C++


I was looking into converting some Slicer code from Python to C++, in particular from the slicer.util module the loadVolume method. Is there an already existing header file that does this for the util module? If not, any pointers on how to approach this task?


Converting Python code to C++ isn’t conceptually difficult, but there are a lot of steps involved and it’s typically not worth the effort, particularly for something like loading a volume, where the python code already calls down in to C++, so there’s no efficiency gained.

Of course you can load data using C++ but you will need to study a lot of the internal architecture to learn how. I’d suggest reading the tests to get a sense of what’s required.

Thanks for the advice.

The reason for doing so is more so for all of our code being in C++, rather than for efficiency. I’ve taken a closer look at the architecture of the existing code and I think I understand how it works. However, I’m at a loss as to what ‘from slicer import app’ is referring to in the util code.

You can find out the types by pasting this code in the python console and then typing app and you can see that it’s a qSlicerApplication. So you need to include the appropriate headers and link the corresponding libraries to use that class in C++.