]> SALOME platform Git repositories - modules/paravis.git/blob - test/demo0.py
Salome HOME
Merge from BR_PARAVIS_DEV 29Dec09
[modules/paravis.git] / test / demo0.py
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. """
4
5 if not ('servermanager' in dir()):
6   from pvsimple import *
7
8 import time, sys, os
9
10 def render(ss, v, title, nframes):
11   print '============================================================'
12   print title
13   res = []
14   res.append(title)
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]
20     v.StillRender()
21     c1 = time.time()
22     for i in range(nframes):
23       c.Elevation(0.5)
24       v.StillRender()
25       sys.stdout.write(".")
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"
32     
33     res.append((ncells, ncells/tpr))
34
35   return res
36
37 def run(filesour, impth, nframes):
38
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
42   averages. """
43
44   # Create a sphere source to use in the benchmarks
45   ss = Sphere(Radius=0.5, ThetaResolution=32, PhiResolution=8)
46
47   # The view and representation
48   v = GetRenderView()
49   if not v:
50     v = CreateRenderView()
51   rep = None
52   rep = GetRepresentation(proxy=None, view=v)
53   results = []
54
55   # Start with these defaults
56   v.UseImmediateMode = 0
57   v.UseTriangleStrips = 0
58   
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)
65
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)
70
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)
76
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)
81
82   # Color by normals
83   lt = MakeBlueToRedLT(-1, 1)
84   rep.LookupTable = lt
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
90   
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)
96
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)
102
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)
108
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)
113
114   newr = []
115   for r in v.Representations:
116    if r != rep:
117      newr.append(r)
118    v.Representations = newr
119   
120   ss = None
121   rep = None
122   
123   v.StillRender()
124   v = None
125
126   if filesour:
127     f = open(filesour, "w")
128   else:
129     f = sys.stdout
130   print >>f, 'configuration, %d, %d' % (results[0][1][0], results[0][2][0])
131   for i in results:
132     print >>f, '"%s", %g, %g' % (i[0], i[1][1], i[2][1])  
133
134
135 testdir = os.getenv("TESTDIR")
136 pvdata = os.getenv("PVDATA")
137
138 if __name__ == "__main__":
139   run(filesour=testdir + "/Pic/Information.txt", impth=testdir + "/Pic/", nframes=10)