<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><BR>Hi,<BR>
&nbsp;<BR>
&nbsp;&nbsp; sorry for another post on the same subject, I have added my source code at the end of this message, if it could help someone to give me advice,<BR>
&nbsp;<BR>
Thanks again,<BR>
Regards<BR>
Pascale<BR><BR><BR><BR>

<HR id=EC_stopSpelling>
<BR>
From: chose29@hotmail.com<BR>To: vtkusers@vtk.org<BR>Date: Wed, 13 Aug 2008 11:15:59 -0400<BR>Subject: [vtkusers] Applying transform to volume<BR><BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass body.EC_hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
Hi,<BR>&nbsp;<BR>&nbsp;&nbsp; I've been using vtkThinPlateSplineTransform and have been successful to get a result applied to landmarks, but have a question for transforming a volume. <BR>&nbsp;<BR>First, is there a way to force connectivity between points in a volume?<BR>&nbsp;<BR>More specifically this is what I have done and where is my problem:<BR>&nbsp;<BR>- I created a thin plate spline transform with source points (from an MR volume) and target points (from a CT volume).<BR>- To apply the transformation to the points, I used <FONT size=2>vtkTransformPolyDataFilter and specified a vtkPolyData structure with positions (vtkPoints) and connectivity (using <FONT size=2>vtkCellArray).</FONT></FONT><BR><FONT size=2><FONT size=2>- The resulting displacement for the source points is valid and they are now moved to the target points.</FONT></FONT><BR><FONT size=2><FONT size=2></FONT></FONT>&nbsp;<BR><FONT size=2><FONT size=2>I want to apply this exact transformation to a volume that contains only intensities. I can use <FONT size=2>vtkImageReslice and specify the transform from vtkThinPlateSplineTransform but the volume intensities do not seem to move exactly as the landmarks do and I wonder if the problem might not be the connectivity that&nbsp;is not respected in the final displacement. I cannot use vtkTransformPolyDataFilter with a volume image. Does anyone have an idea what I could do to specify a connectivity constraint?</FONT></FONT></FONT><BR><FONT size=2><FONT size=2><FONT size=2></FONT></FONT></FONT>&nbsp;<BR>&nbsp;<BR>I have another question regarding inverse. In some examples (but not all) on the web, I see that the transform is inversed before using reslice. In what situation does the inverse need to be used?<BR><BR><FONT size=2><FONT size=2><FONT size=2>Thanks in advance for you help!</FONT></FONT></FONT><BR><FONT size=2><FONT size=2><FONT size=2>Pascale<BR><BR></FONT></FONT></FONT><BR><BR>

