basic.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from __future__ import print_function
  2. import datetime as dt
  3. import sys
  4. from paraview.simple import *
  5. import paraview
  6. def __render(ss, v, title, nframes):
  7. print ('============================================================')
  8. print (title)
  9. res = []
  10. res.append(title)
  11. for phires in (500, 1000):
  12. ss.PhiResolution = phires
  13. c = v.GetActiveCamera()
  14. v.CameraPosition = [-3, 0, 0]
  15. v.CameraFocalPoint = [0, 0, 0]
  16. v.CameraViewUp = [0, 0, 1]
  17. Render()
  18. c1 = dt.datetime.now()
  19. for i in range(nframes):
  20. c.Elevation(0.5)
  21. Render()
  22. tpr = (dt.datetime.now() - c1).total_seconds() / nframes
  23. ncells = ss.GetDataInformation().GetNumberOfCells()
  24. print (tpr, " secs/frame")
  25. print (ncells, " polys")
  26. print (ncells/tpr, " polys/sec")
  27. res.append((ncells, ncells/tpr))
  28. return res
  29. def run(filename=None, nframes=60):
  30. '''Runs the benchmark. If a filename is specified, it will write the
  31. results to that file as csv. The number of frames controls how many times
  32. a particular configuration is rendered. Higher numbers lead to more
  33. accurate averages.
  34. '''
  35. # Turn off progress printing
  36. paraview.servermanager.SetProgressPrintingEnabled(0)
  37. # Create a sphere source to use in the benchmarks
  38. ss = Sphere(ThetaResolution=1000, PhiResolution=500)
  39. rep = Show()
  40. v = Render()
  41. results = []
  42. # Start with these defaults
  43. # v.RemoteRenderThreshold = 0
  44. # Test different configurations
  45. title = 'no triangle strips, solid color'
  46. results.append(__render(ss, v, title, nframes))
  47. # Color by normals
  48. lt = servermanager.rendering.PVLookupTable()
  49. rep.LookupTable = lt
  50. rep.ColorArrayName = "Normals"
  51. lt.RGBPoints = [-1, 0, 0, 1, 0.0288, 1, 0, 0]
  52. lt.ColorSpace = 'HSV'
  53. lt.VectorComponent = 0
  54. title = 'no triangle strips, color by array'
  55. results.append(__render(ss, v, title, nframes))
  56. if filename:
  57. f = open(filename, "w")
  58. else:
  59. f = sys.stdout
  60. print ('configuration, %d, %d' % (results[0][1][0], results[0][2][0]), file=f)
  61. for i in results:
  62. print ('"%s", %g, %g' % (i[0], i[1][1], i[2][1]), file=f)
  63. def test_module():
  64. '''Simply exercises a few components of the module.'''
  65. maximize_logs()
  66. paraview.servermanager.SetProgressPrintingEnabled(0)
  67. ss = Sphere(ThetaResolution=1000, PhiResolution=500)
  68. rep = Show()
  69. v = Render()
  70. print_logs()
  71. if __name__ == "__main__":
  72. if "--test" in sys.argv:
  73. test_module()
  74. else:
  75. run()