mitk::LegacyFileWriterService::LegacyFileWriterService(mitk::FileWriter::Pointer legacyWriter,
                                                       const std::string &description)
  : AbstractFileWriter(legacyWriter->GetSupportedBaseData()), m_LegacyWriter(legacyWriter)
{
  this->SetMimeTypePrefix(IOMimeTypes::DEFAULT_BASE_NAME() + ".legacy.");
  this->SetDescription(description);

  CustomMimeType customMimeType;
  std::vector<std::string> extensions = legacyWriter->GetPossibleFileExtensions();
  for (auto ext = extensions.begin(); ext != extensions.end(); ++ext)
  {
    if (ext->empty())
      continue;

    std::string extension = *ext;
    if (extension.size() > 1 && extension[0] == '*')
    {
      // remove "*"
      extension = extension.substr(1);
    }
    if (extension.size() > 1 && extension[0] == '.')
    {
      // remove "."
      extension = extension.substr(1);
    }
    std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
    customMimeType.AddExtension(extension);
  }
  this->SetMimeType(customMimeType);

  m_ServiceRegistration = RegisterService();
}
Example #2
0
AbstractFileReader::AbstractFileReader(const std::string& extension, const std::string& description)
  : d(new Impl)
{
  CustomMimeType customMimeType;
  customMimeType.AddExtension(extension);
  d->SetMimeType(customMimeType);
  d->SetDescription(description);
}
Example #3
0
mitk::LegacyFileReaderService::LegacyFileReaderService(const std::vector<std::string>& extensions,
                                                       const std::string& category)
  : AbstractFileReader()
{
  this->SetMimeTypePrefix(IOMimeTypes::DEFAULT_BASE_NAME() + ".legacy.");

  CustomMimeType customMimeType;
  customMimeType.SetCategory(category);

  for(auto extension : extensions)
  {

    if (!extension.empty() && extension[0] == '.')
    {
      extension.assign(extension.begin()+1, extension.end());
    }
    customMimeType.AddExtension(extension);
  }
  this->SetDescription(category);
  this->SetMimeType(customMimeType);

  m_ServiceReg = this->RegisterService();
}
Example #4
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();
  }