I hope this code will help you. If you have some questions, ask.<div><br></div><div>Regards,</div><div>Dženan<br><div><br></div><div>void voxelize(Cell *qe, std::string maskSaveFile, VisualizingImageType::Pointer visualizing)</div>

<div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>MeshType::Pointer mesh;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::TriangleMeshToBinaryImageFilter&lt;MeshType,VisualizingImageType&gt; MeshFilterType;</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>MeshFilterType::Pointer meshFilter = MeshFilterType::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meshFilter-&gt;SetInfoImage(visualizing);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>mesh=qe2itkMesh(qe);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meshFilter-&gt;SetInput(mesh);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meshFilter-&gt;Update();</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::ImageFileWriter&lt;VisualizingImageType&gt; WriterType;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>WriterType::Pointer writer = WriterType::New();</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;SetInput(meshFilter-&gt;GetOutput());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;SetFileName(maskSaveFile);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer-&gt;Update();</div><div>}</div><div><br></div><div><div>MeshType::Pointer qe2itkMesh(Cell *cell)</div><div>//copied from objWriteCell</div><div>{</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>MeshType::Pointer mesh=MeshType::New();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>MeshType::PointType p;</div><div><br></div>
<div>
<span class="Apple-tab-span" style="white-space:pre">        </span>// renumber vertices in current order</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>CellVertexIterator vertices(cell);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Vertex *vertex;</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned int id = 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>while ((vertex = vertices.next())!=0)</div><div>

<span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>p[0]=vertex-&gt;pos[0];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>p[1]=vertex-&gt;pos[1];</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>p[2]=vertex-&gt;pos[2];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>mesh-&gt;SetPoint( id, p );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vertex-&gt;setID(++id);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>    CellFaceIterator faces(cell);</div><div>    Face *face;</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>id=0;</div>
<div><br></div><div>    while ((face = faces.next())!=0)</div><div>    {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>CellAutoPointer tr;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>tr.TakeOwnership(new TriangleType);</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>FaceEdgeIterator edges(face);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>Edge *edge;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>unsigned int pid=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>while ((edge = edges.next())!=0)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div>

<div><span class="Apple-tab-span" style="white-space:pre">                        </span>tr-&gt;SetPointId(pid++, edge-&gt;Org()-&gt;getID()-1);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>mesh-&gt;SetCell(id, tr);</div>

<div><span class="Apple-tab-span" style="white-space:pre">                </span>mesh-&gt;SetCellData(id, 0.0);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>face-&gt;setID(++id);</div><div>    }</div><div><br>

</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return mesh;</div><div>}</div></div><br><div class="gmail_quote">On Mon, Dec 13, 2010 at 17:24, Paul Laurent <span dir="ltr">&lt;<a href="mailto:l.paul@uclouvain.be">l.paul@uclouvain.be</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Dear users,<br>
<br>
I have a strange error using TriangleMeshToBinaryImageFilter, and it seems that I&#39;m not the only one to get it.<br>
I have created a stlreader and convert it into a ITK::Mesh.<br>
It seems ok since I get 39844 points and 79684 cells.<br>
When I pass it to TriangleMeshToBinaryImageFilter, I get an error with indices : &quot;no image indices found&quot; (m_StencilIndex.size() = 0)<br>
Does it mean that the mesh lies outside the created image (If I change the exception to a Warning macro, I get a black Image) ?<br>
The mesh comes from a segmentation from the &quot;InfoImage&quot; thus info passed to this filter are correct (I have checked, both images share the same coordinates)...<br>
<br>
    typedef itk::TriangleMeshToBinaryImageFilter &lt; MeshType, InputImageType &gt; MeshToImageType;<br>
    MeshToImageType::Pointer MeshToImage = MeshToImageType::New();<br>
    MeshToImage-&gt;SetInfoImage(ImageReader-&gt;GetOutput()); //Image that was used for segmentation<br>
    MeshToImage-&gt;SetOutsideValue(1000);<br>
    MeshToImage-&gt;SetInsideValue(2000);<br>
    MeshToImage-&gt;SetInput(mesh);<br>
<br>
Thanks for your help.<br>
Cheers,<br>
Laurent.<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div></div>