[Paraview] visualising a network of tubes and spheres using python programmable filter

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Wed Apr 15 12:26:38 EDT 2009


Read in the sphere radii and tube radii as point data on the dataset
that you are creating. Both the glyph filter and the tube filter has
options that allow you to scale the glyph (and the tube) by point
data.

On Wed, Apr 15, 2009 at 9:15 AM, Sreejith Kuttanikkad
<sreejithpk at gmail.com> wrote:
> Dear all,
> Thinking that my question went unnoticed, i am sending it again. i would
> appreciate any tips, in particular for displaying tubes with varying
> diameter.
> Thank you
> Sreejith
>
> On Fri, Apr 10, 2009 at 9:46 AM, Sreejith Kuttanikkad <sreejithpk at gmail.com>
> wrote:
>>
>> 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
>>
>
>
> _______________________________________________
> 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 ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
>
>


More information about the ParaView mailing list