[vtkusers] Can a VTK file consists of Points only

Hal Canary hal at cs.unc.edu
Thu Apr 25 22:21:54 EDT 2013


On 04/25/2013 10:08 PM, Hal Canary wrote:
> On 04/25/2013 10:04 PM, Hayden Smith wrote:
>>       I have a set of points which I would like to use to make a VTK
>> file. As there are several formals, which formats will be suitable. I
>> used Poydata type only with points. But I can't display the points.
>> Please provide me suggestions.
>
> Add a cell array for the vertices. vtkMaskPoints can do that.

Here's an example:

#!/usr/bin/env python
import vtk
fileName = '/tmp/in.csv'
outFileName = '/tmp/out.vtp'
with open(fileName,'r') as f:
     columns = f.readline().strip().split(',')
reader = vtk.vtkDelimitedTextReader()
reader.SetFileName(fileName)
reader.SetFieldDelimiterCharacters(",")
reader.DetectNumericColumnsOn()
reader.SetHaveHeaders(True)
reader.Update()
numberOfRows = reader.GetOutput().GetNumberOfRows()
tableToPolyData = vtk.vtkTableToPolyData()
tableToPolyData.SetInputConnection(reader.GetOutputPort())
tableToPolyData.SetXColumn(columns[0])
tableToPolyData.SetYColumn(columns[1])
tableToPolyData.SetZColumn(columns[2])
try:
     tableToPolyData.PreserveCoordinateColumnsAsDataArraysOn();
except:
     pass # introduced in 5.10?
maskPoints = vtk.vtkMaskPoints()
maskPoints.SetInputConnection(tableToPolyData.GetOutputPort())
maskPoints.SetOnRatio(1)
maskPoints.RandomModeOff()
maskPoints.SetMaximumNumberOfPoints(numberOfRows)
maskPoints.GenerateVerticesOn()
maskPoints.SingleVertexPerCellOn()
writer = vtk.vtkXMLPolyDataWriter()
writer.SetInputConnection(maskPoints.GetOutputPort())
writer.SetFileName(outFileName)
writer.Write()
###############
x,y,z,v
0,0,0,2
0,0,1,3
0,1,0,4
0,1,1,5
1,0,0,6
1,0,1,7
1,1,0,8
1,1,1,9






More information about the vtkusers mailing list