Getting started with Python extension development

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

Getting started with Python extension development

banderie@asu.edu
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Getting started with Python extension development

Steve Pieper-2
Hi Barrett - 

Thanks for sending clear questions - hope these answers help.

#1 - yes, you want to create a node and then Slicer will handle rendering, picking ,etc.  Here's a snippet you can look at:


#2 Once there's a transform set for the model node you can change the matrix like this:


#3 you can add observers to any node and then perform the calculations in the callbacks.


You can use slicer.util.getNodes to find the current nodes in the scene:


#4 Any of the classes subclassed from vtkMRMLDisplayableNode can be visible in 2D or 3D - what you use depends on the exact type of data you want to show.  Maybe when you have a look at the code referenced above you'll have a better idea.

As a general rule in Slicer, you use VTK classes to create and manipulate data but then let Slicer do the rendering.  If you need custom rendering for some reason you write what we call a "displayable manager" but probably you don't need to write one for what you are doing.

Best of luck,
Steve

On Fri, Mar 17, 2017 at 3:08 PM, [hidden email] <[hidden email]> wrote:
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ


_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Getting started with Python extension development

lasso2

#2: In general, you don’t need to transform polydata or actors, or set transforms manually. Just set the parent transform of your model node to the appropriate transform node. Transform nodes are updated automatically through OpenIGTLink.

 

#3: This is all implemented in BreachWarning module. It computes closest distance, can display the value and direction line in the navigation views and can also change color of the breached model and play a warning sound.

 

We have implemented many navigation systems using SlicerIGT and by now we have modules for almost everything. We would be happy to have a skype call with you, it may be easier for you to explain what exactly you need and for us to give advice about implementation in Slicer.

 

Andras

 

From: [hidden email]
Sent: Friday, March 17, 2017 4:28 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [slicer-devel] Getting started with Python extension development

 

Hi Barrett - 

Thanks for sending clear questions - hope these answers help.

#1 - yes, you want to create a node and then Slicer will handle rendering, picking ,etc.  Here's a snippet you can look at:


#2 Once there's a transform set for the model node you can change the matrix like this:


#3 you can add observers to any node and then perform the calculations in the callbacks.


You can use slicer.util.getNodes to find the current nodes in the scene:


#4 Any of the classes subclassed from vtkMRMLDisplayableNode can be visible in 2D or 3D - what you use depends on the exact type of data you want to show.  Maybe when you have a look at the code referenced above you'll have a better idea.

As a general rule in Slicer, you use VTK classes to create and manipulate data but then let Slicer do the rendering.  If you need custom rendering for some reason you write what we call a "displayable manager" but probably you don't need to write one for what you are doing.

Best of luck,
Steve

On Fri, Mar 17, 2017 at 3:08 PM, [hidden email] <[hidden email]> wrote:
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ


_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Getting started with Python extension development

banderie@asu.edu
In reply to this post by banderie@asu.edu
Hi Dr. Pieper,

Great, thanks so much! It looks like this should be plenty of material to get me started. Did you mean to include the same link for #2 and #3?

Thanks,
Barrett

On Fri, Mar 17, 2017 at 1:27 PM, Steve Pieper <[hidden email]> wrote:
Hi Barrett - 

Thanks for sending clear questions - hope these answers help.

#1 - yes, you want to create a node and then Slicer will handle rendering, picking ,etc.  Here's a snippet you can look at:


#2 Once there's a transform set for the model node you can change the matrix like this:


#3 you can add observers to any node and then perform the calculations in the callbacks.


You can use slicer.util.getNodes to find the current nodes in the scene:


#4 Any of the classes subclassed from vtkMRMLDisplayableNode can be visible in 2D or 3D - what you use depends on the exact type of data you want to show.  Maybe when you have a look at the code referenced above you'll have a better idea.

As a general rule in Slicer, you use VTK classes to create and manipulate data but then let Slicer do the rendering.  If you need custom rendering for some reason you write what we call a "displayable manager" but probably you don't need to write one for what you are doing.

Best of luck,
Steve

On Fri, Mar 17, 2017 at 3:08 PM, [hidden email] <[hidden email]> wrote:
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ



_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Getting started with Python extension development

banderie@asu.edu
In reply to this post by Steve Pieper-2
Hi Dr. Lasso,

I see, thank you. A Skype call would be great! I'm pretty swamped for the next two weeks, but I will definitely contact you at some point to arrange a call.

Thanks!
Barrett


On Fri, Mar 17, 2017 at 2:45 PM, Andras Lasso <[hidden email]> wrote:

#2: In general, you don’t need to transform polydata or actors, or set transforms manually. Just set the parent transform of your model node to the appropriate transform node. Transform nodes are updated automatically through OpenIGTLink.

 

#3: This is all implemented in BreachWarning module. It computes closest distance, can display the value and direction line in the navigation views and can also change color of the breached model and play a warning sound.

 

We have implemented many navigation systems using SlicerIGT and by now we have modules for almost everything. We would be happy to have a skype call with you, it may be easier for you to explain what exactly you need and for us to give advice about implementation in Slicer.

 

Andras

 

From: [hidden email]
Sent: Friday, March 17, 2017 4:28 PM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [slicer-devel] Getting started with Python extension development

 

Hi Barrett - 

Thanks for sending clear questions - hope these answers help.

#1 - yes, you want to create a node and then Slicer will handle rendering, picking ,etc.  Here's a snippet you can look at:


#2 Once there's a transform set for the model node you can change the matrix like this:


