0

I want to create line segments in Paraview. The format of my input data for each line segment is as: x0,y0,z0,x1,y1,z1,width I have tried using "Line" command and using https://stackoverflow.com/a/64140580/14367898 @Nico Vuaille's https://stackoverflow.com/users/10219194/nico-vuaille answer I managed to do it. However, since the the number of my line segments gets really high, I need a method that runs faster. I searched and found this method https://discourse.paraview.org/t/rendering-a-few-lines-takes-an-unreasonable-amount-of-memory/667/2:

import vtk
from random import uniform
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
for i in xrange(600):
  pt1 = points.InsertNextPoint(uniform(0, 100), uniform(0, 100), 0)
  pt2 = points.InsertNextPoint(uniform(0, 100), uniform(0, 100), 0)
  lines.InsertNextCell(2, [pt1, pt2])

output.SetPoints(points)
output.SetLines(lines)

It's runs perfectly fast but the line segments doesn't have width. I want to know how can I use the above (or any other appropriate) method, for drawing lines with specific width for each segment. Your help will be much appreciated, Regards, Hamid Rajabi.

Hamid Rajabi
  • 59
  • 1
  • 8

1 Answers1

1

you can add the width as a data array:

import vtk
from random import uniform
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
widths = vtk.vtkDoubleArray()
widths.SetName("width")

for i in range(60):
  pt1 = points.InsertNextPoint(uniform(0, 100), uniform(0, 100), 0)
  pt2 = points.InsertNextPoint(uniform(0, 100), uniform(0, 100), 0)
  w = uniform(0,3)
  widths.InsertNextValue(w)
  widths.InsertNextValue(w)
  lines.InsertNextCell(2, [pt1, pt2])

output.SetPoints(points)
output.GetPointData().AddArray(widths)
output.SetLines(lines)

Then add a Tube filter, choose Vary Radius / By Absolute Scalar (and maybe change the factor)

Nico Vuaille
  • 2,310
  • 1
  • 6
  • 14
  • Thanks for your very proper solution. I, as a person with background, feel it could take me forever to figure this out on my own. I don't why this and look so complicated to me. – Hamid Rajabi Oct 01 '20 at 16:46
  • Those are big framework, an indeed, with a quite hard learning curve. You can find PV doc here : https://docs.paraview.org/en/latest/UsersGuide/index.html for main concepts. – Nico Vuaille Oct 02 '20 at 07:43