<font size="2"><font face="verdana,sans-serif">I solved this (see my other mail). But I still don't know why I had to set origin and position:<br></font></font><div><font class="Apple-style-span" face="verdana, sans-serif"><div>
volume->SetOrigin(-origin[0], -origin[1], -origin[2]);</div><div>volume->SetPosition(-origin[0], -origin[1], -origin[2]);</div><div><br></div><div>Can you explain it? Also, a link to some text explaining vtk's coordinate transformation system for future reference would be very appreciated (if such a text exists). I had been searching but could not find a source which explains in which order are the transformation matrices applied, in which space are voxels of a vtkVolume etc.</div>
<div><br></div><div>Regards,</div><div>Dženan</div><div><br></div></font><div class="gmail_quote">2011/7/1 Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com">dzenanz@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font size="2"><font face="verdana,sans-serif">I did the math, and it should be as simple as this:<br></font></font><div><div class="im"><div style="font-family:verdana, sans-serif"><br></div><div><font face="'courier new', monospace">VisualizingImageType::DirectionType d=logic->visualizing->GetDirection();</font></div>
</div><div><font face="'courier new', monospace">vtkMatrix4x4 *mat=vtkMatrix4x4::New(); //identity matrix</font></div><div class="im"><div><font face="'courier new', monospace">for (int i=0; i<3; i++)</font></div>
<div><font face="'courier new', monospace"> for (int k=0; k<3; k++)</font></div><div><font face="'courier new', monospace"> mat->SetElement(i,k, d(i,k));</font></div>
</div><div class="im"><div><font face="'courier new', monospace">VisualizingImageType::PointType origin=logic->visualizing->GetOrigin();</font></div><div><font face="'courier new', monospace">for (int i=0; i<3; i++)</font></div>
</div><div><font face="'courier new', monospace"> mat->SetElement(i,3, origin[i]);</font></div><div><font face="'courier new', monospace">//mat->Invert(); //inverse produces even wrong orientation</font></div>
<div><font face="'courier new', monospace">volume->SetUserMatrix(mat);</font></div><div style="font-family:verdana, sans-serif"><br></div><div style="font-family:verdana, sans-serif">
However this does not work. This is a simple transformation from scaled index space (vtkVolume handles spacing) to DICOM physical space. If no one has any suggestion, I will simply have to create a system of linear equations from which to construct the VTK's transform matrix. And equations I will have to obtain by passing a number of points through ITK's transformation and add some simple objects to the vtk scene at that spot and on index space spot but with VTK transformation applied.</div>
<div style="font-family:verdana, sans-serif"><br></div><div style="font-family:verdana, sans-serif">Regards,</div><div style="font-family:verdana, sans-serif">Dženan</div><font color="#888888"><div style="font-family:verdana, sans-serif">
<br></div></font><div><div></div><div class="h5"><div class="gmail_quote">2011/6/29 Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font size="2"><font face="verdana,sans-serif">I tried trial and error: premultiply translation, postmultiply, divide</font></font><font size="2"><font face="verdana,sans-serif"> by and multiply by spacing, all that unsuccessfully. Now I need to work out the math :D<br>
</font></font><div><div></div><div><div><font face="verdana, sans-serif"><br></font></div><div><div class="gmail_quote">2011/6/29 David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Dzenan,<br>
<br>
For your code, my guess is that the "translation" part of the 4x4<br>
matrix should be set to something like the origin multiplied by the<br>
rotation matrix, but there might be other little details that you need<br>
to take care of. My only suggestion is that you don't try to fix it<br>
through trial-end-error. Use pencil-and-paper to work through the<br>
math.<br>
<br>
- David<br>
<br>
2011/6/29 Dženan Zukić <<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>>:<br>
<div><div></div><div>> Hi David,<br>
><br>
> with this I try to do what you suggested, i.e. consider VTK's world<br>
> coordinate system as DICOM patient coordinate system:<br>
> //red is the transformation-related code<br>
> void MainWindow::updateVisualization()<br>
> {<br>
> typedef itk::ImageToVTKImageFilter<VisualizingImageType><br>
> itkVtkConverter;<br>
> itkVtkConverter::Pointer conv=itkVtkConverter::New();<br>
> conv->SetInput(logic->visualizing);<br>
> vtkGPUVolumeRayCastMapper *mapper = vtkGPUVolumeRayCastMapper::New();<br>
> mapper->SetInput(conv->GetOutput());<br>
> if (volume)<br>
> volume->Delete();<br>
> volume=vtkVolume::New();<br>
> volume->SetProperty( myTransferFunction );<br>
> volume->SetMapper( mapper );<br>
> mapper->SetBlendModeToComposite();<br>
> VisualizingImageType::DirectionType<br>
> d=logic->visualizing->GetDirection();<br>
> vtkMatrix4x4 *mat=vtkMatrix4x4::New();<br>
> for (int i=0; i<3; i++)<br>
> for (int k=0; k<3; k++)<br>
> mat->SetElement(i,k, d(i,k));<br>
> mat->SetElement(3,3, 1);<br>
> VisualizingImageType::SpacingType sp = logic->visualizing->GetSpacing();<br>
> VisualizingImageType::PointType origin=logic->visualizing->GetOrigin();<br>
> for (int i=0; i<3; i++)<br>
> mat->SetElement(i,3, origin[i]/sp[i]);<br>
> volume->SetUserMatrix(mat); //orientation and size OK, position wrong<br>
> vtkRenderer *renderer =<br>
> vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer();<br>
> renderer->RemoveAllViewProps();<br>
> renderer->AddVolume( volume );<br>
> defaultCameraPos(); //centers view on the volume, looking at it from<br>
> left<br>
> vis->GetRenderWindow()->Render();<br>
><br>
> vis->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->ResetCamera();<br>
> }<br>
> The polygonal data is in DICOM's patient coordinate system (vertex positions<br>
> from itk::Image->TransformIndexToPhysicalPoint() etc). The orientation is<br>
> correct, but I can't get the position correctly. I have tried<br>
> -origin[i]/sp[i], origin[i]*sp[i], origin[i], -origin[i], -2*origin[i] and<br>
> similar combinations but none of them worked. Any suggestion to what am I<br>
> doing wrong?<br>
> Regards,<br>
> Dženan<br>
> 2011/6/29 David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>><br>
>><br>
>> On Tue, Jun 28, 2011 at 9:40 AM, Dženan Zukić <<a href="mailto:dzenanz@gmail.com" target="_blank">dzenanz@gmail.com</a>> wrote:<br>
>> > Hi David,<br>
>> ><br>
>> > I am interested in this too:<br>
>> > Does the above approach affect the polygonal actors in the scene<br>
>> > (segmented<br>
>> > parts of the image)?<br>
>> > Regards,<br>
>> > Dženan<br>
>><br>
>> When the DICOM patient coordinate system is used as the VTK world<br>
>> coordinate system, the assumption is that everything (images AND<br>
>> polydata) would have a either already be in the patient coordinate<br>
>> system, or if not, you would to have a 4x4 transform to set as the<br>
>> actor's UserMatrix (or UserTransform). I.e. a transform to bring the<br>
>> data from its original coordinate system into the patient coordinate<br>
>> system.<br>
>><br>
>> - David<br>
><br>
><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>