Ok, one thing that was clearly wrong was that I should have used the inverse of the transform in my function.<br><br>Also, using x, y, z in the display space yields the correct result. This, I think makes sense:<br><br>So, my mofified code looks as follows. This zooms and then transforms back correctly. However, I still have problems with displaying my cursor when the slice is oblique...
<br><br>void Viewer2D::ImageToDisplaySpace(double x, double y, double z, double out[4])<br>{ <br> double * tp = m_transform->GetLinearInverse()->TransformPoint(x, y, z); <br> <br> out[0] = tp[0];
<br> out[1] = tp[1];<br> out[2] = tp[2];<br> out[3] = 0.0;<br><br> // Permute the points according to the reslice axes<br> vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();<br> if (resliceMat)
<br> {<br> resliceMat->Invert(resliceMat, m_indexInv);<br> m_indexInv->MultiplyPoint(out, out);<br> }<br> }<br><br>I am close but I have been on this fringe for days now!!<br><br>Cheers,<br>
Anja<br><br><div><span class="gmail_quote">On 27/09/06, <b class="gmail_sendername">Anja Ende</b> <<a href="mailto:anja.ende@googlemail.com">anja.ende@googlemail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi everyone,<br><br>I think every day I am getting close to a possible solution to my problem.<br><br>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...
<br><br>So, the scenario is like this: <br><br>- I am using the vtkImageReslice object to slice the volume into 3 orthogonal axes. Also, the reslicer outputs 2D slices<br>- I am using the vtkTransform object with the reslicer to apply rotations and scaling...
<br><br>So, here is the function that I thought would convert from Image to Display space.<br><br>// x, y, z are image pixel positions...<br>void Viewer2D::ImageToDisplaySpace(double x, double y, double z, double out[4])
<br>
{<br> vtkImageData * in = reinterpret_cast<vtkImageData *>(this->m_slicer->GetInput());<br> in->UpdateInformation();<br><br> if (in)<br> {<br> double origin[3];<br> double spacing[3];
<br> in->GetOrigin(origin);<br> in->GetSpacing(spacing);<br> <br> // convert to physical coordinates as per David's advise.<br> double xt = origin[0] + spacing[0] * x;
<br>
double yt = origin[1] + spacing[1] * y;<br> double zt = origin[2] + spacing[2] * z;<br><br> // Apply the transform....<br> double * tp = m_transform->TransformPoint(xt, yt, zt);
<br> <br> // Convert back...<br> out[0] = (tp[0] - origin[0]) / spacing[0];<br> out[1] = (tp[1] - origin[1]) / spacing[1];<br> out[2] = (tp[2] - origin[2]) / spacing[2];
<br> out[3] = 0.0;<br><br> // Permute the points according to the reslice axes<br> // The positions are oin x, y, z...so make it y, z, x for example for the YZ slice..<br> vtkMatrix4x4 * resliceMat = this->m_slicer->GetResliceAxes();
<br> if (resliceMat)<br> {<br> resliceMat->Invert(resliceMat, m_indexInv);<br> m_indexInv->MultiplyPoint(out, out);<br> }<br> }<br><br>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.<br><br>So, the transformation matrix looked like:<br><br>0.5 0 0 0<br>0 0.5 0 0<br>0 0 1 0<br>0 0 0 1<br><br>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.
<br><br>So, I am clearly missing something here. Do I need to convert the points to a homogeneous matrix before I try to transform it?<br><br>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.
<br><br>Thanks for any help you might give me.<br><span class="sg"><br>Anja<br><br>
</span></blockquote></div><br>