<div>Hi Luis,</div>
<div>Thanks a lot for looking into the problem. You are right that the problem was related to the numbr (7426, too large)&nbsp;of landmark points I used to deform the image. Anyhow, you could find the image I wanted to deform and the polydata input file in the following locations:
</div>
<div><a href="http://www.stanford.edu/~mingchao/image/phase1.vtk">http://www.stanford.edu/~mingchao/image/phase1.vtk</a> (image)</div>
<div>and</div>
<div><a href="http://www.stanford.edu/~mingchao/image/LTLung.vtk">http://www.stanford.edu/~mingchao/image/LTLung.vtk</a> (polydata).</div>
<div>Is there an easy way to reduce the number of landmark points in my polydata input files? <br>&nbsp;</div>
<div>Cheers,</div>
<div>Ming<br>&nbsp;</div>
<div><span class="gmail_quote">On 3/20/06, <b class="gmail_sendername">Luis Ibanez</b> &lt;<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>Hi Ming,<br><br>Thanks for your detailed report and for posting your source code.<br><br>Your code seems to be very similar to the example:
<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Insight/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Examples/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Registration/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DeformationFieldInitialization.cxx<br><br><br>The problem seems to be related to the number of landmark points<br>that you are passing for initializing the deformation field.
<br><br>Could you please let us know how many points you are using ?<br><br>Could you send us the input file with the vtkPolyData that you<br>are using for feeding this program ?<br>That data could help us to figure out what may be going wrong
<br>with your code.<br><br><br>&nbsp;&nbsp;Please let us know,<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;Thanks<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Luis<br><br><br>--------------<br>Ming Chao wrote:<br>&gt; Hi,<br>&gt;<br>&gt; I encountered a problem when trying to deform a 3D image. The way I
<br>&gt; deformed the image is as the following: I created a 3D contour for an<br>&gt; organ, say, lung for this image. Along the contours I have a bunch of<br>&gt; points. Then I generated a vector field for these points and used these
<br>&gt; vectors to deform the image. I didn't have trouble deforming any 2D<br>&gt; image. But for 3D image I got an error. I traced down to the point where<br>&gt; the problem occured: in the try-catch block with<br>&gt; deformer-&gt;UpdateLargestPossibleRegion();&nbsp;&nbsp;debugging reports a problem on
<br>&gt; line 417 of vnl_matrix.txx file. For reference purpose I copy and paste<br>&gt; that part of code here:<br>&gt;<br>&gt; //: Sets all elements of matrix to specified value. O(m*n).<br>&gt;<br>&gt; template&lt;class T&gt;
<br>&gt; void vnl_matrix&lt;T&gt;::fill (T const&amp; value)<br>&gt; {<br>&gt;&nbsp;&nbsp; for (unsigned int i = 0; i &lt; this-&gt;num_rows; i++)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; for (unsigned int j = 0; j &lt; this-&gt;num_cols; j++)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;data[i][j] = value;
<br>&gt; &lt;========================================= debugging reports problem !<br>&gt; }<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; Also, I am attaching my code of deforming 3D images below. I would<br>&gt; greatly appreciate it if anybody can help look into it.
<br>&gt;<br>&gt; Best regards,<br>&gt; Ming<br>&gt;<br>&gt;<br>&gt; // ---------------- starting of the code&nbsp;&nbsp;-------------------------<br>&gt; #include &quot;itkVector.h&quot;<br>&gt; #include &quot;itkImage.h&quot;<br>&gt; #include &quot;
itkImageRegionIteratorWithIndex.h&quot;<br>&gt; #include &quot;itkDeformationFieldSource.h &quot;<br>&gt; #include &quot;itkImageFileReader.h&quot;<br>&gt; #include &quot;itkImageFileWriter.h&quot;<br>&gt; #include &quot;
itkWarpImageFilter.h&quot;<br>&gt; #include &quot;itkLinearInterpolateImageFunction.h&quot;<br>&gt;<br>&gt; #include &quot;itkNormalVariateGenerator.h&quot;<br>&gt; #include &quot;vtkPolyDataReader.h&quot;<br>&gt; #include &quot;
vtkPolyDataWriter.h&quot;<br>&gt; #include &quot;vtkFloatArray.h&quot;<br>&gt; #include &quot;vtkPolyData.h&quot;<br>&gt; #include &quot;vtkPointData.h&quot;<br>&gt; #include &quot;vtkPoints.h&quot;<br>&gt;<br>&gt; #include &lt;fstream&gt;
<br>&gt;<br>&gt; int main( int argc, char * argv[] )<br>&gt; {<br>&gt;<br>&gt;&nbsp;&nbsp;if( argc &lt; 2 )<br>&gt;&nbsp;&nbsp;{<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Missing Parameters &quot; &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];
<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot; landmarksFile fixedImage &quot;;<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;movingImage deformedMovingImage&quot; &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; return 1;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;const&nbsp;&nbsp;&nbsp;&nbsp; unsigned int&nbsp;&nbsp; Dimension = 3;
<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VectorComponentType;<br>&gt;<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; itk::Vector&lt; VectorComponentType, Dimension &gt;&nbsp;&nbsp;&nbsp;&nbsp;VectorType;<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; itk::Image&lt; VectorType,&nbsp;&nbsp;Dimension &gt;&nbsp;&nbsp; DeformationFieldType;
<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; float&nbsp;&nbsp;PixelType;<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; itk::Image&lt; PixelType, Dimension &gt;&nbsp;&nbsp;ImageType&nbsp;&nbsp;;<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; itk::ImageFileReader&lt; ImageType&nbsp;&nbsp;&gt;&nbsp;&nbsp;ReaderType ;<br>&gt;&nbsp;&nbsp;typedef&nbsp;&nbsp; itk::ImageFileWriter&lt; ImageType&nbsp;&nbsp;&gt;&nbsp;&nbsp;WriterType ;
<br>&gt;<br>&gt;&nbsp;&nbsp;ReaderType::Pointer Reader = ReaderType::New();<br>&gt;&nbsp;&nbsp;Reader-&gt;SetFileName( argv[1] );<br>&gt;<br>&gt;&nbsp;&nbsp;try<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; Reader-&gt;Update();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;catch( itk::ExceptionObject &amp; excp )
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception thrown &quot; &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; return EXIT_FAILURE;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;WriterType::Pointer Writer = WriterType::New();
<br>&gt;&nbsp;&nbsp;Writer-&gt;SetFileName( argv[2] );<br>&gt;<br>&gt;&nbsp;&nbsp;ImageType::ConstPointer fixedImage = Reader-&gt;GetOutput();<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;typedef itk::DeformationFieldSource&lt; DeformationFieldType &gt;<br>&gt; DeformationSourceType;
<br>&gt;&nbsp;&nbsp;DeformationSourceType::Pointer deformer = DeformationSourceType::New();<br>&gt;&nbsp;&nbsp;deformer-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<br>&gt;&nbsp;&nbsp;deformer-&gt;SetOutputOrigin(&nbsp;&nbsp;fixedImage-&gt;GetOrigin() );
<br>&gt;&nbsp;&nbsp;deformer-&gt;SetOutputRegion(&nbsp;&nbsp;fixedImage-&gt;GetLargestPossibleRegion() );<br>&gt;<br>&gt;&nbsp;&nbsp;typedef DeformationSourceType::LandmarkContainer<br>&gt; LandmarkContainerType;<br>&gt;&nbsp;&nbsp;typedef DeformationSourceType::LandmarkPointType
<br>&gt; LandmarkPointType;<br>&gt;&nbsp;&nbsp;LandmarkContainerType::Pointer sourceLandmarks =<br>&gt; LandmarkContainerType::New();<br>&gt;&nbsp;&nbsp;LandmarkContainerType::Pointer targetLandmarks =<br>&gt; LandmarkContainerType::New();<br>
&gt;<br>&gt;&nbsp;&nbsp;vtkPolyDataReader *reader = vtkPolyDataReader::New();<br>&gt;&nbsp;&nbsp;reader-&gt;SetFileName( argv[2] );<br>&gt;&nbsp;&nbsp;reader-&gt;Update();<br>&gt;&nbsp;&nbsp;vtkPolyData *poly = vtkPolyData::New();<br>&gt;&nbsp;&nbsp;poly-&gt;DeepCopy( reader-&gt;GetOutput());
<br>&gt;&nbsp;&nbsp;reader-&gt;Delete();<br>&gt;&nbsp;&nbsp;vtkPoints *points = poly-&gt;GetPoints();<br>&gt;&nbsp;&nbsp;int NumberOfTotalPoints = points-&gt;GetNumberOfPoints();<br>&gt;<br>&gt;&nbsp;&nbsp;unsigned int pointId = 0;<br>&gt;&nbsp;&nbsp;for ( int i = 0; i&lt; NumberOfTotalPoints; i++)
<br>&gt;&nbsp;&nbsp;{<br>&gt;&nbsp;&nbsp; double pos[3]; points-&gt;GetPoint(i,pos);<br>&gt;<br>&gt;&nbsp;&nbsp; double x = 0;<br>&gt;&nbsp;&nbsp; double y = 0;<br>&gt;&nbsp;&nbsp; double z = 0;<br>&gt;<br>&gt;&nbsp;&nbsp; if ( i &lt; (int)NumberOfTotalPoints/2 ) {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;x = 
0.002*i;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;y = 0.003*i;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;z = 0.0001*i;<br>&gt;&nbsp;&nbsp; } else {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;x = 0.002*(NumberOfTotalPoints-1-i);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;y = 0.003*(NumberOfTotalPoints-1-i);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;z = 0.0001* (NumberOfTotalPoints-1-i);
<br>&gt;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp; std::cout &lt;&lt; &quot;generator 1 and 2 :: &quot; &lt;&lt; i &lt;&lt; &quot;: \t&quot; &lt;&lt; x &lt;&lt; &quot;\t&quot; &lt;&lt; y<br>&gt; &lt;&lt; &quot;\t&quot; &lt;&lt; z &lt;&lt; std::endl;
<br>&gt;<br>&gt;&nbsp;&nbsp; //&nbsp;&nbsp;Create source and target landmarks.<br>&gt;&nbsp;&nbsp; //<br>&gt;&nbsp;&nbsp; LandmarkPointType sourcePoint;<br>&gt;&nbsp;&nbsp; LandmarkPointType targetPoint;<br>&gt;<br>&gt;&nbsp;&nbsp; sourcePoint[0] = pos[0] ;<br>&gt;&nbsp;&nbsp; sourcePoint[1] = pos[1] ;
<br>&gt;&nbsp;&nbsp; sourcePoint[2] = pos[2] ;<br>&gt;<br>&gt;&nbsp;&nbsp; targetPoint[0] = sourcePoint[0] + x ;<br>&gt;&nbsp;&nbsp; targetPoint[1] = sourcePoint[1] + y ;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;targetPoint[2] = sourcePoint[2] + z ;<br>&gt;<br>&gt;&nbsp;&nbsp; sourceLandmarks-&gt;InsertElement( pointId, sourcePoint );
<br>&gt;&nbsp;&nbsp; targetLandmarks-&gt;InsertElement( pointId, targetPoint );<br>&gt;&nbsp;&nbsp; pointId++;<br>&gt;<br>&gt;&nbsp;&nbsp;}<br>&gt;<br>&gt;&nbsp;&nbsp;deformer-&gt;SetSourceLandmarks( sourceLandmarks.GetPointer() );<br>&gt;&nbsp;&nbsp;deformer-&gt;SetTargetLandmarks( 
targetLandmarks.GetPointer() );<br>&gt;<br>&gt;&nbsp;&nbsp;std::cout &lt;&lt; &quot; Up to this point we are still okay....&quot; &lt;&lt; std::endl;<br>&gt;<br>&gt;&nbsp;&nbsp;try<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; deformer-&gt;UpdateLargestPossibleRegion();
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;catch( itk::ExceptionObject &amp; excp )<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception thrown &quot; &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; return EXIT_FAILURE;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;&nbsp;&nbsp;std::cout &lt;&lt; &quot;the deformer is done at this point .... &quot; &lt;&lt; std::endl;<br>&gt;<br>&gt;&nbsp;&nbsp;DeformationFieldType::ConstPointer deformationField =<br>&gt; deformer-&gt;GetOutput();
<br>&gt;&nbsp;&nbsp;typedef itk::WarpImageFilter&lt; ImageType, ImageType,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DeformationFieldType&nbsp;&nbsp;&gt;&nbsp;&nbsp;FilterType;<br>&gt;<br>&gt;&nbsp;&nbsp;FilterType::Pointer warper = FilterType::New();<br>&gt;&nbsp;&nbsp;typedef itk::LinearInterpolateImageFunction&lt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ImageType, double &gt;&nbsp;&nbsp;InterpolatorType;<br>&gt;<br>&gt;&nbsp;&nbsp;InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>&gt;&nbsp;&nbsp;warper-&gt;SetInterpolator( interpolator );<br>&gt;&nbsp;&nbsp;warper-&gt;SetOutputSpacing( deformationField-&gt;GetSpacing() );
<br>&gt;&nbsp;&nbsp;warper-&gt;SetOutputOrigin(&nbsp;&nbsp;deformationField-&gt;GetOrigin() );<br>&gt;&nbsp;&nbsp;warper-&gt;SetDeformationField( deformationField );<br>&gt;&nbsp;&nbsp;warper-&gt;SetInput( Reader-&gt;GetOutput() );<br>&gt;&nbsp;&nbsp;Writer-&gt;SetInput( warper-&gt;GetOutput() );
<br>&gt;<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;try<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; Writer-&gt;Update();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;catch( itk::ExceptionObject &amp; excp )<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception thrown &quot; &lt;&lt; std::endl;
<br>&gt;&nbsp;&nbsp; std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp; return EXIT_FAILURE;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;return EXIT_SUCCESS;<br>&gt;<br>&gt; }<br>&gt;<br>&gt; // ---------------- end --------------------
<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; Insight-users mailing list<br>&gt; <a href="mailto:Insight-users@itk.org">
Insight-users@itk.org</a><br>&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br><br></blockquote></div><br>