[vtkusers] Re: vtkTransform again....transforming a point does not work as expected...simple example

Anja Ende anja.ende at googlemail.com
Sat Sep 23 11:10:01 EDT 2006


Hi,

Another thing that I noticed is that after rotation the image seems to jump
or internally translate..... However, the position of the actor remains the
same.... This probably also affects my calculations as I try to transform
the points to display space correctly...

So, again if someone could suggest how I can adjust to this affect... it
would be great...

Cheers,
Anja

On 23/09/06, Anja Ende <anja.ende at googlemail.com> wrote:
>
> Ok, I have finally managed to get something working that works for normal
> transformation to the image->Display and vice versa...
>
> However, it returns bogus values when a slice is rotated along an axis...
>
> -------------------------------------------------------------------------------------------------------
>
> Display ->Image Space...
>
> // x, y, z are display coordinates
>
> vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();
> double axesTransform[4] = {x, y, z, 0.0};
> resliceMat->MultiplyPoint(axesTransform, axesTransform);
> double * tp = m_transform->TransformPoint(axesTransform[0],
> axesTransform[1], axesTransform[2]);
>
> // Out will contain the image coordinates
>
> out[0] = tp[0];
> out[1] = tp[1];
> out[2] = tp[2];
> out[3] = 0.0;
>
>
> --------------------------------------------------------------------------------
> // Image->Display Space
> This function works if the slice is not rotated...However, if the slice is
> rotated then the values are incorrect... I do not understand why as the
> rotation is reflected in the transformation matrix.
>
> // x, y, z are image coordinates
> // out will contain the values in the display space... or so I hoped!
>
> double * tp = m_transform->GetLinearInverse()->TransformPoint(x, y, z);
> vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();
> out[0] = tp[0];
> out[1] = tp[1];
> out[2] = tp[2];
> out[3] = 0.0;
> resliceMat->Invert(resliceMat, m_indexInv);
> m_indexInv->MultiplyPoint(out, out);
> ---------------------------------------------------------------------------------------------
>
>
> I am really struggling with this, so any help would be really nice!
>
> Thanks,
> Anja
>
> On 23/09/06, Anja Ende < anja.ende at googlemail.com> wrote:
> >
> > So, trying to use the reslice transform and reslice axes as suggested by
> > David:
> >
> > I have an image with the following dimesnions: 256 X 256 X 62. It has
> > been centered using vtkImageChangeInformation...
> >
> > It has been scaled using the vtkTransform object by a factor of 2 in the
> > X and Y direction..
> >
> > So, the transform matrix looks like this:
> >
> >   0.5 0 0 0
> >   0 0.5 0 0
> >   0 0 1 0
> >   0 0 0 1
> >
> >
> > So, I click on the center of the image and I expect that the
> > transformation back should give me the imnage coordinates in the original
> > input image. So, I do the following:
> >
> > Input :255: 255: 62 (in pixels). Ignore the Z value... always 62
> >
> > vtkImageData * in = reinterpret_cast<vtkImageData
> > *>(this->m_slicer->GetInput());
> > in->UpdateInformation();
> >
> > double origin[3];
> > double spacing[3];
> > in->GetOrigin(origin);
> > in->GetSpacing(spacing);
> >
> > // x = 255, y = 255, z = 62
> > // converting to world coordinates
> > double xt = origin[0] + spacing[0] * x;
> > double yt = origin[1] + spacing[1] * y;
> > double zt = origin[2] + spacing[2] * z;
> >
> > // Now transform the points....
> > double * tp = m_transform->TransformPoint(xt, yt, zt);
> >
> > // Reslice axes of my reslicer
> > vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();
> >
> > // converting the transformed points back to display coordinates
> > double bx = (tp[0]  - origin[0]) / spacing[0];
> > double by = (tp[1]  - origin[1]) / spacing[1];
> > double bz = (tp[2]  - origin[2]) / spacing[2];
> >
> > double inout[4] = {bx, by, bz, 0.0};
> > resliceMat->MultiplyPoint(inout, inout);
> >
> > Now, I expected this to return:
> >
> > 127.5: 127.5: 62...center of the data...
> >
> > Instead it returns:
> >
> > 191.75: 191.25: 62 :((((
> >
> > I know I am making some fundamental errors here...so if someone could
> > please help me sort it out... I would be really grateful
> >
> > Best,
> >
> > Anja
> >
> >
> >  On 22/09/06, Anja Ende <anja.ende at googlemail.com> wrote:
> > >
> > > Yes, I, unfortunately, could not get any other way to work... As I
> > > said, I am trying to get the TransformPoints method to work, but with little
> > > success so far.
> > >
> > > Could you point an example as to how to use the ResliceTransform and
> > > the ResliceMatrix??
> > >
> > > Cheers and thanks,
> > >
> > > Anja
> > >
> > > On 22/09/06, David Gobbi < dgobbi at atamai.com> wrote:
> > > >
> > > > I should point out that the IndexMatrix is not a public member of
> > > > the
> > > > class... and if you have a special version of vtkImageReslice that
> > > > makes
> > > > this member public, you are using vtkImageReslice in a way that
> > > > other
> > > > people don't.
> > > >
> > > > Why not just use the ResliceTransform and ResliceMatrix?
> > > >
> > > > - David
> > > >
> > > >
> > > >
> > > > Anja Ende wrote:
> > > > > Forgot to mention...
> > > > >
> > > > > I am using the index matrix in the vtkImageReslice class to do the
> > > >
> > > > > input->output mapping and vice versa (by using the inverse of the
> > > > > matrix).
> > > > >
> > > > > Anja
> > > > >
> > > > ------------------------------------------------------------------------
> > > > >
> > > > > _______________________________________________
> > > > > This is the private VTK discussion list.
> > > > > Please keep messages on-topic. Check the FAQ at:
> > > > http://www.vtk.org/Wiki/VTK_FAQ
> > > > > Follow this link to subscribe/unsubscribe:
> > > > > http://www.vtk.org/mailman/listinfo/vtkusers
> > > > >
> > > >
> > > >
> > >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060923/5f73bae7/attachment.htm>


More information about the vtkusers mailing list