4

I have a question. I'm new to Paraview and I'm learning how to use it. I need to make a graph from data that are stored in .csv file (2 columns). I have them loaded and converted using TabletToPoints filter. I want ask if it's possible to connect these points by point ID so they will create a line (previous point with next point and so on)

I found a solution:

pdi = self.GetPolyDataInput()
pdo =  self.GetPolyDataOutput()
numPoints = pdi.GetNumberOfPoints()
pdo.Allocate()
 for i in range(0, numPoints-1):
 points = [i, i+1]
 # VTK_LINE is 3
 pdo.InsertNextCell(3, 2, points)
Ali_Sh
  • 2,667
  • 3
  • 43
  • 66
NortySP
  • 41
  • 1
  • 5

2 Answers2

0

Quiet late for @NorthySP, I'm afraid, but may be useful for someone who want to build line (vtkPolyline) from points in ParaView now:

  1. Open data file with points coordinates (txt, csv and other formats ParaView can read and parse).
  2. Apply Programmable Filter on loaded table.
  3. In Programmable Filter settings in Script field input
# the single input table this filter is applied to
table = inputs[0]

# print table properties and metrics just for sure
print("table: ", table)
print("table.GetNumberOfRows() = ", table.GetNumberOfRows())

num_rows = table.GetNumberOfRows()

# usual vtk workflow: fill vtkPoints first
vtkpoints = vtk.vtkPoints()
for i in range(0, num_rows):
    vtkpoints.InsertPoint(i,
        table.GetValue(i,0).ToFloat(), #x column
        table.GetValue(i,1).ToFloat(), #y column
        table.GetValue(i,2).ToFloat()  #z column
        )
output.SetPoints(vtkpoints)

# allocate vtkCell, representing single line
# if more lines, use output.Allocate(N_OF_LINES, 1) 
output.Allocate(1, 1) 

vtkpolyline = vtk.vtkPolyLine()
vtkpolyline.GetPointIds().SetNumberOfIds(num_rows)
# enumerate points to include in polyline
for i in range(0,num_rows):
    vtkpolyline.GetPointIds().SetId(i, i)
# assign vtkPolyLine graphical object to created vtkCell
output.InsertNextCell(vtkpolyline.GetCellType(),
                      vtkpolyline.GetPointIds()) 

Alternatively you can use Programmable Source only instead of Table-Programmable Filter chain: create Programmable Source item, open data file in it's python code, get XYZ from there, and the rest workflow (vtkPointsvtkPolylinevtkCell) is just the same as in filter in my example above.

Also my repository with examples of use Programmable Source and Programmable Filter for lines https://github.com/Ornstein89/paraview_orbit.

enter image description here

Ornstein89
  • 598
  • 1
  • 6
  • 15
-1

Not directly. You can write a Programmable Filter that uses a Python script to create the vtkPolyData dataset with the appropriate.

Refer to some of the examples on the ParaView Wiki (http://www.paraview.org/Wiki/Python_Programmable_Filter) to get started.

Ali_Sh
  • 2,667
  • 3
  • 43
  • 66
Utkarsh
  • 1,492
  • 1
  • 11
  • 19