Hi Agata, <br><br>Please find attached the working code.<br><br>Here is the hierarchy that you may want to keep in mind:<br><br><ul><li>One TPS transform has two PointSets</li><li>One PointSet has a PointContainer</li><li>
One PointContainer have PointIterators (const and non-const)</li></ul><br>You can get points from a PointSet by using GetPointid)<br><br> PointType point = pointSet->GetPoint( pointId );<br><br>or you can get them from the PointContainer by using GetElement(id)<br>
<br> PointType point = pointContainer->GetElement( pointId );<br>
<br>or you can get them via Iterators from the PointContainer<br><br> PointConstIterator pointItr = pointContainer->Begin();<br> PointType point = pointItr.Value();<br>
++pointItr;<br> ...etc...<br><br>Note that you shouldn't use "int" or "short" or "long" for the <br>PointId type. One must use PointIdType (which is typedefed<br>from the ElementIdentifier type), this is very important if you<br>
are working on 64 bits.<br><br><br>The attached code shows you both ways of doing this <br>at the end of the file.<br><br>The key lines of code are:<br><br><br><span style="font-family:courier new,monospace"> TPSTransformType::InputPointType trackerPointSourcePosition;</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> TPSTransformType::OutputPointType trackerPointNewPosition;</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> // Test transforming the input landmark themselves</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> for( PointIdType i = 0; i < sourceLandMarks->GetNumberOfPoints(); i++ )</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> {</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> trackerPointSourcePosition = sourceLandMarks->GetPoint(i);</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> trackerPointNewPosition = tps->TransformPoint(trackerPointSourcePosition);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> transformed_points_container->InsertElement(i,trackerPointNewPosition);</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> std::cout << "Input " << trackerPointSourcePosition << " : ";</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> std::cout << "Output " << trackerPointNewPosition << std::endl;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> }</span><br style="font-family:courier new,monospace">
<br><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> // Do the same using Iterators</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> std::cout << std::endl << "Now using Iterators " << std::endl;</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> PointConstIterator inputPointItr = sourceLandMarkContainer->Begin();</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> PointConstIterator inputPointEnd = sourceLandMarkContainer->End();</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> PointIdType pointId = itk::NumericTraits< PointIdType >::Zero;</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> while( inputPointItr != inputPointEnd )</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> {</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> trackerPointNewPosition = tps->TransformPoint(inputPointItr.Value());</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> transformed_points_container->InsertElement(pointId,trackerPointNewPosition);</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> std::cout << "Input " << inputPointItr.Value() << " : ";</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> std::cout << "Output " << trackerPointNewPosition << std::endl;</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ++inputPointItr;</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> }</span><br style="font-family:courier new,monospace">
<br><br><br><br><br> Hope this helps,<br><br> Luis<br><br><br>------------------------------------------------------------<br><div class="gmail_quote">On Sat, Aug 18, 2012 at 12:17 PM, Agata Krasoń <span dir="ltr"><<a href="mailto:agatakrason@gmail.com" target="_blank">agatakrason@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Luis,<div><br></div><div>I am trying to use tps transformation in ITK.</div><div>...</div><div>I created sources and target points.</div>
<div>I made Tps transformation.</div>
<div>I need to receive points after registration</div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>...</div></blockquote><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I have a problem with iterators.</div><div>I would appreciate for any help please. </div>
<div><br></div><div><div>int main(int argc, char* argv[])</div><div>{</div><div><br></div><div><span style="white-space:pre-wrap">        </span>double tab[30] = </div><div><span style="white-space:pre-wrap">        </span>{</div>
<div><span style="white-space:pre-wrap">        </span> // Tracker</div><div><span style="white-space:pre-wrap">        </span>-81.29,-31.07,<span style="white-space:pre-wrap">        </span>-770.58, </div>
<div> -83.11,<span style="white-space:pre-wrap">        </span>-21.26,<span style="white-space:pre-wrap">        </span>-822.64,</div><div> -93.45,<span style="white-space:pre-wrap">        </span>-32.44,<span style="white-space:pre-wrap">        </span>-858.72,</div>
<div> -68.08,<span style="white-space:pre-wrap">        </span>-126.89,-813.07,</div><div> -61.04,<span style="white-space:pre-wrap">        </span>75.74,<span style="white-space:pre-wrap">        </span>-808.36,</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span> // Image</div><div> 140.6,<span style="white-space:pre-wrap">        </span>230.7,<span style="white-space:pre-wrap">        </span>-30.5,</div>
<div> 140.2,<span style="white-space:pre-wrap">        </span>231.7,<span style="white-space:pre-wrap">        </span>-71.1,</div><div> 144.8,<span style="white-space:pre-wrap">        </span>235.9,<span style="white-space:pre-wrap">        </span>-116.1,</div>
<div> 45.8,<span style="white-space:pre-wrap">        </span>220.2,<span style="white-space:pre-wrap">        </span>-66.7,</div><div> 231.6,<span style="white-space:pre-wrap">        </span>211.3,<span style="white-space:pre-wrap">        </span>-66.1</div>
<div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>};</div><div><span style="white-space:pre-wrap">        </span></div><div>
<br></div><div> const unsigned int Dimension = 3;</div><div> typedef unsigned char PixelType;</div><div> typedef double CoordinateRepType;</div><div> typedef itk::ThinPlateSplineKernelTransform< CoordinateRepType,Dimension> TPSTransformType;</div>
<div> typedef itk::Point< CoordinateRepType,Dimension > PointType;</div><div> typedef std::vector< PointType > PointArrayType;</div><div> typedef TPSTransformType::PointSetType PointSetType;</div>
<div> typedef PointSetType::Pointer PointSetPointer;</div><div> typedef PointSetType::PointIdentifier PointIdType;</div><div><br></div><div><br></div><div> // Landmarks correspondances may be associated with the SplineKernelTransforms</div>
<div> // via Point Set containers. Let us define containers for the landmarks.</div><div> PointSetType::Pointer sourceLandMarks = PointSetType::New();</div><div> PointSetType::Pointer targetLandMarks = PointSetType::New();</div>
<div> PointType trackerPoint; PointType imagePoint;</div><div> PointSetType::PointsContainer::Pointer sourceLandMarkContainer = </div><div> sourceLandMarks->GetPoints();</div><div>
PointSetType::PointsContainer::Pointer targetLandMarkContainer = </div><div> targetLandMarks->GetPoints();</div><div> </div><div><br></div><div> // 1 Landmark</div>
<div> trackerPoint[0] = tab[0];</div><div> trackerPoint[1] = tab[1];</div><div> trackerPoint[2] = tab[2];</div><div> imagePoint[0] = tab[15];</div><div> imagePoint[1] = tab[16];</div><div> imagePoint[2] = tab[17];</div>
<div> sourceLandMarkContainer->InsertElement( 0,trackerPoint);</div><div> targetLandMarkContainer->InsertElement(0,imagePoint);</div><div><br></div><div> </div><div> // 2 Landmark</div><div> trackerPoint[0] = tab[3];</div>
<div> trackerPoint[1] = tab[4];</div><div> trackerPoint[2] = tab[5];</div><div> imagePoint[0] = tab[18];</div><div> imagePoint[1] = tab[19];</div><div> imagePoint[2] = tab[20];</div><div> sourceLandMarkContainer->InsertElement(1,trackerPoint);</div>
<div> targetLandMarkContainer->InsertElement(1,imagePoint);</div><div> </div><div> // 3 Landmark</div><div> trackerPoint[0] = tab[6];</div><div> trackerPoint[1] = tab[7];</div><div> trackerPoint[2] = tab[8];</div>
<div> imagePoint[0] = tab[21];</div><div> imagePoint[1] = tab[22];</div><div> imagePoint[2] = tab[23];</div><div> sourceLandMarkContainer->InsertElement( 2,trackerPoint);</div><div> targetLandMarkContainer->InsertElement(2,imagePoint);</div>
<div> </div><div> // 4 Landmark</div><div> trackerPoint[0] = tab[9];</div><div> trackerPoint[1] = tab[10];</div><div> trackerPoint[2] = tab[11];</div><div> imagePoint[0] = tab[24];</div><div> imagePoint[1] = tab[25];</div>
<div> imagePoint[2] = tab[26];</div><div> sourceLandMarkContainer->InsertElement( 3,trackerPoint);</div><div> targetLandMarkContainer->InsertElement(3,imagePoint);</div><div><br></div><div> // 5 Landmark</div><div>
trackerPoint[0] = tab[12];</div><div> trackerPoint[1] = tab[13];</div><div> trackerPoint[2] = tab[14];</div><div> imagePoint[0] = tab[27];</div><div> imagePoint[1] = tab[28];</div><div> imagePoint[2] = tab[29];</div>
<div><br></div><div> sourceLandMarkContainer->InsertElement(4,trackerPoint);</div><div> targetLandMarkContainer->InsertElement(4,imagePoint);</div><div><br></div><div> TPSTransformType::Pointer tps = TPSTransformType::New();</div>
<div> tps->SetSourceLandmarks(sourceLandMarks);</div><div> tps->SetTargetLandmarks(targetLandMarks);</div><div> tps->ComputeWMatrix();</div><div> </div><div><br></div><div> PointSetType::Pointer transformed_points = PointSetType::New();</div>
<div> PointSetType::PointsContainer::Pointer transformed_points_container = transformed_points->GetPoints(); </div><div> TPSTransformType::OutputPointType trackerPointNewPosition;</div><div><br></div><div><font color="#ff0000"> for( int i = 0; i < sourceLandMarks->GetNumberOfPoints(); i++){</font></div>
<div><font color="#ff0000"><span style="white-space:pre-wrap">        </span> PointSetType src_pnt = sourceLandMarks->GetPoints(); // Here It doesn't compile ?</font></div><div><font color="#ff0000"> trackerPointNewPosition = tps->TransformPoint(trackerPoint);</font></div>
<div><font color="#ff0000"> transformed_points_container->InsertElement(i,trackerPointNewPosition); </font></div><div><font color="#ff0000"><span style="white-space:pre-wrap">        </span>std::cout<<" "<<trackerPointNewPosition <<std::endl;</font></div>
<div><font color="#ff0000"> }</font></div><div><br></div><div><br></div><div> return EXIT_SUCCESS;</div><div><br></div><div><br></div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div>I would appreciate for any help please.</div>
<div><br></div><div>Best,</div><div>Agata </div>
</blockquote></div><br>