brief introduction to paraview dev - insa lyondavila/bbtk/software/new/doc/vtk... · load a le:...

78

Upload: others

Post on 09-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

Brief introduction to Paraview dev

Anna Puig Puig and Jordi Campos i Miralles

July 16, 2007

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 2: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

Contents I

Paraview

1 Introduction

2 Using the GUI

3 Using scripts

Internals

4 Architecture

5 Plugins

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 3: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

Contents II

Appendixes

6 Building

7 From VTK to Paraview

8 PV-Dump.py

9 References

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 4: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Part I

Overview

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 5: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Overview

1 Introduction

2 Using the GUI

3 Using scripts

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 6: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Paraview ApplicationExecution modesArchitecture overview

Introduction

1 IntroductionParaview ApplicationExecution modesArchitecture overview

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 7: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Paraview ApplicationExecution modesArchitecture overview

Paraview

ParaView License - BSD style - source redistribution nomandatory

single-processor, multi-processor shared-memory and clusters.

structured and unstructured, time varying and static.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 8: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Paraview ApplicationExecution modesArchitecture overview

Paraview

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 9: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Paraview ApplicationExecution modesArchitecture overview

Modes

Single-User: everything local.

Client-Server: remote server (rendering local or remote).

Client-Distributed Server: multiple remote servers MPI(rendering locally or in parallel).

Client-Distributed Data-Distributed Render: data serverscluster / multiple graphicsHW cluster

RenderWall: display can be tiled for a RenderWall or CAVE.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 10: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Paraview ApplicationExecution modesArchitecture overview

Architecture

Client

Server Manager

Data Srv. Render Srv.

Client: user interface → Server Manager.

Server Manager: layer between data/render servers and user interface. Runs ona single processor.

PVBatchScripts: access to Server Manager without GUI.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 11: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Using the GUI

2 Using the GUI

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 12: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Using the GUI

Follow the paraview-head-example-english.pdf tutorial:

Load a �le: head.vtk

Skull extraction: isosurface density=1200

Changing the visual parameters

Clip the volume (obtain half volume)

Skin extraction: isosurface density=700

Get an slice

Create an animation (moving the slice position)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 13: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Using scripts

3 Using scriptsPython scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 14: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Python scripting

Python scripting: http://www.paraview.org/Wiki/ParaView:pvpython

Execution environments: import paraview

PV Python Shell: inside ParaView application.Stand-alone scripts: using pvpython interpreter (includes aserver manager initialization)

Server connection: connect to an existing data/render server(it may be local).

Proxies: creation/registration; to wrap VTK objects.

Render modules: choose render (or let automatic process).

Displays: choose how to display each object.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 15: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Server Manager

vtkSMProxyManager = singleton to create/manage proxies.

Proxies(vtkSMProxy): placeholders of vtkObjects on theserver (SSObjs)

create SSObjsmantain references to SSObjs (vtkClientServerIDs).mantain a copy of the state of SSObjs. using properties.

Properties(vtkSMProperty): interface to SSobjs.

Domains(vtkSMDomain): possible values Properties can have.

