Software‎ > ‎

ParaView

ParaView is a powerful program, that uses python to make data filters.

This is my attempt to learn it for my 3DEMscanner project.


http://www.vtk.org/doc/release/5.0/html/c2_vtk_e_0.html

http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Examples/DataManipulation/Python/Arrays.py?root=VTK&content-type=text/plain

http://www.bioimagesuite.org/vtkbook/xpvtkbook.pdf

http://www.bu.edu/tech/research/training/presentations/visualizationworkshop08/


And it goes like this:

>>> help(paraview)

Help on package paraview:

NAME

paraview

FILE

/home/radoslav/Downloads/cad/graphics/ParaView-3.14.1-Linux-64bit/lib/paraview-3.14/site-packages/paraview/__init__.py

DESCRIPTION

This module is not meant to be used directly. Please look at one of the modules

it provides:

servermanager

pvfilters

vtk

numeric

util

simple


# create simple Cone() and show it in paraview

>>> from paraview.vtk import *

>>> c = Cone()

>>> Show()

>>> Render()


# create simple Sphere() and show it in paraview

>>> s = Sphere()

>>> Show()

>>> Render()


# select Cone object and delete it

# choose with the mouse Cone object on the left

>>> GetSources()

{('Sphere2', '3006'): <paraview.servermanager.Sphere object at 0x31e3910>, ('Cone3', '2841'): <paraview.servermanager.Cone object at 0x3049a50>}

>>> c = GetActiveSources() # Cone object is selected with mouse

>>> Deletec(c)

>>> del c # fully removes the object from memory and from the variable too

>>> Render()


>>> w = GetActiveSource()
>>> a1_RTData_PVLookupTable = GetLookupTableForArray( "RTData", 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 255.0], VectorMode='Magnitude', ColorSpace='Diverging', ScalarRangeInitialized=1.0)
>>> test = GetRepresentation()
>>> test.LookupTable = a1_RTData_PVLookupTable
>>> Render()
<paraview.servermanager.RenderView object at 0x3555c50>
>>> a1_RTData_PVLookupTable = GetLookupTableForArray( "RTData", 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 255.0, 0.0, 0.0, 0.0, 0.0], VectorMode='Magnitude', ColorSpace='Diverging', ScalarRangeInitialized=1.0 )
>>> test.LookupTable = a1_RTData_PVLookupTable
>>> Render()
<paraview.servermanager.RenderView object at 0x3555c50>
>>> test.LookupTable = a1_RTData_PVLookupTable


Programmable filter example

#reads a poly data and modifies the geometry

pdi = self.GetInputDataObject(0,0)

pdo = self.GetOutputDataObject(0)

newPts = vtk.vtkPoints()

numPts = pdi.GetNumberOfPoints()

for i in range(0, numPts):

    coord = pdi.GetPoint(i)

    x,y,z = coord[:3]

    x = x * 2

    y = y * 0.5

    z = 1

        newPts.InsertPoint(i, x,y,z)

    pdo.SetPoints(newPts)


try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

Sphere1 = GetActiveSource()
ProgrammableFilter4 = ProgrammableFilter()

ProgrammableFilter4.RequestUpdateExtentScript = ''
ProgrammableFilter4.PythonPath = ''
ProgrammableFilter4.RequestInformationScript = ''
ProgrammableFilter4.Script = 'from paraview import vtk\n\npdi = self.GetPolyDataInput()\npdo =  self.GetPolyDataOutput()\nnewPoints = vtk.vtkPoints()\nnumPoints = pdi.GetNumberOfPoints()\nfor i in range(0, numPoints):\n    coord = pdi.GetPoint(i)\n    x, y, z = coord[:3]\n    x = x * 1\n    y = y * 1\n    z = 1 + z*0.3\n    newPoints.InsertPoint(i, x, y, z)\npdo.SetPoints(newPoints)'

RenderView1 = GetRenderView()
DataRepresentation2 = GetDisplayProperties(Sphere1)
DataRepresentation5 = Show()
DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]

RenderView1.CameraClippingRange = [4.0515136114457935, 6.802667228384596]

DataRepresentation2.Visibility = 0

Render()

Create from Paraview menu -> Sources / Wavelet
wavelet = GetActiveSource()
data = servermanager.Fetch(wavelet)              # get actual data from server
pointData = data.GetPointData()                  # get point data of the wavelet
avrg = pointData.GetArray(0).GetTuple1(1330)     # returns the data of point number 1330
dir(pointData.GetArray(0))                       # check all Methods applicable to this class




Comments