[vtkusers] vtkTransform again and question about transformation of a display point back to image space...

Anja Ende anja.ende at googlemail.com
Wed Sep 27 06:10:06 EDT 2006


Hi everyone,

I think every day I am getting close to a possible solution to my problem.

After advise from this group, I am trying to use the vtkTransform object to
get the display position from the image position by applying the
transformation back to the point...

So, the scenario is like this:

- I am using the vtkImageReslice object to slice the volume into 3
orthogonal axes. Also, the reslicer outputs 2D slices
- I am using the vtkTransform object with the reslicer to apply rotations
and scaling...

So, here is the function that I thought would convert from Image to Display
space.

// x, y, z are image pixel positions...
void Viewer2D::ImageToDisplaySpace(double x, double y, double z, double
out[4])
{
        vtkImageData * in = reinterpret_cast<vtkImageData
*>(this->m_slicer->GetInput());
        in->UpdateInformation();

        if (in)
        {
            double origin[3];
            double spacing[3];
            in->GetOrigin(origin);
            in->GetSpacing(spacing);

            // convert to physical coordinates as per David's advise.
            double xt = origin[0] + spacing[0] * x;
            double yt = origin[1] + spacing[1] * y;
            double zt = origin[2] + spacing[2] * z;

            // Apply the transform....
            double * tp = m_transform->TransformPoint(xt, yt, zt);

            // Convert back...
            out[0] = (tp[0]  - origin[0]) / spacing[0];
            out[1] = (tp[1]  - origin[1]) / spacing[1];
            out[2] = (tp[2]  - origin[2]) / spacing[2];
            out[3] = 0.0;

            // Permute the points according to the reslice axes
            // The positions are oin x, y, z...so make it y, z, x for
example for the YZ slice..
            vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();
            if (resliceMat)
            {
                resliceMat->Invert(resliceMat, m_indexInv);
                m_indexInv->MultiplyPoint(out, out);
        }
   }

This, does not work. I think I have to take the reslice axes and the reslice
axes origin into account somewhere as well. For example, if I want to zoom
the image by a factor of 2.0, I had to apply a scaling of 0.5 to the
transformation.

So, the transformation matrix looked like:

0.5 0 0 0
0 0.5 0 0
0 0 1 0
0 0 0 1

However, transformaing a point say (100, 100, 100) had no affect... I would
have expected it to return (200, 200, 100) as that would be the new position
after a double scaling.

So, I am clearly missing something here. Do I need to convert the points to
a homogeneous matrix before I try to transform it?

My linear algebra is not very good, so most of my work here is trial and
error. So, if someone could also tell me how to do rotations without
resorting to using RotateX, RotateY functions and solving it just using
linear algebra, I would be really grateful. I do not need any code, just
some theory or a pointer to maybe a website that explains that for newbies.

Thanks for any help you might give me.

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060927/5c042201/attachment.htm>


More information about the vtkusers mailing list