File: TestComputeBounds.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 (71 lines) | stat: -rwxr-xr-x 2,264 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
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from vtkmodules.vtkCommonCore import (
    vtkMath,
    vtkPoints,
)
from vtkmodules.vtkCommonDataModel import vtkBoundingBox
from vtkmodules.vtkCommonSystem import vtkTimerLog
import sys

# Test speed, serial versus threaded, of compute bounds in
# vtkBoundingBox.

# Control model size
baseSize = 1000
threadingCrossover = 750000
timer = vtkTimerLog()
math = vtkMath()

# Uncomment if you want to use as a little interactive program
#if len(sys.argv) >= 2 :
#    res = int(sys.argv[1])
#else:
#    res = baseSize


# Compares serial to threaded computation of the bounding box.  The current
# crossover point is hardcoded in the code (vtkBoundingBox.cxx) so this test
# may need to be updated in the future. (The crossover point, expressed in
# terms of number of points, is used to switch between a serial computation
# for smaller data, versus a threaded computation for larger data, due to the
# cost of spinning up threads.)

serialPoints = vtkPoints()
serialPoints.SetDataTypeToDouble()
serialPoints.SetNumberOfPoints(threadingCrossover - baseSize)
numSerialPts = threadingCrossover - baseSize;
for i in range(0,numSerialPts):
    serialPoints.SetPoint(i, math.Random(-1.0,1.0),
                          math.Random(-1.0,1.0),
                          math.Random(-1.0,1.0))

threadedPoints = vtkPoints()
threadedPoints.SetDataTypeToDouble()
threadedPoints.SetNumberOfPoints(threadingCrossover + baseSize)
numThreadedPts = threadingCrossover - baseSize;
for i in range(0,numThreadedPts):
    threadedPoints.SetPoint(i, math.Random(-1.0,1.0),
                          math.Random(-1.0,1.0),
                          math.Random(-1.0,1.0))

serialBox = [0.0,0.0,0.0,0.0,0.0,0.0]
threadedBox = [0.0,0.0,0.0,0.0,0.0,0.0]

bbox = vtkBoundingBox()
timer.StartTimer()
bbox.ComputeBounds(serialPoints,serialBox)
timer.StopTimer()
serialTime = timer.GetElapsedTime()

timer.StartTimer()
bbox.ComputeBounds(threadedPoints,threadedBox)
timer.StopTimer()
threadedTime = timer.GetElapsedTime()

print("vtkBoundingBox::ComputeBounds():")
print("\tSerial Time: {0}".format(serialTime))
print("\tBounds: {0}".format(serialBox))
print("\tThreaded Time: {0}".format(threadedTime))
print("\tBounds: {0}".format(threadedBox))