[Insight-users] itk mesh to vtk poly data
Robert Tamburo
robert.tamburo at gmail.com
Wed Jan 31 10:21:49 EST 2007
Hi Tony,
I suspect that you've already found the vtk2itk.cxx example in
InsightApplications. Take a look at line 220. That is where
TriangleVisitor and Quadrilateral visitor are defined.
-Rob
On Jan 31, 2007, at 8:52 AM, tony hakki wrote:
> Hello all;
> I want to convert itk mesh to vtk poly data,does anyone any
> suggestion how to accomplish that?
>
>
> // Get the number of points in the mesh
> int numPoints = mesh->GetNumberOfPoints();
> if(numPoints == 0)
> {
> mesh->Print(std::cerr);
> }
>
> // Create the vtkPoints object and set the number of points
> vtkPoints* vpoints = vtkPoints::New();
> vpoints->SetNumberOfPoints(numPoints);
>
> // iterate over all the points in the itk mesh filling in
> // the vtkPoints object as we go
> MeshType::PointsContainer::Pointer points = mesh->GetPoints();
> for(MeshType::PointsContainer::Iterator i = points->Begin(); i !=
> points->End(); ++i)
> {
> // Get the point index from the point container iterator
> int idx = i->Index();
> // Set the vtk point at the index with the the coord array from
> itk
> // itk returns a const pointer, but vtk is not const correct, so
> // we have to use a const cast to get rid of the const
> vpoints->SetPoint(idx, const_cast<FLOAT*>(i->Value
> ().GetDataPointer()));
> }
> // Set the points on the vtk grid
> polydata->SetPoints(vpoints);
>
> // Now create the cells using the MulitVisitor
> // 1. Create a MultiVisitor
> MeshType::CellType::MultiVisitor::Pointer mv =
> MeshType::CellType::MultiVisitor::New();
>
> // 2. Create a triangle and quadrilateral visitor
> TriangleVisitor::Pointer tv = TriangleVisitor::New(); Here
> It gives error;how can I Define TriangleVisitor and
> Quadriteralvisitor?
> QuadrilateralVisitor::Pointer qv = QuadrilateralVisitor::New();
>
> // 3. Set up the visitors
> int vtkCellCount = 0; // running counter for current cell
> being
> inserted into vtk
> int numCells = mesh->GetNumberOfCells();
> int *types = new int[numCells]; // type array for vtk
> // create vtk cells and estimate the size
> vtkCellArray* cells = vtkCellArray::New();
> cells->EstimateSize(numCells, 4);
>
> // Set the TypeArray CellCount and CellArray for both visitors
> tv->SetTypeArray(types);
> tv->SetCellCounter(&vtkCellCount);
> tv->SetCellArray(cells);
>
> qv->SetTypeArray(types);
> qv->SetCellCounter(&vtkCellCount);
> qv->SetCellArray(cells);
>
> // add the visitors to the multivisitor
> mv->AddVisitor(tv);
> mv->AddVisitor(qv);
> // Now ask the mesh to accept the multivisitor which
> // will Call Visit for each cell in the mesh that matches the
> // cell types of the visitors added to the MultiVisitor
> mesh->Accept(mv);
>
> // Now set the cells on the vtk polydata
> polydata->SetPolys(cells);
>
> // Clean up vtk objects (no vtkSmartPointer ... )
> cells->Delete();
> vpoints->Delete();
> }
>
>
> Expecting? Get great news right away with email Auto-Check.
> Try the Yahoo! Mail Beta.
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070131/97a048d9/attachment.htm
More information about the Insight-users
mailing list