Salome HOME
swith off tests based on TableReader plugin
[modules/paravis.git] / test / demo0.py
1 # Copyright (C) 2010-2016  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
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. """
23
24 if not ('servermanager' in dir()):
25   from pvsimple import *
26
27 import time, sys, os, inspect
28
29 def render(ss, v, title, nframes):
30   print '============================================================'
31   print title
32   res = []
33   res.append(title)
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]
39     v.StillRender()
40     c1 = time.time()
41     for i in range(nframes):
42       c.Elevation(0.5)
43       v.StillRender()
44       sys.stdout.write(".")
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"
51     
52     res.append((ncells, ncells/tpr))
53
54   return res
55
56 def run(filesour, impth, nframes):
57
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
61   averages. """
62
63   # Create a sphere source to use in the benchmarks
64   ss = Sphere(Radius=0.5, ThetaResolution=32, PhiResolution=8)
65
66   # The view and representation
67   v = GetRenderView()
68   if not v:
69     v = CreateRenderView()
70   rep = None
71   rep = GetRepresentation(proxy=None, view=v)
72   results = []
73
74   # Start with these defaults
75   #v.UseImmediateMode = 0
76   #v.UseTriangleStrips = 0
77   
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)
84
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)
89
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)
95
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)
100
101   # Color by normals
102   lt = MakeBlueToRedLT(-1, 1)
103   rep.LookupTable = lt
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
109   
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)
115
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)
121
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)
127
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)
132
133   newr = []
134   for r in v.Representations:
135    if r != rep:
136      newr.append(r)
137    v.Representations = newr
138   
139   ss = None
140   rep = None
141   
142   v.StillRender()
143   v = None
144
145   if filesour:
146     f = open(filesour, "w")
147   else:
148     f = sys.stdout
149   print >>f, 'configuration, %d, %d' % (results[0][1][0], results[0][2][0])
150   for i in results:
151     print >>f, '"%s", %g, %g' % (i[0], i[1][1], i[2][1])  
152
153
154
155 scriptdir = inspect.getframeinfo(inspect.currentframe())[0]
156 testdir = os.path.dirname( os.path.abspath(scriptdir) )
157
158
159 if __name__ == "__main__":
160   run(filesour=testdir + "/Pic/Information.txt", impth=testdir + "/Pic/", nframes=10)