[vtkusers] linear algebra help needed!

Anja Ende anja.ende at googlemail.com
Tue Sep 19 10:51:34 EDT 2006


Hi,

This is a question for all you linear algebra and VTK experts:

Again, I have a vtkImageReslice that outputs 2D slices and has a
vtkTransform parameter. I have extended the vtkImageReslice object, so that
I have access to the index matrix that helps me map output data to reslicer
input data.

Now, earlier I just had scaling on the inout image and I was doing look up
through the vtkImageReslice object. This was workign fantastic!

I had it as follows:

// This function was returning the image pixel from the display x, y, z
void DisplayToImageSpace(int x, int y, int z, double out[4])
{
        // This would get the index matrix...
    vtkMatrix4x4 * mat = m_slicer->GetLookupMatrix();
    if (mat)
    {
        double in[4] = {(double)x, (double)y, (double)z, 0.0};
        mat->MultiplyPoint(in, out);
    }
}

// This function was returning the image pixel from the display coordinates
void ImageToDisplaySpace(double x, double y, double z, double out[4])
{
        vtkMatrix4x4 * mat = m_slicer->GetLookupMatrix();
        if (mat)
        {
                double in[4] = {x, y, z, 0.0};
                // inverse the matrix
                mat->Invert(mat, m_indexInv);
                m_indexInv->MultiplyPoint(in, out);
        }
}

This was working fantastic. I was happy!

Now, I have rotation on the slices:

The rotation is implemented using the vtkTransform.

So, I tried to implement the DisplayToImageSpace function as follows and set
my cursor...

void TestTransformation(double x, double y, double z)
{
        // First transform the display point using the vtkTransform object
        double * transformed = m_transform->TransformPoint(x, y, z);

        vtkMatrix4x4 * mat = m_slicer->GetLookupMatrix();
        if (mat)
        {
                // Now pass the transformed point through the look up
matrix..
                double out [4] = {0.0, 0.0, 0.0, 0.0};
                double in[4] = {transformed[0], transformed[1],
transformed[2], 0.0};
                mat->Invert(mat, m_indexInv);
                m_indexInv->MultiplyPoint(in, out);

                double currentXPos, currentYPos;
                GetCurrentPosition(currentXPos, currentYPos);

                SetCursorPosition(out[0] + currentXPos, out[1] +
currentYPos);
        }
}

However, this does not return the correct values. I have 2 issues:

- Once the image is rotated, how to calculate the correct actor2D position?
The image is always displayed in the center and I think I have to calculate
the offset from the lower left corner of the image. With only scaling it was
pretty easy...

- Second, I wonder if I am doing this transformation correctly. Can someone
tell me, for example, how I can map a particular coordinate from the
original image to the transformed (rotated) image and vice-versa.

Hope I made the question clear enough. I have been racking my brains for 2
days over this now. I would really appreciate some help.

Please help!

Thanks,
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060919/682fb365/attachment.htm>


More information about the vtkusers mailing list