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<MeshType,VisualizingImageType> 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->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->SetInput(mesh);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>meshFilter->Update();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>typedef itk::ImageFileWriter<VisualizingImageType> 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->SetInput(meshFilter->GetOutput());</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>writer->SetFileName(maskSaveFile);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>writer->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->pos[0];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>p[1]=vertex->pos[1];</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>p[2]=vertex->pos[2];</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>mesh->SetPoint( id, p );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>vertex->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->SetPointId(pid++, edge->Org()->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->SetCell(id, tr);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>mesh->SetCellData(id, 0.0);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>face->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"><<a href="mailto:l.paul@uclouvain.be">l.paul@uclouvain.be</a>></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'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 : "no image indices found" (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 "InfoImage" thus info passed to this filter are correct (I have checked, both images share the same coordinates)...<br>
<br>
typedef itk::TriangleMeshToBinaryImageFilter < MeshType, InputImageType > MeshToImageType;<br>
MeshToImageType::Pointer MeshToImage = MeshToImageType::New();<br>
MeshToImage->SetInfoImage(ImageReader->GetOutput()); //Image that was used for segmentation<br>
MeshToImage->SetOutsideValue(1000);<br>
MeshToImage->SetInsideValue(2000);<br>
MeshToImage->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>