[Insight-users] Problem with TriangleMeshToBinaryImage
Kun
kun_ch at 163.com
Wed Jun 18 11:54:41 EDT 2008
Hi, All,
I try to use TriangleMeshToBinaryImageFilter to convert the mesh to an image, but I found there is one problem. My code is as followed:
-------------------------------------------------------
void MeshStorage::MeshConstruct ( FloatMatrix & MeshVertex, IntMatrix & MeshLine, IntMatrix & MeshTriangle, int TotalTriangle, int TotalVertex, UCharImageType::Pointer & OutputImage,SizeType & m_Size, SpacingType & m_Spacing, IndexType & m_Start )
{
TriangleMeshType::Pointer meshSource = TriangleMeshType::New();
TriangleMeshType::CellAutoPointer cellpointer;
int i;
for(i = 0; i<TotalVertex; i++)
{
//meshSource->SetPoint(i, TriangleMeshType::PointType(MeshVertex[i]));
TriangleMeshType::PointType p;
p[0] = MeshVertex[i][0];
p[1] = MeshVertex[i][1];
p[2] = MeshVertex[i][2];
meshSource->SetPoint(i,p);
}
int vertex1, vertex2, vertex3;
/////////////////////////////////////////////////////////////
for(i =0; i<TotalTriangle; i++)
{
vertex1 = MeshLine[MeshTriangle[i][0]][0];
vertex2 = MeshLine[MeshTriangle[i][0]][1];
vertex3 = MeshLine[MeshTriangle[i][1]][0] + MeshLine[MeshTriangle[i][1]][1] + MeshLine[MeshTriangle[i][2]][0] + MeshLine[MeshTriangle[i][2]][1] - vertex1 - vertex2;
vertex3 = vertex3/2;
cellpointer.TakeOwnership(new TriangleType);
cellpointer->SetPointId(0,vertex1);
cellpointer->SetPointId(1,vertex2);
cellpointer->SetPointId(2,vertex3);
meshSource->SetCell(i,cellpointer);
}
MeshToImage -> SetInput(meshSource);
MeshToImage -> SetSize(m_Size);
//MeshToImage -> SetOrigin(m_Start);
//MeshToImage -> SetSpacing(m_Spacing);
MeshToImage -> Update();
typedef itk::ImageFileWriter<UCharImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer -> SetInput(MeshToImage -> GetOutput());
writer -> SetFileName("Mask1.hdr");
writer -> Update();
OutputImage = MeshToImage -> GetOutput();
}
----------------------------------------------------------------
Here, I use the MeshVertex to store the position of the vertex, MeshLine to store the the vertex sequence number of each line, and MeshTriangle to store the line sequence number. And I use "for" loop to do the conversion, like
--------------------------------
for(int i =0 ; i<2; i++) MeshConstruct(MeshVertex, MeshLine, MeshTriangle,TotalTriangle, TotalVertex, OutputImage,m_Size, m_Spacing, m_Start );
---------------------------------
The MeshVertex, MeshLine, MeshTriangle have changed for each iterate. When I use the code for the first time, it's OK. But the second time, it is generate the same image as the first time. I don't know why.
Could any one help me?
Thanks very much.
Kun
Jun. 18 2008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080618/a22dc7ee/attachment.htm>
More information about the Insight-users
mailing list