question about python code

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

question about python code

John Fredy
Hello all, I am preparing one guide about vtk python programming in Slicer, I prepared the following code in Slicer 3.6

volumen.GetIJKToRASMatrix(matriz)
volumeRendering = vtk.vtkVolume()
volumeRendering.SetMapper(mapper)
volumeRendering.SetProperty(propiedades)
volumeRendering.PokeMatrix(matriz)
viewer = slicer.ApplicationGUI.GetActiveViewerWidget()
viewer.GetMainViewer().AddViewProp(volumeRendering)
viewer.RequestRender()

But this instruction don't work in Slicer 4

viewer = slicer.ApplicationGUI.GetActiveViewerWidget()

Traceback (most recent call last):

File "<console>", line 1, in <module>

AttributeError: 'module' object has no attribute 'ApplicationGUI'



How I can now obtain the ApplicationGUI in Slicer 4?

Best!

--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: [slicer-devel] question about python code

Steve Pieper
Hi John - 

Things have changed a lot between slicer3 and slicer4, particularly with respect to the user interface and the python infrastructure (definitely improvements!).

Here's a summary page:


Be sure to look at the Self Tests and Scripted Modules for examples.

With respect to what was the ApplicationGUI in slicer3, the closest things are the qSlicerApplication, from which you can get the mainWindow() and the layoutManager() to do the kinds of things you describe.  


Programming slicer (in C++ or Python) is a big topic and It would be great to have more comprehensive documentation than is currently available -- if you assemble material that you think others might learn from, please make it available and we hopefully 'crowd source' the process of fleshing it out with more detail.

Best,
Steve
 

On Wed, Jan 16, 2013 at 7:20 PM, John Fredy <[hidden email]> wrote:
Hello all, I am preparing one guide about vtk python programming in Slicer, I prepared the following code in Slicer 3.6

volumen.GetIJKToRASMatrix(matriz)
volumeRendering = vtk.vtkVolume()
volumeRendering.SetMapper(mapper)
volumeRendering.SetProperty(propiedades)
volumeRendering.PokeMatrix(matriz)
viewer = slicer.ApplicationGUI.GetActiveViewerWidget()
viewer.GetMainViewer().AddViewProp(volumeRendering)
viewer.RequestRender()

But this instruction don't work in Slicer 4

viewer = slicer.ApplicationGUI.GetActiveViewerWidget()

Traceback (most recent call last):

File "<console>", line 1, in <module>

AttributeError: 'module' object has no attribute 'ApplicationGUI'



How I can now obtain the ApplicationGUI in Slicer 4?

Best!

--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
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-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: [slicer-devel] question about python code

Julien Finet
In reply to this post by John Fredy
Hi John,

The closest to slicer.ApplicationGUI.GetActiveViewerWidget() is probably:
slicer.app.layoutManager().threeDWidget(0)

However you are calling for trouble by trying to add your own VTK mapper into a renderer. It is done automatically for you if you use the MRML nodes.
You can look at the volume rendering information for developer documentation:

Hth,
Julien.


On Wed, Jan 16, 2013 at 7:20 PM, John Fredy <[hidden email]> wrote:
Hello all, I am preparing one guide about vtk python programming in Slicer, I prepared the following code in Slicer 3.6

volumen.GetIJKToRASMatrix(matriz)
volumeRendering = vtk.vtkVolume()
volumeRendering.SetMapper(mapper)
volumeRendering.SetProperty(propiedades)
volumeRendering.PokeMatrix(matriz)
viewer = slicer.ApplicationGUI.GetActiveViewerWidget()
viewer.GetMainViewer().AddViewProp(volumeRendering)
viewer.RequestRender()

But this instruction don't work in Slicer 4

viewer = slicer.ApplicationGUI.GetActiveViewerWidget()

Traceback (most recent call last):

File "<console>", line 1, in <module>

AttributeError: 'module' object has no attribute 'ApplicationGUI'



