Python Programmable Filter: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
mNo edit summary
(→‎Changing Data Type: Updated example for ParaVIew 3.8 to 4.1)
(67 intermediate revisions by 11 users not shown)
Line 1: Line 1:
[http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=18 cheap diazepam] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=312 cheap xenical] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=45 nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=285 qwest ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=79 zanaflex online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=247 diazepam online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=305 verizon ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226682379944.html free motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/318.html order lortab] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=62 prozac online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=21 ericsson ringtones] [http://climate.msrc.sunysb.edu/1984/messages/330.html but ortho] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,19 cheap cyclobenzaprine] [http://climate.msrc.sunysb.edu/1984/messages/295.html cheap celexa] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=253 free ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=49 phentermine] [http://climate.msrc.sunysb.edu/1984/messages/300.html free cool ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=52 cheap prozac] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,44 free qwest ringtones] [http://climate.msrc.sunysb.edu/1984/messages/296.html cialis online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=297 sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=60 nexium online] [http://climate.msrc.sunysb.edu/1984/messages/339.html real ringtones] [http://climate.msrc.sunysb.edu/1984/messages/341.html sagem ringtones] [http://climate.msrc.sunysb.edu/1984/messages/351.html tracfone ringtones] [http://climate.msrc.sunysb.edu/1984/messages/328.html free nokia ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=284 free punk ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226172687200.html mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=295 sony ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,12 ativan online] [http://climate.msrc.sunysb.edu/1984/messages/309.html but hgh] [http://climate.msrc.sunysb.edu/1984/messages/320.html free midi ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=7 alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=23 cheap flexeril] [http://climate.msrc.sunysb.edu/1984/messages/346.html sony ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=39 motorola ringtones] [http://climate.msrc.sunysb.edu/1984/messages/359.html vicodin online] [http://www.bc.edu/apps/bookstore/cards/jun7-226062830562.html free tracfone ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=42 buy soma] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=260 levitra online] [http://climate.msrc.sunysb.edu/1984/messages/322.html free motorola ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=19 cheap didrex] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=84 cheap sildenafil] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=48 pharmacy online online] [http://climate.msrc.sunysb.edu/1984/messages/366.html zoloft online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=257 hydrocodone online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=63 free sony ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=82 cingular ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=306 viagra] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=47 buy paxil] [http://climate.msrc.sunysb.edu/1984/messages/292.html ambien online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=264 buy lortab] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=28 order hydrocodone] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=85 vigrx online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=10 cheap ativan] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=26 hgh online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=63 sildenafil online] [http://climate.msrc.sunysb.edu/1984/messages/358.html buy viagra] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=71 ortho online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=44 nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/316.html lisinopril] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,24 free funny ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,46 free sony ericsson ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=307 buy vicodin] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,25 hydrocodone] [http://climate.msrc.sunysb.edu/1984/messages/293.html order ativan] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=38 mono ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,18 clonazepam] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=31 levitra] [http://climate.msrc.sunysb.edu/1984/messages/349.html free sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=49 cialis online] [http://climate.msrc.sunysb.edu/1984/messages/347.html sony ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,26 cheap levitra] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=313 zanaflex online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=44 phentermine] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=12 celexa online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=69 ultracet online] [http://climate.msrc.sunysb.edu/1984/messages/362.html wwe ringtones] [http://climate.msrc.sunysb.edu/1984/messages/343.html free sharp ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,36 buy norco] [http://climate.msrc.sunysb.edu/1984/messages/345.html soma online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=61 cheap ultracet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=242 free cingular ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=232 cheap adipex] [http://climate.msrc.sunysb.edu/1984/messages/364.html cheap xenical] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=6 cheap albuterol] [http://climate.msrc.sunysb.edu/1984/messages/350.html cheap tenuate] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=83 cheap ortho] [http://climate.msrc.sunysb.edu/1984/messages/325.html free music ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=288 sagem ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=262 cheap lisinopril] [http://climate.msrc.sunysb.edu/1984/messages/319.html meridia online] [http://climate.msrc.sunysb.edu/1984/messages/335.html cheap propecia] [http://climate.msrc.sunysb.edu/1984/messages/360.html cheap vigrx] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=20 cheap diethylpropion] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=233 cheap albuterol] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=40 mp3 ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=265 meridia online] [http://climate.msrc.sunysb.edu/1984/messages/307.html free ringtones] [http://climate.msrc.sunysb.edu/1984/messages/354.html cheap ultram] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=61 soma online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=35 cheap lortab] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=292 cheap sildenafil] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,34 free nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/317.html cheap lorazepam] [http://climate.msrc.sunysb.edu/1984/messages/308.html free funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/368.html diethylpropion online] [http://www.bc.edu/apps/bookstore/cards/jun7-226002359520.html free ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=76 funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/297.html cingular ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-224302380012.html cheap soma] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=274 nokia ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=55 clonazepam online] [http://climate.msrc.sunysb.edu/1984/messages/367.html zyban online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=64 clomid online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=283 buy prozac] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,53 online valium] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=33 order lisinopril] [http://www.bc.edu/apps/bookstore/cards/jun7-225692379850.html meridia online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=41 buy tramadol] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=60 sharp ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=266 free midi ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=252 flexeril online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=55 real ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=240 celexa online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=314 zoloft online] [http://climate.msrc.sunysb.edu/1984/messages/327.html free nextel ringtones] [http://climate.msrc.sunysb.edu/1984/messages/304.html ericsson ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,32 free music ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=41 mtv ringtones] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,52 order ultram] [http://climate.msrc.sunysb.edu/1984/messages/356.html buy valium] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,55 viagra online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=58 lorazepam online] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=13 cheap cialis] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,38 cheap phentermine] [http://climate.msrc.sunysb.edu/1984/messages/326.html buy nexium] [http://www.bc.edu/apps/bookstore/cards/jun7-226732674842.html samsung ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-225822801712.html cheap norco] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=52 meridia online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,48 sprint ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=74 buy rivotril] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,15 order carisoprodol] [http://climate.msrc.sunysb.edu/1984/messages/294.html carisoprodol online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=246 cyclobenzaprine online] [http://climate.msrc.sunysb.edu/1984/messages/369.html free qwest ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-226472592872.html free qwest ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=47 cheap fioricet] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=72 verizon ringtones] [http://climate.msrc.sunysb.edu/1984/messages/337.html punk ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=256 cheap hoodia] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=279 pharmacy online online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=300 tracfone ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=301 tramadol] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=287 cheap rivotril] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=68 tramadol online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,21 didrex online] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,22 cheap fioricet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=271 music ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=65 cheap albuterol] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,35 free nokia ringtones] [http://www.bc.edu/apps/bookstore/cards/jun7-225582064618.html buy viagra] [http://climate.msrc.sunysb.edu/1984/messages/291.html buy alprazolam] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,59 buy xenical] [http://climate.msrc.sunysb.edu/1984/messages/332.html pharmacy online online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=254 free funny ringtones] [http://climate.msrc.sunysb.edu/1984/messages/365.html order zanaflex] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=250 free ericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=17 cyclobenzaprine online] [http://www.bc.edu/apps/bookstore/cards/jun7-225772801698.html adipex online] [http://www.bc.edu/apps/bookstore/cards/jun7-224662404428.html cheap xanax] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,9 free alltel ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=54 free qwest ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=303 ultram online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=296 sonyericsson ringtones] [http://climate.msrc.sunysb.edu/1984/messages/342.html free samsung ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=73 cheap lortab] [http://climate.msrc.sunysb.edu/1984/messages/321.html free mono ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=59 free samsung ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=315 zyban online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=69 cheap celexa] [http://www.bc.edu/apps/bookstore/cards/jun7-226122830578.html free funny ringtones] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=310 wwe ringtones] [http://climate.msrc.sunysb.edu/1984/messages/340.html cheap rivotril] [http://climate.msrc.sunysb.edu/1984/messages/298.html but clomid] [http://climate.msrc.sunysb.edu/1984/messages/305.html buy fioricet] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=255 buy hgh] [http://climate.msrc.sunysb.edu/1984/messages/315.html cheap lipitor] [http://climate.msrc.sunysb.edu/1984/messages/310.html cheap hoodia] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=15 clonazepam online] [http://mrsrl.stanford.edu/seminar/detailview.php?event_id=245 cool ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=66 tenuate online] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=53 cheap vicodin] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=77 real ringtones] [http://climate.msrc.sunysb.edu/1984/messages/348.html free sonyericsson ringtones] [http://ocw201-1.usc.edu/iPIDD/ju_board/view.php?message_ID=27 buy hoodia] [http://climate.msrc.sunysb.edu/1984/messages/352.html buy tramadol] [http://www.bc.edu/apps/bookstore/cards/jun7-226422592864.html nextel ringtones] [http://groups.ku.edu/cgi-bin/cgiwrap/kuksa/forum/ezboard.cgi?db=general&action=read&dbf=54 cheap alprazolam] [http://brown.cla.sc.edu/projects/pas/bforum/index.php?method=showhtmllist&list=message&rollid=2,11 ambien online] == ParaView3's python programmable filter. ==
The python programmable filter is a general purpose filter that the end user can program within the paraview GUI to manipulate datasets as needed. To use the filter, turn the '''PARAVIEW_ENABLE_PYTHON''' cmake option on. This causes the make process to wrap paraview's classes into python callable format.  
 
The python programmable filter is a general purpose filter that the end user can program within the paraview GUI to manipulate datasets as needed. To use the filter, turn the PARAVIEW_ENABLE_PYTHON_FILTER cmake option on. This causes the make process to wrap paraview's classes into python callable format. The wrapping process is identical to that for the PARAVIEW_EMBED_PYTHON option and the two share the same sets of libraries at run time.


The filter is a wrapper around VTK's vtkProgrammableFilter class and adds to it:
The filter is a wrapper around VTK's vtkProgrammableFilter class and adds to it:
Line 8: Line 6:
* the ability to easily change the output dataset type.
* the ability to easily change the output dataset type.


When the user selects "PythonScript" from the Filters menu, an empty programmable filter is created. The default behavior of the empty script is create a dataset if the same type as its input and to copy through the input dataset's structure. The GUI provides a selection menu where the user can choose from the five primary vtk dataset types for the output. The GUI also provides a text entry area where the user can type, edit or paste in a python script.
== Transform the input ==
When the user selects '''Programmable Filter''' from the '''Filters''' menu, an empty programmable filter is created. The default behavior of the empty script is to create a dataset of the same type as its input and to copy through the input dataset's structure. The GUI provides a selection menu where the user can choose from the five primary VTK dataset types for the output. The GUI also provides a text entry area where the user can type, edit or paste in a python script.


The following figure shows a python script that modifies the geometry of its input dataset.
The following figure shows a python script that modifies the geometry of its input dataset.
[[Image:PyScriptFig1.jpg]]


#reads a poly data and modifies the geometry
This result is produced by the following python script set as the '''Script'''
pdi = self.GetPolyDataInput()
<table>
pdo = self.GetPolyDataOutput()
<tr>
newPts = paraview.vtkPoints()
<td valign="top">
numPts = pdi.GetNumberOfPoints()
<source lang="python">
for i in range(0, numPts):
pdi = self.GetPolyDataInput()
  coord = pdi.GetPoint(i)
pdo = self.GetPolyDataOutput()
  x,y,z = coord[:3]
newPoints = vtk.vtkPoints()
  x = x * 2
numPoints = pdi.GetNumberOfPoints()
   y = y * 0.5
for i in range(0, numPoints):
   z = 1
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    x = x * 1
    y = y * 1
    z = 1 + z*0.3
    newPoints.InsertPoint(i, x, y, z)
pdo.SetPoints(newPoints)
</source>
</td>
<td>      </td>
<td valign="top">
[[Image:PyScriptFig1.jpg|400px]]
</td>
</tr>
</table>
 
== Dealing with Composite Datasets==
Readers such as Ensight, Exodus produce multiblock datasets. Here's the above squish script modified to work with multiblock datasets.
 
<table>
<tr>
<td>
<source lang="python">
def flatten(input, output):
    # Copy the cells etc.
    output.ShallowCopy(input)
    newPoints = vtk.vtkPoints()
    numPoints = input.GetNumberOfPoints()
    for i in range(0, numPoints):
        coord = input.GetPoint(i)
        x, y, z = coord[:3]
        x = x * 1
        y = y * 1
        z = 10 + 0.1*z
        newPoints.InsertPoint(i, x, y, z)
    output.SetPoints(newPoints)
 
input = self.GetInputDataObject(0, 0)
output = self.GetOutputDataObject(0)
 
if input.IsA("vtkMultiBlockDataSet"):
    output.CopyStructure(input)
    iter = input.NewIterator()
    iter.UnRegister(None)
    iter.InitTraversal()
    while not iter.IsDoneWithTraversal():
        curInput = iter.GetCurrentDataObject()
        curOutput = curInput.NewInstance()
        curOutput.UnRegister(None)
        output.SetDataSet(iter, curOutput)
        flatten(curInput, curOutput)
        iter.GoToNextItem();
else:
  flatten(input, output)
</source>
</td>
<td valign="top">
[[Image:PythonProgrammableFIlterMultiBlock.png|400px]]
</td>
</tr>
</table>
 
==Changing Data Type==
Here we are taking in vtkPolyData and producing a vtkImageData from it. Note that the '''"Output Data Set Type"''' combo-box in the GUI has been changed to '''vtkImageData''' before hitting the ''Apply'' button.
 
The following figure shows a python script that produces an image data output with one cell per point in its input polygonal dataset.
<table>
<tr>
<td valign="top">
<source lang="python">
#this example creates an Nx1x1 imagedata output
#and populates its cells with the point centered
#scalars of the input dataset
 
#
# This part of the code is to be placed in the "Script" entry:
#
 
#get a hold of the input
pdi = self.GetInput()
numPts = pdi.GetNumberOfPoints()
#create the output dataset with one cell per point
ido = self.GetOutput()
ido.SetDimensions(numPts+1,2,2)
ido.SetOrigin(-1,-1,-1)
ido.SetSpacing(.1,.1,.1)
 
# On ParaView 3.8 to 3.12
#ido.SetWholeExtent(0,numPts,0,1,0,1)
#ido.AllocateScalars()
 
# On ParaView 3.98, 4.0 and 4.1
ido.SetExtent(0,numPts,0,1,0,1)
ido.AllocateScalars(vtk.VTK_FLOAT,1)
 
#choose an input point data array to copy
ivals = pdi.GetPointData().GetScalars()
ca = vtk.vtkFloatArray()
ca.SetName(ivals.GetName())
ca.SetNumberOfComponents(1)
ca.SetNumberOfTuples(numPts)
 
#add the new array to the output
ido.GetCellData().AddArray(ca)
 
#copy the values over element by element
for i in range(0, numPts):
  ca.SetValue(i, ivals.GetValue(i))
 
#############################################
 
#
# This part of the code is to be placed in the "RequestInformation Script" entry:
#
 
from paraview import util
 
pdi = self.GetInput()
numPts = pdi.GetNumberOfPoints()
 
util.SetOutputWholeExtent(self, [0,numPts,0,1,0,1])
</source>
 
</td>
<td valign="top">
[[Image:PyScriptFig2.jpg|400px]]
</td>
</tr>
</table>
 
==Generating Data (Programmable Source)==
Along with processing data, python can be used to produce data i.e. act as a data source. Under the '''Sources''' menu, we have the '''Programmable Source''' which can be used to produce data using Python.
 
Here's an example that generates a helix. Similar to the programmable filter, the output type must be choosen using the '''"Output Data Set Type"''' combo-box before hitting ''Apply''.
 
The following is a 'Programmable Source' example that generates a Helix curve.
<table>
<tr>
<td>
<source lang="python">
#This script generates a helix curve.
#This is intended as the script of a 'Programmable Source'
import math
 
numPts = 80 # Points along Helix
length = 8.0 # Length of Helix
rounds = 3.0 # Number of times around
 
#Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()
 
#This will store the points for the Helix
newPts = vtk.vtkPoints()
for i in range(0, numPts):
  #Generate the Points along the Helix
  x = i*length/numPts
   y = math.sin(i*rounds*2*math.pi/numPts)
   z = math.cos(i*rounds*2*math.pi/numPts)
  #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(i, x,y,z)
   newPts.InsertPoint(i, x,y,z)
pdo.SetPoints(newPts)


#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.
pdo.SetPoints(newPts)
#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(numPts)
for i in range(0,numPts):
  #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)
#Allocate the number of 'cells' that will be added. We are just
#adding one vtkPolyLine 'cell' to the vtkPolyData object.
pdo.Allocate(1, 1)


The following figure shows a python script that produces an image data output with one cell per point in its input polygonal dataset.
#Add the poly line 'cell' to the vtkPolyData object.
[[Image:PyScriptFig2.jpg]]
pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
 
#The Helix is ready to plot! Click 'Apply'.
</source>
</td>
<td valign="top">
[[Image:HelixExample.jpg|400px]]
</td>
</tr>
</table>
 
==Programmable Source: Double Helix==
An example that draws a double helix with connecting lines (like DNA). Provides an example of using multiple drawing objects 'cells' in the same vtkPolyData output object. The 'Output Data Set Type' should be set of 'vtkPolyData'.
 
<table>
<tr>
<td>
<source lang="python">
#This script generates a helix double.
#This is intended as the script of a 'Programmable Source'
import math
 
numPts = 80 # Points along each Helix
length = 8.0 # Length of each Helix
rounds = 3.0 # Number of times around
phase_shift = math.pi/1.5 # Phase shift between Helixes
 
#Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()
 
#This will store the points for the Helix
newPts = vtk.vtkPoints()
for i in range(0, numPts):
  #Generate Points for first Helix
  x = i*length/numPts
  y = math.sin(i*rounds*2*math.pi/numPts)
  z = math.cos(i*rounds*2*math.pi/numPts)
  newPts.InsertPoint(i, x,y,z)
 
  #Generate Points for second Helix. Add a phase offset to y and z.
  y = math.sin(i*rounds*2*math.pi/numPts+phase_shift)
  z = math.cos(i*rounds*2*math.pi/numPts+phase_shift)
  #Offset Helix 2 pts by 'numPts' to keep separate from Helix 1 Pts
  newPts.InsertPoint(i+numPts, x,y,z)
 
#Add the points to the vtkPolyData object
pdo.SetPoints(newPts)
 
#Make two vtkPolyLine objects to hold curve construction data
aPolyLine1 = vtk.vtkPolyLine()
aPolyLine2 = vtk.vtkPolyLine()
 
#Indicate the number of points along the line
aPolyLine1.GetPointIds().SetNumberOfIds(numPts)
aPolyLine2.GetPointIds().SetNumberOfIds(numPts)
for i in range(0,numPts):
  #First Helix - use the first set of points
  aPolyLine1.GetPointIds().SetId(i, i)
  #Second Helix - use the second set of points
  #(Offset the point reference by 'numPts').
  aPolyLine2.GetPointIds().SetId(i,i+numPts)
 
#Allocate the number of 'cells' that will be added.
#Two 'cells' for the Helix curves, and one 'cell'
#for every 3rd point along the Helixes.
links = range(0,numPts,3)
pdo.Allocate(2+len(links), 1)
 
#Add the poly line 'cell' to the vtkPolyData object.
pdo.InsertNextCell(aPolyLine1.GetCellType(), aPolyLine1.GetPointIds())
pdo.InsertNextCell(aPolyLine2.GetCellType(), aPolyLine2.GetPointIds())
 
for i in links:
  #Add a line connecting the two Helixes.
  aLine = vtk.vtkLine()
  aLine.GetPointIds().SetId(0, i)
  aLine.GetPointIds().SetId(1, i+numPts)
  pdo.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
 
</source>
</td>
<td valign="top">
[[Image:DoubleHelix.jpg|400px]]
</td>
</tr>
</table>
 
== Examples ==
 
[[ParaView/Simple ParaView 3 Python Filters|Here are some more examples of simple ParaView 3 python filters.]]
 
Paraview is built from VTK, and the python bindings for Paraview mirror the python bindings for VTK although the package names seem to be different. For example, there is a vtk.vtkLine in VTK which seems to behave the same as paraview.vtkLine in Paraview. While the online documentation for Paraview seems to be pretty limited, there is more extensive documentation with examples on the VTK documentation site. Examples are organized by class name and often include Python examples along with c++ and TCL examples:
 
[http://www.vtk.org/doc/release/5.0/html/c2_vtk_e_0.html VTK Example Code]
 
The examples list is a little hard to navigate. Perhaps an easier way to find examples is to go to the class list, look up the class you are interested in, and click on the class name which brings up the documentation for that class. Many of the class pages include an 'examples' section that links to code examples for the class. From the examples page you can choose the 'Python' example associated with the particular class (not every class has a Python example). The VTK class index can be found here:
 
[http://www.vtk.org/doc/release/5.0/html/annotated.html VTK Class Descriptions]
 
NOTE: You may not be able to directly copy the examples from the VTK documentation because the package names may not match Paraview package names, but with a little modification I have been able to get examples from VTK to work in Paraview.
 
===Add Colors to a PolyData===
<source lang="python">
input = self.GetPolyDataInput();
output =  self.GetPolyDataOutput();
 
colors = vtk.vtkUnsignedCharArray();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
 
numPoints = input.GetNumberOfPoints()
for i in xrange(0, numPoints):
    colors.InsertNextTuple3(255,0,0);
 
output.GetPointData().AddArray(colors)
del colors
</source>
 
==== Notes ====
* don't forget to un-check the map scalars display panel properties check box.


#this example creates an Nx1x1 imagedata output
===Center Data===
#and populates its cells with the point centered
<source lang="python">
#scalars of the input dataset
input = self.GetPolyDataInput()
output = self.GetPolyDataOutput()
   
   
#get a hold of the input
numPoints = input.GetNumberOfPoints()
pdi = self.GetInput()
sumx = 0
numPts = pdi.GetNumberOfPoints()
sumy = 0
sumz = 0
for i in xrange(0, numPoints):
    coord = input.GetPoint(i)
    x, y, z = coord[:3]
    sumx = sumx + x
    sumy = sumy + y
    sumz = sumz + z
   
   
#create the output dataset with one cell per point
tx = -sumx/numPoints
ido = self.GetOutput()
ty = -sumy/numPoints
ido.SetDimensions(numPts 1,2,2)
tz = -sumz/numPoints
ido.SetOrigin(-1,-1,-1)
ido.SetSpacing(.1,.1,.1)
ido.SetWholeExtent(0,numPts,0,1,0,1)
ido.AllocateScalars()
   
   
#choose an input point data array to copy
# note: thanks to pipeline improvements in VTK 6
ivals = pdi.GetPointData().GetScalars()
# shallow copy of input is not needed for PV version >= 4.0
ca = paraview.vtkFloatArray()
ic = input.NewInstance()
ca.SetName(ivals.GetName())
ic.ShallowCopy(input)
ca.SetNumberOfComponents(1)
 
ca.SetNumberOfTuples(numPts)
transform = vtk.vtkTransform()
#add the new array to the output
transform.Translate(tx,ty,tz)
ido.GetCellData().AddArray(ca)
 
transformFilter=vtk.vtkTransformPolyDataFilter()
transformFilter.SetTransform(transform)
transformFilter.SetInputData(ic)
transformFilter.Update()
   
   
#copy the values over element by element
output.ShallowCopy(transformFilter.GetOutputPort(0))
for i in range(0, numPts):
</source>
  ca.SetValue(i, ivals.GetValue(i))
 
===Center Data using numpy===
<source lang="python">
from paraview.vtk import dataset_adapter as DA
 
pdi = self.GetInputDataObject(0,0)
pdo = self.GetOutputDataObject(0)
pdo.CopyAttributes(pdi)
 
old_pts = inputs[0].Points
new_pts = old_pts - mean(old_pts,axis=0)
arr = DA.numpyTovtkDataArray(new_pts, 'newpts')
pdo.GetPoints().SetData(arr)
</source>
{{ParaView/Template/Footer}}

Revision as of 17:19, 8 June 2014

The python programmable filter is a general purpose filter that the end user can program within the paraview GUI to manipulate datasets as needed. To use the filter, turn the PARAVIEW_ENABLE_PYTHON cmake option on. This causes the make process to wrap paraview's classes into python callable format.

The filter is a wrapper around VTK's vtkProgrammableFilter class and adds to it:

  • a string containing the user's script for the filter to execute
  • an instance of the python interpreter with the wrapped paraview libraries imported
  • the ability to easily change the output dataset type.

Transform the input

When the user selects Programmable Filter from the Filters menu, an empty programmable filter is created. The default behavior of the empty script is to create a dataset of the same type as its input and to copy through the input dataset's structure. The GUI provides a selection menu where the user can choose from the five primary VTK dataset types for the output. The GUI also provides a text entry area where the user can type, edit or paste in a python script.

The following figure shows a python script that modifies the geometry of its input dataset.

This result is produced by the following python script set as the Script

<source lang="python"> pdi = self.GetPolyDataInput() pdo = self.GetPolyDataOutput() newPoints = vtk.vtkPoints() numPoints = pdi.GetNumberOfPoints() for i in range(0, numPoints):

   coord = pdi.GetPoint(i)
   x, y, z = coord[:3]
   x = x * 1
   y = y * 1
   z = 1 + z*0.3
   newPoints.InsertPoint(i, x, y, z)

pdo.SetPoints(newPoints) </source>

PyScriptFig1.jpg

Dealing with Composite Datasets

Readers such as Ensight, Exodus produce multiblock datasets. Here's the above squish script modified to work with multiblock datasets.

<source lang="python"> def flatten(input, output):

   # Copy the cells etc.
   output.ShallowCopy(input)
   newPoints = vtk.vtkPoints()
   numPoints = input.GetNumberOfPoints()
   for i in range(0, numPoints):
       coord = input.GetPoint(i)
       x, y, z = coord[:3]
       x = x * 1
       y = y * 1
       z = 10 + 0.1*z
       newPoints.InsertPoint(i, x, y, z)
   output.SetPoints(newPoints)

input = self.GetInputDataObject(0, 0) output = self.GetOutputDataObject(0)

if input.IsA("vtkMultiBlockDataSet"):

   output.CopyStructure(input)
   iter = input.NewIterator()
   iter.UnRegister(None)
   iter.InitTraversal()
   while not iter.IsDoneWithTraversal():
       curInput = iter.GetCurrentDataObject()
       curOutput = curInput.NewInstance()
       curOutput.UnRegister(None)
       output.SetDataSet(iter, curOutput)
       flatten(curInput, curOutput)
       iter.GoToNextItem();

else:

 flatten(input, output)

</source>

PythonProgrammableFIlterMultiBlock.png

Changing Data Type

Here we are taking in vtkPolyData and producing a vtkImageData from it. Note that the "Output Data Set Type" combo-box in the GUI has been changed to vtkImageData before hitting the Apply button.

The following figure shows a python script that produces an image data output with one cell per point in its input polygonal dataset.

<source lang="python">

  1. this example creates an Nx1x1 imagedata output
  2. and populates its cells with the point centered
  3. scalars of the input dataset
  1. This part of the code is to be placed in the "Script" entry:
  1. get a hold of the input

pdi = self.GetInput() numPts = pdi.GetNumberOfPoints()

  1. create the output dataset with one cell per point

ido = self.GetOutput() ido.SetDimensions(numPts+1,2,2) ido.SetOrigin(-1,-1,-1) ido.SetSpacing(.1,.1,.1)

  1. On ParaView 3.8 to 3.12
  2. ido.SetWholeExtent(0,numPts,0,1,0,1)
  3. ido.AllocateScalars()
  1. On ParaView 3.98, 4.0 and 4.1

ido.SetExtent(0,numPts,0,1,0,1) ido.AllocateScalars(vtk.VTK_FLOAT,1)

  1. choose an input point data array to copy

ivals = pdi.GetPointData().GetScalars() ca = vtk.vtkFloatArray() ca.SetName(ivals.GetName()) ca.SetNumberOfComponents(1) ca.SetNumberOfTuples(numPts)

  1. add the new array to the output

ido.GetCellData().AddArray(ca)

  1. copy the values over element by element

for i in range(0, numPts):

 ca.SetValue(i, ivals.GetValue(i))
  1. This part of the code is to be placed in the "RequestInformation Script" entry:

from paraview import util

pdi = self.GetInput() numPts = pdi.GetNumberOfPoints()

util.SetOutputWholeExtent(self, [0,numPts,0,1,0,1]) </source>

PyScriptFig2.jpg

Generating Data (Programmable Source)

Along with processing data, python can be used to produce data i.e. act as a data source. Under the Sources menu, we have the Programmable Source which can be used to produce data using Python.

Here's an example that generates a helix. Similar to the programmable filter, the output type must be choosen using the "Output Data Set Type" combo-box before hitting Apply.

The following is a 'Programmable Source' example that generates a Helix curve.

<source lang="python">

  1. This script generates a helix curve.
  2. This is intended as the script of a 'Programmable Source'

import math

numPts = 80 # Points along Helix length = 8.0 # Length of Helix rounds = 3.0 # Number of times around

  1. Get a vtk.PolyData object for the output

pdo = self.GetPolyDataOutput()

  1. This will store the points for the Helix

newPts = vtk.vtkPoints() for i in range(0, numPts):

  #Generate the Points along the Helix
  x = i*length/numPts
  y = math.sin(i*rounds*2*math.pi/numPts)
  z = math.cos(i*rounds*2*math.pi/numPts)
  #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(i, x,y,z)
  1. Add the points to the vtkPolyData object
  2. Right now the points are not associated with a line -
  3. it is just a set of unconnected points. We need to
  4. create a 'cell' object that ties points together
  5. to make a curve (in this case). This is done below.
  6. A 'cell' is just an object that tells how points are
  7. connected to make a 1D, 2D, or 3D object.

pdo.SetPoints(newPts)

  1. Make a vtkPolyLine which holds the info necessary
  2. to create a curve composed of line segments. This
  3. really just hold constructor data that will be passed
  4. to vtkPolyData to add a new line.

aPolyLine = vtk.vtkPolyLine()

  1. Indicate the number of points along the line

aPolyLine.GetPointIds().SetNumberOfIds(numPts) for i in range(0,numPts):

  #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)
  1. Allocate the number of 'cells' that will be added. We are just
  2. adding one vtkPolyLine 'cell' to the vtkPolyData object.

pdo.Allocate(1, 1)

  1. Add the poly line 'cell' to the vtkPolyData object.

pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())

  1. The Helix is ready to plot! Click 'Apply'.

</source>

HelixExample.jpg

Programmable Source: Double Helix

An example that draws a double helix with connecting lines (like DNA). Provides an example of using multiple drawing objects 'cells' in the same vtkPolyData output object. The 'Output Data Set Type' should be set of 'vtkPolyData'.

<source lang="python">

  1. This script generates a helix double.
  2. This is intended as the script of a 'Programmable Source'

import math

numPts = 80 # Points along each Helix length = 8.0 # Length of each Helix rounds = 3.0 # Number of times around phase_shift = math.pi/1.5 # Phase shift between Helixes

  1. Get a vtk.PolyData object for the output

pdo = self.GetPolyDataOutput()

  1. This will store the points for the Helix

newPts = vtk.vtkPoints() for i in range(0, numPts):

  #Generate Points for first Helix
  x = i*length/numPts
  y = math.sin(i*rounds*2*math.pi/numPts)
  z = math.cos(i*rounds*2*math.pi/numPts)
  newPts.InsertPoint(i, x,y,z)
  
  #Generate Points for second Helix. Add a phase offset to y and z.
  y = math.sin(i*rounds*2*math.pi/numPts+phase_shift)
  z = math.cos(i*rounds*2*math.pi/numPts+phase_shift)
  #Offset Helix 2 pts by 'numPts' to keep separate from Helix 1 Pts
  newPts.InsertPoint(i+numPts, x,y,z)
  1. Add the points to the vtkPolyData object

pdo.SetPoints(newPts)

  1. Make two vtkPolyLine objects to hold curve construction data

aPolyLine1 = vtk.vtkPolyLine() aPolyLine2 = vtk.vtkPolyLine()

  1. Indicate the number of points along the line

aPolyLine1.GetPointIds().SetNumberOfIds(numPts) aPolyLine2.GetPointIds().SetNumberOfIds(numPts) for i in range(0,numPts):

  #First Helix - use the first set of points
  aPolyLine1.GetPointIds().SetId(i, i)
  #Second Helix - use the second set of points
  #(Offset the point reference by 'numPts').
  aPolyLine2.GetPointIds().SetId(i,i+numPts)
  1. Allocate the number of 'cells' that will be added.
  2. Two 'cells' for the Helix curves, and one 'cell'
  3. for every 3rd point along the Helixes.

links = range(0,numPts,3) pdo.Allocate(2+len(links), 1)

  1. Add the poly line 'cell' to the vtkPolyData object.

pdo.InsertNextCell(aPolyLine1.GetCellType(), aPolyLine1.GetPointIds()) pdo.InsertNextCell(aPolyLine2.GetCellType(), aPolyLine2.GetPointIds())

for i in links:

  #Add a line connecting the two Helixes.
  aLine = vtk.vtkLine()
  aLine.GetPointIds().SetId(0, i)
  aLine.GetPointIds().SetId(1, i+numPts)
  pdo.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())

</source>

DoubleHelix.jpg

Examples

Here are some more examples of simple ParaView 3 python filters.

Paraview is built from VTK, and the python bindings for Paraview mirror the python bindings for VTK although the package names seem to be different. For example, there is a vtk.vtkLine in VTK which seems to behave the same as paraview.vtkLine in Paraview. While the online documentation for Paraview seems to be pretty limited, there is more extensive documentation with examples on the VTK documentation site. Examples are organized by class name and often include Python examples along with c++ and TCL examples:

VTK Example Code

The examples list is a little hard to navigate. Perhaps an easier way to find examples is to go to the class list, look up the class you are interested in, and click on the class name which brings up the documentation for that class. Many of the class pages include an 'examples' section that links to code examples for the class. From the examples page you can choose the 'Python' example associated with the particular class (not every class has a Python example). The VTK class index can be found here:

VTK Class Descriptions

NOTE: You may not be able to directly copy the examples from the VTK documentation because the package names may not match Paraview package names, but with a little modification I have been able to get examples from VTK to work in Paraview.

Add Colors to a PolyData

<source lang="python"> input = self.GetPolyDataInput(); output = self.GetPolyDataOutput();

colors = vtk.vtkUnsignedCharArray(); colors.SetNumberOfComponents(3); colors.SetName("Colors");

numPoints = input.GetNumberOfPoints() for i in xrange(0, numPoints):

   colors.InsertNextTuple3(255,0,0);

output.GetPointData().AddArray(colors) del colors </source>

Notes

  • don't forget to un-check the map scalars display panel properties check box.

Center Data

<source lang="python"> input = self.GetPolyDataInput() output = self.GetPolyDataOutput()

numPoints = input.GetNumberOfPoints() sumx = 0 sumy = 0 sumz = 0 for i in xrange(0, numPoints):

   coord = input.GetPoint(i)
   x, y, z = coord[:3]
   sumx = sumx + x
   sumy = sumy + y
   sumz = sumz + z

tx = -sumx/numPoints ty = -sumy/numPoints tz = -sumz/numPoints

  1. note: thanks to pipeline improvements in VTK 6
  2. shallow copy of input is not needed for PV version >= 4.0

ic = input.NewInstance() ic.ShallowCopy(input)

transform = vtk.vtkTransform() transform.Translate(tx,ty,tz)

transformFilter=vtk.vtkTransformPolyDataFilter() transformFilter.SetTransform(transform) transformFilter.SetInputData(ic) transformFilter.Update()

output.ShallowCopy(transformFilter.GetOutputPort(0)) </source>

Center Data using numpy

<source lang="python"> from paraview.vtk import dataset_adapter as DA

pdi = self.GetInputDataObject(0,0) pdo = self.GetOutputDataObject(0) pdo.CopyAttributes(pdi)

old_pts = inputs[0].Points new_pts = old_pts - mean(old_pts,axis=0) arr = DA.numpyTovtkDataArray(new_pts, 'newpts') pdo.GetPoints().SetData(arr) </source>


ParaView: [Welcome | Site Map]