<div> Hi, All,<br><br>I try to use TriangleMeshToBinaryImageFilter to convert the mesh to an image, but I found there is one problem. My code is as followed:<br><br>-------------------------------------------------------<br>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 )<br>{<br> TriangleMeshType::Pointer meshSource = TriangleMeshType::New(); <br><br> TriangleMeshType::CellAutoPointer cellpointer;<br> <br> int i;<br> for(i = 0; i<TotalVertex; i++)<br> {<br> //meshSource->SetPoint(i, TriangleMeshType::PointType(MeshVertex[i]));<br> <br> TriangleMeshType::PointType p;<br> p[0] = MeshVertex[i][0];<br> p[1] = MeshVertex[i][1];<br> p[2] = MeshVertex[i][2];<br> meshSource->SetPoint(i,p);<br><br> }<br> <br> int vertex1, vertex2, vertex3;<br><br> /////////////////////////////////////////////////////////////<br> <br> for(i =0; i<TotalTriangle; i++)<br> {<br> vertex1 = MeshLine[MeshTriangle[i][0]][0];<br> vertex2 = MeshLine[MeshTriangle[i][0]][1];<br> vertex3 = MeshLine[MeshTriangle[i][1]][0] + MeshLine[MeshTriangle[i][1]][1] + MeshLine[MeshTriangle[i][2]][0] + MeshLine[MeshTriangle[i][2]][1] - vertex1 - vertex2;<br> vertex3 = vertex3/2;<br><br> cellpointer.TakeOwnership(new TriangleType);<br> cellpointer->SetPointId(0,vertex1);<br> cellpointer->SetPointId(1,vertex2);<br> cellpointer->SetPointId(2,vertex3);<br> meshSource->SetCell(i,cellpointer);<br> <br> }<br> <br><br> MeshToImage -> SetInput(meshSource);<br> MeshToImage -> SetSize(m_Size);<br> //MeshToImage -> SetOrigin(m_Start);<br> //MeshToImage -> SetSpacing(m_Spacing);<br> <br> MeshToImage -> Update();<br> <br> typedef itk::ImageFileWriter<UCharImageType> WriterType;<br> WriterType::Pointer writer = WriterType::New();<br><br> writer -> SetInput(MeshToImage -> GetOutput());<br> writer -> SetFileName("Mask1.hdr");<br> writer -> Update();<br><br> OutputImage = MeshToImage -> GetOutput();<br><br><br>}<br></div><div>----------------------------------------------------------------<br>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 <br>--------------------------------<br>for(int i =0 ; i<2; i++) MeshConstruct(MeshVertex, MeshLine, MeshTriangle,TotalTriangle,
TotalVertex, OutputImage,m_Size, m_Spacing, m_Start );<br>---------------------------------<br>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.<br><br><br>Could any one help me?<br><br><br>Thanks very much.<br><br><br>Kun<br>Jun. 18 2008<br></div><div> </div><div> </div><br><!-- footer --><br>
<hr>
<font style="font-size:12px;line-height:15px;"> </font><a style="font-size:12px;line-height:15px; color:blue; text-decoration:underline;" href="http://pro.163.com/event.ng/Type=click&FlightID=114731&AdID=116137&TargetID=635&Values=31,43,51,60,72,82,90,100,110,150,312,316,330,332,457,499,582,733,734,774,775,788,942,943,944,948,949,950,951,1008&Redirect=http://www.kfc.com.cn/w">两两来Win为中国</a>