File: PointGaussianProperties.py

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (99 lines) | stat: -rw-r--r-- 2,963 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

import os, sys
from paraview import simple
from vtk.vtkPVServerManagerRendering import *
from vtk import *
from paraview import smtesting


NUM_POINTS = 5

### Create the geometry
points = vtkPoints()
points.SetNumberOfPoints(NUM_POINTS)

for i in xrange(NUM_POINTS):
    points.SetPoint(i, i, 0.0, 0.0)

verts = vtkCellArray()
verts.InsertNextCell(NUM_POINTS)

for i in xrange(NUM_POINTS):
    verts.InsertCellPoint(i)

polyData = vtkPolyData()
polyData.SetPoints(points)
polyData.SetVerts(verts)

### Create some point data
pointData = polyData.GetPointData();

# Set up a data array containing the point ordinal values
ordinalArrayName = "Ordinal";
ordinalRange = [ 0, NUM_POINTS - 1 ]
ordinalArray = vtkDoubleArray()
ordinalArray.SetName(ordinalArrayName);
ordinalArray.SetNumberOfComponents(1);
ordinalArray.SetNumberOfTuples(NUM_POINTS);

for i in xrange(NUM_POINTS):
    ordinalArray.SetTuple1(i, i)

pointData.AddArray(ordinalArray)

source = simple.TrivialProducer()
source.GetClientSideObject().SetOutput(polyData)

# create a calculator to compute distance
calculator1 = simple.Calculator(Input=source)
calculator1.ResultArrayName = 'Distance'
calculator1.Function = 'mag(coords)'

# create another calculator to compute inverse distance
calculator2 = simple.Calculator(Input=calculator1)
calculator2.ResultArrayName = 'Inverse Distance'
calculator2.Function = '%s-Distance' % str(NUM_POINTS - 1)

# Get the representation
rep = simple.Show(calculator2)

# Set up coloring by one array
rep.Representation = 'Point Gaussian'
simple.ColorBy(rep, ('POINTS', 'Ordinal'))
vtkSMPVRepresentationProxy.RescaleTransferFunctionToDataRange(rep.SMProxy, 'Ordinal', 0, False)

# Set up sizing by another array
scaleTransferFunction = simple.CreatePiecewiseFunction(Points=[0.0, 0.05, 0.5, 0.0, NUM_POINTS - 1, 0.15, 0.5, 0.0])
rep.ScaleTransferFunction = scaleTransferFunction
rep.SetScaleArray = 'Distance'
rep.ScaleByArray = 1
rep.GaussianRadius = 1

# And finally, set up opacity by a third array
opacityTransferFunction = simple.CreatePiecewiseFunction(Points=[0.0, 0.2, 0.5, 0.0, NUM_POINTS - 1, 1.0, 0.5, 0.0])
rep.OpacityTransferFunction = opacityTransferFunction
rep.OpacityArray = 'Inverse Distance'
rep.OpacityByArray = 1

# Now set a custom shader snippet
rep.CustomShader = '''
//VTK::Color::Impl
float dist = dot(offsetVCVSOutput.xy,offsetVCVSOutput.xy);
if (dist > 9.0) {
  discard;
}
'''

# Now render, configure the view, and re-render
renderView = simple.Render()

renderView.CenterOfRotation         = [ (NUM_POINTS - 1) / 2.0 , 0, 0              ]
renderView.CameraPosition           = [ (NUM_POINTS - 1) / 2.0 , 0, NUM_POINTS * 2 ]
renderView.CameraFocalPoint         = [ (NUM_POINTS - 1) / 2.0 , 0, 0              ]
renderView.CameraViewAngle          = 30.0
renderView.CameraParallelProjection = 0

simple.Render(renderView)

if not smtesting.DoRegressionTesting(renderView.SMProxy):
    raise smtesting.TestError('Image comparison failed.')