1 of 10

Introduction to VTK: Transforms

2 of 10

Types of Transforms

  • Basic transforms include:

  • “Rigid” transforms
    • Translation
    • Rotation
  • “Similarity” transformations
    • Scale

3 of 10

Translation

4 of 10

Rotation

5 of 10

Scale

6 of 10

Order is Important!

  • A translation followed by a rotation typically does not produce the same result as a rotation followed by a translation

  • This is because the rotation is performed on the whole space around the world origin

  • transform->PostMultiply() makes operations behave in the order that you specify them

7 of 10

Order is Important Demo

http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/TransformOrder

Translation Then Rotation

Rotation Then Translation

8 of 10

Transformations in VTK

  • Can apply transformation either to the data itself (before Mapper) or to an Actor

  • Why transform data?
    • You have access to the numerical result
  • Why transform actor?
    • Faster
    • Can have multiple instances of the same data

  • In either case, there is no reason to ever look at a transformation matrix

9 of 10

Transforming Data

  • Construct a vtkTransform and then apply it with vtkTransformPolyDataFilter

vtkSmartPointer<vtkTransform> transformation=

vtkSmartPointer<vtkTransform>::New();

transformation >Translate(double x, double y, double z);

transformation ->RotateX(double angle);

transformation ->Scale(double x, double y, double z);

vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =

vtkSmartPointer<vtkTransformPolyDataFilter>::New();

transformFilter->SetInputConnection(sphereSource->GetOutputPort()); transformFilter->SetTransform(transformation);

transformFilter->Update();

10 of 10

Transforming Actor

  • Construct a vtkTransform and then apply it directly to an actor

vtkSmartPointer<vtkTransform> transform =

vtkSmartPointer<vtkTransform>::New();

transform->RotateZ(90.0);  

actor->SetUserTransform(transform);