#3 you can add observers to any node and then perform the calculations in the callbacks.


You can use slicer.util.getNodes to find the current nodes in the scene:


#4 Any of the classes subclassed from vtkMRMLDisplayableNode can be visible in 2D or 3D - what you use depends on the exact type of data you want to show.  Maybe when you have a look at the code referenced above you'll have a better idea.

As a general rule in Slicer, you use VTK classes to create and manipulate data but then let Slicer do the rendering.  If you need custom rendering for some reason you write what we call a "displayable manager" but probably you don't need to write one for what you are doing.

Best of luck,
Steve

On Fri, Mar 17, 2017 at 3:08 PM, [hidden email] <[hidden email]> wrote:
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ



_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Getting started with Python extension development

Steve Pieper-2
In reply to this post by banderie@asu.edu
Hi Barrett - 

Ah, right - I meant to paste this:

https://github.com/Slicer/Slicer/blob/5c0fbf9082e3ba9a6f2869b167f3b0d87a62301e/Modules/Scripted/Endoscopy/Endoscopy.py#L185

It's not a perfect example but you'll find lots of other places in the code where AddObserver is used to get callbacks when things happen in the scene.

As a general rule though I suggest following the advice from Andras and using the OpenIGTLink code wherever possible, and if you need extra features try extending the existing code.

Best,
Steve

On Fri, Mar 17, 2017 at 10:47 PM, [hidden email] <[hidden email]> wrote:
Hi Dr. Pieper,

Great, thanks so much! It looks like this should be plenty of material to get me started. Did you mean to include the same link for #2 and #3?

Thanks,
Barrett

On Fri, Mar 17, 2017 at 1:27 PM, Steve Pieper <[hidden email]> wrote:
Hi Barrett - 

Thanks for sending clear questions - hope these answers help.

#1 - yes, you want to create a node and then Slicer will handle rendering, picking ,etc.  Here's a snippet you can look at:


#2 Once there's a transform set for the model node you can change the matrix like this:


#3 you can add observers to any node and then perform the calculations in the callbacks.


You can use slicer.util.getNodes to find the current nodes in the scene:


#4 Any of the classes subclassed from vtkMRMLDisplayableNode can be visible in 2D or 3D - what you use depends on the exact type of data you want to show.  Maybe when you have a look at the code referenced above you'll have a better idea.

As a general rule in Slicer, you use VTK classes to create and manipulate data but then let Slicer do the rendering.  If you need custom rendering for some reason you write what we call a "displayable manager" but probably you don't need to write one for what you are doing.

Best of luck,
Steve

On Fri, Mar 17, 2017 at 3:08 PM, [hidden email] <[hidden email]> wrote:
Hello All,

I am new to both Slicer and VTK and I'm struggling to get started with Python extensions. I have a decent programming background (mostly Python and MATLAB), but I'm struggling to grasp how to properly manipulate the Slicer environment. 

For a little background, I am using a Polaris Vicra with the SlicerIGT extension to do stereotactic navigation, and I have managed to get that part of my system running (I have a good phantom object and corresponding DICOM series and have learned to register the phantom). What I want to do now is write an extension that allows me to place 3D objects in the scene at the tip of my stylus. I have been reading through the Python scripting documentation and examples, but have yet to find example code related to what I am trying to do. I also looked at the source code the the CreateModel module within SlicerIGT to try to understand how to create 3D objects, but didn't get very far because it is written in C++. I have also been reading some messages from the slicer development mailing list, which have been somewhat helpful, but I am still pretty lost. Here is what I am struggling with:

1. Create VTK object and add it to the 3D scene. I tried creating a sphere source, adding it to a mapper, adding that to an actor, and then adding it to the 3D scene renderer using "renderer=slicer.app.layoutManager().threeDWidget(0).threeDView().renderWindow().GetRenderers().GetFirstRenderer()," but nothing happened (and this feels like the wrong way to do it). Do I need to create a new node first? Can someone explain the proper way to add nodes and get them to visualize, or point me to some example code? Do I used Slicer-specific methods, or straight VTK?

2. Extract the transformation matrix that transforms the tip of my stylus to RAS so that I can then apply it to my VTK objects so that they appear at the right location (at the tip of the stylus). I have absolutely no idea how to do this, but I assume it isn't too difficult. Also, what does "harden transform" do?

3. Calculate the distance between the tip of my stylus and objects in the 3D scene. I need to know how far the tip of my stylus is from all of the objects I place in the scene, so that I can create an alert when the tip of the stylus gets too close to a given object. I have no idea where to start with this. 

4. Get objects to visualize in both the 3D and 2D views. Does this have to do with the distinction between a model and a volume? I need to the objects that I place in the 3D scene to show up on top of my DICOM images like they do when I use the Editor to segment anatomy. I would appreciate if someone could explain how to get objects to visualize in both 3D and 2D, or point me to an example.

I think the main reason I am stuck is that I am not sure if I should be using exclusively VTK methods, or if there are special Slicer methods that call VTK methods. On the Python scripting documentation page I get the feeling that there are Slicer-specific methods and objects that I should be using, but I have no idea what they are, or how they are organized. I have tried using the Python interpreter and autocomplete to browse the methods for various objects in the slicer environment, but there are so many that I just get confused. 

I'm sure my questions are quite naive, and I apologize if these questions are answered somewhere in the documentation, but I have not been able to find anything. I would greatly appreciate any assistance, explanation, or direction to examples!

Thanks and best regards,

Barrett

_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ




_______________________________________________
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
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