<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div><br></div><div>Dear all,</div><div><br></div><div>I&#39;m using itk::TriangleMeshToBinaryImageFilter (ITK v4.3.1) to rasterize a triangular mesh as a binary image.</div>
<div><br></div><div>The rasterization seems to produce many mis-labelled voxels inside the mesh. I tried to attach two CSV files with the mesh vertices and triangles to help reproduce the result, but it seems that it&#39;s too big for the insight-users mailing list. I can provide them via email, though.</div>

<div><br></div><div>I attach a picture of the mesh as well as resulting slices 231 and 300, to illustrate the problem.</div><div><br></div><div>The output image parameters I&#39;m using are:</div><div><br></div><div><div>

Resolution (spacing) = [2.539e-05, 2.539e-05, 2.441e-05]</div><div>Size = [415, 460, 900]</div><div>Origin = [0.006221, 0.008633, 0.000976]</div></div><div><br></div><div>Some things I have tried:</div><div><br></div><div>

 * Play with the Tolerance value. In this example the program sets it to 2.4410e-06. I have tried reducing it to 1e-12, but the solution doesn&#39;t improve.</div><div><br></div><div> * Scale the mesh vertex coordinates, and correspondingly the output image voxel size and origin coordinates. The solution is the same.</div>

<div><br></div><div>I have programmed another function that doesn&#39;t suffer from these artifacts (using the library CGAL, without ITK), but it&#39;s a lot slower than the ITK solution, so it&#39;d be great to make the ITK approach work</div>

<div><br></div><div><a href="https://code.google.com/p/gerardus/source/browse/trunk/matlab/CgalToolbox/CgalInSurfaceTriangulation.cpp?r=1347" target="_blank">https://code.google.com/p/gerardus/source/browse/trunk/matlab/CgalToolbox/CgalInSurfaceTriangulation.cpp?r=1347</a><br>

</div><div><br></div><div><br></div><div><br></div><div>I&#39;m running the ITK-based solution as a MEX function from Matlab. The full code is here<br></div><div><br></div><div><a href="https://code.google.com/p/gerardus/source/browse/trunk/matlab/ItkToolbox/ItkTriRasterization.cpp?r=1347" target="_blank">https://code.google.com/p/gerardus/source/browse/trunk/matlab/ItkToolbox/ItkTriRasterization.cpp?r=1347</a><br>

</div><div><br></div><div>but the relevants part of the code to ITK are</div><div><br></div><div><table style="border-collapse:collapse;font-size:12px;white-space:pre-wrap;font-family:Monaco,&#39;DejaVu Sans Mono&#39;,&#39;Bitstream Vera Sans Mono&#39;,&#39;Lucida Console&#39;,monospace;margin:0px;padding:0px">

