[Insight-developers] Iterators & "operator *"
Luis Ibanez
luis.ibanez at kitware.com
Mon May 19 15:14:42 EDT 2008
Hi Gert,
Yes, the dereferoperator*() was purposely not used because it has an
inherent
ambiguity between the "Get" and "Set" operations.
As you already pointed out, ImageAdaptors are part of the reason
why we need to keep the Get/Set interface for the iterators.
ITK image iterators differ from STL one in the characteristics
that they are not linear, and in that they are not defined as
traits of the classes over which they iterate.
ITK iterators are "smarter" than STL iterators, in the sense that
they know a lot more about the object they are iterating. This
could also be seen as an encapsulation breach... :-/
One STL-style operation that will be particularly inefficient
if implemented with ITK iterators is the typical while-loop:
while( iter != image->end() )
{
*iter = value;
++iter;
}
The call to end() will result in a construction of an iterator
at every call. The comparison != will require to compare the
index location of the iterator in the image.
Granted,... they may have been implemented in a way that
would not sacrifice too much performance....
The basic reason why Iterators in ITK use a different design
is that one image can be visited in many different ways, and
we found useful to make possible the use of many types of
iterators with a given image, instead of having the image
define a single type of iterator.
Attempting to use ITK iterators in STL algorithms may work
in very particular cases, *if* we add to the ITK iterator
all the concept checks that are required by the STL algorithm
using the iterator. It may be interesting to give it a try.. :-)
Regards,
Luis
----------------------
Gert Wollny wrote:
> Hello,
>
> is there any specific reason, why the standard de-referencing operator
> *() is not implemented for iterators? It seems, the "Value()" method
> does exactly what this operator is for.
>
> It appears that adding *() would make the iterators compatible to the
> STL algorithms as long as no ImageAdaptors are used.
>
> Many thanks,
>
> Gert
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list