File: TestStaticPointLocator3.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 181; javascript: 165; objc: 153; tcl: 59
file content (103 lines) | stat: -rwxr-xr-x 2,761 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import (
    vtkIdTypeArray,
    vtkMath,
)
from vtkmodules.vtkCommonDataModel import (
    vtkPointLocator,
    vtkStaticPointLocator,
)
from vtkmodules.vtkCommonSystem import vtkTimerLog
from vtkmodules.vtkFiltersSources import vtkPointSource
from vtkmodules.test import Testing

try:
    import numpy as np
except ImportError:
    print("This test requires numpy")
    Testing.skip()

from vtkmodules.util.numpy_support import vtk_to_numpy

# Test the vtkStaticPointLocator::MergePoints() method.

# create a test dataset
#
math = vtkMath()

# Note: the bigger the data the better vtkStaticPointLocator performs (as
# compared to vtkPointLocator).
#testSize = "large"
#testSize = "medium"
testSize = "small"

if testSize == "large":
    numPts = 20000000
elif testSize == "medium":
    numPts = 2000000
else:
    numPts = 20000

# Create an initial set of points and associated dataset
rpts = vtkPointSource()
rpts.SetNumberOfPoints(numPts)
rpts.SetDistributionToUniform()
rpts.SetRadius(1)
rpts.Update()
polydata = rpts.GetOutput()

# Print initial statistics
print("Processing NumPts: {0}".format(numPts))

timer = vtkTimerLog()

# Create the locator.
sclean = vtkStaticPointLocator()
sclean.SetDataSet(polydata)

timer.StartTimer()
sclean.BuildLocator()
timer.StopTimer()
time = timer.GetElapsedTime()
print("Build Static Point Locator (threaded): {0}".format(time))
print("Number of Divisions: ", sclean.GetDivisions())

# Create a comparison point locator.
clean = vtkPointLocator()
clean.SetDataSet(polydata)

timer.StartTimer()
clean.BuildLocator()
timer.StopTimer()
time = timer.GetElapsedTime()
print("Build Point Locator (serial): {0}".format(time))
print("Number of Divisions: ", clean.GetDivisions())

# The merge map indicates how input points are merged to output points.
mergeMapArray = vtkIdTypeArray()
mergeMapArray.SetNumberOfTuples(polydata.GetNumberOfPoints())
mergeMap = vtk_to_numpy(mergeMapArray)

# Test the point merging process - 0 tolerance. The traversal
# ordering mode is irrelevant.
timer.StartTimer()
sclean.MergePoints(0.0, mergeMap)
timer.StopTimer()
time = timer.GetElapsedTime()
print("\nStatic Point Locator: Merge Points (zero tolerance): {0}".format(time))

# POINT_ORDERING - serial traversal
timer.StartTimer()
sclean.SetTraversalOrder(0)
sclean.MergePoints(0.01, mergeMap)
timer.StopTimer()
time = timer.GetElapsedTime()
print("Static Point Locator: Merge Points (0.01 tolerance, serial): {0}".format(time))

# BIN_ORDERING - threaded traversal
timer.StartTimer()
sclean.SetTraversalOrder(1)
sclean.MergePoints(0.01, mergeMap)
timer.StopTimer()
time = timer.GetElapsedTime()
print("Static Point Locator: Merge Points (0.01 tolerance, threaded): {0}".format(time))