<tbody style="padding:0px;margin:0px"><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">/* ITK headers */</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">#include</span><span> </span><span style="color:rgb(0,136,0)">&lt;itkImage.h&gt;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">#include</span><span> </span><span style="color:rgb(0,136,0)">&lt;itkMesh.h&gt;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">#include</span><span> </span><span style="color:rgb(0,136,0)">&lt;itkTriangleMeshToBinaryImageFilter.h&gt;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">#include</span><span> </span><span style="color:rgb(0,136,0)">&lt;itkTriangleCell.h&gt;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">// type definitions</span><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">static</span><span> </span><span style="color:rgb(0,0,136)">const</span><span> </span><span style="color:rgb(0,0,136)">unsigned</span><span> </span><span style="color:rgb(0,0,136)">int</span><span>                       </span><span style="color:rgb(102,0,102)">Dimension</span><span> </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(0,102,102)">3</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> uint8_T                                 </span><span style="color:rgb(102,0,102)">PixelType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> </span><span style="color:rgb(0,0,136)">float</span><span>                                   </span><span style="color:rgb(102,0,102)">MeshDataType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> itk</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">PointSet</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">MeshDataType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">&gt;</span><span>  </span><span style="color:rgb(102,0,102)">PointSetType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> </span><span style="color:rgb(102,0,102)">PointSetType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">CoordRepType</span><span>              </span><span style="color:rgb(102,0,102)">CoordType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> itk</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">Mesh</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">MeshDataType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">&gt;</span><span>      </span><span style="color:rgb(102,0,102)">MeshType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> itk</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">Image</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">PixelType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">&gt;</span><span>        </span><span style="color:rgb(102,0,102)">ImageType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> </span><span style="color:rgb(102,0,102)">PointSetType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">PointType</span><span>                 </span><span style="color:rgb(102,0,102)">PointType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> </span><span style="color:rgb(102,0,102)">MeshType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">CellType</span><span>                      </span><span style="color:rgb(102,0,102)">CellType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> itk</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">TriangleCell</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">CellType</span><span style="color:rgb(102,102,0)">&gt;</span><span>             </span><span style="color:rgb(102,0,102)">TriangleType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> </span><span style="color:rgb(102,0,102)">CellType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">CellAutoPointer</span><span>               </span><span style="color:rgb(102,0,102)">CellAutoPointer</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(0,0,136)">typedef</span><span> itk</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">TriangleMeshToBinaryImageFilter</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">MeshType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">ImageType</span><span style="color:rgb(102,102,0)">&gt;</span><span> </span><span style="color:rgb(102,0,102)">MeshFilterType</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span style="color:rgb(136,0,0)">/*<br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">

