[vtkusers] transforming actor collections

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Oct 18 12:23:58 EDT 2004


I have two sets of actors, and I would like to register one set with
another.  For concreteness, the first set are surface electrodes and
the second set are subdural electrodes.  I have the x,y,z positions of
each of these, acquired with different instruments in different
coordinate systems, and I want to register them ( I also have some
common reference points in both sets).  Because the measurement of the
surface electrodes is problematic (lots of measurement error), there
will be a certain amount of "hand-tuning" the registration process.  I
would like to use the actor based transformations "a" of the
interactor style to help in this process.  I can do this with single
elements (I use a cylinder to represent single electrodes, but for
some of the operations I would like to apply to mouse movement (actor
based pan, zoom, rotate) to all of the elements of the set.  I naively
tried making the two sets each an vtkActorCollection, but the actor
based interactor movements only applied to the actor under point.
Ideally, I would like to be able to apply the transformations to the
entire set at once, or to elements of the set.

On a related question: if I have x,y,z coords for an ordered set of N
points, and another set of x,y,z coords for the same N points with the
same ordering but in a different coordinate system with measurement
error in both sets, what is the transformation on the second set that
would minimize the sum of squared distances to the points in the
first?  Pointers to tutorials, references, etc, appreciated. 

Thanks!
JDH

Here is the python script I am using for testing, in which I create
two collections of sphere actors


#!/usr/local/bin/python
import os

import pygtk
pygtk.require('2.0')

import gtk
import vtk
from random import random
from vtk.gtk.GtkGLExtVTKRenderWindow import GtkGLExtVTKRenderWindow
from vtk.gtk.GtkGLExtVTKRenderWindowInteractor import GtkGLExtVTKRenderWindowInteractor


window = gtk.Window()
window.set_title("A GtkGLExtVTKRenderWindow Demo!")
window.connect("destroy", gtk.mainquit)
window.connect("delete_event", gtk.mainquit)
window.set_border_width(10)
winwidth, winheight = 600,600
window.set_size_request(winwidth, winheight)

renwinInteractor = GtkGLExtVTKRenderWindowInteractor()        
renwinInteractor.set_size_request(winwidth, winheight)
renwinInteractor.show()
renderer = vtk.vtkRenderer()
renWin = renwinInteractor.GetRenderWindow()
renWin.AddRenderer(renderer)
interactor = renWin.GetInteractor()


vbox = gtk.VBox(spacing=3)
vbox.show()
vbox.pack_start(renwinInteractor, gtk.TRUE, gtk.TRUE)

button = gtk.Button('Quit')
button.show()
button.connect('clicked', gtk.mainquit)
vbox.pack_start(button, gtk.FALSE, gtk.FALSE)
window.add(vbox)


def sphere_collection(color=(1,0,0)):
    collection = vtk.vtkActorCollection()
    for i in range(10):
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(20)
        res = 20
        sphere.SetThetaResolution(res)
        sphere.SetPhiResolution(res)
        center = [100*random() for i in range(3)]
        sphere.SetCenter(*center)
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInput(sphere.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetOpacity(0.5)
        actor.GetProperty().SetColor(*color)        
        renderer.AddActor(actor)
        collection.AddItem(actor)
    return collection

c1 = sphere_collection(color=(1,0,0))
c2 = sphere_collection(color=(0,1,0))

# show the main window and start event processing.
window.show()
gtk.mainloop()





More information about the vtkusers mailing list