[vtk-developers] interesting problem with vtkObject Update()

Charl P. Botha c.p.botha at its.tudelft.nl
Wed Feb 19 10:59:14 EST 2003


Dear developers,

I have attached a modified deciFran.py example.  If you run it, it should
result in a segfault on real operating systems and whatever's equivalent to
that on the Wintendo gaming system. ;)

In anycase, the reason that it segfaults is that Update() is called on the
object when that object's ProgressMethod is called.  Now you might ask the
question on why anyone would want to call Update() on an object in that
object's ProgressMethod() callback, but this simulates what happens in a GUI
+ VTK application:  

1. The object calls its ProgressMethod() callback.
2. The callback wants to update the GUI progress bars, so yields a
   time-slice to the GUI event-loop.
3. During that time-slice, the GUI redraws its windows, of which one
   possibly contains a vtkRenderWindow.
4. This redraw results in a Render() on the vtkRenderWindow.  The Render
   results in an Update() on its mapper inputs, which in turn results in an
   Update() on the object's whose ProgressMethod() is still in progress!
5. BOOM

I ran into this problem whilst developing such a GUI + VTK application.  My
questions are:

1. Can this be considered a bug?
2. Is there a way to lock the Update() method of a vtkObject?  This would of
   course solve the problem above.

Any information would be greatly appreciated.

Thanks,
Charl

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/
-------------- next part --------------
#!/usr/bin/env python

# This example shows how to use decimation to reduce a polygonal
# mesh. We also use mesh smoothing and generate surface normals to
# give a pleasing result.

import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# We start by reading some data that was originally captured from a
# Cyberware laser digitizing system.
fran = vtk.vtkPolyDataReader()
fran.SetFileName(VTK_DATA_ROOT + "/Data/fran_cut.vtk")

def progressCallback(processObject):
    print "IN"
    print processObject.GetProgressText() + ' ' + str(processObject.GetProgress())
    # here we call update (yes, from the progress method) - this will result
    # in progressCallback being called before this instance is done
    # VTK go bye-bye (note all the unmatched "IN"s)
    processObject.Update()
    print "OUT"

# We want to preserve topology (not let any cracks form). This may
# limit the total reduction possible, which we have specified at 90%.
deci = vtk.vtkDecimate()
deci.SetInput(fran.GetOutput())
deci.SetTargetReduction(0.999)
deci.PreserveTopologyOn()
deci.SetProgressText('decimating Fran, hehehehe')
deci.SetProgressMethod(lambda deci=deci: progressCallback(deci))
normals = vtk.vtkPolyDataNormals()
normals.SetInput(deci.GetOutput())
normals.FlipNormalsOn()
franMapper = vtk.vtkPolyDataMapper()
franMapper.SetInput(normals.GetOutput())
franActor = vtk.vtkActor()
franActor.SetMapper(franMapper)
franActor.GetProperty().SetColor(1.0, 0.49, 0.25)

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

# Add the actors to the renderer, set the background and size
ren.AddActor(franActor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(250, 250)

cam1 = vtk.vtkCamera()
cam1.SetClippingRange(0.0475572, 2.37786)
cam1.SetFocalPoint(0.052665, -0.129454, -0.0573973)
cam1.SetPosition(0.327637, -0.116299, -0.256418)
cam1.SetViewUp(-0.0225386, 0.999137, 0.034901)
ren.SetActiveCamera(cam1)

iren.Initialize()
renWin.Render()
iren.Start()


More information about the vtk-developers mailing list