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