<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Since your points reside in an image, an easy<div>parameterization is to assign their location to&nbsp;</div><div>their x,y,z location in the image. &nbsp;Does that make</div><div>sense?<br><div><div><br><div><div>On Jan 10, 2012, at 5:19 AM, Kerstin Müller wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br>Hi,<br><br>yes I also used your sample code, but still I got a heap corruption error. That's why I just wanted to try if my sample points are the problem.<br>Do I need to scale them to a range between [0 1]?<br><br>
Best Regards,<br><br>Kerstin<br><br><div class="gmail_quote">2012/1/10 Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com">ntustison@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi Kerstin,<div><br></div><div>Please keep the correspondence on the user's list. &nbsp;</div><div><br></div><div>Why are you setting your vector to all zeros?&nbsp;</div><div class="im"><div><br>
</div><div><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VectorType v;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[0] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[1] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[2] = 0.0;<br></blockquote><br></div></div><div>and why are you setting the location of your points to&nbsp;</div>
<div>(idx,idx,idx,t)?</div><div class="im"><div><br></div><div><blockquote type="cite">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; point[0] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[1] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[2] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[3] = t;<br></blockquote>
<br></div></div><div>That can't possibly be right. &nbsp;Did you look at the sample</div><div>code I gave you?</div><div><br></div><div>Nick</div><div><div class="h5"><div><br></div><div><br></div><div><br><div><div>On Jan 9, 2012, at 2:04 AM, Kerstin Müller wrote:</div>
<br><blockquote type="cite">Hi,<br><br>thank you very much!<br>However I'm still struggeling with a heap corruption problem. I'm not sure if I set my parameters correct.<br><br>&nbsp;&nbsp;&nbsp; typedef float RealType;<br>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; typedef itk::Vector&lt;RealType, 3&gt; VectorType;<br>
&nbsp;&nbsp;&nbsp; typedef itk ::Image &lt;VectorType , 4 &gt; TimeVaryingDeformationFieldType;<br>&nbsp;&nbsp;&nbsp; typedef itk :: PointSet &lt;VectorType , 4 &gt; TimeVaryingDeformationFieldPointSetType;<br><br>&nbsp;&nbsp;&nbsp; TimeVaryingDeformationFieldPointSetType::Pointer fieldPoints = TimeVaryingDeformationFieldPointSetType:: New ();<br>

&nbsp;&nbsp;&nbsp; fieldPoints-&gt;Initialize();<br><br>&nbsp;&nbsp;&nbsp; // Set the sample points just for testing 10 linear points no movement<br>&nbsp;&nbsp;&nbsp; for ( int t = 0; t &lt; m_configuration.num_projections ; t++ ) <br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int num = 0;<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for( int idx = 0; idx &lt;= 10; idx++ )<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; VectorType v;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[0] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[1] = 0.0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[2] = 0.0;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TimeVaryingDeformationFieldPointSetType::PointType point;<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[0] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[1] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[2] = idx;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; point[3] = t;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fieldPoints-&gt;SetPoint( num, point );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fieldPoints-&gt;SetPointData(num, v);<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; num++;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br><br>&nbsp;&nbsp;&nbsp; TimeVaryingDeformationFieldType::PointType&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; origin;<br>&nbsp;&nbsp;&nbsp; TimeVaryingDeformationFieldType::SpacingType&nbsp;&nbsp;&nbsp; spacing;<br>&nbsp;&nbsp;&nbsp; TimeVaryingDeformationFieldType::SizeType&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; size;<br>

<br>&nbsp;&nbsp;&nbsp; // Define the parametric domain<br>&nbsp;&nbsp;&nbsp; spacing[0] = 1.0f;<br>&nbsp;&nbsp;&nbsp; spacing[1] = 1.0f;<br>&nbsp;&nbsp;&nbsp; spacing[2] = 1.0f;<br>&nbsp;&nbsp;&nbsp; spacing[3] = 2.0f;<br><br>&nbsp;&nbsp;&nbsp; size[0] = 128;<br>&nbsp;&nbsp;&nbsp; size[1] = 128;<br>&nbsp;&nbsp;&nbsp; size[2] = 128;<br>&nbsp;&nbsp;&nbsp; size[3] = 66;<br>

&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; origin[0] = 0.0f;<br>&nbsp;&nbsp;&nbsp; origin[1] = 0.0f;<br>&nbsp;&nbsp;&nbsp; origin[2] = 0.0f;<br>&nbsp;&nbsp;&nbsp; origin[3] = 0.0f;<br><br>&nbsp;&nbsp;&nbsp; // Define the filter and set the parameters<br>&nbsp;&nbsp;&nbsp; typedef itk::myBSplineScatteredDataPointSetToImageFilter&lt;TimeVaryingDeformationFieldPointSetType, TimeVaryingDeformationFieldType&gt; BSplineFilterType;<br>

