-
Notifications
You must be signed in to change notification settings - Fork 7
MicroPlugin
In the present tutorial lesson 11 we will develop our second Orthanc plugin for our RadioLogicArchive. The C++ code is contained in the file MicroPlugin.cpp, saved in the folder /OrthancPlugins/MicroPlugin/ in the present repository.
If we compare the code with the NanoPlugin code we discover the following changes:
- the line
OrthancPlugins::RegisterRestCallback<Moien>("/moien", true);
has been replaced with
OrthancPluginRegisterOnStoredInstanceCallback(context, ScaleDicomImage);
- the short callback function
void Moien()
has been replaced with a large callback function OrthancPluginErrorCode ScaleDicomImage()
.
This callback function is called when a new instance has been stored. The function provides the data and ID of this instance and writes it to a temporary folder:
OrthancPluginErrorCode writeError = OrthancPluginWriteFile()
The instance is decompressed with a system call to the gdcmconv
executable of the GDCM library.
std::string gdcmconvCommand = "/GDCM-3.0.3-Linux-x86_64/bin/gdcmconv --raw /tmp/original.dcm /tmp/raw.dcm";
int dcmscaleStatus = system(dcmscaleCommand.c_str());
In a next step the instance is downscaled with a system call to the dcmscale
excutable of the DCMTK library.
std::string dcmscaleCommand = "/dcmtk-3.6.4-linux-x86_64-static/bin/dcmscale +Sxf 0.5 /tmp/raw.dcm /tmp/scaled.dcm";
int dcmscaleStatus = system(dcmscaleCommand.c_str());
The modified instance is read from the temporary folder
OrthancPluginErrorCode readError = OrthancPluginReadFile
and restored to the server:
OrthancPluginErrorCode storeError = OrthancPluginRestApiPost()
If an error (read, write, store, ...) happens during the process, the callback function returns with the related error-code. If the process terminates well, the memory buffers are freed and the temporary files are removed. The callback function returns with a success message.
If we compile this code, no issue will be raised, but if we run the code, the plugin will turn in an endless loop. When the modified instance is uploaded to the server, the OnStoredInstanceCallback
is called again, and the whole scaling process is repeated. The image gets smaller and smaller and the process will probably stop once, due to a miscalculation.
To prevent the plugin from entering a loop, we check the origin of the callback call at the beginning of the function with the statement
if (OrthancPluginGetInstanceOrigin(context, instance) == OrthancPluginInstanceOrigin_Plugin) {return OrthancPluginErrorCode_Success;}
If the origin is the plugin, we stop the process and return the callback function.
If we compare the CMakeLists.txt file and the Resources folder we don't find any changes, except the project name.
You probably wonder how the gdcmconv and dcmscale executables are popping up in the Docker container. Short answer: we must install them. Here comes the recipe:
- run a new development container
In lesson 10 we learned how to create a development container. We use the same procedure for the MicroPlugin.
docker container run -it --name RadioLogicDevelopment dev-snapshot /bin/bash
- install DCMTK
cd /
wget ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk364/bin/dcmtk-3.6.4-linux-x86_64-static.tar.bz2
tar -xvjf dcmtk-3.6.4-linux-x86_64-static.tar.bz2
rm -r dcmtk-3.6.4-linux-x86_64-static.tar.bz2
chmod -R 777 dcmtk-3.6.4-linux-x86_64-static
- install GDCM
wget https://github.com/malaterre/GDCM/releases/download/v3.0.3/GDCM-3.0.3-Linux-x86_64.tar.gz
tar xvzf GDCM-3.0.3-Linux-x86_64.tar.gz
rm -r GDCM-3.0.3-Linux-x86_64.tar.gz
chmod -R 777 GDCM-3.0.3-Linux-x86_64
Meanwhile we know how to build a plugin inside a Docker container. The next figure shows that building the MicroPlugin is also a success story.
We know also how to commit an image with the embedded DCMTK and GDCM libraries, how to copy the MiniPlugin into the plugins folder and how to run a new RadioLogicArchive container from this image. Feel free to go back to earlier lessons if you are not sure what to do. If the container is running, you can upload a DICOM instance with a HTTP POST request to scale the image to half-size. Here is the curl command to send a file to the archive:
curl -u username:password -X POST https://<orthanc-ip-address:8042>/instances/ --data-binary @test.dcm
When the RadioLogicArchive is run in verbose
mode we should see the following information:
In the All patients webpage two instances have been added with the same Patient-, Study- and Series-UID. The first instance contains the original image, the second the down-scaled image. The following figures show the related DICOM tags.
A preview displays the scaled image.
In the next lesson we will add more complexity to the plugin which gets a promotion from micro
to mini
.