[vtkusers] Can a VTK file consists of Points only

Marco Nawijn nawijn at gmail.com
Mon Apr 29 13:28:01 EDT 2013


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()







On Fri, Apr 26, 2013 at 3:45 PM, Hayden Smith <s_hayden_28 at yahoo.com> wrote:

> Hi,
>    I have tried the following .vtk data file with the foloowing tcl code.
> I tried to generate glyphs at each point. But my screen in blank without
> any output. I have placed the code here. Please help me clarify what's
> going wrong, is it something with code (tcl file) or the data file?
> /******************************************/
> package require vtk
> package require vtkinteraction
>  # Create arc plots
> # get the interactor ui
>
> vtkCamera camera
> # read the bore
> v
> tkPolyDataReader bore
>
> bore SetFileName "bore.vtk"
>
> vtkMaskPoints ptMask
>
> ptMask SetInputConnection [bore GetOutputPort]
>
>  ptMask SetOnRatio 1
> ptMask RandomModeOff
> ptMask SetMaximumNumberOfPoints 10
> ptMask GenerateVerticesOn
> ptMask SingleVertexPerCellOn
>
> vtkArrowSource arrow
>
> arrow SetTipResolution 6
> arrow SetTipRadius 0.25
> arrow SetTipLength 0.5
> arrow SetShaftResolution 6
> arrow SetShaftRadius 0.125
>
> vtkGlyph3D glyph
>
> glyph SetInput [ptMask GetOutput]
> glyph SetSource [arrow GetOutput]
> glyph SetVectorModeToUseVector
> glyph SetColorModeToColorByScalar
> glyph SetScaleModeToDataScalingOff
> glyph OrientOn
> glyph SetScaleFactor 0.5
>
> vtkPolyDataMapper mapBore
>
> mapBore SetInputConnection [glyph GetOutputPort]
> mapBore ScalarVisibilityOff
>
> vtkActor boreActor
>
> boreActor SetMapper mapBore
> [boreActor GetProperty] SetColor 0 0 0
>
> # create the arc plots
> #
> # Create graphics objects
> # Create the rendering window renderer and interactive renderer
> vtkRenderer ren1
>
> ren1 SetActiveCamera camera
>
> vtkRenderWindow renWin
>
> renWin AddRenderer ren1
>
> vtkRenderWindowInteractor iren
>
> iren SetRenderWindow renWin
>
> # Add the actors to the renderer set the background and size
> ren1 AddActor boreActor
> ren1 SetBackground 1 1 1
> renWin SetSize 235 500
> camera SetClippingRange 14144 32817
> camera SetFocalPoint -1023 680 5812
> camera SetPosition 15551 -2426 19820
> camera SetViewUp -0.651889 -0.07576 0.754521
> camera SetViewAngle 20
> renWin Render
> # render the image
> #
> iren AddObserver UserEvent {wm deiconify .vtkInteract}
> iren Initialize
> # prevent the tk window from showing up then start the event loop
> wm withdraw .
>
> /******************************************/
>
> Thanks,
> Hayden
>
>   *From:* Hal Canary <hal at cs.unc.edu>
> *To:* Hayden Smith <s_hayden_28 at yahoo.com>
> *Cc:* "vtkusers at vtk.org" <vtkusers at vtk.org>
> *Sent:* Friday, April 26, 2013 6:54 AM
>
> *Subject:* Re: [vtkusers] Can a VTK file consists of Points only
>
> Try this:
>
> /**************************************************/
> # vtk DataFile Version 3.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 20
> 1 0
> 1 1
> 1 2
> 1 3
> 1 4
> 1 5
> 1 6
> 1 7
> 1 8
> 1 9
> /**************************************************/
>
>
> On 04/26/2013 12:12 AM, Hayden Smith wrote:
> > 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
>
>
>
>
> _______________________________________________
> Powered by 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/20130429/5f7ecc60/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vertex_demo.vtu
Type: application/octet-stream
Size: 1347 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130429/5f7ecc60/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vertex_demo.py
Type: application/octet-stream
Size: 1576 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130429/5f7ecc60/attachment-0001.obj>


More information about the vtkusers mailing list