Hi,
The message you see is an error that says that you don't have a package called
"Scientific" ..
It isn't actually needed in order to read/write a file.
See the attached file, I did modify it... Normaly, it should work fine.
you have to call the program from a command line "python PointCloud.py
input.txt" where input.txt contains one "X Y Z" per line
HTH
Thomas
**********************
Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium
**********************
Date: Wed, 9 Apr 2008 14:30:26 +0800
From: [EMAIL PROTECTED]
To: [email protected]
Subject: [MayaVi-users] converting xyz(txt) to unstructured grid(vtk)
Hi
I found this link
http://mayavi.sourceforge.net/mwiki/PointCloudson converting point clouds to
vtk's unstructured grid form. Unfortunately, I dun know python, is there a C++
program that I can use or could someone show me how to convert the file, I have
installed python on windows and linux. I dun need to install vtk to run this
program rite.. I can just run it from the console...?
anyway, i tried running the script without much knowledge of course, in
windows, I received this error
Traceback (most recent call last):
File "C:\Documents and Settings\kalpanak\Desktop\ppp\xyz2vtk.py", line 1, in
<module>
from Scientific.IO.TextFile import pointclouddatafile
ImportError: No module named Scientific.IO.TextFile
I hope someone could guide me...
#!/usr/bin/env python
"""
Converts xyz point cloud into something renderable
Original code by Rod Holland & Prabhu Ramachandran
Handy to visualise raw ascii column file
questions: [EMAIL PROTECTED] (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=[]
f = open(filename,'r')
for line in f.readlines():
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()-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
MayaVi-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mayavi-users