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>{&nbsp;&nbsp;&nbsp;  &nbsp;  <br>&nbsp;&nbsp;&nbsp; &nbsp; double * tp = m_transform-&gt;GetLinearInverse()-&gt;TransformPoint(x, y, z); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp; out[0] = tp[0];
<br>&nbsp;&nbsp;&nbsp; &nbsp; out[1] = tp[1];<br>&nbsp;&nbsp;&nbsp; &nbsp; out[2] = tp[2];<br>&nbsp;&nbsp;&nbsp; &nbsp; out[3] = 0.0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp; // Permute the points according to the reslice axes<br>&nbsp;&nbsp;&nbsp; &nbsp; vtkMatrix4x4 * resliceMat = this-&gt;m_slicer-&gt;GetResliceAxes();<br>&nbsp;&nbsp;&nbsp; &nbsp; if (resliceMat)
<br>&nbsp;&nbsp;&nbsp; &nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; resliceMat-&gt;Invert(resliceMat, m_indexInv);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_indexInv-&gt;MultiplyPoint(out, out);<br>&nbsp;&nbsp;&nbsp; &nbsp; }<br>&nbsp;}<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> &lt;<a href="mailto:anja.ende@googlemail.com">anja.ende@googlemail.com</a>&gt; 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>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkImageData * in = reinterpret_cast&lt;vtkImageData *&gt;(this-&gt;m_slicer-&gt;GetInput());<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; in-&gt;UpdateInformation();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (in)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double origin[3];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double spacing[3];
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; in-&gt;GetOrigin(origin);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; in-&gt;GetSpacing(spacing);<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // convert to physical coordinates as per David's advise.<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double xt = origin[0] + spacing[0] * x;
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double yt = origin[1] + spacing[1] * y;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double zt = origin[2] + spacing[2] * z;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Apply the transform....<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double * tp = m_transform-&gt;TransformPoint(xt, yt, zt);
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Convert back...<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out[0] = (tp[0]&nbsp; - origin[0]) / spacing[0];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out[1] = (tp[1]&nbsp; - origin[1]) / spacing[1];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out[2] = (tp[2]&nbsp; - origin[2]) / spacing[2];
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out[3] = 0.0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Permute the points according to the reslice axes<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The positions are oin x, y, z...so make it y, z, x for example for the YZ slice..<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkMatrix4x4 * resliceMat = this-&gt;m_slicer-&gt;GetResliceAxes();
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (resliceMat)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; resliceMat-&gt;Invert(resliceMat, m_indexInv);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_indexInv-&gt;MultiplyPoint(out, out);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; }<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>