View Issue Details

IDProjectCategoryView StatusLast Update
0003923Slicer4Core: Base Codepublic2018-03-02 11:02
Reporterpohl Assigned Tojcfr  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product VersionSlicer 4.4.0 
Target VersionFixed in VersionSlicer 4.7.0 
Summary0003923: AddArchetypeScalarVolume fails when running through Slicer --launch
Description

Executing AddArchetypeScalarVolume in a python script invoked through --launch fails even tough it works fine when running it through the python shell provided by Slicer

ERROR: In /software/Slicer4/trunk/Libs/MRML/Core/vtkMRMLVolumeArchetypeStorageNode.cxx, line 367
vtkMRMLVolumeArchetypeStorageNode (0x2c38980): ReadData: Cannot read file as a volume of type Volume[fullName = /software/Slicer4Sandbox/white.nrrd]
Number of files listed in the node = 0.
File reader says it was able to read 0 files.
File reader used the archetype file name of /software/Slicer4Sandbox/white.nrrd []

Steps To Reproduce
  • Compile slicer with CTK Shell
    cd CTK-build/; ccmake . ; setting CTK_APP_ctkSimplePythonShell to On; make
  • bash
    SLICERSUPER=/software/Slicer4/superbuild
    export PYTHONPATH="$PYTHONPATH:${SLICERSUPER}/VTKv6-build/lib"
    ${SLICERSUPER}/Slicer-build/Slicer --launcher-no-splash --launch ${SLICERSUPER}/CTK-build/CTK-build/bin/ctkSimplePythonShell

and then enter

modules = ('os', 'sys', 'vtk', 'qt', 'slicer','vtkSlicerVolumesModuleLogic')

for m in modules:
exec('import %s' % m)
print('imported %s' % m)

mrmlScene = slicer.vtkMRMLScene()
volumesLogic = vtkSlicerVolumesModuleLogic.vtkSlicerVolumesLogic()
volumesLogic.SetMRMLScene(mrmlScene)

volumesLogic.AddArchetypeScalarVolume('./share/Slicer-4.4/qt-loadable-modules/EMSegment/Testing/TestData/MRI-Human-Brain/small_atlas_t1_stripped.nrrd', 'Image', 0, None)

Additional Information

this worked in Slicer 4.2.2

TagsNo tags attached.

Activities

jcfr

jcfr

2015-10-06 21:00

administrator   ~0013352

Since r23915, VTK module can be imported and example can be simplified. It is not needed to explicitly updated the PYTHONPATH.

For reference:

//--------------
ENH: Allow vtk module to be imported from Slicer python

This commit update launcher settings associated with VTKv6 project so that
"import vtk" can be successfully executed from the python interpreter
executed in the Slicer environment.

./Slicer --launch python -c 'import vtk'
//--------------

jcfr

jcfr

2015-10-06 22:40

administrator   ~0013353

Last edited: 2015-10-06 22:41

Here is the solution:

(1) Apply the last commit associated with this branch: https://github.com/jcfr/Slicer/tree/3923-allow-registration-of-itk-factory-from-python

(2) Update your snipped to set ITK_AUTOLOAD_PATH and register the factory using ctypes

Updated example:

SLICERSUPER=/software/Slicer4/superbuild
${SLICERSUPER}/Slicer-build/Slicer --launcher-no-splash --launch ${SLICERSUPER}/CTK-build/CTK-build/bin/ctkSimplePythonShell
export ITK_AUTOLOAD_PATH="${SLICERSUPER}/Slicer-build/lib/Slicer-4.4/ITKFactories"

.. and the code to copy in the CTK python shell:

8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----
library_path = './bin/libITKFactoryRegistration.so'
import ctypes
library = ctypes.cdll.LoadLibrary(library_path)
library.register_itk_factory()

modules = ('os', 'sys', 'vtk', 'slicer', 'vtkSlicerVolumesModuleLogic')

for m in modules:
exec('import %s' % m)
print('imported %s' % m)

mrmlScene = slicer.vtkMRMLScene()
volumesLogic = vtkSlicerVolumesModuleLogic.vtkSlicerVolumesLogic()
volumesLogic.SetMRMLScene(mrmlScene)

volumesLogic.AddArchetypeScalarVolume('./share/Slicer-4.4/qt-loadable-modules/EMSegment/Testing/TestData/MRI-Human-Brain/small_atlas_t1_stripped.nrrd', 'Image', 0, None)
8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----

