[vmtk-users] convert .DAT file to a .VTP file

360 views
Skip to first unread message

Haim Ezer

unread,
Jul 4, 2013, 7:40:31 AM7/4/13
to vmtk-...@lists.sourceforge.net
Hello, Luca, everybody.

I wonder if there is a simple way, to convert many files, saved by VMTK in dat format, to the vtp format.

I saved about a 100 centerlines, in the dat format, for the use in matlab, and now I want to use it in VMTK.

VMTK doesn't seem to read this file format, although it saves in this format.

Thanks

Haim
 
--
Haim Ezer, MD
Department of Neurosurgery,
The western Galilee hospital in Nahariya
Israel

Luca Antiga

unread,
Jul 5, 2013, 6:04:45 AM7/5/13
to Haim Ezer, vmtk-...@lists.sourceforge.net
Hello Haim,
 as you know the dat format throws away the cell connectivity information (it only retains the point coordinates), 
so there's not generic way of recreating a vtp from it.
However, as in your case, we can probably infer the connectivity by the fact that lines are written as a sequential
list of points.

One question before I can suggest you a solution: how many lines are there per file (i.e. do your dat files contain
once centerline per file or do you have more?)

Best,


Luca


------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev_______________________________________________
vmtk-users mailing list
vmtk-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vmtk-users

--
Luca Antiga, PhD
Cofounder and Principal Scientist, Orobix Srl
via L.A. Muratori 3, 24123 Bergamo, Italy


Ieva Vaišnoraitė-Navikienė

unread,
Dec 3, 2016, 6:18:08 AM12/3/16
to vmtk-users, haim...@yahoo.com, vmtk-...@lists.sourceforge.net
Hi Luca,

I also had a similar problem (file format without cell connectivity information). There exists many points for many centerlines in one file. Maybe you have an idea how I can convert that file to vtp?

Thank you for your time,
Ieva

Luca Antiga

unread,
Dec 4, 2016, 11:22:16 AM12/4/16
to vmtk-users, haim...@yahoo.com
Hi Leva,
I don’t know if this is true in your case, but usually it is reasonable to assume that between the end of one and the beginning of another the distance between points is greater than the average distance between two points belonging to the same centerlines.
You can write a small Python code that does the parsing line by line and builds a vtkPolyData centerline, creating a new line.
Reading a file: 

with open('data.txt', 'r') as f:
data = f.readlines()

# data is now a list of text lines.

import vtk

points = vtk.vtkPoints()
points.SetNumberOfPoints(len(data))
cells = vtk.vtkCellArray()
radii = vtk.vtkFloatArray()
radii.SetName(‘MaximumInscribedSphereRadius’)
radii.SetNumberOfTuples(len(data))

centerlines = vtk.vtkPolyData()
centerlines.SetPoints(points)
centerlines.SetLines(cells)
centerlines.GetPointData().AddArray(radii)

distance_threshold = 0.1

cellpts = []
prev = None
for i, line in enumerate(data):
x, y, z, r = [float(el) for el in line.split()[:4]]
if not prev:
prev = [x,y,z]
id = points.SetPoint(i,x,y,z)
radii.SetValue(i,r)
        if vtk.vtkDistance2BetweenPoints([x,y,z],prev)**0.5 > distance_threshold:
cells.InsertNextCell(len(cellpts))
for ptid in cellpts:
cells.InsertCellPoint(ptid)
cellpts = []
cellpts.append(id)
prev = [x,y,z]

writer = vtk.vtkXMLPolyDataWriter()
writer.SetInput(centerlines)
writer.SetFileName(‘foo.vtp’)
writer.Write()


Disclaimer: I just banged out the code in my email, I don’t guarantee it will just work, but you get the idea.


Luca


--
You received this message because you are subscribed to the Google Groups "vmtk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vmtk-users+...@googlegroups.com.
To post to this group, send email to vmtk-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages