1 # Copyright (C) 2010-2014 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """ This module can be used to run a simple rendering benchmark test. This
21 test renders a sphere with various rendering settings and reports the rendering
22 rate achieved in triangles/sec. """
24 if not ('servermanager' in dir()):
25 from pvsimple import *
27 import time, sys, os, inspect
29 def render(ss, v, title, nframes):
30 print '============================================================'
34 for phires in (500, 1000):
35 ss.PhiResolution = phires
36 c = v.GetActiveCamera()
37 v.CameraPosition = [-3, 0, 0]
38 v.CameraViewUp = [0, 0, 1]
41 for i in range(nframes):
45 sys.stdout.write("\n")
46 tpr = (time.time() - c1)/nframes
47 ncells = ss.GetDataInformation().GetNumberOfCells()
48 print tpr, " secs/frame"
49 print ncells, " polys"
50 print ncells/tpr, " polys/sec"
52 res.append((ncells, ncells/tpr))
56 def run(filesour, impth, nframes):
58 """ Runs the benchmark. If a filename is specified, it will write the
59 results to that file as csv. The number of frames controls how many times
60 a particular configuration is rendered. Higher numbers lead to more accurate
63 # Create a sphere source to use in the benchmarks
64 ss = Sphere(Radius=0.5, ThetaResolution=32, PhiResolution=8)
66 # The view and representation
69 v = CreateRenderView()
71 rep = GetRepresentation(proxy=None, view=v)
74 # Start with these defaults
75 #v.UseImmediateMode = 0
76 #v.UseTriangleStrips = 0
78 # Test different configurations
79 title = 'display lists, no triangle strips, solid color'
80 #v.UseImmediateMode = 0
81 #v.UseTriangleStrips = 0
82 results.append(render(ss, v, title, nframes))
83 WriteImage(filename = (impth + "demo0_1.png"), view=v, Magnification=2)
85 title = 'display lists, triangle strips, solid color'
86 #v.UseTriangleStrips = 1
87 results.append(render(ss, v, title, nframes))
88 #WriteImage(filename = (impth + "demo0_2.png"), view=v, Magnification=2)
90 title = 'no display lists, no triangle strips, solid color'
91 #v.UseImmediateMode = 1
92 #v.UseTriangleStrips = 0
93 results.append(render(ss, v, title, nframes))
94 #WriteImage(filename = (impth + "demo0_3.png"), view=v, Magnification=2)
96 title = 'no display lists, triangle strips, solid color'
97 #v.UseTriangleStrips = 1
98 results.append(render(ss, v, title, nframes))
99 #WriteImage(filename = (impth + "demo0_4.png"), view=v, Magnification=2)
102 lt = MakeBlueToRedLT(-1, 1)
104 rep.ColorAttributeType = 0 # point data
105 rep.ColorArrayName = "Normals"
106 lt.RGBPoints = [-1, 0, 0, 1, 0.0288, 1, 0, 0]
107 lt.ColorSpace = 1 # HSV
108 lt.VectorComponent = 0
110 title = 'display lists, no triangle strips, color by array'
111 #v.UseImmediateMode = 0
112 #v.UseTriangleStrips = 0
113 results.append(render(ss, v, title, nframes))
114 #WriteImage(filename = (impth + "demo0_5.png"), view=v, Magnification=2)
116 title = 'display lists, triangle strips, color by array'
117 #v.UseTriangleStrips = 1
118 results.append(render(ss, v, title, nframes))
119 #v.UseImmediateMode = 1
120 #WriteImage(filename = (impth + "demo0_6.png"), view=v, Magnification=2)
122 title = 'no display lists, no triangle strips, color by array'
123 #v.UseOCImmediateMode = 1
124 #v.UseTriangleStrips = 0
125 results.append(render(ss, v, title, nframes))
126 #WriteImage(filename = (impth + "demo0_7.png"), view=v, Magnification=2)
128 title = 'no display lists, triangle strips, color by array'
129 #v.UseTriangleStrips = 1
130 results.append(render(ss, v, title, nframes))
131 WriteImage(filename = (impth + "demo0_8.png"), view=v, Magnification=2)
134 for r in v.Representations:
137 v.Representations = newr
146 f = open(filesour, "w")
149 print >>f, 'configuration, %d, %d' % (results[0][1][0], results[0][2][0])
151 print >>f, '"%s", %g, %g' % (i[0], i[1][1], i[2][1])
155 scriptdir = inspect.getframeinfo(inspect.currentframe())[0]
156 testdir = os.path.dirname( os.path.abspath(scriptdir) )
159 if __name__ == "__main__":
160 run(filesour=testdir + "/Pic/Information.txt", impth=testdir + "/Pic/", nframes=10)