[vtkusers] Can a VTK file consists of Points only
Hayden Smith
s_hayden_28 at yahoo.com
Fri Apr 26 00:12:36 EDT 2013
Hello,
Thank you very much for the reply. Could you tell me what is the problem with the following vtk file, why it shows error reading cell data?
/**************************************************/# vtk DataFile Version 1.0
track data of XX well
ASCII
DATASET POLYDATA
POINTS 10 float
0.00 0.00 0.00
0.00 0.00 1400.00
0.00 0.48 1466.00
0.50 2.34 1600.00
2.68 4.17 1800.00
5.53 4.68 2000.00
9.15 4.36 2200.00
12.02 1.95 2400.00
8.68 -0.86 2599.96
-1.14 4.81 2799.95
VERTICES 10 10
0 0.00 0.00 0.00
1 0.00 0.00 1400.00
2 0.00 0.48 1466.00
3 0.50 2.34 1600.00
4 2.68 4.17 1800.00
5 5.53 4.68 2000.00
6 9.15 4.36 2200.00
7 12.02 1.95 2400.00
8 8.68 -0.86 2599.96
9 -1.14 4.81 2799.95
CELLS 10 10
1 0.00 0.00 0.00
1 0.00 0.00 1400.00
1 0.00 0.48 1466.00
1 0.50 2.34 1600.00
1 2.68 4.17 1800.00
1 5.53 4.68 2000.00
1 9.15 4.36 2200.00
1 12.02 1.95 2400.00
1 8.68 -0.86 2599.96
1 -1.14 4.81 2799.95
CELL_TYPES 10
/***************************************************/
Thanks,
Hayden
________________________________
From: Hal Canary <hal at cs.unc.edu>
To: vtkusers at vtk.org
Sent: Thursday, April 25, 2013 9:21 PM
Subject: Re: [vtkusers] Can a VTK file consists of Points only
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
_______________________________________________
Powered by http://www.kitware.com/
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130425/6407a05c/attachment.htm>
More information about the vtkusers
mailing list