Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkLegacyFileWriterService.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <mitkCustomMimeType.h>
16 #include <mitkDataNode.h>
17 #include <mitkIOMimeTypes.h>
18 
20  const std::string &description)
21  : AbstractFileWriter(legacyWriter->GetSupportedBaseData()), m_LegacyWriter(legacyWriter)
22 {
24  this->SetDescription(description);
25 
26  CustomMimeType customMimeType;
27  std::vector<std::string> extensions = legacyWriter->GetPossibleFileExtensions();
28  for (auto ext = extensions.begin(); ext != extensions.end(); ++ext)
29  {
30  if (ext->empty())
31  continue;
32 
33  std::string extension = *ext;
34  if (extension.size() > 1 && extension[0] == '*')
35  {
36  // remove "*"
37  extension = extension.substr(1);
38  }
39  if (extension.size() > 1 && extension[0] == '.')
40  {
41  // remove "."
42  extension = extension.substr(1);
43  }
44  std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
45  customMimeType.AddExtension(extension);
46  }
47  this->SetMimeType(customMimeType);
48 
49  m_ServiceRegistration = RegisterService();
50 }
51 
53 {
54 }
55 
57 
59 {
60  if (m_LegacyWriter.IsNull())
61  mitkThrow() << "LegacyFileWriterService was incorrectly initialized: Has no LegacyFileWriter.";
62 
64 
65  LocalFile localFile(this);
66 
67  m_LegacyWriter->SetFileName(localFile.GetFileName().c_str());
68  m_LegacyWriter->SetInput(const_cast<BaseData *>(this->GetInput()));
69  m_LegacyWriter->Write();
70 }
71 
73 {
75  return Unsupported;
77  node->SetData(const_cast<BaseData *>(this->GetInput()));
78  return m_LegacyWriter->CanWriteDataType(node) ? Supported : Unsupported;
79 }
80 
81 mitk::LegacyFileWriterService *mitk::LegacyFileWriterService::Clone() const
82 {
83  return new LegacyFileWriterService(*this);
84 }
void Write() override
Write the base data to the specified location or output stream.
LegacyFileWriterService(mitk::FileWriter::Pointer legacyWriter, const std::string &description)
ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
static std::string DEFAULT_BASE_NAME()
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:45
static Pointer New()
#define mitkThrow()
const BaseData * GetInput() const override
Get the input data set via SetInput().
A local file representation for streams.
void AddExtension(const std::string &extension)
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetMimeType(const CustomMimeType &mimeType)
void SetMimeTypePrefix(const std::string &prefix)
Base class for writing mitk::BaseData objects to files or streams.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.