Extract 3D Coordinates from VTK Output File

Hello everybody,

How do you extract de 3D coordinates from a VTK output file? This VTK output file is created using the Model-to-Model Distance module. It does not matter if the coordinates are in the LPS or RAS system, as I need to compare different coordinates. I need to export these coordinates to Excel.

Any suggestions would be really helpful, thankyou in advance.

Kind regards,

You can use arrayFromModelPoints

@pieper thanks for providing the link. I’m wondering if we should always use latest tag (https://slicer.readthedocs.io/en/latest…) instead of a specific version (https://slicer.readthedocs.io/en/v4.11) in forum posts, because these posts may be read in several months or even years later and by that time specific tags may be outdated. We could also add a “stable” tag to readthedocs.

Yes, that’s always a tradeoff. There’s a risk that things will get reformatted and we end up with a dead link. On the wiki we would have a header that was added to pages when new versions were created; can we easily do the same on readthedocs?

There’s a similar tradeoff with github links to line numbers in branches which can get out of date compared to a link to the commit+line number.

There is no automatic redirect. Maybe after structure of documentation is stabilized we can establish a policy of never deleting documentation page but add links to pages where content is moved to.

1 Like

Hi Pieper,

I too need to extract the x,y,z coordinates from a VTK file that I imported to Slicer. I was hoping you could be a little more explicit about how to use arrayFromModelPoints? I have imported the VTK and can see the mesh in the viewer, now what? Sorry if this is a trivial question, I’m relatively new to Slicer.

Here’s what I’m looking at:

If you can see at the bottom, I attempted to run ‘slicer.util.arrayFromModelPoints(mesh)’ since my “Node” is named mesh as far as I can tell. Dead end and I got the error “NameError: name ‘mesh’ is not defined”

You need to use something like:

meshModelNode = slicer.util.getNode("mesh")
points = slicer.util. arrayFromModelPoints(meshModelNode)

(you can leave out slicer.util when typing at the console).

To get used to slicer python programming you can have a look at the FAQ and some of the tutorials.

1 Like