Classes | Public Types | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions

mitk::DicomSeriesReader Class Reference

#include <mitkDicomSeriesReader.h>

List of all members.

Classes

class  CallbackCommand

Public Types

typedef std::vector< std::string > StringContainer
typedef std::map< std::string,
StringContainer
UidFileNamesMap
typedef void(* UpdateCallBackMethod )(float)

Static Public Member Functions

static DataNode::Pointer LoadDicomSeries (const StringContainer &filenames, UpdateCallBackMethod callback=0)
static bool LoadDicomSeries (const StringContainer &filenames, DataNode &node, UpdateCallBackMethod callback=0)
static bool IsDicom (const std::string &filename)
static UidFileNamesMap GetSeries (const std::string &dir, bool additional_criteria=false, const StringContainer &restrictions=StringContainer())
static StringContainer GetSeries (const std::string &dir, const std::string &series_uid, bool additional_criteria=false, const StringContainer &restrictions=StringContainer())

Protected Types

typedef itk::DICOMImageIO2 DcmIoType

Protected Member Functions

 DicomSeriesReader ()
 ~DicomSeriesReader ()

Static Protected Member Functions

template<typename PixelType >
static void LoadDicom (const StringContainer &filenames, DataNode &node, UpdateCallBackMethod callback)

Detailed Description

Provides functions for loading DICOM series. The series is specified through an enumeration of all files contained in it. A method for the creation of file name enumerations of all series contained in a particular directory is also provided. After loading the series, the generated DataNode is not named. The caller is responsible for given the node a name.

Definition at line 49 of file mitkDicomSeriesReader.h.


Member Typedef Documentation

typedef itk::DICOMImageIO2 mitk::DicomSeriesReader::DcmIoType [protected]

Definition at line 100 of file mitkDicomSeriesReader.h.

typedef std::vector<std::string> mitk::DicomSeriesReader::StringContainer

Definition at line 52 of file mitkDicomSeriesReader.h.

Definition at line 53 of file mitkDicomSeriesReader.h.

Definition at line 54 of file mitkDicomSeriesReader.h.


Constructor & Destructor Documentation

mitk::DicomSeriesReader::DicomSeriesReader (  ) [inline, protected]

Definition at line 91 of file mitkDicomSeriesReader.h.

  {}
mitk::DicomSeriesReader::~DicomSeriesReader (  ) [inline, protected]

Definition at line 94 of file mitkDicomSeriesReader.h.

  {}

Member Function Documentation

DicomSeriesReader::UidFileNamesMap mitk::DicomSeriesReader::GetSeries ( const std::string &  dir,
bool  additional_criteria = false,
const StringContainer restrictions = StringContainer() 
) [static]

Find all series in a particular directory. For each series, an enumeration of the files contained in it is created. Optionally, more criteria can be used to distinguish between different series, and series restrictions can be specified.

Definition at line 112 of file mitkDicomSeriesReader.cpp.

Referenced by mitk::DataNodeFactory::ReadFileSeriesTypeDCM().

{
  DcmFileNamesGeneratorType::Pointer name_generator = DcmFileNamesGeneratorType::New();

  name_generator->SetUseSeriesDetails(additional_criteria);
  name_generator->SetDirectory(dir.c_str());

  const StringContainer::const_iterator restrictions_end = restrictions.end();

  for(StringContainer::const_iterator it = restrictions.begin(); it != restrictions_end; ++it)
  {
    name_generator->AddSeriesRestriction(*it);
  }

  UidFileNamesMap map;
  const StringContainer &series_uids = name_generator->GetSeriesUIDs();
  const StringContainer::const_iterator series_end = series_uids.end();

  for(StringContainer::const_iterator it = series_uids.begin(); it != series_end; ++it)
  {
    const std::string &uid = *it;

    map[uid] = name_generator->GetFileNames(uid);
  }

  return map;
}
DicomSeriesReader::StringContainer mitk::DicomSeriesReader::GetSeries ( const std::string &  dir,
const std::string &  series_uid,
bool  additional_criteria = false,
const StringContainer restrictions = StringContainer() 
) [static]

Find a particular series in a directory. For each series, an enumeration of the files contained in it is created. Optionally, more criteria can be used to distinguish between different series, and series restrictions can be specified.

Definition at line 140 of file mitkDicomSeriesReader.cpp.

