1 """ This module can be used to run a simple rendering benchmark test. This
2 test renders a sphere with various rendering settings and reports the rendering
3 rate achieved in triangles/sec. """
5 if not ('servermanager' in dir()):
10 def render(ss, v, title, nframes):
11 print '============================================================'
15 for phires in (500, 1000):
16 ss.PhiResolution = phires
17 c = v.GetActiveCamera()
18 v.CameraPosition = [-3, 0, 0]
19 v.CameraViewUp = [0, 0, 1]
22 for i in range(nframes):
26 sys.stdout.write("\n")
27 tpr = (time.time() - c1)/nframes
28 ncells = ss.GetDataInformation().GetNumberOfCells()
29 print tpr, " secs/frame"
30 print ncells, " polys"
31 print ncells/tpr, " polys/sec"
33 res.append((ncells, ncells/tpr))
37 def run(filesour, impth, nframes):
39 """ Runs the benchmark. If a filename is specified, it will write the
40 results to that file as csv. The number of frames controls how many times
41 a particular configuration is rendered. Higher numbers lead to more accurate
44 # Create a sphere source to use in the benchmarks
45 ss = Sphere(Radius=0.5, ThetaResolution=32, PhiResolution=8)
47 # The view and representation
50 v = CreateRenderView()
52 rep = GetRepresentation(proxy=None, view=v)
55 # Start with these defaults
56 v.UseImmediateMode = 0
57 v.UseTriangleStrips = 0
59 # Test different configurations
60 title = 'display lists, no triangle strips, solid color'
61 v.UseImmediateMode = 0
62 v.UseTriangleStrips = 0
63 results.append(render(ss, v, title, nframes))
64 WriteImage(filename = (impth + "demo0_1.png"), view=v, Magnification=2)
66 title = 'display lists, triangle strips, solid color'
67 v.UseTriangleStrips = 1
68 results.append(render(ss, v, title, nframes))
69 #WriteImage(filename = (impth + "demo0_2.png"), view=v, Magnification=2)
71 title = 'no display lists, no triangle strips, solid color'
72 v.UseImmediateMode = 1
73 v.UseTriangleStrips = 0
74 results.append(render(ss, v, title, nframes))
75 #WriteImage(filename = (impth + "demo0_3.png"), view=v, Magnification=2)
77 title = 'no display lists, triangle strips, solid color'
78 v.UseTriangleStrips = 1
79 results.append(render(ss, v, title, nframes))
80 #WriteImage(filename = (impth + "demo0_4.png"), view=v, Magnification=2)
83 lt = MakeBlueToRedLT(-1, 1)
85 rep.ColorAttributeType = 0 # point data
86 rep.ColorArrayName = "Normals"
87 lt.RGBPoints = [-1, 0, 0, 1, 0.0288, 1, 0, 0]
88 lt.ColorSpace = 1 # HSV
89 lt.VectorComponent = 0
91 title = 'display lists, no triangle strips, color by array'
92 v.UseImmediateMode = 0
93 v.UseTriangleStrips = 0
94 results.append(render(ss, v, title, nframes))
95 #WriteImage(filename = (impth + "demo0_5.png"), view=v, Magnification=2)
97 title = 'display lists, triangle strips, color by array'
98 v.UseTriangleStrips = 1
99 results.append(render(ss, v, title, nframes))
100 v.UseImmediateMode = 1
101 #WriteImage(filename = (impth + "demo0_6.png"), view=v, Magnification=2)
103 title = 'no display lists, no triangle strips, color by array'
104 v.UseImmediateMode = 1
105 v.UseTriangleStrips = 0
106 results.append(render(ss, v, title, nframes))
107 #WriteImage(filename = (impth + "demo0_7.png"), view=v, Magnification=2)
109 title = 'no display lists, triangle strips, color by array'
110 v.UseTriangleStrips = 1
111 results.append(render(ss, v, title, nframes))
112 WriteImage(filename = (impth + "demo0_8.png"), view=v, Magnification=2)
115 for r in v.Representations:
118 v.Representations = newr
127 f = open(filesour, "w")
130 print >>f, 'configuration, %d, %d' % (results[0][1][0], results[0][2][0])
132 print >>f, '"%s", %g, %g' % (i[0], i[1][1], i[2][1])
135 testdir = os.getenv("TESTDIR")
136 pvdata = os.getenv("PVDATA")
138 if __name__ == "__main__":
139 run(filesour=testdir + "/Pic/Information.txt", impth=testdir + "/Pic/", nframes=10)