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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import (
reference,
vtkIdList,
vtkMath,
vtkPoints,
)
from vtkmodules.vtkCommonDataModel import (
vtkPolyData,
vtkStaticPointLocator2D,
)
from vtkmodules.vtkCommonSystem import vtkTimerLog
# create a test dataset
#
math = vtkMath()
math.RandomSeed(314159)
# Note: the bigger the data the better vtkStaticPointLocator performs
#testSize = "large"
#testSize = "medium"
testSize = "small"
if testSize == "large":
numPts = 100000000
numProbes = 1000000
elif testSize == "medium":
numPts = 2000000
numProbes = 50000
else:
numPts = 20000
numProbes = 5000
# Create an initial set of points and associated dataset
points = vtkPoints()
points.SetDataTypeToDouble()
points.SetNumberOfPoints(numPts)
for i in range(0,numPts):
points.SetPoint(i,math.Random(-1,1),math.Random(-1,1), 0.0)
polydata = vtkPolyData()
polydata.SetPoints(points)
points.ComputeBounds()
# Create points array which are positions to probe data with
# FindClosestPoint(), We also create an array to hold the results of this
# probe operation.
probePoints = vtkPoints()
probePoints.SetDataTypeToDouble()
probePoints.SetNumberOfPoints(numProbes)
for i in range (0,numProbes):
probePoints.SetPoint(i,math.Random(-1,1),math.Random(-1,1), 0.0)
staticClosest = vtkIdList()
staticClosest.SetNumberOfIds(numProbes)
# Print initial statistics
print("Processing NumPts: {0}".format(numPts))
print("\n")
# StaticPointLocator
# Time the creation of static point locator
staticLocator = vtkStaticPointLocator2D()
staticLocator.SetDataSet(polydata)
staticLocator.SetNumberOfPointsPerBucket(5)
staticLocator.AutomaticOn()
staticTimer = vtkTimerLog()
staticTimer.StartTimer()
staticLocator.BuildLocator()
staticTimer.StopTimer()
BuildTime = staticTimer.GetElapsedTime()
print("Build Static Point Locator: {0}".format(BuildTime))
# Now probe the dataset with FindClosestPoint()
math.RandomSeed(314159)
staticTimer.StartTimer()
for i in range (0,numProbes):
staticClosest.SetId(i, staticLocator.FindClosestPoint(probePoints.GetPoint(i)))
staticTimer.StopTimer()
staticOpTime = staticTimer.GetElapsedTime()
print(" Static Closest point probing: {0}".format(staticOpTime))
print(" Divisions: {0}".format( staticLocator.GetDivisions() ))
# Poke other methods before deleting static locator class
staticClosestN = vtkIdList()
staticLocator.FindClosestNPoints(10, probePoints.GetPoint(0), staticClosestN)
# Intersect with line
# Out of plane line intersection
a0 = [0.5, 0.5, 1]
a1 = [0.5, 0.5, -1]
tol = 0.001
t = reference(0.0)
lineX = [0.0,0.0,0.0]
ptX = [0.0,0.0,0.0]
ptId = reference(-100)
staticLocator.IntersectWithLine(a0,a1,tol,t,lineX,ptX,ptId)
print(" Out of plane line intersection: PtId {0}".format(ptId))
# In plane line intersection
a0 = [-1.5, 0.5, 0]
a1 = [ 1.5, 0.5, 0]
tol = 0.001
t = reference(0.0)
lineX = [0.0,0.0,0.0]
ptX = [0.0,0.0,0.0]
ptId = reference(-100)
staticLocator.IntersectWithLine(a0,a1,tol,t,lineX,ptX,ptId)
print(" In plane line intersection: PtId {0}".format(ptId))
# Okay now delete class
staticTimer.StartTimer()
del staticLocator
staticTimer.StopTimer()
StaticTime2 = staticTimer.GetElapsedTime()
totalStaticTime = BuildTime + staticOpTime + StaticTime2
print(" Delete Point Locator: {0}".format(StaticTime2))
print(" Static Point Locator (Total): {0}".format(totalStaticTime))
print("\n")
|