How I can now obtain the ApplicationGUI in Slicer 4?

Best!

--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
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-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: [slicer-devel] question about python code

Julien Finet

Hi John,
The closest to slicer.ApplicationGUI.GetActiveViewerWidget() is probably:
slicer.app.layoutManager().threeDWidget(0)

However you are calling for trouble by trying to add your own VTK mapper into a renderer. It is done automatically for you if you use the MRML nodes.
You can look at the volume rendering information for developer documentation:
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/VolumeRendering

Hth,
Julien.

On Wed, Jan 16, 2013 at 7:20 PM, John Fredy <[hidden email]> wrote:
Hello all, I am preparing one guide about vtk python programming in Slicer, I prepared the following code in Slicer 3.6

volumen.GetIJKToRASMatrix(matriz)
volumeRendering = vtk.vtkVolume()
volumeRendering.SetMapper(mapper)
volumeRendering.SetProperty(propiedades)
volumeRendering.PokeMatrix(matriz)
viewer = slicer.ApplicationGUI.GetActiveViewerWidget()
viewer.GetMainViewer().AddViewProp(volumeRendering)
viewer.RequestRender()

But this instruction don't work in Slicer 4

viewer = slicer.ApplicationGUI.GetActiveViewerWidget()

Traceback (most recent call last):

File "<console>", line 1, in <module>

AttributeError: 'module' object has no attribute 'ApplicationGUI'



How I can now obtain the ApplicationGUI in Slicer 4?

Best!

--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
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-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
Reply | Threaded
Open this post in threaded view
|

Re: [slicer-devel] question about python code

John Fredy
Thanks Steve and Julien

I finally use the code in the web link that Julien send me
>>> logic = slicer.modules.volumerendering.logic()
>>> volumeNode = slicer.mrmlScene.GetNodeByID('vtkMRMLScalarVolumeNode1')
>>> displayNode = logic.CreateVolumeRenderingDisplayNode()
>>> slicer.mrmlScene.AddNode(displayNode)
>>> displayNode.UnRegister(logic)
>>> logic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)
>>> volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())

Here, in the Universidad de Antioquia, we have a lot of python code for educational purposes, is a honor share our exercises, the slicer team help us every time we need

I will give some order to the guides

Best!

On Thu, Jan 17, 2013 at 8:32 AM, Julien Finet <[hidden email]> wrote:

Hi John,
The closest to slicer.ApplicationGUI.GetActiveViewerWidget() is probably:
slicer.app.layoutManager().threeDWidget(0)

However you are calling for trouble by trying to add your own VTK mapper into a renderer. It is done automatically for you if you use the MRML nodes.
You can look at the volume rendering information for developer documentation:
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/VolumeRendering

Hth,
Julien.

On Wed, Jan 16, 2013 at 7:20 PM, John Fredy <[hidden email]> wrote:
Hello all, I am preparing one guide about vtk python programming in Slicer, I prepared the following code in Slicer 3.6

volumen.GetIJKToRASMatrix(matriz)
volumeRendering = vtk.vtkVolume()
volumeRendering.SetMapper(mapper)
volumeRendering.SetProperty(propiedades)
volumeRendering.PokeMatrix(matriz)
viewer = slicer.ApplicationGUI.GetActiveViewerWidget()
viewer.GetMainViewer().AddViewProp(volumeRendering)
viewer.RequestRender()

But this instruction don't work in Slicer 4

viewer = slicer.ApplicationGUI.GetActiveViewerWidget()

Traceback (most recent call last):

File "<console>", line 1, in <module>

AttributeError: 'module' object has no attribute 'ApplicationGUI'



How I can now obtain the ApplicationGUI in Slicer 4?

Best!

--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
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





--
John Ochoa
Docente de Bioingeniería
Universidad de Antioquia

_______________________________________________
slicer-users mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-users
To unsubscribe: send email to [hidden email] with unsubscribe as the subject