XML is parsed from a �le or string to indicate proxies andproperties creation/con�guration (see Servers/ServerManager/Resources/*.xml).

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 16: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Python Shell

Menu - Tools - Python Shell:

Environment: automatically imported "paraview" pythonmodule.

Connection to PV: paraview.ActiveConnection

Proxy Manager: paraview.pyProxyManager()

Introspection:

Print: useful object information.Iterators: ex. groups in a proxy collection. . .ListProperties: list proxy available properties.dir(): all symbols associated.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 17: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: List all proxies I

(press back arrow after pasting code into the PV-Python-Shell before pushing Enter)

# PV -XX -PVshell -ListProxies.pyproxies = paraview.pyProxyManager (). GetProxiesOnConnection(

paraview.ActiveConnection )

# Iteratorfor group in proxies: # - groups

print "* ", group

for name in proxies[group ]: # -- proxiesprint " - ", name , " ( ", proxies[group ][name]. SMProxy.GetXMLGroup (), " )"

print

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 18: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Properties I

(First: start PV, load some data, and create a �rst Contour �lter; Nest: execute line by line and

interpret output)

# PV -XX -PVshell -ListProxies.pyproxies = paraview.pyProxyManager (). GetProxiesOnConnection(

paraview.ActiveConnection )

contour = proxies["sources"]["Contour1"] # Get contour

print contour.ListProperties () # Get propertiesprint contour.GetContourValues ()

contour.SetContourValues( 700. ) # Set propertiescontour.UpdateVTKObjects ()

print dir( contour ) # Internalsprint dir( contour.SMProxy )print contour.SMProxy.GetVTKClassName ()print contour.SMProxy.GetClassName ()

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 19: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Stand-alone scripts

Interpreter: pvpython

Imports: import paraview

Connection: paraview.ActiveConnection = paraview.Connect()

Sources: always register in "sources", updateVTKObjreader = paraview.CreateProxy("sources", "legacyreader", "sources")reader.SetFileName("ironProt.vtk") ; reader.UpdateVTKObjects()

thresh = paraview.CreateProxy("filters", "Threshold", "sources")thresh.SetInput( reader ) ; thresh.SetThresholdBetween(80, 255)thresh.UpdateVTKObjects()

Window: renderW = paraview.CreateRenderWindow()

How to display: create one display per "actor"disp = paraview.CreateDisplay(trifil, renderW)disp.SetOpacity( 0.5 )disp.SetRepresentation( 1 ) # 0=Points, 1=Wireframe, 2=Surface, 3=Outline, 4=Voldisp.UpdateVTKObjects()

Non-interactive rendering:renderW.ResetCamera() ; renderW.StillRender() ; raw_input("Push Enter to finish")renderM.WriteImage("screenshot.png", "vtkPNGWriter")

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 20: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Sphere - screenshot

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 21: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example:Sphere - Stand-alone script I

# (use pvpython to execute) PV -01- Sphere.pyimport paraview

paraview.ActiveConnection = paraview.Connect () # Create a built -in server

source = paraview.CreateProxy("sources", # Create & register a sphere"SphereSource", "sources")

renderW = paraview.CreateRenderWindow () # Create a renderWin module

display = paraview.CreateDisplay(source ,renderW) # Create a display

renderW.ResetCamera ()renderW.StillRender () # Renders at full resolutionraw_input("Enter to finish")

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 22: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Displays - screenshot

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 23: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Displays I

# (use pvpython to execute) PV -04- Displays.pyimport paraviewparaview.ActiveConnection = paraview.Connect () # Create a built -in server

renderW = paraview.CreateRenderWindow () # RenderWindow

source1 = paraview.CreateProxy("sources", # Sphere: source"SphereSource", "sources")

disp1 = paraview.CreateDisplay(source1 , renderW) # Sphere: displaydisp1.SetRepresentation( 1 ) ; disp1.SetOpacity( 0.5 )disp1.SetScale( 0.8, 1.2, 1. ) ; disp1.UpdateVTKObjects ()

source2 = paraview.CreateProxy("sources", # Cone: source"ConeSource", "sources")

disp2 = paraview.CreateDisplay(source2 , renderW) # Cone: displaydisp2.SetRepresentation( 2 ) ; disp2.SetColor( 1, 1, 0 )disp2.SetPosition( -0.25, 0, 0 ) ; disp2.SetOrientation( 0, 0, 20 )disp2.UpdateVTKObjects ()

renderW.ResetCamera () ; renderW.StillRender ()raw_input("Enter to finish")

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 24: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Generating XML status

Menu - File - Save state(use a text editor to check the XML created �le)

Easy to understand / update.

Useful to create unit-tests.

BUT: you can't create a batch script.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 25: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Generating scripts

PV 2.x: was able to generate Tcl scripts

PV 3.0: is not able to generate scripts by defaultPV-Dump.py: self-created script to generate python codeusing introspection (the code is listed in Appendixes):

Menu - Tools - Python Shell - Run script

locate and choose PV-Dump.py

help(Dump): help about Dump tools

Dump.proxyList(): list current proxies

Dump.allToPython("script.py"): create script

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 26: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Apply masks to an original dataset

1 Load teddy-64.bin (643)

2 Load teddy-64-seg1-mascara.bin with ScalarArrayName="Mask"

3 Filter: Append Attributes (having both data sets selected)

4 Filter: Calculator with formula "ImageFile*Mask/255"

5 Menu - Tools - Python Shell - Run script: PV-Dump.py

6 Generate the script with Dump.allToPython("script.py")7 Test the generated script:

as a stand-alone script: pvpython script.py

inside PV-GUI: start PV and Run script from the Python

Shell

8 Modify the generated script:to allow to apply all the masks to the original data set.to save only the volume of interest of each mask.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 27: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Apply masks to an original dataset I

# (use pvpython to execute) PV -XX -TeddyMasks.pyimport sysimport paraviewif paraview.ActiveConnection == None : CONSOLE = Trueelse : CONSOLE = False

def main ():if CONSOLE: # INI: Conn. and RenderM

paraview.ActiveConnection = paraview.Connect ()renderM = paraview.CreateRenderWindow ()

else:renders = paraview.pyProxyManager (). GetProxiesInGroup("multirendermodule",

paraview.ActiveConnection)renderM = renders.values ()[0]. GetRenderModules ()[0]

for i in [ 1, 4, 6, 8, 10, 12 ]: # Extract ROIsextractROI( i, ".", "teddy -64. bin", "teddy -64-seg"+str(i)+"-mascara.bin",

"teddy -64-seg"+str(i)+"-extracted.vti", renderM )

if CONSOLE: # END: renderrenderM.ResetCamera ()renderM.StillRender ()import time ; time.sleep (2)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 28: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Apply masks to an original dataset II

def extractROI(idx , workingDir , dataFile , maskFile , outFile , renderM ):data = paraview.CreateProxy("sources", # Data

"ImageReader", "sources", dataFile )data.SetFilePrefix ( workingDir + "/" + dataFile )data.SetDataScalarType (3) ; data.SetScalarArrayName ("ImageFile")data.SetFileDimensionality (3) ; data.SetNumberOfScalarComponents (1)data.SetDataOrigin (0, 0, 0) ; data.SetDataSpacing (1, 1, 1)data.SetDataExtent (0, 63, 0, 63, 0, 63)data.UpdateVTKObjects ()

mask = paraview.CreateProxy("sources", # Mask"ImageReader", "sources", maskFile)

mask.SetFilePrefix ( workingDir + "/" + maskFile )mask.SetDataScalarType (3) ; mask.SetScalarArrayName ("Mask")mask.SetFileDimensionality (3) ; mask.SetNumberOfScalarComponents (1)mask.SetDataOrigin (0, 0, 0) ; mask.SetDataSpacing (1, 1, 1)mask.SetDataExtent (0, 63, 0, 63, 0, 63)mask.UpdateVTKObjects ()

append = paraview.CreateProxy("filters", # Append"AppendAttributes", "sources", "append"+dataFile)

append.AddToInput( data ) ; append.AddToInput( mask )append.UpdateVTKObjects ()

calc = paraview.CreateProxy("filters", # Apply mask"Calculator", "sources", "calc"+dataFile)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 29: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Apply masks to an original dataset III

calc.SetInput( append )calc.SetAddScalarVariable( "ImageFile", "ImageFile", "0", "Mask", "Mask", "0" )if idx != 6: calc.SetFunction( "ImageFile *(Mask /255)" ) # normalelse: calc.SetFunction( "ImageFile *( abs(Mask -255) / 255)" ) # inversecalc.SetAttributeMode( 1 ) ; calc.SetCoordinateResults( 0 )calc.SetReplaceInvalidValues( 1 ) ; calc.SetReplacementValue( 0 )calc.SetResultArrayName( "Result" )calc.UpdateVTKObjects ()

thresh = paraview.CreateProxy("filters", # ROI"Threshold", "sources", "thresh"+dataFile)

thresh.SetInput( calc ) ; thresh.SetAllScalars( 1 )thresh.SetSelectInputScalars( "Result" ) ; thresh.SetThresholdBetween( 1, 42 )thresh.UpdateVTKObjects ()

extract = paraview.CreateProxy("filters", # ROIextraction"ExtractGrid", "sources", "extract"+dataFile)

extract.SetInput( calc )b = thresh.SMProxy.GetDataInformation (). GetBounds () # - get ROI boundsextract.SetVOI( int(b[0]),int(b[1]),int(b[2]),int(b[3]),int(b[4]),int(b[5]) )extract.SetSampleRateI (1); extract.SetSampleRateJ (1); extract.SetSampleRateK (1)extract.SetIncludeBoundary( 1 )extract.UpdateVTKObjects ()

writer = paraview.CreateProxy("writers", # Writer"XMLImageDataWriter", "sources", "writer"+dataFile)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 30: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

IntroductionUsing the GUIUsing scripts

Python scriptingArchitecture - the Server ManagerPV Python ShellStand-alone scriptsSaving GUI status

Example: Apply masks to an original dataset IV

writer.SetInput( extract )writer.SetFileName( workingDir + "/" + outFile )writer.SetDataMode( 1 ) # 0=Ascii 1= Binary 2= Appendwriter.UpdateVTKObjects () ; writer.SMProxy.UpdatePipeline ()

main()

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 31: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Part II

Internals

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 32: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Internals

4 Architecture

5 Plugins

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 33: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Architecture

4 ArchitectureProxies, Properties and DomainsDisplays and Render ModulesOther proxies

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 34: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Proxies

Proxy = wrapper of VTK Objects

Example:<ServerManagerConfiguration>

<ProxyGroup name="filters"><SourceProxy name="MyFilter" class="vtkMyFilter" label="MyFilter"></SourceProxy>

</ProxyGroup></ServerManagerConfiguration>

Creation: vtkSMProxyManager::NewProxy(group, name)

Storage: map< string, map<string, vtkSmartPointer< vtkPVXMLElement > > >

RegisterProxy/UnRegisterProxy: to pass the proxymanagement from user code to the Proxy Manager.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 35: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Properties

Property = (method + arguments) of a VTK Object

Types: vtkSMProperty (no args),vtkSMIntVectorProperty (vector of ints),vtkSMStringVectorProperty (vector of strings, ints anddoubles) . . .

Example:<SourceProxy name="SphereSource" class="vtkSphereSource" label="Sphere">

<DoubleVectorProperty name="Radius" command="SetRadius" number_of_elements="1"animateable="1" default_values="0.5" >

<DoubleRangeDomain name="range" min="0"/></DoubleVectorProperty>...

</SourceProxy>

AddProperty/GetProperty: accessors.

UpdateVTKObjects: apply all modi�ed properties.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 36: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Domains

Domain = domain of a property (possible values)

Literals:<DoubleVectorProperty name="Radius" ...>

<DoubleRangeDomain name="range" min="0"/></DoubleVectorProperty>

From other properties:<IntVectorProperty name="TimeStepRangeInfo" ...>...</IntVectorProperty><IntVectorProperty name="TimeStep" ...>

<IntRangeDomain name="range"><RequiredProperties>

<Property name="TimeStepRangeInfo" function="Range"/></RequiredProperties>

</IntRangeDomain></IntVectorProperty>

AddProperty/GetProperty: accessors.

UpdateVTKObjects: apply all modi�ed properties.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 37: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Proxies I

#!/usr/local/bin/pvpython# PV -02- Proxies.pyimport paraview

paraview.ActiveConnection = paraview.Connect () # Create a built -in server

manager = paraview.pyProxyManager () # Access to Proxy Manager

for defin in manager.definition_iter("sources"): # Get all available proxiesprint "%s : %s" % (defin["group"], defin["key"])

print manager.ListProperties("sources", # Get property names"SphereSource") # w/o creating proxy

proxy = paraview.CreateProxy("sources", # Create a proxy"SphereSource", "sources")

proxy.SetThetaResolution (20) # Calling accessorsproxy.UpdateVTKObjects () # Apply changes

print proxy.ListProperties () # Get property names

for property in proxy: print property # List all Properties

print proxy.GetDocumentation (). GetShortHelp () # Obtain documentation

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 38: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Proxies II

print manager.GetProxiesInGroup("sources") # Get current proxies/cnnction

for prxy in manager: print prxy.GetXMLName () # Iterate on current prxyies

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 39: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Displays and Render Modules

vtkSMProxy

...

vtkSMDisplayProxy

...

vtkSMRenderModuleProxy

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 40: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Displays

Display = everyting required to render an object.

Consumer

...

Axes

DataObj LOD Comp Multi IceT

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 41: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Displays I

# (use pvpython to execute) PV -04- Displays.pyimport paraviewparaview.ActiveConnection = paraview.Connect () # Create a built -in server

renderW = paraview.CreateRenderWindow () # RenderWindow

source1 = paraview.CreateProxy("sources", # Sphere: source"SphereSource", "sources")

disp1 = paraview.CreateDisplay(source1 , renderW) # Sphere: displaydisp1.SetRepresentation( 1 ) ; disp1.SetOpacity( 0.5 )disp1.SetScale( 0.8, 1.2, 1. ) ; disp1.UpdateVTKObjects ()

source2 = paraview.CreateProxy("sources", # Cone: source"ConeSource", "sources")

disp2 = paraview.CreateDisplay(source2 , renderW) # Cone: displaydisp2.SetRepresentation( 2 ) ; disp2.SetColor( 1, 1, 0 )disp2.SetPosition( -0.25, 0, 0 ) ; disp2.SetOrientation( 0, 0, 20 )disp2.UpdateVTKObjects ()

renderW.ResetCamera () ; renderW.StillRender ()raw_input("Enter to finish")

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 42: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Render Modules

Render Module = all required to display and render a dataset. PVmay automatically choose one of them.

Simple LOD Compos.

MPI

IceTDesk IceT

Cave

LOD (local), IceTDesk (cli/srv), IceT (tiled)[IceT: tiled distributed rendering librfary] MPI HAS DISAPEARED?

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 43: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Render Modules I

TODO

#!/usr/local/bin/pvpython# PV -03- RenderM.pyimport paraview

paraview.ActiveConnection = paraview.Connect () # Create a built -in server

source1 = paraview.CreateProxy("sources", # Sources"SphereSource", "sources")

renderW = paraview.CreateRenderWindow () # RenderWindows

disp1 = paraview.CreateDisplay(source1 , renderW) # Displays

# TODO: play with camera parameters

renderW.ResetCamera ()renderW.StillRender ()#renderW.WriteImage ("PV -03- RenderM.png", "vtkPNGWriter ")raw_input("Enter to finish")

# I'M INTERESTED IN CONNECTING TO A RUNNING PARAVIEW (LOCAL IN MY MACHINE),# CREATE THE SCENE AND AFTERWARDS LET THE USER INTERACT , IS IT POSSIBLE ???

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 44: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Other proxies

There are proxies for the other VTK objects:http://www.paraview.org/Wiki/ProxyXMLName

sources, �lters, readers/writers

mappers, renderers, interactors

axes, piecewise_functions, 3d_widgets...

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 45: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Other proxies I

#!/usr/local/bin/pvpython# PV -05- OtherProxies.pyimport paraview

paraview.ActiveConnection = paraview.Connect () # Create a built -in server

reader = paraview.CreateProxy("sources", # Reader"XMLImageDataReader", "sources")

reader.SetFileName("head.vti") ; reader.UpdateVTKObjects ()

filter = paraview.CreateProxy("filters", # Filter"Contour", "filters")

filter.SetInput( reader )filter.SetContourValues( 1500. ) ; filter.UpdateVTKObjects ()

axes = paraview.CreateProxy("sources", # Axes"Axes", "sources")

axes.SetOrigin( 100, 100, 100 ) ; axes.SetScaleFactor( 100 )axes.SetSymmetric( 0 ) ; axes.UpdateVTKObjects ()

light = paraview.CreateProxy("lights", # Lights"Light", "lights")

light.SetLightAmbientColor( 0, 1, 0 )light.SetLightIntensity( 1. )light.SetLightType( 2 ) # HOW USING VTK_LIGHT_TYPE_CAMERA_LIGHT CONSTANT ???

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 46: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

Proxies, Properties and DomainsDisplays and Render ModulesOther proxies

Example: Other proxies II

light.SetLightSwitch( 1 )#light.SetFocalPoint( 0, 0, 0) # FAILS , HOW SHOULD IT BE DONE ???#light.SetPosition( 1000, 0, 1000 ) # FAILS , HOW SHOULD IT BE DONE ???light.UpdateVTKObjects ()

renderW = paraview.CreateRenderWindow () # Render Windowprint renderW.ListProperties ()# HOW CAN I ADD LIGHT ???

display = paraview.CreateDisplay(filter , renderW) # Displaysdisplay = paraview.CreateDisplay(axes , renderW)

renderW.ResetCamera ()renderW.StillRender ()raw_input("Enter to finish")

writer = paraview.CreateProxy("writers", # Writer"XMLImageDataWriter", "writers")

writer.SetInput( filter )writer.SetFileName("skull.vti")writer.UpdateVTKObjects ()writer.InvokeCommand("Write")# IT DOES NOT WORK , WHY ??? (I also try with XMLPolyDataWriter)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 47: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

Plugins

5 PluginsVTK objectsQt widgetsToolbarsViews

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 48: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

Plugins

Plugins: http://www.paraview.org/Wiki/Plugin_HowTo

Extending:

VTK objects: readers, writers, �lters. . .Qt widgets:Toolbars:Views: in addition to the existing render view, line chart andbar chart.

May contain both client and server extensions and work if theappropriate client side libraries are on the server.

Use:

Manually: Menu Tools/Plugin Manager.At startup: PV_PLUGIN_PATH = list of semi-colon separateddirectories where plugins exists.

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 49: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

VTK objects

CMakeLists.txt:FIND_PACKAGE(ParaView REQUIRED)INCLUDE($PARAVIEW_USE_FILE) # $ADD_PARAVIEW_PLUGIN(SMMyPluginFilter "1.0"

SERVER_MANAGER_XML MyPluginFilter.xmlSERVER_MANAGER_SOURCES vtkMyPluginFilter.cxx)

xml: Proxy declaration.<ServerManagerConfiguration>

<ProxyGroup name="filters"><SourceProxy name="MyPluginFilter" class="vtkMyPluginFilter" label="MyFilter">

<Documentation long_help="Long" short_help="Short"> Doc</Documentation><InputProperty name="Input" command="SetInputConnection">...

</SourceProxy></ProxyGroup>

</ServerManagerConfiguration>

sources: normal vtk *.h and *.cxxbuild:ccmake .

ParaView_DIR /opt/local/fonts/ParaView3-bin (dir with ParaViewConfig.cmake)EXECUTABLE_OUTPUT_PATH (your local output dir)LIBRARY_OUTPUT_PATH (your local output dir)

make install

(see cpp/PV-01-PluginFilter)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 50: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

GUI development

XML: TODO

Qt: TODOQtDesigner: can be used to view/update UIaptitude install qt4-designer # and use QtDesignerdesigner-qt4 Qt/Components/Resources/UI/pqAnimationPanel.ui

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 51: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

Toolbars

TODO

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 52: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

ArchitecturePlugins

VTK objectsQt widgetsToolbarsViews

Views

TODO

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 53: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Part III

Appendixes

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 54: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Appendixes

6 Building

7 From VTK to Paraview

8 PV-Dump.py

9 References

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 55: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Building

6 Building

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 56: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV Build I

cvs -d :pserver:[email protected]:/cvsroot/ParaView3 login # Empty passwordcvs -d :pserver:[email protected]:/cvsroot/ParaView3 co -r ParaView-3-0 ParaView3

mkdir ParaView3-bin ; cd ParaView3-bin # Out-source built

aptitude install libqt4-dev python2.5-dev

ccmake ../Paraview3BUILD_SHARED_LIBS ONCMAKE_BUILD_TYPE DebugPARAVIEW_ENABLE_PYTHON ONVTK_USE_RPATH ON

makemake install

paraview # Installation finished

cmake -GKDevelop3 ../ParaView3 # You can create a KDevelop projectkdevelop ParaView.kdevelop

aptitude install qt4-designer # and use QtDesignerdesigner-qt4 Qt/Components/Resources/UI/pqAnimationPanel.ui

aptitude install tk8.4-dev # To build vtkpython

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 57: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV Build II

cd VTK # (to run 'VTK only' examples)ccmake ../../Paraview3/VTK # (not required for PVpython ex)

BUILD_SHARED_LIBS ONVTK_WRAP_PYTHON ON

makemake install

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:/usr/local/lib/paraview-3.0/export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.4/site-packages/

vtkpython <any *.py using vtk> # Installation finished

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 58: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

From VTK to Paraview

7 From VTK to Paraview

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 59: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

From VTK to Paraview

VTK Paraview

readers, writers, �lters use "sources"

mappers, actors use "displays"

camera, lights use "render module"(When a source is created using the GUI, its corresponding displayis directly created also. Thus, not only the last pipeline step isrendered, but all the intermmediate steps can be rendered.)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 60: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py

8 PV-Dump.py

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 61: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py

PV-Dump.py = self-created script to generate python code.How to dump a PV session to a script:

1 Start Paraview (PV)2 Use the GUI to build the desired pipeline3 Load PV-Dump.py: Menu - Tools - Python Shell - Run script4 Dump session to a script: Dump.allToPython("script.py")

You can use the resulting script:

to learn how PV builds the pipeline.

as an stand-alone script (pvpython script.py)

to restore the session (it works also from inside PV-GUI).

to build "batch" scripts: add loops, get data from onepipeline step to modify another step, access your own �les. . .

(see an example in the Overview part)Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 62: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py I

# PV -Dump.py# Script to be run inside Paraview:# Menu Tools -> Python Shell , Run Script# Afterwards try using "help(Dump)", "Dump.proxyList ()" ...import re

class Dump:"""Collection of 'static methods ' useful to inspect a running Paraviewpipeline (dumping information to screen or Python code)."""

@staticmethoddef proxyList ():

"""Prints current proxies groups and names"""proxies = Dump.__getProxies ()for group in proxies:

print "* ", groupfor name in proxies[group ]:

print " - ", name , " ( ", proxies[group ][name]. SMProxy.GetXMLGroup (), " )"print

@staticmethoddef allToPython( fileName=None ):

"""Prints the python code necessary to recreate the current PV session.If a file name is provided , it is save into the file."""import sys

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 63: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py II

if fileName:stdoutOrig = sys.stdoutfile = open( fileName , 'w')sys.stdout = file

Dump.__scriptStart ()Dump.proxiesToPython ()Dump.__scriptEnd ()

if fileName:sys.stdout = stdoutOrigfile.close ()

@staticmethoddef proxiesToPython( includeAll=False ):

"""Prints python code to create the current proxies.By default some PV infrastructure proxies are not printed ,but if includeAll is True all of them are printed."""proxies = Dump.__getProxies ()

order = Dump.__orderProxies( proxies ) # Get proxies# ordered by dependencies among them

for level in order:for item in level:

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 64: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py III

(group , name) = item.split(':') # Iterate on them

wrapName = proxies[group ][name]. SMProxy.GetXMLName ()

if includeAll or wrapName not in Dump.__HIDDENPROXIES: # Avoid defaultsDump.proxyToPython( group , name , Dump.__niceLabel(name)) # Dump code

print

@staticmethoddef proxyToPython(group , name , varName='proxy '):

"""Prints the python code necessary to create and setup the given proxy ,using varName as the variable identifier"""proxies = Dump.__getProxies ()proxy = proxies[group ][name]wrapGroup = proxy.SMProxy.GetXMLGroup ()wrapName = proxy.SMProxy.GetXMLName ()

print ' '*54, "# ", varName # Code: createif wrapName == "LODDisplay": # - display proxy

dispInput = Dump.__niceLabel( Dump.__proxyIdLabel( proxy.GetInput ()[0] ) )print varName +' = paraview.CreateDisplay(' \

+ dispInput +', renderM)'elif wrapName == "LODRenderModule": # - render proxy

varName = "renderM"else: # - other proxies

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 65: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py IV

print varName +' = paraview.CreateProxy ("' \+ wrapGroup +'", "'+ wrapName +'", "' \+ group +'", "'+ name +'")'

patternName = re.compile(' *XMLName: *(.*) ')patternValues = re.compile(' *Values: *(.*) ')patternNum = re.compile('^[ -+]?[0 -9.]+$')patternHex = re.compile('^0x[0-9a-f]+$')patternBadProp= re.compile('LightK \:| Displays|InteractorStyle ')for prop in proxy: # For each property

match = patternName.search( str(prop) )propName = match.groups ()[0]

match = patternValues.search( str(prop) ) # Get property.Valuesif match:

values = match.groups ()[0]valuesArray = values.strip (). split(' ')

if patternNum.match( valuesArray [0] ): # If numeric: no quotevaluesList = ', '.join( valuesArray )

elif patternHex.match( valuesArray [0] ): # If hex: fetch objectvaluesArray = proxy.__getattr__("Get"+propName )()valuesList = ', '.join( Dump.__niceLabel( Dump.__proxyIdLabel(p) )

for p in valuesArray)

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 66: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py V

else: # If alpha: quotevaluesList = ', '.join('"' + p + '"' for p in valuesArray)

# Code: set valueif not patternBadProp.search( propName ) and \

valuesList != "none" and \valuesList != '""':

print varName +'.Set'+ propName +'( '+ valuesList +' )'else: # Code: comment

print '# '+ varName +'.Set'+ propName +'( '+ valuesList +' )'#else:# print '# '+ varName +'.'+ propName +': no match for Values '

print varName +'.UpdateVTKObjects ()'print

@staticmethoddef getProxy( group , name ):

"""Return the proxy group:name"""proxies = Dump.__getProxies ()return proxies[group ][name]

# Private -----------------------------------------------

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 67: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py VI

__HIDDENPROXIES = [ "Manipulators", "InteractorStyle", "TrackballZoom","PVAnimationScene", "TimeKeeper", "ElementInspectorView","MultiViewRenderModule" ]

@staticmethoddef __getProxies ():

"""Returns the list of proxies in the current connection"""proxies = paraview.pyProxyManager (). GetProxiesOnConnection( \

paraview.ActiveConnection )return proxies

@staticmethoddef __orderProxies( proxies ):

"""Returns an array , where each entry contains the names of the proxies thatdepend on the previous array entry."""patternName = re.compile(' *XMLName: *(.*) ')patternValues = re.compile(' *Values: *(.*) ')patternHex = re.compile('^0x[0-9a-f]+$')pmanager = paraview.pyProxyManager ()

dependencies = {} # COLLECT DEPSfor group in proxies: # For each proxy

for name in proxies[group ]:dependencies[group+':'+name] = {} # Init its depend.proxy = proxies[group ][name]

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 68: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py VII

for prop in proxy:match = patternName.search( str(prop) )propName = match.groups ()[0]match = patternValues.search( str(prop) ) # Check prop. valuesif match:

values = match.groups ()[0]valuesArray = values.strip (). split(' ')

if patternHex.match( valuesArray [0] ): # If memory addressvaluesArray = proxy.__getattr__("Get"+propName )()for mother in valuesArray:

motherProxyVTK = mother.SMProxy

for motherGroup in proxies: # Find proxy by addrmotherName= pmanager.IsProxyInGroup( motherProxyVTK , motherGroup )if motherName:

dependencies[group+':'+name][ motherGroup+':'+motherName ]=1

order = [] ; currentLevel = [] ; previousLevel = [] # ORDER DEPS

for proxy in pmanager.GetProxiesInGroup('view_modules ', # Start by Viewsparaview.ActiveConnection ):

previousLevel.append( 'view_modules:'+ proxy )

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 69: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py VIII

renders = pmanager.GetProxiesInGroup("multirendermodule", # add Renderersparaview.ActiveConnection)

for renderM in renders.keys ():previousLevel.append( 'multirendermodule:'+renderM )

order.append( previousLevel )

while len( previousLevel ) > 0: # Follow depend.

for item in previousLevel:currentLevel.extend( dependencies[ item ].keys() )

if len(currentLevel) > 0 :order.append( currentLevel )

previousLevel = [] ; previousLevel.extend( currentLevel )currentLevel = []

order.reverse () # First pxs w/o deps

uniqueOrder = [] ; alreadyDeclared = {} # Remove duplicatesfor level in order:

newLevel = []for item in level:

if not alreadyDeclared.get( item ):alreadyDeclared[ item ] = True

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 70: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py IX

newLevel.append( item )

uniqueOrder.append( newLevel )

return uniqueOrder

@staticmethoddef __niceLabel( label ):

"""Returns a string that can be used as var name(starting by a letter , without .-_, ...)"""if not label: return "none"

label = label.replace('.', '') # drop .-_label = label.replace('-', '')label = label.replace('_', '')

if re.compile('[A-z]1').match( label [-2:] ):label = label [0: -1] # drop suffix '1'

if re.compile('^[0 -9]').match( label ):label = 'v' + label # add preffix when starts by number

label = label [0]. lower () + label [1:] # lower 1st char

return label

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 71: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py X

@staticmethoddef __proxyIdLabel( proxy ):

"""Returns the given proxy 's PV displayed name"""proxyVTK = proxy.SMProxypmanager = paraview.pyProxyManager ()proxies = Dump.__getProxies ()for group in proxies:

idLabel = pmanager.IsProxyInGroup( proxyVTK , group )if idLabel:

return idLabelreturn None

@staticmethoddef __scriptStart ():

print '#!/ usr/local/bin/pvpython 'print '# <script >.py'print 'import paraview 'print 'if paraview.ActiveConnection == None : CONSOLE = True'print 'else : CONSOLE = False 'print 'if CONSOLE: # init Conn and RenderM 'print ' paraview.ActiveConnection = paraview.Connect ()'print ' renderM = paraview.CreateRenderWindow ()'print 'else:'print ' renders = paraview.pyProxyManager (). GetProxiesInGroup (" multirendermodule",'

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 72: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

PV-Dump.py XI

print ' paraview.ActiveConnection)'print ' renderM = renders.values ()[0]. GetRenderModules ()[0] 'print

@staticmethoddef __scriptEnd ():

printprint 'if CONSOLE:'print ' renderM.ResetCamera ()'print ' renderM.StillRender ()'print ' raw_input ("Enter to finish ")'print ' #import time ; time.sleep (2)'printprint '#renderM.WriteImage (" screenshot.png", "vtkPNGWriter ")'

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 73: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Example: script generated by PV-Dump.py I

# (use pvpython to execute) PV -06- FrogContourScreenshot.pyimport paraviewif paraview.ActiveConnection == None : CONSOLE = Trueelse : CONSOLE = Falseif CONSOLE: # init Conn and RenderM

paraview.ActiveConnection = paraview.Connect ()renderM = paraview.CreateRenderWindow ()

else:renders = paraview.pyProxyManager (). GetProxiesInGroup("multirendermodule",

paraview.ActiveConnection)renderM = renders.values ()[0]. GetRenderModules ()[0]

# sourcesource = paraview.CreateProxy("sources", "legacyreader", "sources", "frog.vtk")source.SetFileName( "frog.vtk" )source.UpdateVTKObjects ()

# scalarOpacityFunctionscalarOpacityFunction = paraview.CreateProxy("piecewise_functions",

"PiecewiseFunction", "pq_helper_proxies .77", "ScalarOpacityFunction")scalarOpacityFunction.SetPoints( 0, 0, 1, 1 )scalarOpacityFunction.UpdateVTKObjects ()

# contourcontour = paraview.CreateProxy("filters", "Contour", "sources", "Contour1")contour.SetInput( source )contour.SetComputeGradients( 0 )contour.SetComputeNormals( 1 )

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 74: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Example: script generated by PV-Dump.py II

contour.SetComputeScalars( 0 )contour.SetContourValues( 107 )contour.SetSelectInputScalars( "ImageFile" )contour.UpdateVTKObjects ()

# dispdisp = paraview.CreateDisplay(contour , renderM)disp.SetInput( contour )disp.SetVisibility( 1 )disp.SetOpacity( 1 )disp.SetColorMode( 1 )disp.SetColor( 1, 1, 1 )disp.SetDiffuseColor( 1, 1, 1 )disp.SetAmbientColor( 1, 1, 1 )disp.SetMapScalars( 1 )disp.UpdateVTKObjects ()

# RenderrenderM.SetBackground( 0.329412 , 0.34902 , 0.427451 )renderM.SetCameraFocalPoint( 130.57 , 115.332 , 36.0827 )renderM.SetCameraFocalPointInfo( 130.57 , 115.332 , 36.0827 )renderM.SetCameraParallelProjection( 0 )renderM.SetCameraPosition( 386.84 , 502.75 , -398.694 )renderM.SetCameraPositionInfo( 386.84 , 502.75 , -398.694 )renderM.SetCameraViewAngle( 30 )renderM.SetCameraViewUp( -0.285638 , -0.625687 , -0.725897 )renderM.SetCameraViewUpInfo( -0.285638 , -0.625687 , -0.725897 )renderM.UpdateVTKObjects ()

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 75: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

Example: script generated by PV-Dump.py III

if CONSOLE:renderM.ResetCamera ()renderM.StillRender ()raw_input("Enter to finish")#import time ; time.sleep (2)

renderM.WriteImage("screenshot.png", "vtkPNGWriter")

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 76: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

References

9 References

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 77: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

References I

Paraview

Paraview Guide:http://www.kitware.com/products/paraviewguide.html

KW Newsletter:http://www.kitware.com/products/newsletter.html

PV Doc:

User: ParaView3/Documentation/GUIOverview.htmlDeveloper: cd Utilities/Doxygen/ ; make ; source

doc_makeall.sh ; firefox

Utilities/Doxygen/doc/html IS THERE A BETTER WAYTO CREATE PV-Doxygen?

PVpython:http://www.paraview.org/Wiki/ParaView:pvpython

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev

Page 78: Brief introduction to Paraview dev - INSA Lyondavila/bbtk/Software/new/doc/VTK... · Load a le: head.vtk Skull extraction: isosurface density=1200 Changing the visual parameters Clip

BuildingFrom VTK to Paraview

PV-Dump.pyReferences

References II

VTK

VTK User's Guide:http://www.kitware.com/products/vtkguide.html

VTKbook: http://www.bioimagesuite.org/vtkbook/

KW Newsletter:http://www.kitware.com/products/newsletter.html

Anna Puig Puig and Jordi Campos i Miralles Brief introduction to Paraview dev