[Insight-users] How to use TriangleMeshToBinaryImageFilter?
Dženan Zukić
dzenanz at gmail.com
Fri Dec 17 05:54:04 EST 2010
I hope this code will help you. If you have some questions, ask.
Regards,
Dženan
void voxelize(Cell *qe, std::string maskSaveFile,
VisualizingImageType::Pointer visualizing)
{
MeshType::Pointer mesh;
typedef itk::TriangleMeshToBinaryImageFilter<MeshType,VisualizingImageType>
MeshFilterType;
MeshFilterType::Pointer meshFilter = MeshFilterType::New();
meshFilter->SetInfoImage(visualizing);
mesh=qe2itkMesh(qe);
meshFilter->SetInput(mesh);
meshFilter->Update();
typedef itk::ImageFileWriter<VisualizingImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(meshFilter->GetOutput());
writer->SetFileName(maskSaveFile);
writer->Update();
}
MeshType::Pointer qe2itkMesh(Cell *cell)
//copied from objWriteCell
{
MeshType::Pointer mesh=MeshType::New();
MeshType::PointType p;
// renumber vertices in current order
CellVertexIterator vertices(cell);
Vertex *vertex;
unsigned int id = 0;
while ((vertex = vertices.next())!=0)
{
p[0]=vertex->pos[0];
p[1]=vertex->pos[1];
p[2]=vertex->pos[2];
mesh->SetPoint( id, p );
vertex->setID(++id);
}
CellFaceIterator faces(cell);
Face *face;
id=0;
while ((face = faces.next())!=0)
{
CellAutoPointer tr;
tr.TakeOwnership(new TriangleType);
FaceEdgeIterator edges(face);
Edge *edge;
unsigned int pid=0;
while ((edge = edges.next())!=0)
{
tr->SetPointId(pid++, edge->Org()->getID()-1);
}
mesh->SetCell(id, tr);
mesh->SetCellData(id, 0.0);
face->setID(++id);
}
return mesh;
}
On Mon, Dec 13, 2010 at 17:24, Paul Laurent <l.paul at uclouvain.be> wrote:
> Dear users,
>
> I have a strange error using TriangleMeshToBinaryImageFilter, and it seems
> that I'm not the only one to get it.
> I have created a stlreader and convert it into a ITK::Mesh.
> It seems ok since I get 39844 points and 79684 cells.
> When I pass it to TriangleMeshToBinaryImageFilter, I get an error with
> indices : "no image indices found" (m_StencilIndex.size() = 0)
> 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) ?
> 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)...
>
> typedef itk::TriangleMeshToBinaryImageFilter < MeshType, InputImageType
> > MeshToImageType;
> MeshToImageType::Pointer MeshToImage = MeshToImageType::New();
> MeshToImage->SetInfoImage(ImageReader->GetOutput()); //Image that was
> used for segmentation
> MeshToImage->SetOutsideValue(1000);
> MeshToImage->SetInsideValue(2000);
> MeshToImage->SetInput(mesh);
>
> Thanks for your help.
> Cheers,
> Laurent.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101217/e21ebd4e/attachment.htm>
More information about the Insight-users
mailing list