<HR>
<BR>
&nbsp;<BR><FONT size=2>
vtkThinPlateSplineTransform * TPSTransfo = vtkThinPlateSplineTransform::New();<BR>
vtkGeneralTransform * TPSGeneralTransfo = vtkGeneralTransform::New ();<BR>
vtkPolyData * InPolyData = vtkPolyData::New(); <BR>
vtkImageReslice * reslice = vtkImageReslice::New();<BR></FONT><FONT color=#008000 size=2>
/*<BR>
see example : /Hybrid/Testing/Tcl/TestThinPlateWarp3D.tcl - <BR>
*/<BR></FONT><FONT size=2>
TPSTransfo-&gt;SetBasisToR(); </FONT><FONT color=#008000 size=2>// data is in 3D<BR></FONT><FONT size=2>
TPSTransfo-&gt;SetSourceLandmarks(Points[ModalityTwo]);<BR>
TPSTransfo-&gt;SetTargetLandmarks(Points[ModalityOne]);<BR>
TPSTransfo-&gt;Modified();<BR>
TPSTransfo-&gt;Update();<BR>
TPSGeneralTransfo-&gt;SetInput (TPSTransfo);<BR>
TPSGeneralTransfo-&gt;Update();<BR>
vtkTransformPolyDataFilter *TransformPoints = vtkTransformPolyDataFilter::New();<BR>
InPolyData-&gt;SetPoints(Points[ModalityTwo]); </FONT><FONT color=#008000 size=2>// modify points from MR to fit CT<BR></FONT><FONT size=2>
</FONT><FONT color=#008000 size=2>// create connectivity between points<BR></FONT><FONT size=2>
vtkCellArray * TriangleCells = ConstructCellArray();<BR>
InPolyData-&gt;Allocate(TriangleCells-&gt;GetNumberOfCells());<BR>
InPolyData-&gt;SetPolys(TriangleCells);<BR>
InPolyData-&gt;Update();<BR>
TransformPoints-&gt;SetInput(InPolyData);<BR>
TransformPoints-&gt;SetTransform(TPSGeneralTransfo);<BR>
TransformPoints-&gt;Update();<BR>
<BR>
<BR>
</FONT><FONT color=#008000 size=2>// up to here works ok, mr landmarks are moved to their corresponding ct point match (tested output)<BR></FONT><FONT size=2>
vtkPolyData * Result = TransformPoints-&gt;GetOutput();<BR>
vtkPoints * ResultPoints = Result-&gt;GetPoints();<BR>
OutputPointsSet(ResultPoints);<BR>
&nbsp;<BR>
</FONT><FONT color=#008000 size=2>// transform volume according to TPS found <BR></FONT><FONT size=2>
VTKTransform VTKTransfo;<BR>
vtkImageData * Volume = NULL;<BR>
<BR>
</FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>( mUseGrid == TRUE )<BR>
{<BR>
&nbsp;&nbsp; Volume = VTKTransfo.CreateGridVolume(mMRVolume);<BR>
}<BR>
</FONT><FONT color=#0000ff size=2>else<BR></FONT><FONT size=2>
{<BR>
&nbsp;&nbsp; Volume = VTKTransfo.Local2VTK(mMRVolume);<BR>
}<BR>
</FONT><FONT color=#008000 size=2>// transform volume using reslice<BR></FONT><FONT size=2>
reslice-&gt;SetInput(Volume);<BR>
&nbsp;<BR>
&nbsp;<BR></FONT><FONT color=#008000 size=2>
//******* Not sure what to use here. <BR>
</FONT><FONT size=2></FONT><FONT color=#008000 size=2>// TPSGeneralTransfo-&gt;Inverse(); &lt;- should it be used here? Why is it used in certain situations?<BR></FONT><FONT size=2>
reslice-&gt;SetResliceTransform(TPSGeneralTransfo);<BR>
</FONT><FONT color=#008000 size=2>//reslice-&gt;SetResliceTransform(TransformPoints-&gt;GetTransform());<BR>
&nbsp;<BR>
&nbsp;<BR>
&nbsp;<BR></FONT><FONT size=2>
reslice-&gt;SetInterpolationModeToCubic(); <BR>
SbVec3f Space; Spacing-&gt;GetPixelSpacing(mMRVolume, Space);<BR>
reslice-&gt;SetOutputSpacing(Space[0], Space[1], Space[2]); <BR>
</FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>( i=0; i&lt;3; i++ ) <BR>
&nbsp;&nbsp; VoxPos[i] = 0; <BR>
Transfo.voxel2world(mMRVolume, VoxPos, WorldPos);<BR>
reslice-&gt;SetOutputOrigin(WorldPos[0], WorldPos[1], WorldPos[2]);<BR>
reslice-&gt;Update();<BR>
<BR>
DebugIm = VTKTransfo.Vtk2Local(reslice-&gt;GetOutput(), mMRVolume);<BR>
TPSTransfo-&gt;Delete();<BR>
TPSGeneralTransfo-&gt;Delete();<BR>
InPolyData-&gt;DeleteCells();<BR>
InPolyData-&gt;Delete();<BR>
reslice-&gt;Delete();<BR>
&nbsp;<BR>
<BR>
</FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> DebugIm;<BR></FONT><A href="http:///" target=_blank></A><br /><hr /> <a href='' target='_new'></a></body>
</html>