[vtkusers] Modifying sphere radius from actor
    Andrea Gavana 
    andrea.gavana at gmail.com
       
    Tue May 13 09:57:05 EDT 2008
    
    
  
Hi All,
    I am visualizing a bunch of spheres, and depending on some user's
choices, I need to change the radius and the colour of these spheres.
So, instead of removing and re-creating the sphere actor every time I
need to change some sphere property, I thought to use a suggestion
from Amy I found in the archives:
http://www.vtk.org/pipermail/vtkusers/2001-August/057091.html
What I do, is something like this:
sphereMapper = sphereActor.GetMapper()
print "SOURCE:", sphereMapper.GetInput().GetSource()
But this always prints "None" if I execute the attached code (in
Python, using wxVTKRenderWindow). If you run the code, simply press
any key: this activates the OnKeyDown method which tries to extract
the vtkSphereSource from its mapper. Am I missing something? Is it
possible to do what I am asking or I need to re-create every time the
sphere, mapper and actor?
Thank you for your suggestions.
Andrea.
# Begin Code
import wx
import vtk
from vtk.wx.wxVTKRenderWindow import wxVTKRenderWindow
from vtk.util.colors import red, green, blue
class wxVTKRW(wxVTKRenderWindow):
    def __init__(self, parent):
        wxVTKRenderWindow.__init__(self, parent, -1)
        self.ren = vtk.vtkRenderer()
        self.GetRenderWindow().AddRenderer(self.ren)
        centers = [(0, 0, 0), (2, 2, 2), (-3, -3, -3)]
        colours = (red, green, blue)
        for center, colour in zip(centers, colours):
            sphere = vtk.vtkSphereSource()
            sphere.SetCenter(*center)
            sphereMapper = vtk.vtkPolyDataMapper()
            sphereMapper.SetInput(sphere.GetOutput())
            sphereActor = vtk.vtkActor()
            sphereActor.SetMapper(sphereMapper)
            sphereActor.GetProperty().SetColor(colour)
            self.ren.AddActor(sphereActor)
        self.ren.ResetCamera()
        # Store the last actor
        self.lastActor = sphereActor
    def OnKeyDown(self, event):
        # Try to retrieve the sphere source
        # Here is where the problem lies: GetSource() returns None!
        sphereMapper = self.lastActor.GetMapper()
        print "SOURCE:", sphereMapper.GetInput().GetSource()
#--------------------------------------------------------------------
def wxVTKRWExample():
    """Like it says, just a simple example
    """
    # every wx app needs an app
    app = wx.PySimpleApp()
    # create the top-level frame, sizer and wxVTKRWI
    frame = wx.Frame(None, -1, "wxVTKRWI", size=(600, 500))
    frame.CenterOnScreen()
    widget = wxVTKRW(frame)
    # show the window
    frame.Show()
    app.MainLoop()
if __name__ == "__main__":
    wxVTKRWExample()
# End code
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
    
    
More information about the vtkusers
mailing list