&nbsp;&nbsp;&nbsp; BSplineFilterType::Pointer filter = BSplineFilterType::New();<br><br>&nbsp;&nbsp;&nbsp; filter -&gt;SetSize( size );<br>&nbsp;&nbsp;&nbsp; filter -&gt;SetOrigin( origin );<br>&nbsp;&nbsp;&nbsp; filter -&gt;SetSpacing( spacing );<br>&nbsp;&nbsp;&nbsp; filter -&gt; SetGenerateOutputImage ( false );<br>

&nbsp;&nbsp;&nbsp; filter -&gt; SetNumberOfLevels ( 2 );<br>&nbsp;&nbsp;&nbsp; filter -&gt; SetSplineOrder ( 3 );<br><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; BSplineFilterType :: ArrayType ncps;<br>&nbsp;&nbsp;&nbsp; ncps.SetElement(0,8);<br>&nbsp;&nbsp;&nbsp; ncps.SetElement(1,8);<br>&nbsp;&nbsp;&nbsp; ncps.SetElement(2,8);<br>

&nbsp;&nbsp;&nbsp; ncps.SetElement(3,34);<br>&nbsp;&nbsp;&nbsp; filter -&gt; SetNumberOfControlPoints ( ncps );<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; filter -&gt;SetInput( fieldPoints );<br><br>&nbsp;&nbsp;&nbsp; filter-&gt;SetDebug(true);<br><br>&nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; filter -&gt;Update ();<br>

&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch ( itk::ExceptionObject &amp; excp )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std :: cerr &lt;&lt; "Test 2: itkBSplineScatteredDataImageFilter exception thrown" &lt;&lt; std:: endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr&lt;&lt; excp &lt;&lt;std::endl;<br>

&nbsp;&nbsp;&nbsp; }<br><br>Thank you very much!<br><br>Best,<br><br>Kerstin<br><div class="gmail_quote">2012/1/4 Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com" target="_blank">ntustison@gmail.com</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Okay, here's some pseudocode which hasn't been tested</div><div>since you have to provide it the interface to your values&nbsp;</div>


<div>but you should get the general idea.</div><div><br></div><div>&nbsp; typedef float RealType;</div><div><div>&nbsp; typedef itk::Image&lt;RealType, ImageDimension&gt; RealImageType;</div><div><br></div><div>&nbsp; // Read in your reference image which will define the domain of&nbsp;</div>


<div>&nbsp; // your B-spline displacement field. &nbsp;Assume, for simplicity, that it</div><div>&nbsp; // has identity direction</div><div><br></div><div>&nbsp; typedef itk::ImageFileReader&lt;RealImageType&gt; ImageReaderType;</div><div>&nbsp; typename ImageReaderType::Pointer reader = ImageReaderType::New();</div>


<div>&nbsp; reader-&gt;SetFileName( XXXX );</div><div>&nbsp; reader-&gt;Update();</div><div><br></div><div>&nbsp; typedef itk::Vector&lt;RealType, ImageDimension&gt; VectorType;</div><div>&nbsp; typedef itk::Image&lt;VectorType, ImageDimension+1&gt; TimeVaryingDeformationFieldType;</div>


<div><br></div><div>&nbsp; typedef itk::PointSet&lt;VectorType, ImageDimension+1&gt; TimeVaryingDeformationFieldPointSetType;</div></div><div>&nbsp; typename&nbsp;TimeVaryingDeformationFieldPointSetType::Pointer fieldPoints =</div><div>


&nbsp; &nbsp;&nbsp;TimeVaryingDeformationFieldPointSetType::New();</div><div>&nbsp; fieldPoints-&gt;Initialize();</div><div>&nbsp; unsigned long count = 0;</div><div><br></div><div>&nbsp; // Assume points are stored in a 2-D matrix called 'mySamplePoints' where the column</div>


<div>&nbsp; // is the time point and the row is the point</div><div><br></div><div>&nbsp; for( unsigned int t = 0; t &lt; numberOfTimePoints; t++ )</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; for( unsigned int n = 0; &nbsp;n &lt; numberOfPointsPerTimePoint; n++ )</div>


<div>&nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; VectorType displacement = mySamplePoints[n][t] - mySamplePoints[n][0];</div><div>&nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp;&nbsp;TimeVaryingDeformationFieldPointSetType::PointType parametric point;</div><div>&nbsp; &nbsp; &nbsp; for( unsigned int d = 0; d &lt; ImageDimension; d++ )</div>


<div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; point[d] = ( mySamplePoints[n][0] )[d];</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; point[ImageDimension] = t;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; fieldPoints-&gt;SetPoint( count, point );</div><div>&nbsp; &nbsp; &nbsp; fieldPoints-&gt;SetPointData( count, displacement );</div>


<div>&nbsp; &nbsp; &nbsp; count++;</div><div>&nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; } &nbsp;&nbsp;</div><div><br></div><div><div>&nbsp; TimeVaryingDeformationFieldType::PointType origin;</div></div><div><div>&nbsp; TimeVaryingDeformationFieldType::SpacingType spacing;</div>


