MCPcopy Create free account
hub / github.com/Kitware/VTK / testEncodings

Method testEncodings

Web/Core/Testing/Python/TestDataEncoder.py:20–84  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

18
19class TestDataEncoder(Testing.vtkTest):
20 def testEncodings(self):
21 # Render something
22 cylinder = vtkCylinderSource()
23 cylinder.SetResolution(8)
24
25 cylinderMapper = vtkPolyDataMapper()
26 cylinderMapper.SetInputConnection(cylinder.GetOutputPort())
27
28 cylinderActor = vtkActor()
29 cylinderActor.SetMapper(cylinderMapper)
30 cylinderActor.RotateX(30.0)
31 cylinderActor.RotateY(-45.0)
32
33 ren = vtkRenderer()
34 renWin = vtkRenderWindow()
35 renWin.AddRenderer(ren)
36 ren.AddActor(cylinderActor)
37 renWin.SetSize(200, 200)
38
39 ren.ResetCamera()
40 ren.GetActiveCamera().Zoom(1.5)
41 renWin.Render()
42
43 # Get a vtkImageData with the rendered output
44 w2if = vtkWindowToImageFilter()
45 w2if.SetInput(renWin)
46 w2if.SetShouldRerender(1)
47 w2if.SetReadFrontBuffer(0)
48 w2if.Update()
49 imgData = w2if.GetOutput()
50
51 # Use vtkDataEncoder to convert the image to PNG format and Base64 encode it
52 encoder = vtkDataEncoder()
53 base64String = encoder.EncodeAsBase64Png(imgData).encode('ascii')
54
55 # Now Base64 decode the string back to PNG image data bytes
56 inputArray = array.array('B', base64String)
57 outputBuffer = bytearray(len(inputArray))
58
59 try:
60 utils = vtkBase64Utilities()
61 except:
62 print('Unable to import required vtkBase64Utilities')
63 raise Exception("TestDataEncoder failed.")
64
65 actualLength = utils.DecodeSafely(inputArray, len(inputArray), outputBuffer, len(outputBuffer))
66 outputArray = bytearray(actualLength)
67 outputArray[:] = outputBuffer[0:actualLength]
68
69 # And write those bytes to the disk as an actual PNG image file
70 with open('TestDataEncoder.png', 'wb') as fd:
71 fd.write(outputArray)
72
73 # Create a vtkTesting object and specify a baseline image
74 rtTester = vtkTesting()
75 for arg in sys.argv[1:]:
76 rtTester.AddArgument(arg)
77 rtTester.AddArgument("-V")

Callers

nothing calls this directly

Calls 15

RotateXMethod · 0.80
RotateYMethod · 0.80
GetActiveCameraMethod · 0.80
EncodeAsBase64PngMethod · 0.80
arrayMethod · 0.80
DecodeSafelyMethod · 0.80
RenderMethod · 0.65
vtkCylinderSourceClass · 0.50
vtkPolyDataMapperClass · 0.50
vtkActorClass · 0.50
vtkRendererClass · 0.50
vtkRenderWindowClass · 0.50

Tested by

no test coverage detected