dgobbi / vtk-dicom

A set of classes for using DICOM in VTK.
BSD 3-Clause "New" or "Revised" License
253 stars 94 forks source link

subdirectory not processed by vtkDICOMDirectory #56

Closed josp70 closed 9 years ago

josp70 commented 9 years ago

I have the following directory structure:

DICOM
  \__00000000
           \__00000000 
           \__00000001

When doing, with argv[1]=="DICOM"

  dicomdir->SetDirectoryName( argv[1] );
  dicomdir->SetScanDepth( 3 );
  dicomdir->Update( );

Only DICOM/00000000/00000001 is visited.

I have traced the execution of void vtkDICOMDirectory::ProcessDirectory and found that

The directories are iterated in this order

  first DICOM/00000000/00000001
  then DICOM/00000000/00000000

with this order, the condition:

  if (viter == this->Visited->end() || *viter < realname)

evaluate to false and the directory DICOM/00000000/00000000 is not visited.

I think that the condition must be:

if (viter == this->Visited->end() || *viter != realname)

This is because std::lower_bound returns an iterator which is greater than or equal the value. For example:

#include <iostream>     // std::cout
#include <algorithm>    // std::lower_bound, std::upper_bound, std::sort
#include <vector>       // std::vector

int main () {
  std::string dir1( "/home/jsperez/Data/pcmr/Sequences/SIEMENS/CVS/DICOM/00000000/00000001" );
  std::vector<std::string> v;
  v.push_back( dir1 );
  std::string dir0( "/home/jsperez/Data/pcmr/Sequences/SIEMENS/CVS/DICOM/00000000/00000000" );

  std::vector<std::string>::iterator low;
  low = std::lower_bound (v.begin(), v.end(), dir0);
  if( low != v.end() )
    {
    std::cout << "low = " << *low <<std::endl;
    }

  return 0;
}
dgobbi commented 9 years ago

Thanks, I've merged a patch into the master branch. Perhaps I originally meant to use "*viter > realname" and got it the wrong way around. But using "!=" is better.

This bug had slipped my notice because I do my development on OS X, which always iterated through the directories in lexical order. But I can even reproduce this bug on my Mac, because it iterates through the directories in case-insensitive order, whereas the "Visited" vector needs to be in case-sensitive order.

It probably would have been a long, long time before I noticed this bug myself, because I keep all my DICOM files on OS X.