<span style="color:rgb(136,0,0)"> * mexFunction(): entry point for the mex function<br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span style="color:rgb(136,0,0)"> */</span><span><br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span style="color:rgb(0,0,136)">void</span><span> mexFunction</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,0,136)">int</span><span> nlhs</span><span style="color:rgb(102,102,0)">,</span><span> mxArray </span><span style="color:rgb(102,102,0)">*</span><span>plhs</span><span style="color:rgb(102,102,0)">[],</span><span> </span><span style="color:rgb(0,0,136)">int</span><span> nrhs</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(0,0,136)">const</span><span> mxArray </span><span style="color:rgb(102,102,0)">*</span><span>prhs</span><span style="color:rgb(102,102,0)">[])</span><span> </span><span style="color:rgb(102,102,0)">{</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span>...

  </span><span style="color:rgb(136,0,0)">// instantiate mesh</span><span><br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span>  </span><span style="color:rgb(102,0,102)">MeshType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">Pointer</span><span> mesh </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(102,0,102)">MeshType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">New</span><span style="color:rgb(102,102,0)">();</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// read vertices</span><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span>...
  </span><span style="color:rgb(102,0,102)">PointSetType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">Pointer</span><span> x </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(102,0,102)">PointSetType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">New</span><span style="color:rgb(102,102,0)">();
</span><span>
...</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// populate mesh with vertices</span><span><br></span></td></tr>
<tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  mesh</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetPoints</span><span style="color:rgb(102,102,0)">(</span><span>x</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">GetPoints</span><span style="color:rgb(102,102,0)">());</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// read triangles</span><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(102,0,102)">PointType</span><span> triDef</span><span style="color:rgb(102,102,0)">;</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  triDef</span><span style="color:rgb(102,102,0)">.</span><span style="color:rgb(102,0,102)">Fill</span><span style="color:rgb(102,102,0)">(</span><span>mxGetNaN</span><span style="color:rgb(102,102,0)">());</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(0,0,136)">for</span><span> </span><span style="color:rgb(102,102,0)">(</span><span>mwIndex i </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">;</span><span> i </span><span style="color:rgb(102,102,0)">&lt;</span><span> nrowsTRI</span><span style="color:rgb(102,102,0)">;</span><span> </span><span style="color:rgb(102,102,0)">++</span><span>i</span><span style="color:rgb(102,102,0)">)</span><span> </span><span style="color:rgb(102,102,0)">{</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(102,0,102)">PointType</span><span> triangle </span><span style="color:rgb(102,102,0)">=</span><span> matlabImport</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">ReadRowVectorFromMatlab</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">CoordType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">PointType</span><span style="color:rgb(102,102,0)">&gt;(</span><span>inTRI</span><span style="color:rgb(102,102,0)">,</span><span> i</span><span style="color:rgb(102,102,0)">,</span><span> triDef</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// create a triangle cell to read the vertex indices of the current input triangle</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(102,0,102)">CellAutoPointer</span><span> cell</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    cell</span><span style="color:rgb(102,102,0)">.</span><span style="color:rgb(102,0,102)">TakeOwnership</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,0,136)">new</span><span> </span><span style="color:rgb(102,0,102)">TriangleType</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// assign to the 0, 1, 2 elements in the triangle cell the vertex</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// indices that we have just read. Note that we have to substract</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// 1 to convert Matlab&#39;s index convention 1, 2, 3, ... to C++</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// convention 0, 1, 2, ...</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    cell</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetPointId</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">,</span><span> triangle</span><span style="color:rgb(102,102,0)">[</span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">]</span><span> </span><span style="color:rgb(102,102,0)">-</span><span> </span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    cell</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetPointId</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">,</span><span> triangle</span><span style="color:rgb(102,102,0)">[</span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">]</span><span> </span><span style="color:rgb(102,102,0)">-</span><span> </span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    cell</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetPointId</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">2</span><span style="color:rgb(102,102,0)">,</span><span> triangle</span><span style="color:rgb(102,102,0)">[</span><span style="color:rgb(0,102,102)">2</span><span style="color:rgb(102,102,0)">]</span><span> </span><span style="color:rgb(102,102,0)">-</span><span> </span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(136,0,0)">// insert cell into the mesh</span><span><br></span></td></tr>
<tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    mesh</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetCell</span><span style="color:rgb(102,102,0)">(</span><span>i</span><span style="color:rgb(102,102,0)">,</span><span> cell</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(102,102,0)">}</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
</td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>...

  </span><span style="color:rgb(136,0,0)">// get user input parameters for the output rasterization</span><span><br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">

</td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>...
  </span><span style="color:rgb(102,0,102)">ImageType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">SpacingType</span><span> spacing </span><span style="color:rgb(102,102,0)">=</span><span> ...</span></td>

</tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span>...
<font color="#660066">  ImageType</font></span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">SizeType</span><span> size </span><span style="color:rgb(102,102,0)">=</span><span> ...</span></td>

</tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span>...
  </span><span style="color:rgb(102,0,102)">ImageType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">PointType</span><span> origin </span><span style="color:rgb(102,102,0)">=</span><span> ...</span></td>

</tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">

<span>
  </span><span style="color:rgb(136,0,0)">// instantiate rasterization filter</span><span><br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">

<span>  </span><span style="color:rgb(102,0,102)">MeshFilterType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">Pointer</span><span> meshFilter </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(102,0,102)">MeshFilterType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">New</span><span style="color:rgb(102,102,0)">();</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;vertical-align:top"><span><span style="white-space:pre-wrap">
  // smallest voxel side length
  ImageType::SpacingValueType minSpacing = spacing[0];
  for (mwIndex i = 1; i &lt; Dimension; ++i) {
    minSpacing = std::min(minSpacing, spacing[i]);
  }
<br></span></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// pass input parameters to the filter</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetInput</span><span style="color:rgb(102,102,0)">(</span><span>mesh</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetSpacing</span><span style="color:rgb(102,102,0)">(</span><span>spacing</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetSize</span><span style="color:rgb(102,102,0)">(</span><span>size</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetOrigin</span><span style="color:rgb(102,102,0)">(</span><span>origin</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetTolerance</span><span style="color:rgb(102,102,0)">(minSpacing / 10.0</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetInsideValue</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">1</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetOutsideValue</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(102,0,102)">ImageType</span><span style="color:rgb(102,102,0)">::</span><span style="color:rgb(102,0,102)">IndexType</span><span> start</span><span style="color:rgb(102,102,0)">;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  start</span><span style="color:rgb(102,102,0)">.</span><span style="color:rgb(102,0,102)">Fill</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">SetIndex</span><span style="color:rgb(102,102,0)">(</span><span>start</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// convert image size from itk::Size format to std::vector&lt;mwSize&gt;</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// so that we can use it in GraftItkImageOntoMatlab</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  std</span><span style="color:rgb(102,102,0)">::</span><span>vector</span><span style="color:rgb(0,136,0)">&lt;mwSize&gt;</span><span> sizeStdVector</span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(0,0,136)">for</span><span> </span><span style="color:rgb(102,102,0)">(</span><span style="color:rgb(0,0,136)">unsigned</span><span> </span><span style="color:rgb(0,0,136)">int</span><span> i </span><span style="color:rgb(102,102,0)">=</span><span> </span><span style="color:rgb(0,102,102)">0</span><span style="color:rgb(102,102,0)">;</span><span> i </span><span style="color:rgb(102,102,0)">&lt;</span><span> </span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">;</span><span> </span><span style="color:rgb(102,102,0)">++</span><span>i</span><span style="color:rgb(102,102,0)">)</span><span> </span><span style="color:rgb(102,102,0)">{</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    sizeStdVector</span><span style="color:rgb(102,102,0)">[</span><span>i</span><span style="color:rgb(102,102,0)">]</span><span> </span><span style="color:rgb(102,102,0)">=</span><span> size</span><span style="color:rgb(102,102,0)">[</span><span>i</span><span style="color:rgb(102,102,0)">];</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(102,102,0)">}</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// graft ITK filter outputs onto Matlab outputs</span><span><br>
</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  matlabExport</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">GraftItkImageOntoMatlab</span><span style="color:rgb(102,102,0)">&lt;</span><span style="color:rgb(102,0,102)">PixelType</span><span style="color:rgb(102,102,0)">,</span><span> </span><span style="color:rgb(102,0,102)">Dimension</span><span style="color:rgb(102,102,0)">&gt;</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>    </span><span style="color:rgb(102,102,0)">(</span><span>outIM</span><span style="color:rgb(102,102,0)">,</span><span> meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">GetOutput</span><span style="color:rgb(102,102,0)">(),</span><span> sizeStdVector</span><span style="color:rgb(102,102,0)">);</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span><br></span></td></tr><tr style="padding:0px;margin:0px">
<td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top">
<span><font color="#880000">...</font>  <br></span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  </span><span style="color:rgb(136,0,0)">// run rasterization</span><span><br>

</span></td></tr><tr style="padding:0px;margin:0px"><td style="padding:0px 0px 0px 4px;white-space:pre-wrap;vertical-align:top"><span>  meshFilter</span><span style="color:rgb(102,102,0)">-&gt;</span><span style="color:rgb(102,0,102)">Update</span><span style="color:rgb(102,102,0)">();</span></td>

</tr></tbody></table><br></div><div>...</div>}<div><br></div><div><br></div><div>Any ideas are welcome, thanks!</div><div><br></div><div>Best regards,</div><div><br></div><div>Ramon.<span class="HOEnZb"><font color="#888888"><br clear="all">
<div><br></div>-- <br>Dr. Ramón Casero Cañas<br>
<br>Oxford e-Research Centre (OeRC)<br>University of Oxford<br>7 Keble Rd<br>Oxford OX1 3QG<br><br>tlf     <a href="tel:%2B44%20%280%29%201865%20610739" value="+441865610739" target="_blank">+44 (0) 1865 610739</a><br>web     <a href="http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas" target="_blank">http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas</a><br>

photos  <a href="http://www.flickr.com/photos/rcasero/" target="_blank">http://www.flickr.com/photos/rcasero/</a>
</font></span></div></div>
</div><br><br clear="all"><div><br></div>-- <br>Dr. Ramón Casero Cañas<br><br>Oxford e-Research Centre (OeRC)<br>University of Oxford<br>7 Keble Rd<br>Oxford OX1 3QG<br><br>tlf     +44 (0) 1865 610739<br>web     <a href="http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas" target="_blank">http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas</a><br>
photos  <a href="http://www.flickr.com/photos/rcasero/" target="_blank">http://www.flickr.com/photos/rcasero/</a>
</div>