[vtkusers] Can a VTK file consists of Points only
Andrew Maclean
andrew.amaclean at gmail.com
Tue Apr 30 22:03:31 EDT 2013
For VTK 6, you will need to replace:
writer.SetInput(grid)
with
writer.SetInputData(grid)
See: http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput
Regards
Andrew
---------- Forwarded message ----------
> From: Marco Nawijn <nawijn at gmail.com>
> To: Hayden Smith <s_hayden_28 at yahoo.com>
> Cc: "vtkusers at vtk.org" <vtkusers at vtk.org>
> Date: Mon, 29 Apr 2013 19:28:01 +0200
> Subject: Re: [vtkusers] Can a VTK file consists of Points only
> Hi Hayden,
>
> Find below a fully functional example in Python for creating a "mesh"
> with only vertices as cells.
>
> I provided some comments in the file, so it should be relatively easy to
> follow. If not drop
> more questions on the list and we will try to help. I also attached the
> file that is produced
> by the script.
>
> ===== SCRIPT ========================================
> #!/usr/bin/env python
>
> from vtk import vtkPoints, vtkCellArray, vtkVertex, vtkUnstructuredGrid
> from vtk import vtkFloatArray
> from vtk import vtkXMLUnstructuredGridWriter
>
> from random import random
>
> coords = (
> (0,0,2),
> (1,0,2),
> (1,1,2),
> (0,1,2),
> (2,0,2),
> (3,0,2),
> (3,1,2),
> (2,1,2))
>
> #=== Create a VTK array to store points
> points = vtkPoints()
>
> #=== Loop over the list of coordinates and insert them into the array;
> store
> # corresponding point index (or id)
> pids = []
> for crd in coords:
> pids.append(points.InsertNextPoint(crd))
>
> # Create a VTK array to store cells
> cells = vtkCellArray()
>
> vertex = vtkVertex()
> typecode = vertex.GetCellType()
> ncellpoints = vertex.GetNumberOfPoints()
>
> for p in pids:
> # Notify the cells array of how many cellpoints are needed to describe
> the
> # next cell that we want to insert
> cells.InsertNextCell(ncellpoints)
>
> # For a vertex, we only need to insert a single point index; for a
> triangle
> # this would typically be a loop
> cells.InsertCellPoint(p)
>
> # Create a data array
> #
>
> temperature = vtkFloatArray()
> temperature.SetName('temperature')
>
> npoints = points.GetNumberOfPoints()
> temperature.SetNumberOfValues(npoints)
>
> # Insert some random data
> for i in range(npoints):
> temperature.SetValue(i, random())
>
> grid = vtkUnstructuredGrid()
> grid.SetPoints(points)
> grid.SetCells(typecode, cells)
>
> grid.GetPointData().SetScalars(temperature)
>
> writer = vtkXMLUnstructuredGridWriter()
> writer.SetDataModeToAscii()
> writer.SetInput(grid)
> writer.SetFileName('vertex_demo.vtu')
> writer.Write()
>
>
>
>
>
>
>
--
___________________________________________
Andrew J. P. Maclean
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130501/3eb080d0/attachment.htm>
More information about the vtkusers
mailing list