<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Does anybody try the following code,does it work correctly?</DIV>
<DIV> </DIV>
<DIV>* Convert itk mesh to <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">PolyData</B> */<BR>/************************************************************************/<BR>void MeshToPolyData(MeshType* mesh, vtkPolyData* <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">polydata</B>)<BR>{<BR> // Get the number of points in the mesh<BR> int numPoints = mesh->GetNumberOfPoints();<BR> if(numPoints == 0)<BR> {<BR> mesh->Print(std::cerr);<BR> }<BR><BR> // Create the vtkPoints object and set the number of points<BR> vtkPoints* vpoints = vtkPoints::New();<BR> vpoints->SetNumberOfPoints(numPoints);<BR><BR> // iterate over all the points in the itk mesh
filling in<BR> // the vtkPoints object as we go<BR> MeshType::PointsContainer::Pointer points = mesh->GetPoints();<BR> for(MeshType::PointsContainer::Iterator i = points->Begin(); i != <BR>points->End(); ++i)<BR> {<BR> // Get the point index from the point container iterator<BR> int idx = i->Index();<BR> // Set the <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> point at the index with the the coord array from itk<BR> // itk returns a const pointer, but <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> is not const correct, so<BR> // we have to use a const cast to get rid of the const<BR> vpoints->SetPoint(idx, const_cast<FLOAT*>(i->Value().GetDataPointer()));<BR> }<BR> // Set the points on the <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> grid<BR> <B style="COLOR:
black; BACKGROUND-COLOR: #99ff99">polydata</B>->SetPoints(vpoints);<BR><BR> // Now create the cells using the MulitVisitor<BR> // 1. Create a MultiVisitor<BR> MeshType::CellType::MultiVisitor::Pointer mv = <BR>MeshType::CellType::MultiVisitor::New();<BR><BR> // 2. Create a triangle and quadrilateral visitor<BR> TriangleVisitor::Pointer tv = TriangleVisitor::New();<BR> QuadrilateralVisitor::Pointer qv = QuadrilateralVisitor::New();<BR><BR> // 3. Set up the visitors<BR> int vtkCellCount = 0; // running counter for current cell being <BR>inserted into <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B><BR> int numCells = mesh->GetNumberOfCells();<BR> int *types = new int[numCells]; // type array for <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B><BR> // create <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> cells and estimate the
size<BR> vtkCellArray* cells = vtkCellArray::New();<BR> cells->EstimateSize(numCells, 4);<BR><BR> // Set the TypeArray CellCount and CellArray for both visitors<BR> tv->SetTypeArray(types);<BR> tv->SetCellCounter(&vtkCellCount);<BR> tv->SetCellArray(cells);<BR><BR> qv->SetTypeArray(types);<BR> qv->SetCellCounter(&vtkCellCount);<BR> qv->SetCellArray(cells);<BR><BR> // add the visitors to the multivisitor<BR> mv->AddVisitor(tv);<BR> mv->AddVisitor(qv);<BR> // Now ask the mesh to accept the multivisitor which<BR> // will Call Visit for each cell in the mesh that matches the<BR> // cell types of the visitors added to the MultiVisitor<BR> mesh->Accept(mv);<BR><BR> // Now set the cells on the <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> <B style="COLOR: black; BACKGROUND-COLOR: #99ff99">polydata</B><BR> <B style="COLOR:
black; BACKGROUND-COLOR: #99ff99">polydata</B>->SetPolys(cells);<BR><BR> // Clean up <B style="COLOR: black; BACKGROUND-COLOR: #a0ffff">vtk</B> objects (no vtkSmartPointer ... )<BR> cells->Delete();<BR> vpoints->Delete();<BR>}<BR></DIV></div><br>
<hr size=1>It's here! Your new message!<br>Get
<a href="http://us.rd.yahoo.com/evt=49938/*http://tools.search.yahoo.com/toolbar/features/mail/"> new email alerts</a> with the free <a href="
http://us.rd.yahoo.com/evt=49938/*http://tools.search.yahoo.com/toolbar/features/mail/">Yahoo! Toolbar.</a></body></html>