[Insight-users] A bug (?) in ImageSliceConstIteratorWithIndex class

Paul Yushkevich pauly@cognitica.com
Fri, 08 Nov 2002 16:18:44 -0500


Hi everyone,

I found what I think may be a bug in ImageSliceConstIteratorWithIndex 
class.  

The following code is intended to copy the contents of a slice 'slice' 
to the 2D array 'sliceArray'.

SomeClass::SomeClass(...) {
    // Create a slice iterator and choose a slice
    slicer = 
ImageSliceConstIteratorWithIndex<ImageType>(imagePtr,imagePtr->getLargestPossibleRegion());
    slicer.setFirstDimension(0);
    slicer.setFirstDimension(1);
}

void SomeClass::setSlice(int slice) {

    // Skip to the right slice
    slicer.GoToBegin();
    for(int i=0;i<slice;i++) {
        slicer.NextSlice();
    }

    // BUG-SOLVING-LINE: slicer.SetIndex(slicer.GetIndex());

    // Fill out the 2D image
    int sliceIdx = 0;
    while ( !slicer.IsAtEndOfSlice() ) {
        while ( !slicer.IsAtEndOfLine() ) {
            sliceArray[sliceIdx++] = (unsigned char) floor(255 * 
slicer.Value());
            ++slicer;
        }  
        slicer.NextLine();
    }
}

No matter which slice number I pass on to this piece of code, it places 
the first slice of the 3D image into the 2D array.

However, if I uncomment the line labeled BUG-SOLVING-LINE, things start 
working again.  Seems like the iterator is keeping a pair
of internal references to the currently selected pixel, and they are 
getting out of sync.

BTW, can someone tell me how to get a userid and password for posting a 
bug using the online system?

Thanks!

Paul Yushkevich
Cognitica Corporation
pauly@cognitica.com