[Insight-users] Deformable Model Mesh to VTK
Luis Ibanez
luis . ibanez at kitware . com
Thu, 08 May 2003 13:08:26 -0400
Hi Marisa,
You can find an example of this conversion in one
of the VolView plugins in InsightApplications
http://www.itk.org/cgi-bin/cvsweb.cgi/InsightApplications/VolviewPlugIns/?cvsroot=Insight
Please look at the file
vvITKDeformableModelModule.txx
http://www.itk.org/cgi-bin/cvsweb.cgi/InsightApplications/VolviewPlugIns/vvITKDeformableModelModule.txx?cvsroot=Insight
In particular to the method: PostProcessData() (line 192).
This VolView Plugin is running a DeformableModel and passing
the resulting mesh for being visualized with VTK.
Regards,
Luis
---------------------------
marisa aurelio wrote:
> Hi,
>
> Im triying to send the output mesh of the Deformable model application
> into a vtk converter so i can show the mesh with VTK. I tried to use the
> VTK2ITKdouble example but the mesh in this example is diferent. Can
> anyone tell me how to convert the output mesh into an vtk readable??
>
> thanks in advance,
>
> Marisa Aurélio
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>
------------------------------------
Code Extract
typedef typename MeshType::Pointer MeshPointer;
MeshPointer mesh = m_DeformableModelFilter->GetOutput();
// now put the results into the data structure
const unsigned int numberOfPoints = mesh->GetNumberOfPoints();
opds->NumberOfMeshPoints = numberOfPoints;
float * points = new float[ numberOfPoints * 3 ];
opds->MeshPoints = points;
float * outputPointsItr = points;
typedef typename MeshType::PointsContainer::ConstIterator PointIterator;
PointIterator pointItr = mesh->GetPoints()->Begin();
PointIterator pointsEnd = mesh->GetPoints()->End();
while( pointItr != pointsEnd )
{
ofs << pointItr.Value() << std::endl;
*outputPointsItr++ = pointItr.Value()[0];
*outputPointsItr++ = pointItr.Value()[1];
*outputPointsItr++ = pointItr.Value()[2];
++pointItr;
}
opds->NumberOfMeshCells = mesh->GetNumberOfCells();
unsigned int numEntries = 0;
typedef typename MeshType::CellsContainer::ConstIterator CellIterator;
CellIterator cellItr = mesh->GetCells()->Begin();
CellIterator cellEnd = mesh->GetCells()->End();
// Cell connectivity entries follow the format of vtkCellArray:
// n1, id1, id2,... idn1, n2, id1, id2,.. idn2....
while( cellItr != cellEnd )
{
// one position for the number of points
numEntries += 1;
// plus one position per each point Id
numEntries += cellItr.Value()->GetNumberOfPoints();
++cellItr;
}
int * cellsTopology = new int [ numEntries ];
opds->MeshCells = cellsTopology;
typedef typename MeshType::CellType CellType;
typedef typename CellType::PointIdConstIterator PointIdIterator;
cellItr = mesh->GetCells()->Begin();
int * cellsTopItr = cellsTopology;
while( cellItr != cellEnd )
{
const CellType * cell = cellItr.Value();
const unsigned int np = cell->GetNumberOfPoints();
ofs << std::endl << np << " ";
*cellsTopItr = np;
++cellsTopItr;
PointIdIterator pointIdItr = cell->PointIdsBegin();
PointIdIterator pointIdEnd = cell->PointIdsEnd();
while( pointIdItr != pointIdEnd )
{
ofs << *pointIdItr << " ";
*cellsTopItr = *pointIdItr;
++cellsTopItr;
++pointIdItr;
}
++cellItr;
}