[vtkusers] UserTransform/UserMatrix

David Gobbi dgobbi at irus.rri.on.ca
Wed Aug 9 13:42:09 EDT 2000


Hi All,

I've finally modified the vtkProp3D SetUserTransform and SetUserMatrix
methods so that they both do exactly the same thing.  I.e. the Actors'
store only one UserMatrix, which can be set using either SetUserMatrix
or SetUserTransform.

So if you:
  SetUserMatrix(matrix)
then
  GetUserMatrix() will return 'matrix' and
  GetUserTransform() will return a transform that matches 'matrix'

And if you
  SetUserTransform(transform)
then
  GetUserTransform() will return 'transform' and
  GetUserMatrix() will return 'transform->GetMatrix()'

The reason that you would want to use SetUserTransform() is that you
can pipeline transforms together, i.e. vtkTransform() has a 
SetInput() method that you can use like this:

trans1 = vtkTransform()

trans2 = vtkTransform()
trans2.SetInput(trans1)
trans2.Translate(5.0, 0.0, 0.0)

actor1 = vtkActor()
actor1.SetUserTransform(trans1)

actor2 = vtkActor()
actor2.SetUserTransform(trans2)

Now, actor2 will always be translated by x+5.0 relative to actor1,
and if you do things like
  trans1.RotateX(30)
the transformations and actors will automatically update.

Perhaps the greatest benefit of SetUserTransform() is that if you give
each actor a UserTransform(), you can move actors around the same way
you would in OpenGL i.e.

actor->SetUserTransform(trans)
trans->Translate(1.0, 0.0, 0.0)
trans->RotateX(90.0)

and hence completely avoid the confusing (IMHO) SetPosition(),
AddPosition(), RotateWXYZ(), RotateX() etc. actor methods.
(I mean that whenever I use these methods I have to write out the
sequence of internal matrix multiplications just to figure out
what the final result will be, it is easier for me to just build
the darn matrix myself).

Apologies for the editorial.

 - David

--
  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario





More information about the vtkusers mailing list