{
  DcmFileNamesGeneratorType::Pointer name_generator = DcmFileNamesGeneratorType::New();

  name_generator->SetUseSeriesDetails(additional_criteria);
  name_generator->SetDirectory(dir.c_str());

  const StringContainer::const_iterator restrictions_end = restrictions.end();

  for(StringContainer::const_iterator it = restrictions.begin(); it != restrictions_end; ++it)
  {
    name_generator->AddSeriesRestriction(*it);
  }

  return name_generator->GetFileNames(series_uid);
}
bool mitk::DicomSeriesReader::IsDicom ( const std::string &  filename ) [static]

Checks if a specific file is a DICOM.

Definition at line 105 of file mitkDicomSeriesReader.cpp.

Referenced by mitk::DataNodeFactory::GenerateData().

{
  DcmIoType::Pointer io = DcmIoType::New();

  return io->CanReadFile(filename.c_str());
}
template<typename PixelType >
void mitk::DicomSeriesReader::LoadDicom ( const StringContainer filenames,
DataNode node,
UpdateCallBackMethod  callback 
) [static, protected]

Performs the loading of a series and creates an image having the specified pixel type.

Definition at line 34 of file mitkDicomSeriesReader.txx.

References MITK_DEBUG, mitk::Image::New(), and mitk::DataNode::SetData().

{
  const char* previousCLocale = setlocale(LC_NUMERIC, NULL);
  setlocale(LC_NUMERIC, "C");
  std::locale previousCppLocale( std::cin.getloc() );
  std::locale l( "C" );
  std::cin.imbue(l);

  try
  {
    mitk::Image::Pointer image = mitk::Image::New();
    CallbackCommand *command = callback ? new CallbackCommand(callback) : 0;

#if GDCM_MAJOR_VERSION >= 2

    /******** Workaround for 4D data ***************/
    gdcm::Sorter sorter;

    sorter.SetSortFunction(DicomSeriesReader::GdcmSortFunction);
    sorter.Sort(filenames);

    gdcm::Tag acq_time(0x0008,0x0032);
    gdcm::Scanner scanner;

    scanner.AddTag(acq_time);
    scanner.Scan(sorter.GetFilenames());

    std::list<StringContainer> decomposed_filenames;
    const StringContainer::const_iterator f_end = sorter.GetFilenames().end();
    const char *act_value = scanner.GetValue(sorter.GetFilenames().front().c_str(), acq_time);
    unsigned int volume_count = 1u;

    decomposed_filenames.push_back(StringContainer());
    decomposed_filenames.back().push_back(sorter.GetFilenames().front());

    for (StringContainer::const_iterator f_it = ++sorter.GetFilenames().begin(); f_it != f_end; ++f_it)
    {
      const char *value = scanner.GetValue(f_it->c_str(), acq_time);

      if (strcmp(act_value, value))
      {
        act_value = value;
        decomposed_filenames.push_back(StringContainer());
        ++volume_count;
      }

      decomposed_filenames.back().push_back(*f_it);
    }
    /******** End: Workaround for 4D data **********/

    if (volume_count > 1)
    {
      typedef itk::Image<PixelType, 4> ImageType;
      typedef itk::ImageSeriesReader<ImageType> ReaderType;

      DcmIoType::Pointer io = DcmIoType::New();
      typename ReaderType::Pointer reader = ReaderType::New();

      reader->SetImageIO(io);
      reader->ReverseOrderOff();

      if (command)
      {
        reader->AddObserver(itk::ProgressEvent(), command);
      }

      const std::list<StringContainer>::const_iterator df_end = decomposed_filenames.end();
      unsigned int act_volume = 1u;

      reader->SetFileNames(decomposed_filenames.front());
      reader->Update();
      image->InitializeByItk(reader->GetOutput(), 1, volume_count);
      image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), 0u);

      MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << ", " << image->GetDimension(3) << "]";
      MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";

      for (std::list<StringContainer>::iterator df_it = ++decomposed_filenames.begin(); df_it != df_end; ++df_it)
      {
        reader->SetFileNames(*df_it);
        reader->Update();
        image->SetImportVolume(reader->GetOutput()->GetBufferPointer(), act_volume++);
      }
    }
    else
    {
      typedef itk::Image<PixelType, 3> ImageType;
      typedef itk::ImageSeriesReader<ImageType> ReaderType;

      DcmIoType::Pointer io = DcmIoType::New();
      typename ReaderType::Pointer reader = ReaderType::New();

      reader->SetImageIO(io);
      reader->ReverseOrderOff();

      if (command)
      {
        reader->AddObserver(itk::ProgressEvent(), command);
      }

      reader->SetFileNames(filenames);
      reader->Update();
      image->InitializeByItk(reader->GetOutput());
      image->SetImportVolume(reader->GetOutput()->GetBufferPointer());

      MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]";
      MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";
    }

