Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert .csv file to .vtp file (vmtk PolyData type data)

Tags:

python

csv

vtk

I'm working to convert the data of a line in a csv file (comma separated file) to a .vtp file.

What I have done is to store the points in the .csv file into a vtkPolyData type variable. The vtkPolyData can be displayed with the render window correctly.

Then I tried to use vtkPolyDataWriter to write the vtkPolyData into a vtp file. But It did not work

writer = vtk.vtkPolyDataWriter()
writer.SetInput(vtkpoint.getVtkPolyData) 
## vtkpoint is an instance of a class which I wrote to store the csv data,
## and .getVtkPolyData returns the vtkPolyData typed data 
writer.SetFileName('TestCenterline.vtp')
writer.SetFileTypeToBinary()
writer.Write()

This vtp file is not readable.

like image 437
diodeBucks Avatar asked Feb 22 '26 13:02

diodeBucks


1 Answers

If you want to inspect the file by reading its content, use

writer->SetDataModeToAscii();

instead if binary.

Also vtkpoint.getVtkPolyData looks a bit suspect. Maybe it's just bad naming or bad copy/paste, but are you sure that that is the actual polydata and not just a method? Are you able to get the correct value by calling vtkpoint.getVtkPolyData.GetNumberOfPoints()?

like image 94
lib Avatar answered Feb 25 '26 16:02

lib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!