[Paraview] visualising a network of tubes and spheres using python programmable filter
Sreejith Kuttanikkad
sreejithpk at gmail.com
Fri Apr 10 03:46:37 EDT 2009
Dear paraview,
Following the examples given in paraview wiki, i have made a script to
create a network of lines. After that I apply both tube and glyph(sphere)
filter on it and the resulting
view is attached in the figure. But what i would like to have is to be able
to create varying tube radius and varying sphere radius. Ihave the radii of
each tube and sphere in a file and i like to be able to get this into
paraview. Any help in this regard is appreciated.
here is a sample script.
##---------------------script-----------------##
#!/usr/bin/python
#This is intended as the script of a 'Programmable Source'
#Get a paraview.vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()
filename="network.dat"
#Allocate the number of 'cells' that will be added. We are just
#adding one vtkPolyLine 'cell' to the vtkPolyData object.
no_of_tubes=7
pdo.Allocate(no_of_tubes, 1)
#This will store the points for the lines
newPts = vtk.vtkPoints()
offset=0
file=open(filename,'r')
lines=file.readlines()
for line in lines:
# skip lines starting comment char #
point=0
if line[0]=='#':
pass
else:
#read x,y,z values
#check 3d or 2d network
#end points of tube (x1,y1,z1) & (x2,y2,z2)
if(len(line.split())==6):
x1 = float(line.split()[0])
x2 = float(line.split()[3])
y1 = float(line.split()[1])
y2 = float(line.split()[4])
z1 = float( line.split()[2])
z2 = float( line.split()[5])
else:
x1 = float(line.split()[0])
x2 = float(line.split()[2])
y1 = float(line.split()[1])
y2 = float(line.split()[3])
z1=0.0
z2=0.0
#Insert the Points into the vtkPoints object
#The first parameter indicates the reference.
#value for the point. Here we add them sequentially.
#Note that the first point is at index 0 (not 1).
newPts.InsertPoint(point+offset, x1,y1,z1)
point+=1
pdo.SetPoints(newPts)
#print x1,y1,z1
newPts.InsertPoint(point+offset, x2,y2,z2)
point+=1
pdo.SetPoints(newPts)
#print x2,y2,z2
#Add the points to the vtkPolyData object
#Right now the points are not associated with a line -
#it is just a set of unconnected points. We need to
#create a 'cell' object that ties points together
#to make a curve (in this case). This is done below.
#A 'cell' is just an object that tells how points are
#connected to make a 1D, 2D, or 3D object.
#Make a vtkPolyLine which holds the info necessary
#to create a curve composed of line segments. This
#really just hold constructor data that will be passed
#to vtkPolyData to add a new line.
aPolyLine = vtk.vtkPolyLine()
#Indicate the number of points along the line
aPolyLine.GetPointIds().SetNumberOfIds(point)
for i in range(0,point):
#Add the points to the line. The first value indicates
#the order of the point on the line. The second value
#is a reference to a point in a vtkPoints object. Depends
#on the order that Points were added to vtkPoints object.
#Note that this will not be associated with actual points
#until it is added to a vtkPolyData object which holds a
#vtkPoints object.
aPolyLine.GetPointIds().SetId(i, i+offset)
#Add the poly line 'cell' to the vtkPolyData object.
offset+=point
pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
file.close()
##----------- sample input file network.dat--------##
#end1 end2
0 0 0 1 0 0
1 0 0 1 1 0
1 1 0 0 1 0
0 1 0 0 0 0
1 0 0 2 0 0
2 0 0 2 1 0
2 1 0 1 1 0
Another problem, when i tried to take a screenshot using paraview menu
(file->save screenshot), the paraview got crashed saying Segmentation fault
. I am using paraview linux version 3.4.0 in debian lenny. What would be the
problem?
thank you,
Sreejith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090410/1951af02/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: network.jpeg
Type: image/jpeg
Size: 72046 bytes
Desc: not available
URL: <http://www.paraview.org/pipermail/paraview/attachments/20090410/1951af02/attachment-0001.jpeg>
More information about the ParaView
mailing list