<br>Hi Dženan<br><br><br>Thanks a lot for sharing the solution that you found.<br><br>That's the Open Source spirit !<br><br><br> Luis<br><br><br>------------------------------------------------------------------------<br>
<div class="gmail_quote">2010/4/28 Dženan Zukić <span dir="ltr"><<a href="mailto:dzenanz@gmail.com">dzenanz@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>Hi Luis!</div><div><br></div><div>Thanks for the provided code, but in the end it didn't really help me (aside from encouraging me that transformations are not that complicated). I re-read 3D matrix operations, did a lot of trial and error, and ended up with this code (it might be useful to someone):</div>
<div><br></div><div><div><font face="'courier new', monospace">osg::ref_ptr<osg::Group> stuff=segmentInterestingStructures(...); //vertices have physical image coordinates</font></div>
<div><font face="'courier new', monospace">osg::ref_ptr<osg::Group> isosurface=marchingCubesGPU(...); //accounts for spacing, so scaling is handled</font></div><div><font face="'courier new', monospace">VisualizingImageType::DirectionType d=visualizing->GetDirection();</font></div>
<div><font face="'courier new', monospace">d=d.GetTranspose(); //ITK matrix is in column-major format, OSG matrix is row major (trial and error)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace">osg::Matrix matrix(d(0,0), d(0,1), d(0,2), 0,</font></div><div><span style="white-space: pre;"><font face="'courier new', monospace">                                </font></span><font face="'courier new', monospace"> d(1,0), d(1,1), d(1,2), 0,</font></div>
<div><span style="white-space: pre;"><font face="'courier new', monospace">                                </font></span><font face="'courier new', monospace"> d(2,0), d(2,1), d(2,2), 0,</font></div>
<div><span style="white-space: pre;"><font face="'courier new', monospace">                                </font></span><font face="'courier new', monospace"> 0,</font><span style="white-space: pre;"><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace"> 0,</font><span style="white-space: pre;"><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace"> 0,</font><span style="white-space: pre;"><font face="'courier new', monospace">        </font></span><font face="'courier new', monospace"> 1);</font></div>
<div><font face="'courier new', monospace">osg::Matrix t;</font></div><div><font face="'courier new', monospace">VisualizingImageType::PointType origin=visualizing->GetOrigin();</font></div>
<div><font face="'courier new', monospace">t.makeTranslate(origin[0], origin[1], origin[2]);</font></div><div><font face="'courier new', monospace">matrix.postMult(t);</font></div>
<div><font face="'courier new', monospace">osg::ref_ptr<osg::MatrixTransform> mt=new osg::MatrixTransform(matrix);</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace">osg::ref_ptr<Group> grp=new osg::Group;</font></div><div><font face="'courier new', monospace">mt->addChild(isosurface);</font></div>
<div><font face="'courier new', monospace">grp->addChild(mt);</font></div><div><font face="'courier new', monospace">grp->addChild(stuff);</font></div>
<div><font face="'courier new', monospace">mainForm.vis->setSceneData(grp);</font></div></div><div><br></div>Regards,<div>Dženan<br><br><div class="gmail_quote">2010/4/28 Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com" target="_blank">luis.ibanez@kitware.com</a>></span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Hi Dženan<br><br>This is indeed a common problem,<br>so, it is great that you bring it up.<br><br><br>Following the numbering of your questions:<br><br>a) No, there is no direct way of forcing the direction<br> matrix to be an identity. (and if there was such <br>
method we will strongly discourage you from using it)<br><br>b) You can change the direction matrix of the image,<br> by using the ChangeImageInformationFilter.<br> (but we strongly discourage you from doing so).<br>
<br>c) The RIGHT thing to do is to use the direction<br> matrix to correct the orientation of the isosurface<br> after you extract it. In that way, the iso-surface<br> will occupy the same coordinate system as the<br>
original image.<br><br><br>Options (a) and (b) are VERY dangerous if you are<br>dealing with real patient data.<br><br><br>Please find attached an example of how to do this<br>with ITK and VTK. You could directly use this example,<br>
or you can probably follow the math and apply the<br>equivalent processing using OSG.<br><br><br>You will find the full source code at:<br><br> InsightApplications/Auxiliary/vtk<br><br><br><br><br> Regards,<br>
<br><br> Luis<br> <br><br>---------------------------------------------------------------------<br><div class="gmail_quote">2010/4/27 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="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>Hi everybody,<div><br></div><div>I guess someone has dealt with a problem similar to mine before. I am doing segmentation in a magnetic resonance image. The result of my segmentation is a polygonal model. Problem: How to visualize the resulting polygonal model along with scalar-field image?</div>
<div><br></div><div>I use Qt, ITK and OpenSceneGraph. First I tried using osgVolume (ray-casting renderer) together with polygonal data in the same scene, but with that setup the depth information is lost. I resorted to using isosurface of the image instead of the image itself. It works, but I have to manage physical coordinates by myself - which is both a reinvention of the wheel and error-prone.</div>
<div><br></div><div>So I decided to use ITK's physical coordinate managing routines (TransformPhysicalPointToIndex), but I ran into a problem. GetDirection does not return identity matrix for my images (at least not for sagittal ones), therefore my segmented parts end up displayed <b>outside</b> of the image.</div>
<div>a) Is there a way to force image reading routines to load images into memory in such a way to have an identity matrix for directions?<br>b) If not, is there a way to transform image data (using a filter) to get an image with identity matrix as "directions". Is that filter ChangeInformationImageFilter?<br>
c) What is the proper way to construct a transformation matrix to be applied to the isosurface of the image (which was generated assuming identity matrix directions) in order to bring it to same coordinates I get when using TransformIndexToPhysicalPoint? Just using matrix returned by GetDirection and adding translation to account for origin does not work.</div>
<div><br></div><div>If anyone knows a better way to visualize a polygonal model alongside 3D image, I would like to hear it.</div><div>Off topic question: is combining polygons with scalar fields so simple in VTK to justify a switch from OSG to VTK?</div>
<div><br></div><div>Thanks to anyone who takes interest in this.</div><div><br></div><div>Best regards,</div><div>Dženan</div></div></div></blockquote></div></blockquote></div></div></div>
</div>
</blockquote></div><br>