[Dcmlib] gdcmSerieHelper

David Feng dfeng at cs.unc.edu
Thu Feb 14 17:06:48 CET 2008


I recently downloaded GDCM 1.3.2 and noticed a problem with the 
SerieHelper::ImagePositionPatientOrdering function.  It caused my image 
series to skip half of the slices in my data.  I browsed the source 
online, and it appears that the bug still exists around line 777 of 
gdcmSerieHelper.cxx.

The code is attempting to sort a series and discard entries that 
duplicate an existing z position.  The buggy code is as follows:

if (DropDuplicatePositions)
{
    /// \todo ImagePositionPatientOrdering  wrong duplicates are found ???
    it3 =  distmultimap.upper_bound((*it3).first); // skip all duplicates

    if (it3 == distmultimap.end() )  // if last image, stop iterate
        break;
}

I'm assuming from the comment that this is a known bug.  The problem is 
that the upper_bound function increments the iterator to the next 
non-duplicate entry.  The for loop iteration also increments the 
iterator, which causes the code to skip every other image.  A simple fix 
would be to decrement the iterator after the upper_bound function call.

I also have concerns about a section of code below this one, which 
handles reverse sorting.  It also uses the upper_bound function, but 
this function finds the next highest value, which is the opposite of 
what we want when reverse sorting.  Using lower_bound instead of 
upper_bound will not fix this, as lower_bound finds the next element 
that is less than or *equal to* the current value. I haven't tested this 
bit of code, though.

Thanks,
David




More information about the Dcmlib mailing list