#else
    typedef itk::Image<PixelType, 3> ImageType;
    typedef itk::ImageSeriesReader<ImageType> ReaderType;

    DcmIoType::Pointer io = DcmIoType::New();
    typename ReaderType::Pointer reader = ReaderType::New();

    reader->SetImageIO(io);
    reader->ReverseOrderOff();

    if (command)
    {
      reader->AddObserver(itk::ProgressEvent(), command);
    }

    reader->SetFileNames(filenames);
    reader->Update();
    image->InitializeByItk(reader->GetOutput());
    image->SetImportVolume(reader->GetOutput()->GetBufferPointer());

    MITK_DEBUG << "Volume dimension: [" << image->GetDimension(0) << ", " << image->GetDimension(1) << ", " << image->GetDimension(2) << "]";
    MITK_DEBUG << "Volume spacing: [" << image->GetGeometry()->GetSpacing()[0] << ", " << image->GetGeometry()->GetSpacing()[1] << ", " << image->GetGeometry()->GetSpacing()[2] << "]";

#endif

    node.SetData(image);
    
    setlocale(LC_NUMERIC, previousCLocale);
    std::cin.imbue(previousCppLocale);

  }
  catch (std::exception& e)
  {
    setlocale(LC_NUMERIC, previousCLocale);
    std::cin.imbue(previousCppLocale);

    throw e;
  }
}
bool mitk::DicomSeriesReader::LoadDicomSeries ( const StringContainer filenames,
DataNode node,
UpdateCallBackMethod  callback = 0 
) [static]

Loads a DICOM series composed by the file names enumerated in the file names container. If a callback method is supplied, it will be called after every progress update with a progress value in [0,1].

Definition at line 45 of file mitkDicomSeriesReader.cpp.

References MITK_ERROR.

{
  DcmIoType::Pointer io = DcmIoType::New();

  try
  {
    if (io->CanReadFile(filenames.front().c_str()))
    {
      io->SetFileName(filenames.front().c_str());
      io->ReadImageInformation();

      switch (io->GetComponentType())
      {
      case DcmIoType::UCHAR:
        DicomSeriesReader::LoadDicom<unsigned char>(filenames, node, callback);
        return true;
      case DcmIoType::CHAR:
        DicomSeriesReader::LoadDicom<char>(filenames, node, callback);
        return true;
      case DcmIoType::USHORT:
        DicomSeriesReader::LoadDicom<unsigned short>(filenames, node, callback);
        return true;
      case DcmIoType::SHORT:
        DicomSeriesReader::LoadDicom<short>(filenames, node, callback);
        return true;
      case DcmIoType::UINT:
        DicomSeriesReader::LoadDicom<unsigned int>(filenames, node, callback);
        return true;
      case DcmIoType::INT:
        DicomSeriesReader::LoadDicom<int>(filenames, node, callback);
        return true;
      case DcmIoType::ULONG:
        DicomSeriesReader::LoadDicom<long unsigned int>(filenames, node, callback);
        return true;
      case DcmIoType::LONG:
        DicomSeriesReader::LoadDicom<long int>(filenames, node, callback);
        return true;
      case DcmIoType::FLOAT:
        DicomSeriesReader::LoadDicom<float>(filenames, node, callback);
        return true;
      case DcmIoType::DOUBLE:
        DicomSeriesReader::LoadDicom<double>(filenames, node, callback);
        return true;
      default:
        MITK_ERROR << "Unknown pixel type!";
      }
    }
  }
  catch(itk::MemoryAllocationError e)
  {
    MITK_ERROR << "Memory allocation!";
  }
  catch(...)
  {
    MITK_ERROR << "Unknown!";
  }

  return false;
}
DataNode::Pointer mitk::DicomSeriesReader::LoadDicomSeries ( const StringContainer filenames,
UpdateCallBackMethod  callback = 0 
) [static]

Loads a DICOM series composed by the file names enumerated in the file names container. If a callback method is supplied, it will be called after every progress update with a progress value in [0,1].

Definition at line 31 of file mitkDicomSeriesReader.cpp.

References mitk::DataNode::New().

Referenced by mitk::DataNodeFactory::ReadFileSeriesTypeDCM().

{
  DataNode::Pointer node = DataNode::New();

  if (DicomSeriesReader::LoadDicomSeries(filenames, *node, callback))
  {
    return node;
  }
  else
  {
    return 0;
  }
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines