Python plugin interaction with image visualization

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Python plugin interaction with image visualization

ClearPEMSonic
Hi,

we are having a problem in dealing with the way python plugins interact with image visualization in 3DSlicer.

We import an image into 3DSlicer using a CLI, plugin programmatically invoked by a python plugin. This works correctly, but the image is displayed with interpolation turned on. We would like it to be turned off, so we are trying to call the SetInterpolation() method on the volume previously loaded from inside the python plugin itself.
The problem is that if we try to call the SetInterpolation(0) from the python interactor (after importing the image), i.e.

---------------
import Slicer
from Slicer import slicer
volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3")
displayNode=volume.GetVolumeDisplayNode()
displayNode.SetInterpolate(0)
---------------

it works correctly, while if we do it directly into the python plugin, it doesn't. What we do is

---------------
o=plugin.Execute(PEMVol) #loads an image into the vtkMRMLScalarVolumeNode PEMVol
volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3") #we get the volume using its ID instead of using PEMVol directly
display=volume.GetVolumeDisplayNode()
display.SetInterpolate(0)
---------------

and what we get is

---------------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/clearpem/Slicer/Slicer3-3.6-2010-06-10-linux-x86_64/lib/Slicer3/Modules/Image Loader/ImageLoader.py", line 88, in ProcessGUIEvents
    self.Apply()
  File "/home/clearpem/Slicer/Slicer3-3.6-2010-06-10-linux-x86_64/lib/Slicer3/Modules/Image Loader/ImageLoader.py", line 501, in Apply
    display.SetInterpolate(0)
AttributeError: 'list' object has no attribute 'SetInterpolate'
---------------

Also using directly PEMVol instead of volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3") gives the same error.
So it seems that the PEMVol is no more defined in the python plugin, or no more related to the image we loaded before, which is weird given that it does work in python console.
Are we making any mistake in the python plugin? Maybe we are not able to correctly refer to the Volume just loaded, but we'd like to know what's the difference between the python plugin and python console since they seem to behave in very different ways in this case.

Furthermore, maybe this can be useful for you: if we run the same python plugin again, it creates another volume and correctly applies SetInterpolation(0) to the previously loaded volume, but not to the new one.. quite confusing!

Thanks very much,

Marco
Reply | Threaded
Open this post in threaded view
|

Re: Python plugin interaction with image visualization

pieper
Administrator
Hi Marco -

On this one I think the issue is that the volume that comes freshly out
of the command line executable doesn't get a have a display node --
there is code in Base/Logic/vtkSlicerSliceLayerLogic.cxx around line 251
that adds the display node if it doesn't have one at the time of
rendering (the comments in that code call this behavior a hack - perhaps
we can think of a better place to put that code).

So in your situation, you could either force a render (by calling the tk
update command) or, better I think in this situation, create the display
node in your code and set it with the desired properties.

-Steve


On 03/07/2011 06:18 AM, ClearPEMSonic wrote:

> Hi,
>
> we are having a problem in dealing with the way python plugins interact with
> image visualization in 3DSlicer.
>
> We import an image into 3DSlicer using a CLI, plugin programmatically
> invoked by a python plugin. This works correctly, but the image is displayed
> with interpolation turned on. We would like it to be turned off, so we are
> trying to call the SetInterpolation() method on the volume previously loaded
> from inside the python plugin itself.
> The problem is that if we try to call the SetInterpolation(0) from the
> python interactor (after importing the image), i.e.
>
> ---------------
> import Slicer
> from Slicer import slicer
> volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3")
> displayNode=volume.GetVolumeDisplayNode()
> displayNode.SetInterpolate(0)
> ---------------
>
> it works correctly, while if we do it directly into the python plugin, it
> doesn't. What we do is
>
> ---------------
> o=plugin.Execute(PEMVol) #loads an image into the vtkMRMLScalarVolumeNode
> PEMVol
> volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3") #we get the
> volume using its ID instead of using PEMVol directly
> display=volume.GetVolumeDisplayNode()
> display.SetInterpolate(0)
> ---------------
>
> and what we get is
>
> ---------------
> Traceback (most recent call last):
>    File "", line 1, in
>    File
> "/home/clearpem/Slicer/Slicer3-3.6-2010-06-10-linux-x86_64/lib/Slicer3/Modules/Image
> Loader/ImageLoader.py", line 88, in ProcessGUIEvents
>      self.Apply()
>    File
> "/home/clearpem/Slicer/Slicer3-3.6-2010-06-10-linux-x86_64/lib/Slicer3/Modules/Image
> Loader/ImageLoader.py", line 501, in Apply
>      display.SetInterpolate(0)
> AttributeError: 'list' object has no attribute 'SetInterpolate'
> ---------------
>
> Also using directly PEMVol instead of
> volume=slicer.MRMLScene.GetNodeByID("vtkMRMLScalarVolumeNode3") gives the
> same error.
> So it seems that the PEMVol is no more defined in the python plugin, or no
> more related to the image we loaded before, which is weird given that it
> does work in python console.
> Are we making any mistake in the python plugin? Maybe we are not able to
> correctly refer to the Volume just loaded, but we'd like to know what's the
> difference between the python plugin and python console since they seem to
> behave in very different ways in this case.
>
> Furthermore, maybe this can be useful for you: if we run the same python
> plugin again, it creates another volume and correctly applies
> SetInterpolation(0) to the previously loaded volume, but not to the new
> one.. quite confusing!
>
> Thanks very much,
>
> Marco
>
> --
> View this message in context: http://slicer-devel.65872.n3.nabble.com/Python-plugin-interaction-with-image-visualization-tp2645779p2645779.html
> Sent from the slicer-devel mailing list archive at Nabble.com.
> _______________________________________________
> slicer-devel mailing list
> [hidden email]
> http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
> To unsubscribe: send email to [hidden email] with unsubscribe as the subject
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject