File: pickCellPoints.py

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (61 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
import sys
import vtk

# Quad
pts = vtk.vtkPoints()
pts.SetNumberOfPoints(6)
coords = [(0,0,0),(2,0,0),(4,0,0),(0,4,0),(2,4,0),(4,4,0)]
for i in range(0,6):
    pts.InsertPoint(i,coords[i])
quads = vtk.vtkCellArray()
cellpoints=[(0,1,4,3),(1,2,5,4)]
for i in range(0,2):
    quads.InsertNextCell(4)
    for j in range(0,4):
        quads.InsertCellPoint(cellpoints[i][j])

poly = vtk.vtkPolyData()
poly.SetPoints(pts)
poly.SetPolys(quads)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(poly)

actor = vtk.vtkActor()
actor.SetMapper(mapper)

ren = vtk.vtkRenderer()
ren.AddActor(actor)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(200,200)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renWin.Render()
iren.Initialize()

pos =         [ (1,1),    (35,40),  (80,40),  (120,40), (165,40),
                (199,160),(165,160),(120,160),(80,160), (35,160)  ]
pickedCells = [ -1,       0,        0,        1,        1,
                -1,       1,        1,        0,        0 ]
pickedPoints= [ -1,       0,        1,        1,        2,
                -1,       5,        4,        4,        3 ]

cellErrors  = 0
pointErrors = 0
cellPicker = vtk.vtkCellPicker()
for i in range(0,len(pos)):
    cellPicker.Pick(pos[i][0],pos[i][1],0,ren)
    if cellPicker.GetCellId() != pickedCells[i]:
        print("pos [{0}] : picked cell id={1} expected cell id={2}".format(pos[i],cellPicker.GetCellId(),pickedCells[i]))
        cellErrors = cellErrors + 1
    if cellPicker.GetPointId() != pickedPoints[i]:
        print("pos [{0}] : picked point id={1} expected point id={2}".format(pos[i],cellPicker.GetPointId(),pickedPoints[i]))
        pointErrors = pointErrors + 1
if pointErrors or cellErrors:
    print( "ERROR: Cell picker : {0} cell-id errors, {1} point-id errors".format(cellErrors,pointErrors) )
    sys.exit(1)