[vtkusers] Obtaining transformation matrix for vtkPolyData

David Gobbi david.gobbi at gmail.com
Fri Aug 18 17:50:17 EDT 2017


Hi Eric,

The typical solution is to save the transform.  Make it into a member of
your class.  It's convenient to have the transform filter as a member, too.

def __init__(self):
        self.MeshTransform = vtk.vtkTransform()
        self.MeshTransformFilter = vtk.vtkTransformPolyDataFilter()
        self.MeshTransformFilter.SetInput( < insert original, untransformed
data here> )
        self.MeshTransformFilter.SetTransform(self.MeshTransform)

def Rotate(self, alpha, beta, gamma):
        self.MeshTransform.RotateX(alpha)
        self.MeshTransform.RotateY(beta)
        self.MeshTransform.RotateZ(gamma)
        self.MeshTransformFilter.Update();
        tf.SetInputData(self.MeshData)
        self.MeshData.ShallowCopy(self.MeshTransformFilter.GetOutput())

The idea here is to keep a copy of your original, unmodified data to use as
input to vtkTransformPolyData, though depending on what other kinds of
editing you are doing, this might be tricky.

 - David


On Fri, Aug 18, 2017 at 2:50 PM, Eric Petersen <peer9802 at gmail.com> wrote:

> Thanks David,
>
> I've got a class setup for reading/writing STL files along with basic
> manipulation.  My rotation code is below and called successive times.  I
> guess the question is does VTK "remember" past transformations on a
> vtkPolyData object()?  If so, what's the best way of accessing them?
>
> def Rotate(self, alpha, beta, gamma):
>         t = vtk.vtkTransform()
>         t.RotateX(alpha)
>         t.RotateY(beta)
>         t.RotateZ(gamma)
>         tf = vtk.vtkTransformPolyDataFilter()
>         tf.SetInputData(self.MeshData)
>         tf.SetTransform(t)
>         tf.Update()
>         self.MeshData.ShallowCopy(tf.GetOutput())
>
> On Fri, Aug 18, 2017 at 8:33 AM, David E DeMarle <dave.demarle at kitware.com
> > wrote:
>
>> Howdy Eric,
>>
>> How are you doing the transform?
>> * vtkTransformFIlter?
>> * vtkActor::Transform?
>> * manually changing the points in the vtkPolyData object?
>>
>> For either of the first two you can get the current matrix (and its
>> inverse) from the transform object.
>>
>> hope that helps
>>
>>
>> David E DeMarle
>> Kitware, Inc.
>> Principal Engineer
>> 21 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-881-4909 <(518)%20881-4909>
>>
>> On Fri, Aug 18, 2017 at 8:11 AM, Eric Petersen <peer9802 at gmail.com>
>> wrote:
>>
>>> Hello,
>>>
>>> I currently have a Python script where I am successively translating,
>>> and rotating, a vtkPolyData object.  The script currently does not track
>>> individual transforms but I would like to know the current 4x4 transform
>>> matrix.  Is there any way to directly obtain this information from the
>>> vtkPolyData object or am I stuck rewriting the script to track individual
>>> transformations?
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170818/ba57e879/attachment.html>


More information about the vtkusers mailing list