jcfr

jcfr

2015-10-06 22:42

administrator   ~0013354

@Kilian: Let me know if the solution discuss in http://www.na-mic.org/Bug/view.php?id=3923#c13353 works for you. Thanks

pohl

pohl

2015-10-14 12:21

developer   ~0013386

I think it worked - I am just not sure if the following warning messgae is ok or not :

cannot import name _qSlicerCoreApplicationInstance

Here is what I dud :
1) I downloaded your branch and did a fresh compile
2) I went to CTK-build ; ccmake . ; set CTK_APP_ctkSimplePythonShell ON; regenerated cmake files; and ran make
3) SLICERSUPER=/software/Slicer4/superbuild
export ITK_AUTOLOAD_PATH="${SLICERSUPER}/Slicer-build/lib/Slicer-4.4/ITKFactories"
cd ${SLICERSUPER}/Slicer-build/
./Slicer --launcher-no-splash --launch ${SLICERSUPER}/CTK-build/CTK-build/bin/ctkSimplePythonShell
4) Ran the following in the shell

library_path = './bin/libITKFactoryRegistration.so'
import ctypes
library = ctypes.cdll.LoadLibrary(library_path)

library.register_itk_factory()
0
modules = ('os', 'sys', 'vtk', 'slicer', 'vtkSlicerVolumesModuleLogic')
for m in modules:
... exec('import %s' % m)
... print('imported %s' % m)
...
imported os
imported sys
imported vtk
cannot import name _qSlicerCoreApplicationInstance
cannot import name _qSlicerCoreApplicationInstance
cannot import name _qSlicerCoreApplicationInstance
cannot import name _qSlicerCoreApplicationInstance
imported slicer
imported vtkSlicerVolumesModuleLogic
mrmlScene = slicer.vtkMRMLScene()
volumesLogic = vtkSlicerVolumesModuleLogic.vtkSlicerVolumesLogic()
volumesLogic.SetMRMLScene(mrmlScene)

volumesLogic.AddArchetypeScalarVolume('./share/Slicer-4.4/qt-loadable-modules/EMSegment/Testing/TestData/MRI-Human-Brain/small_atlas_t1_stripped.nrrd', 'Image', 0, None)
(vtkMRMLScalarVolumeNode)0x7f421c043f50

jcfr

jcfr

2015-10-27 10:28

administrator   ~0013431

The message is expected for now. It should be possible to tweak Slicer to avoid it.

lassoan

lassoan

2017-07-25 22:54

developer   ~0014987

Last edited: 2017-07-25 22:54

View 2 revisions

Many things have changed since the problem was reported, but this works fine now:

Slicer.exe --no-main-window --show-python-interactor

volumesLogic = slicer.modules.volumes.logic()
volumesLogic.AddArchetypeScalarVolume(&quot;./share/Slicer-4.7/qt-loadable-modules/EMSegment/Tasks/MRI-Human-Brain/atlas_t2.nrrd&quot;, 'Image', 0, None)

Issue History

Date Modified Username Field Change
2014-12-19 08:28 pohl New Issue
2014-12-19 08:28 pohl Status new => assigned
2014-12-19 08:28 pohl Assigned To => jcfr
2015-10-06 21:00 jcfr Note Added: 0013352
2015-10-06 22:40 jcfr Note Added: 0013353
2015-10-06 22:40 jcfr Note Edited: 0013353
2015-10-06 22:41 jcfr Note Edited: 0013353
2015-10-06 22:41 jcfr Status assigned => feedback
2015-10-06 22:42 jcfr Note Added: 0013354
2015-10-14 12:21 pohl Note Added: 0013386
2015-10-27 10:28 jcfr Status feedback => acknowledged
2015-10-27 10:28 jcfr Target Version Slicer 4.5.0-1 =>
2015-10-27 10:28 jcfr Note Added: 0013431
2017-07-25 22:54 lassoan Status acknowledged => resolved
2017-07-25 22:54 lassoan Resolution open => fixed
2017-07-25 22:54 lassoan Fixed in Version => Slicer 4.7.0
2017-07-25 22:54 lassoan Note Added: 0014987
2017-07-25 22:54 lassoan Note Edited: 0014987 View Revisions
2018-03-02 11:02 jcfr Status resolved => closed