VTK - Tcl vs. Python Render speed

Randall Hopper aa8vb at yahoo.com
Fri Apr 28 09:33:51 EDT 2000


     Big differences in Render() times between Tcl and Python.

     renWin.Render is taking 1/4 of a second, when called from Python.  But
when called from Tcl, its nearly instantaneous.  Any ideas?

     For example, attached is a trivial conversion of the 3DMorph.tcl
example program to Python.  I've inserted timing prints to show how long
VTK calls are taking.  (See below)

     Once the update/render loop is complete and the VTK mouse interactor
takes over, it's fluid 30 fps in both Tcl and Python scripts (this is a H/W
accelerated SGI Octane).  But in the update/render loop, it takes VTK-Tcl 3
seconds and VTK-Python 11 seconds to complete all 40 iterations.

     Thoughts?

-- 
Randall Hopper
aa8vb at yahoo.com



interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.25 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.26 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.26 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.26 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.25 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.26 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.28 sec
interpolate.SetT() - 0.00 sec
renWin.Render()    - 0.25 sec
interpolate.SetT() - 0.00 sec
...
-------------- next part --------------
#!/usr/bin/env python

import os
try:
  VTK_DATA = os.environ['VTK_DATA']
except KeyError:
  VTK_DATA = '../../../vtkdata/'

from libVTKCommonPython import *
from libVTKGraphicsPython import *

#--- Some timing helpers ---
import time

start_time = 0
def start():
  global start_time
  start_time = time.time()
def elapsed():
  global start_time
  return time.time() - start_time
#---------------------------

#
# get some nice colors
from colors import *

# make the letter v
letterV = vtkVectorText()
letterV.SetText( 'v' )

# read the geometry file containing the letter t
letterT = vtkVectorText()
letterT.SetText( 't' )

# read the geometry file containing the letter k
letterK = vtkVectorText()
letterK.SetText( 'k' )

# create implicit models of each
blobbyV = vtkImplicitModeller()
blobbyV.SetInput( letterV.GetOutput() )
blobbyV.SetMaximumDistance( .2 )
blobbyV.SetSampleDimensions( 50, 50, 12 )
blobbyV.SetModelBounds( -0.5, 1.5, -0.5, 1.5, -0.5, 0.5 )

# create implicit models of each
blobbyT = vtkImplicitModeller()
blobbyT.SetInput( letterT.GetOutput() )
blobbyT.SetMaximumDistance( .2 )
blobbyT.SetSampleDimensions( 50, 50, 12 )
blobbyT.SetModelBounds( -0.5, 1.5, -0.5, 1.5, -0.5, 0.5 )

# create implicit models of each
blobbyK = vtkImplicitModeller()
blobbyK.SetInput( letterK.GetOutput() )
blobbyK.SetMaximumDistance( .2 )
blobbyK.SetSampleDimensions( 50, 50, 12 )
blobbyK.SetModelBounds( -0.5, 1.5, -0.5, 1.5, -0.5, 0.5 )

# Interpolate the data
interpolate = vtkInterpolateDataSetAttributes()
interpolate.AddInput( blobbyV.GetOutput() )
interpolate.AddInput( blobbyT.GetOutput() )
interpolate.AddInput( blobbyK.GetOutput() )
interpolate.SetT( 0.0 )

# extract an iso surface
blobbyIso = vtkContourFilter()
blobbyIso.SetInput( interpolate.GetOutput() )
blobbyIso.SetValue( 0, 0.1 )

# map to rendering primitives
blobbyMapper = vtkPolyDataMapper()
blobbyMapper.SetInput( blobbyIso.GetOutput() )
blobbyMapper.ScalarVisibilityOff()

# now an actor
blobby = vtkActor()
blobby.SetMapper( blobbyMapper )
blobby.GetProperty().SetDiffuseColor( banana )

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer( ren1 )
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow( renWin )

camera = vtkCamera()
camera.SetClippingRange( 0.265, 13.2 )
camera.SetFocalPoint( 0.539, 0.47464, 0 )
camera.SetPosition( 0.539, 0.474674, 2.644 )
camera.ComputeViewPlaneNormal()
camera.SetViewUp( 0, 1, 0 )
ren1.SetActiveCamera( camera )

#  now  make a renderer and tell it about lights and actors
renWin.SetSize( 300, 350 )
  
ren1.AddActor( blobby )
ren1.SetBackground( 1, 1, 1 )
renWin.Render()

subIters = 20

for i in range( 2 ):
  for j in range( 1, subIters + 1 ):
    t = i + float(j) / subIters
    start()
    interpolate.SetT( t )
    print "interpolate.SetT() - %.2f sec" % elapsed()

    start()
    renWin.Render()
    print "renWin.Render()    - %.2f sec" % elapsed()
    

renWin.SetFileName( "3DMorph.tcl.ppm" )
#renWin.SaveImageAsPPM()

# enable user interface interactor
#
iren.Initialize()

iren.Start()


More information about the vtkusers mailing list