[vtkusers] point cloud
Axel Steuwer
steuwer at ill.fr
Mon Dec 1 08:28:34 EST 2003
Hi
I have a little experience in this from trying to visualise
CMM point clouds etc. There are several ways of doing this.
In vtk: if you want the closed (?) surface rendered, there is an
example for reading a simple ascii point cloud and reconstructing
the surface in the /Examples/Modelling/Python/reconstructSurface.py
file. This approach uses the programmable source filter.
You can play around with that.
If you want more interaction (rather than scripting vtk) try Paraview
(Kitware) or Mayavi. I have attached a python script which
converts an ascii xyz column file and creates an unstructured grid vtk 2.0
data file. My script gives each point a colour equivalent to the
z-coordinate, but that's easy to change.
The vtk file can be loaded into Paraview and rendered
there directly. If you want to use Mayavi as a front-end, you'll have to
load the vtk file and then load the surfacemap module to be able
to see the surface. The latest release of Mayavi comes also with a
Delaunay2D/3D filter module for triangulation of the point cloud which
might give you a nice surface. There's a way of calling the Delaunay3D
filter in paraview, and I posted that somewhere on that list.
A simple xyz import filter is on my wishlist, too, for both Paraview
and Mayavi.
Hope that helps.
Axel
-----------------cut here---------------xyz2vtk.py-------------------
#Converts xyz point cloud into something renderable
#Original code by Rod Holland & Prabhu Ramachandran
#Handy to visualise raw ascii column file
#
#questions: a.steuwer at ill.fr (2003)
#
#feel free to simplify the textfile interactions.
#it doesn't really require scientific/numeric to
#be installed to do what it does.
from Scientific.IO.TextFile import TextFile
from Numeric import *
import sys
from sys import argv
if len(argv)>1:
filename = argv[1]
output = str(filename[:-3])+"vtk"
print "output to:", output
else :
print """Usage: 'python xyz2vtk.py pointclouddatafile'
Converts xyz file into vtk UNSTRUCTURED GRID format
for point cloud rendering."""
sys.exit(0)
# change i for headers in ascii file
i=0
x=[]
y=[]
z=[]
for line in TextFile(filename):
words = string.split(line)
i=i+1
if i>0:
if len(words)> 0:
#for j in range(len(words)):
x.append(words[0])
y.append(words[1])
z.append(words[2])
n=len(x)
print "n:",n
# write data to vtk polydata file
# write header
out = open(output, 'w')
h1 = """# vtk DataFile Version 2.0
loop
ASCII
DATASET UNSTRUCTURED_GRID
POINTS """ + str(n) + """ float
"""
out.write(h1)
# write xyz data
for i in range(n):
#s = '%15.2f %15.2f %15.2f' % (x[i], y[i], z[i])
out.write(str(x[i])+" "+str(y[i])+" "+str(z[i])+'\n')
# write cell data
out.write("CELLS "+ str(n)+ " "+ str(2*n)+'\n')
for i in range(n):
#s = '1 %d \n' % (i)
out.write("1 "+str(i)+"\n")
# write cell types
out.write("CELL_TYPES " + str(n)+'\n')
for i in range(n): out.write("1 \n")
# write z scalar values
h2 = '\n' + """POINT_DATA """ + str(n) + "\n"
h3 = """SCALARS Z_Value float 1
LOOKUP_TABLE default"""
out.write(h2+ h3+'\n')
for i in range(n):
sc=(z[i])
out.write(str(sc)+ "\n")
out.write('\n')
out.close()
-------------------------xyz2vtk.py---------------------------------
> Hi,
>
> I'd like to display a cloud of points.
>
> The only way I can think of doing it is to make an vtkUnstructuredGrid
> and to view an actor made from it with SetRepresentationToPoints().
>
> but the grid is complete overkill - can't I make an actor out of
> vtkPoints in some way?
>
> Or another way?
>
> thanks,
>
>
>
> Luke J West : Research Assistant : e-Science
> --------------------------------------------
> Rm. 566/12, School of Ocean & Earth Sciences
> Southampton Oceanography Centre, Southampton
> SO14 3ZH United Kingdom
> --------------------------------------------
> Tel: +44 23 8059 4801 Fax: +44 23 8059 3052
> Mob: +44 79 6107 4783
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq> Follow this link to
> subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list