[Insight-developers] Cell Interface Test

Alexandre GOUAILLARD hanfei at caltech.edu
Fri Aug 3 19:30:14 EDT 2007


Hi,

Trying to extend the coverage for QuadEdgeMEshPolygonCell, I realyzed that
the itkCellInterfaceTest was not covering the const versions of GetPointIds,
PointIdsBegin, and PointIdsEnd.

My understanding of const correctnes is still limited so I'm not sure if all
I'm going to say is correct. Please correct me.

My guess is that the following lines were supposed to do that,
std::cout << "    ConstIterator test: PointIds for empty cell: ";
Typename Tcell::PointIdConstIterator cpointId = cell->PointIdsBegin();
Typename Tcell::PointIdConstIterator cendId   = cell->PointIdsEnd();
While(...)
  { ... }

but it seems that the object itself must be const, and not only the return
type, to call the right method.

I could not create a const version of the cells and pass it through because
the first lines of the function:
CellAutoPointer cell(aCell,true);
Create a new cell, dropping the const attribute.

The only solution I found is to change the cpointId and cendId as follows:
Typename Tcell::PointIdConstIterator cpointId
  = (const_cast<const Tcell*>(aCell))->PointIdsBegin();
Typename Tcell::PointIdConstIterator cendId   = cell->PointIdsEnd();
  = (const_cast<const Tcell*>(aCell))->PointIdsEnd();

It solves the probleme (and increase the coverage of every single cell type)
but is it really the right way to do it?

Alex Hanfei.




More information about the Insight-developers mailing list