Commit 8d9fe712 authored by finetjul's avatar finetjul
Browse files

ENH: Support shared CLI modules.

To be able to read volumes(slicer:0x263f5c0#vtkMRMLScalarVolumeNode1), the
CLI modules need to load MRMLImageIOPlugin, it is done automatically by ITK
by scanning plugins in the directory retrieved from the environment
variable ITK_AUTOLOAD_PATH.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@14853 3bd1e089-480b-0410-8dfb-8563597acbee
parent f1c79ef5
......@@ -65,6 +65,7 @@
// VTK includes
#include "vtkSmartPointer.h"
#include <vtksys/SystemTools.hxx>
// Slicer includes
#include "vtkSlicerVersionConfigure.h" // For Slicer3_VERSION_{MINOR, MAJOR}, Slicer3_VERSION_FULL
......@@ -95,6 +96,8 @@ public:
/// Given the program name, attempt to return the corresponding binary directory
void discoverSlicerBinDirectory();
void discoverITKFactoriesDirectory();
///
/// Parse arguments
bool parseArguments();
......@@ -116,6 +119,7 @@ public:
/// SlicerBin doesn't contain Debug/Release/... (see IntDir)
QString SlicerBin;
QString SlicerHome;
QString ITKFactoriesDir;
/// On windows platform, after the method 'discoverSlicerBinDirectory' has been called,
/// IntDir should be set to either Debug,
/// Release, RelWithDebInfo, MinSizeRel or any other custom build type.
......@@ -237,6 +241,30 @@ void qSlicerCoreApplicationPrivate::discoverSlicerBinDirectory()
}
}
//-----------------------------------------------------------------------------
void qSlicerCoreApplicationPrivate::discoverITKFactoriesDirectory()
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QDir itkFactoriesDir (this->SlicerHome);
itkFactoriesDir.cd(Slicer3_INSTALL_ITKFACTORIES_DIR);
if (!this->IntDir.isEmpty())
{
itkFactoriesDir.cd(this->IntDir);
}
QString relativeAutoLoadPath = env.value("ITK_AUTOLOAD_PATH");
if (relativeAutoLoadPath.isEmpty())
{
itkFactoriesDir.cd(relativeAutoLoadPath);
}
this->ITKFactoriesDir = itkFactoriesDir.absolutePath();
if (!itkFactoriesDir.exists())
{
qWarning() << "ITK_AUTOLOAD_PATH doesn't exists:"<< this->ITKFactoriesDir;
}
env.insert("ITK_AUTOLOAD_PATH", this->ITKFactoriesDir);
}
//-----------------------------------------------------------------------------
bool qSlicerCoreApplicationPrivate::parseArguments()
{
......@@ -292,6 +320,15 @@ qSlicerCoreApplication::qSlicerCoreApplication(int &_argc, char **_argv):Supercl
// in order to be used in the constructor of qSlicerApplication (to initialize the
// QCoreApplication::addLibraryPath (to handle the iconengines plugin) )
d->discoverSlicerHomeDirectory();
d->discoverITKFactoriesDirectory();
// Qt can't set environment variables for child processes that are not QProcess.
// As the command line modules are not QProcess and need ITK_AUTOLOAD_PATH to
// be able to read Slicer volumes, we need to change the current process env.
QString setEnv = QString("Slicer3_HOME=") + d->SlicerHome;
vtksys::SystemTools::PutEnv(setEnv.toLatin1());
setEnv = QString("ITK_AUTOLOAD_PATH=") + d->ITKFactoriesDir;
vtksys::SystemTools::PutEnv(setEnv.toLatin1());
}
//-----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment