Exemplo n.º 1
0
ItkImageIO::ItkImageIO(const CustomMimeType& mimeType, itk::ImageIOBase::Pointer imageIO, int rank)
  : AbstractFileIO(Image::GetStaticNameOfClass(), mimeType, std::string("ITK ") + imageIO->GetNameOfClass())
  , m_ImageIO(imageIO)
{
  if (m_ImageIO.IsNull() )
  {
    mitkThrow() << "ITK ImageIOBase argument must not be NULL";
  }

  this->AbstractFileReader::SetMimeTypePrefix(IOMimeTypes::DEFAULT_BASE_NAME() + ".image.");

  if (rank)
  {
    this->AbstractFileReader::SetRanking(rank);
    this->AbstractFileWriter::SetRanking(rank);
  }

  this->RegisterService();
}
Exemplo n.º 2
0
  ItkImageIO::ItkImageIO(itk::ImageIOBase::Pointer imageIO)
    : AbstractFileIO(Image::GetStaticNameOfClass()), m_ImageIO(imageIO)
  {
    if (m_ImageIO.IsNull())
    {
      mitkThrow() << "ITK ImageIOBase argument must not be NULL";
    }

    this->AbstractFileReader::SetMimeTypePrefix(IOMimeTypes::DEFAULT_BASE_NAME() + ".image.");
    this->InitializeDefaultMetaDataKeys();

    std::vector<std::string> readExtensions = m_ImageIO->GetSupportedReadExtensions();

    if (readExtensions.empty())
    {
      std::string imageIOName = m_ImageIO->GetNameOfClass();
      MITK_DEBUG << "ITK ImageIOBase " << imageIOName << " does not provide read extensions";
      readExtensions = FixUpImageIOExtensions(imageIOName);
    }

    CustomMimeType customReaderMimeType;
    customReaderMimeType.SetCategory("Images");
    for (std::vector<std::string>::const_iterator iter = readExtensions.begin(), endIter = readExtensions.end();
         iter != endIter;
         ++iter)
    {
      std::string extension = *iter;
      if (!extension.empty() && extension[0] == '.')
      {
        extension.assign(iter->begin() + 1, iter->end());
      }
      customReaderMimeType.AddExtension(extension);
    }
    this->AbstractFileReader::SetMimeType(customReaderMimeType);

    std::vector<std::string> writeExtensions = imageIO->GetSupportedWriteExtensions();
    if (writeExtensions.empty())
    {
      std::string imageIOName = imageIO->GetNameOfClass();
      MITK_DEBUG << "ITK ImageIOBase " << imageIOName << " does not provide write extensions";
      writeExtensions = FixUpImageIOExtensions(imageIOName);
    }

    if (writeExtensions != readExtensions)
    {
      CustomMimeType customWriterMimeType;
      customWriterMimeType.SetCategory("Images");
      for (std::vector<std::string>::const_iterator iter = writeExtensions.begin(), endIter = writeExtensions.end();
           iter != endIter;
           ++iter)
      {
        std::string extension = *iter;
        if (!extension.empty() && extension[0] == '.')
        {
          extension.assign(iter->begin() + 1, iter->end());
        }
        customWriterMimeType.AddExtension(extension);
      }
      this->AbstractFileWriter::SetMimeType(customWriterMimeType);
    }

    std::string description = std::string("ITK ") + imageIO->GetNameOfClass();
    this->SetReaderDescription(description);
    this->SetWriterDescription(description);

    this->RegisterService();
  }