[Insight-developers] const flood fill conversion

Damion Shelton dmshelto@andrew.cmu.edu
Mon, 09 Sep 2002 12:39:53 -0400


Ok, I've been experimenting with FloodFilledFunctionConditionalIterator and 
FloodFilledFunctionConditionalConstIterator. Everything seems to work 
pretty much ok, except for:

  void Set( const PixelType & value)
    { m_Image->GetPixel(m_IndexStack.top() ) = value; }

which produces the error:

   error C2166: l-value specifies const object

m_Image is protected member of ConditionalConstIterator, declared as:

ImageType::ConstPointer m_Image;

The rest of the code, in terms of the split between const and non-const is 
layed out fairly similarly to the neighborhood iterators. How can you 
access a const member variable in a base class as a non-const variable in a 
derived class? Is there a trick I'm missing?

Thanks,
-Damion-

--On Monday, September 09, 2002 11:19 AM -0400 "Miller, James V (Research)" 
<millerjv@crd.ge.com> wrote:

> The issue here is that when the const versions of all the iterators
> were created, the code was just duplicated into disjoint classes.
> What should have happened was that the non-const versions should have
> subclassed the const versions, only added the methods to "set" the
> items under the iterator.  This way the algorithm would only exist
> in one place.
>
> This is a problem with many of iterator classes. The exception I believe
> is the NeighborhoodIterator heirarchy, which does have the non-const
> versions inherit from the const versions.