[Insight-users] ITK Polygon representation

Luis Ibanez luis.ibanez@kitware.com
Mon, 18 Nov 2002 21:19:52 -0500


Hi Ofri,

You got it all right !,

---

You create a mesh of the same
dimensionality as your image.
(it seems to be 2D in your case)

You select any PixelType to be
associated with the mesh points.
(let's say for now 'char').

This will look like:

     typedef itk::Mesh< char, 2 > MeshType;

and the typical creation:

     MeshType::Pointer mesh = MeshType::New();

Then you can add lines to represent your
polyline. ITK has a set of cell types.
The linear cell is :

itk::LineCell
http://www.itk.org/Doxygen/html/classitk_1_1LineCell.html

All the cell types use traits from the Mesh.
Traits are a GenericProgramming mechanism for
passing types around making sure that things
are compatible. For example, among the Mesh traits
you will find the "PointType" of the Mesh.

In order to propagate all the types relevant to
the Cell, the Mesh provides a trait called "CellType".
All the Cells intented to be attached to the mesh
are templated over this trait.  This will look like:

typedef MeshType::CellType   CellType;

typedef itk::LineCell< CellType >  LineType;

If you are used to the VTK mesh structure, please
keep in mind that ITK has a quite different design.

The reason is that the ITK mesh is mainly intented
to support dynamic modifications of the mesh in order
to facilitate its use in segmentation algorithms
that use deformable geometries or growing organisms.
See for example:
http://www.itk.org/HTML/Morphogenesis.htm

and the animation:
http://www.itk.org/Art/MorphogenesisSegmentation.mpg

----

Now you can insert points into the Mesh by
calling the SetPoint methods. The identifier is just
an integer counter that you manage by yourself.
So you could do the following for adding three points:

  MeshType::PointType p0;
  MeshType::PointType p1;
  MeshType::PointType p2;

  p0[0] = -1.0;  // x of p0
  p0[1] =  0.0;  // y of p0
  p0[2] =  0.0;  // z of p0

  p1[0] =  1.0;  // x of p1
  p1[1] =  0.0;  // y of p1
  p1[2] =  0.0;  // z of p1

  p2[0] =  1.0;  // x of p2
  p2[1] =  1.0;  // y of p2
  p2[2] =  0.0;  // z of p2

   unsigned int id = 0
   mesh->SetPoint( id++, p0 );
   mesh->SetPoint( id++, p1 );
   mesh->SetPoint( id++, p2 );


-----

You may want to look at the examples in
the directory:

Insight/Examples/DataRepresentation/Mesh

in particular to

           Mesh1.cxx

and

           Mesh2.cxx

The examples in this directory are being restructured
at this point with the aim of making them parallel to
the ITK SoftwareGuide. That will ensure that the
code apprearing in the book is exactly the same that
is compiled every night.


Please let us know if you have further questions.

    Thanks


     Luis


============================================
Ofri Sadowsky wrote:

> OK. Let me see if I get this right.
> 
> 1. I should create a Mesh of dimension 2 and some arbitrary PixelType (for
> now I'm only interested in the coordinates of the vertices, and
> I don't want to store any additional information).
> 2. I have to create a PolygonalCell using the Mesh's CellType.
> 3. Somehow, I have to add points to the PolygonalCell. The class provides the
> methods SetPointIds with PointIdConstIterator parameters.
> But I am still puzzled about how to get point-id's and where to take the
> iterator from. This is as far as I could track the documentation.
> 
> Ofri.
> 
>