[Insight-users] Gradient Vecotr Flow Snake in itk
Pingkun Yan
pingkun at ieee.org
Fri Oct 15 00:27:54 EDT 2004
Hi, Xujf,
Hope the following code can help you. Rgds,
/************************************************************************/
/* Convert itk mesh to vtk PolyData */
/************************************************************************/
void MeshToPolyData(MeshType* mesh, vtkPolyData* polydata)
{
// 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();
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();
}
----- Original Message -----
From: "xujf" <xujf at sjtu.edu.cn>
To: <insight-users at itk.org>
Sent: Thursday, October 14, 2004 8:34 PM
Subject: Re: Re: [Insight-users] Gradient Vecotr Flow Snake in itk
> hello, Luis:
>
> In the examples you descriped, I only find the tranformation from
> itkSimplexMesh to vtkPolyData
> and the transformation from itkMesh to vtkUnstructedGrid. the method that
> transforms itkMesh to vtkPolyData is not found. Is there any method that
> transforms itkMesh to vtkPolyData?
>
> I just tried to translate my semgmentation result which is itkMesh to
> vtkUnStructedGrid (according the example
> InsightApplications/Auxiliary/vtk/vtk2itk.cxx),then I visulize the
> result. however the result is very bad, and the surface of the result is
> not smooth.
>
> my ultimate aim is to realize tranditional snake or GVF snake. I wonder
> whether ITK provider such
> classes to realize it?
>
> Best Regards!
> xujf
>
> ----- Original Message -----
> From: Luis Ibanez <luis.ibanez at kitware.com>
> To: xujf at sjtu.edu.cn
> Cc: Insight-users at itk.org
> Subject: Re: [Insight-users] Gradient Vecotr Flow Snake in itk
>
>
> Hi Xujf
>
> You will find multiple examples on how to convert an ITK
> itk::Mesh in to a VTK vtkPolyData in the directory
>
> InsightApplications/Auxiliary/vtk
>
>
> you will also find an example on this in the demo application
>
>
> InsightApplications/DeformableModelSimplexMesh
>
>
>
> Regards,
>
>
> Luis
>
>
> -------------------
> xujf wrote:
>
>> Hello,Luis:
>> According the
>> example:Insight/Examples/Segmentation/DeformableModel1.cxx,I wrote my
>> code in vc++.
>> In order to visilize the segmenatation result, I have to transform
>> itkMesh (itk::DeformableMesh3DFilter->GetOutput()) to vtkPolyData. I
>> wonder how to realize the transformation.
>>
>> Best Regards!
>> xujf
>> ----- Original Message -----
>> From: Luis Ibanez <luis.ibanez at kitware.com>
>> To: xujf at sjtu.edu.cn
>> Cc: insight-users at itk.org
>> Subject: Re: [Insight-users] Gradient Vecotr Flow Snake in itk
>>
>>
>> Hi Xujf,
>>
>> Please look at the examples:
>>
>>
>> Insight/Examples/Segmentation/
>> DeformableModel1.cxx
>> DeformableModel2.cxx
>>
>>
>> The classes in ITK that implement deformable models
>> on the "Snake" family are:
>>
>> A)
>> http://www.itk.org/Insight/Doxygen/html/classitk_1_1DeformableMesh3DFilter.html
>>
>> B)
>> http://www.itk.org/Insight/Doxygen/html/classitk_1_1DeformableSimplexMesh3DBalloonForceFilter.html
>>
>>
>>
>> (A) uses a classical triangulation mesh
>>
>> (B) uses a Simplex mesh, contributed by Thomas Bottger of
>> the MBI group at the German Cancer Research Center (DKZF).
>>
>>
>>
>> You will find a demo application using (B) (the simplex mesh) under
>>
>> InsightApplications/
>> DeformableModelSimplexMesh
>>
>>
>> This application was contributed by Leila Baghdadi from the Mouse
>> Imaging Center (MICE) at the Hospital for Sick Kids in Toronto.
>> This application will require you to intall VTK and FLTK.
>>
>> Note that deformable models are quite sensitive to the parameter
>> settings, so be prepared to be patient when fine tunning those
>> parameters.
>>
>>
>>
>> Regards,
>>
>>
>> Luis
>>
>>
>>
>> -------------------
>> xujf wrote:
>>
>>
>>>hello,everyone:
>>> how to realize GVFS(Gradient Vecotr Flow Snake) segmentation. which
>>> itk classes I should use ?
>>>
>>>Thanks in advance!
>>>xujf
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
>
>
More information about the Insight-users
mailing list