Back to index

salome-paravis  6.5.0
demo0.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 """ This module can be used to run a simple rendering benchmark test. This
00021 test renders a sphere with various rendering settings and reports the rendering
00022 rate achieved in triangles/sec. """
00023 
00024 if not ('servermanager' in dir()):
00025   from pvsimple import *
00026 
00027 import time, sys, os
00028 
00029 def render(ss, v, title, nframes):
00030   print '============================================================'
00031   print title
00032   res = []
00033   res.append(title)
00034   for phires in (500, 1000):
00035     ss.PhiResolution = phires
00036     c = v.GetActiveCamera()
00037     v.CameraPosition = [-3, 0, 0]
00038     v.CameraViewUp = [0, 0, 1]
00039     v.StillRender()
00040     c1 = time.time()
00041     for i in range(nframes):
00042       c.Elevation(0.5)
00043       v.StillRender()
00044       sys.stdout.write(".")
00045       sys.stdout.write("\n")
00046     tpr = (time.time() - c1)/nframes
00047     ncells = ss.GetDataInformation().GetNumberOfCells()
00048     print tpr, " secs/frame"
00049     print ncells, " polys"
00050     print ncells/tpr, " polys/sec"
00051     
00052     res.append((ncells, ncells/tpr))
00053 
00054   return res
00055 
00056 def run(filesour, impth, nframes):
00057 
00058   """ Runs the benchmark. If a filename is specified, it will write the
00059   results to that file as csv. The number of frames controls how many times
00060   a particular configuration is rendered. Higher numbers lead to more accurate
00061   averages. """
00062 
00063   # Create a sphere source to use in the benchmarks
00064   ss = Sphere(Radius=0.5, ThetaResolution=32, PhiResolution=8)
00065 
00066   # The view and representation
00067   v = GetRenderView()
00068   if not v:
00069     v = CreateRenderView()
00070   rep = None
00071   rep = GetRepresentation(proxy=None, view=v)
00072   results = []
00073 
00074   # Start with these defaults
00075   #v.UseImmediateMode = 0
00076   #v.UseTriangleStrips = 0
00077   
00078   # Test different configurations
00079   title = 'display lists, no triangle strips, solid color'
00080   #v.UseImmediateMode = 0
00081   #v.UseTriangleStrips = 0
00082   results.append(render(ss, v, title, nframes))
00083   WriteImage(filename = (impth + "demo0_1.png"), view=v, Magnification=2)
00084 
00085   title = 'display lists, triangle strips, solid color'
00086   #v.UseTriangleStrips = 1
00087   results.append(render(ss, v, title, nframes))
00088   #WriteImage(filename = (impth + "demo0_2.png"), view=v, Magnification=2)
00089 
00090   title = 'no display lists, no triangle strips, solid color'
00091   #v.UseImmediateMode = 1
00092   #v.UseTriangleStrips = 0
00093   results.append(render(ss, v, title, nframes))
00094   #WriteImage(filename = (impth + "demo0_3.png"), view=v, Magnification=2)
00095 
00096   title = 'no display lists, triangle strips, solid color'
00097   #v.UseTriangleStrips = 1
00098   results.append(render(ss, v, title, nframes))
00099   #WriteImage(filename = (impth + "demo0_4.png"), view=v, Magnification=2)
00100 
00101   # Color by normals
00102   lt = MakeBlueToRedLT(-1, 1)
00103   rep.LookupTable = lt
00104   rep.ColorAttributeType = 0 # point data
00105   rep.ColorArrayName = "Normals"
00106   lt.RGBPoints = [-1, 0, 0, 1, 0.0288, 1, 0, 0]
00107   lt.ColorSpace = 1 # HSV
00108   lt.VectorComponent = 0
00109   
00110   title = 'display lists, no triangle strips, color by array'
00111   #v.UseImmediateMode = 0
00112   #v.UseTriangleStrips = 0
00113   results.append(render(ss, v, title, nframes))
00114   #WriteImage(filename = (impth + "demo0_5.png"), view=v, Magnification=2)
00115 
00116   title = 'display lists, triangle strips, color by array'
00117   #v.UseTriangleStrips = 1
00118   results.append(render(ss, v, title, nframes))
00119   #v.UseImmediateMode = 1
00120   #WriteImage(filename = (impth + "demo0_6.png"), view=v, Magnification=2)
00121 
00122   title = 'no display lists, no triangle strips, color by array'
00123   #v.UseOCImmediateMode = 1
00124   #v.UseTriangleStrips = 0
00125   results.append(render(ss, v, title, nframes))
00126   #WriteImage(filename = (impth + "demo0_7.png"), view=v, Magnification=2)
00127 
00128   title = 'no display lists, triangle strips, color by array'
00129   #v.UseTriangleStrips = 1
00130   results.append(render(ss, v, title, nframes))
00131   WriteImage(filename = (impth + "demo0_8.png"), view=v, Magnification=2)
00132 
00133   newr = []
00134   for r in v.Representations:
00135    if r != rep:
00136      newr.append(r)
00137    v.Representations = newr
00138   
00139   ss = None
00140   rep = None
00141   
00142   v.StillRender()
00143   v = None
00144 
00145   if filesour:
00146     f = open(filesour, "w")
00147   else:
00148     f = sys.stdout
00149   print >>f, 'configuration, %d, %d' % (results[0][1][0], results[0][2][0])
00150   for i in results:
00151     print >>f, '"%s", %g, %g' % (i[0], i[1][1], i[2][1])  
00152 
00153 
00154 testdir = os.getenv("TESTDIR")
00155 pvdata = os.getenv("PVDATA")
00156 
00157 if __name__ == "__main__":
00158   run(filesour=testdir + "/Pic/Information.txt", impth=testdir + "/Pic/", nframes=10)