File: pickCellPoints.py

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (62 lines) | stat: -rwxr-xr-x 1,916 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
62
#!/usr/bin/env python
import sys
import vtk
from vtk.test import Testing

# 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)