</div><div><div>&nbsp; TimeVaryingDeformationFieldType::SizeType size;</div></div><div><br></div><div>&nbsp; &nbsp;for( unsigned int d = 0; d &lt; ImageDimension; d++ )</div><div>&nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; origin[d] = reader-&gt;GetOutput()-&gt;GetOrigin()[d];</div>


<div>&nbsp; &nbsp; &nbsp; size[d] = reader-&gt;GetOutput()-&gt;GetLargestPossibleRegion().GetSize()[d];</div><div>&nbsp; &nbsp; &nbsp; spacing[d] = reader-&gt;GetOutput()-&gt;GetSpacing()[d];</div><div>&nbsp; &nbsp; &nbsp; }</div><div>&nbsp; // Now include the temporal information. &nbsp;You can change this to whatever</div>


<div>&nbsp; // resolution you like. &nbsp;You just need to make sure that&nbsp;</div><div>&nbsp; // &nbsp;( size[ImageDimension] - 1 ) * spacing[ImageDimension] = ( numberOfTimePoints - 1)</div><div>&nbsp; //&nbsp;</div><div>&nbsp; origin[ImageDimension] = 0;</div>


<div>&nbsp; size[ImageDimension] &nbsp;=&nbsp;numberOfTimePoints&nbsp;- 1;</div><div>&nbsp; spacing[ImageDimension] = 1;</div><div><br></div><div><div>&nbsp; typedef itk::BSplineScatteredDataPointSetToImageFilter</div><div>&nbsp; &nbsp; &lt;TimeVaryingDeformationFieldPointSetType, TimeVaryingDeformationFieldType&gt; BSplineFilterType;</div>


<div>&nbsp; typename BSplineFilterType::Pointer bspliner = BSplineFilterType::New();</div></div><div><div>&nbsp; bspliner-&gt;SetOrigin( origin );</div><div>&nbsp; bspliner-&gt;SetSpacing( spacing );</div><div>&nbsp; bspliner-&gt;SetSize( size );</div>


<div>&nbsp; bspliner-&gt;SetGenerateOutputImage( XXXX );</div><div>&nbsp; bspliner-&gt;SetNumberOfLevels( XXXX );</div><div>&nbsp; bspliner-&gt;SetSplineOrder( XXXX );</div><div>&nbsp; bspliner-&gt;SetNumberOfControlPoints( XXXX );</div><div>


&nbsp; bspliner-&gt;SetInput( fieldPoints );</div></div><div>&nbsp; bspliner-&gt;Update();</div><div><div><div><br></div><div><br></div><div><br></div><br><div><div>On Jan 4, 2012, at 2:52 AM, Kerstin Müller wrote:</div>
<br><blockquote type="cite">Hi,<br><br>yes correctly.<br><br><div class="gmail_quote">2012/1/3 Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com" target="_blank">ntustison@gmail.com</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>Okay, I'm assuming that these points correspond in&nbsp;</div><div>time, correct? &nbsp;For example, point 937 in time point 0</div><div>corresponds to point 937 in time point 1, 2, 3, ...133,</div>



<div>right? &nbsp;</div><div><div><div><br></div><div><br></div><br><div><div>On Jan 3, 2012, at 11:55 AM, Kerstin Müller wrote:</div><br><blockquote type="cite">Hi,<br><br>the basic problem I wanna solve:<br><br>I'll have scattered points in 3D which vary over time, they describe a motion of a surface over time. They are not ordered in x-y-and z-dimension.<br>



Now I want to represent that motion by BSplines in order to generate a dense motion vector field defined on specific 3D voxel positions.<br>
I'll have 133 timesteps and ~960 sample points in each time step. Now I want to fit the BSpline to it and resample it.<br><br>All the best,<br><br>Kerstin<br><br><div class="gmail_quote">2012/1/3 Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com" target="_blank">ntustison@gmail.com</a>&gt;</span><br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">In that case, let's start with the basic problem set-up.<div>Before, you described your problem as follows:<div>




<br><div><div><br><blockquote type="cite"><span style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><blockquote type="cite">




<div><div>I'm using the<span>&nbsp;</span><b>BSplineScatteredDataPointSetToImageFilter<span>&nbsp;</span></b>from the Insight Journal. However,<br>I cannot find the correct parameter in order to make the filter work and does not crash during the evaluation.<br>




I'll have scattered 3-D points over time and I want to fit a 4-D Bspline field to that points. Afterwards I want to evaluate the Bspline on a dense volume grid to one time step.</div></div></blockquote></span></blockquote>




</div></div></div></div><div><br></div><div>What do these scattered 3D+t points represent? &nbsp;</div><div>Is it a curve, a time-varying scalar field, or something</div><div>else?</div><div><br></div></div></blockquote></div>




<br>
</blockquote></div><br></div></div></div></blockquote></div><br>
</blockquote></div><br></div></div></div></blockquote></div><br>
</blockquote></div><br></div></div></div></div></blockquote></div><br>
</blockquote></div><br></div></div></div></body></html>