File: TestThreadedWriter.py

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (69 lines) | stat: -rwxr-xr-x 1,809 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
#!/usr/bin/env python
import sys
import os
import time

from vtkmodules.vtkIOAsynchronous import vtkThreadedImageWriter
from vtkmodules.vtkImagingCore import vtkRTAnalyticSource
from vtkmodules.util.misc import vtkGetTempDir

VTK_TEMP_DIR = vtkGetTempDir()

# Write all file types: tif, tiff, bpm, png, jpg, jpeg, vti, Z, ppm, raw
fileNames = [
    'threaded-writer.vti',
    # 'threaded-writer.ppm', # Only for unsigned char
    'threaded-writer.Z',
    # 'threaded-writer.jpg', # Only for unsigned char
    # 'threaded-writer.png', # Only for unsigned char
    # 'threaded-writer.bpm', # Only for unsigned char
    # 'threaded-writer.tif', # Only for unsigned char
    'threaded-writer.raw'
]

# Generate Data
source = vtkRTAnalyticSource()
source.Update()
image = source.GetOutput()

# Initialize writer
writer = vtkThreadedImageWriter()

# Reduce the number of worker threads
writer.SetMaxThreads(2)
writer.Initialize()

# Write all files
wroteFiles = []
t0 = time.time()
for i in range(10):
    for fileName in fileNames:
        filePath = '%s/%s-%s' % (VTK_TEMP_DIR, i, fileName)
        wroteFiles.append(filePath)
        writer.EncodeAndWrite(image, filePath)

t1 = time.time()

# Try to put the print outside the write loop
# to see if that remove time on mum for the dashboard
for filePath in wroteFiles:
    print('write: %s' % filePath)

# Wait for the work to be done
writer.Finalize()
t2 = time.time()

print('Write time', t1 - t0)
print('Wait time', t2 - t1)
print('Total time', t2 - t0)

# The timing is too flicky on the dashboard
# Removing the error detection
if (t1 - t0) > t2 - t1: # The write time should be smaller than the wait time
    print('Calling Write should be like a NoOp and therefore should be fast')

# Validate data checksum
# ...TODO

print("All good...")
# sys.exit(0)