Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
mitkAbstractFileIO.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 
13 #include "mitkAbstractFileIO.h"
14 
15 #include "mitkCustomMimeType.h"
16 
17 namespace mitk
18 {
20  us::Any AbstractFileIO::GetReaderOption(const std::string &name) const { return AbstractFileReader::GetOption(name); }
22  {
24  }
25 
26  void AbstractFileIO::SetReaderOption(const std::string &name, const us::Any &value)
27  {
28  AbstractFileReader::SetOption(name, value);
29  }
30 
32  us::Any AbstractFileIO::GetWriterOption(const std::string &name) const { return AbstractFileWriter::GetOption(name); }
34  {
36  }
37 
38  void AbstractFileIO::SetWriterOption(const std::string &name, const us::Any &value)
39  {
40  AbstractFileWriter::SetOption(name, value);
41  }
42 
44  {
46  }
47 
49  {
51  }
52 
53  std::pair<us::ServiceRegistration<IFileReader>, us::ServiceRegistration<IFileWriter>> AbstractFileIO::RegisterService(
54  us::ModuleContext *context)
55  {
56  std::pair<us::ServiceRegistration<IFileReader>, us::ServiceRegistration<IFileWriter>> result;
57  result.first = this->AbstractFileReader::RegisterService(context);
58  const CustomMimeType *writerMimeType = this->AbstractFileWriter::GetMimeType();
59  if (writerMimeType == nullptr || (writerMimeType->GetName().empty() && writerMimeType->GetExtensions().empty()))
60  {
63  }
64  result.second = this->AbstractFileWriter::RegisterService(context);
65  return result;
66  }
67 
69  {
70  }
71 
72  AbstractFileIO::AbstractFileIO(const std::string &baseDataType)
74  {
75  }
76 
77  AbstractFileIO::AbstractFileIO(const std::string &baseDataType,
78  const CustomMimeType &mimeType,
79  const std::string &description)
80  : AbstractFileIOReader(mimeType, description),
81  AbstractFileIOWriter(baseDataType, CustomMimeType(mimeType.GetName()), description)
82  {
83  }
84 
86  {
87  this->AbstractFileReader::SetMimeType(mimeType);
89  }
90 
92  {
93  const CustomMimeType *mimeType = this->AbstractFileReader::GetMimeType();
94  if (mimeType->GetName() != this->AbstractFileWriter::GetMimeType()->GetName())
95  {
96  MITK_WARN << "Reader and writer mime-tpyes are different, using the mime-type from IFileReader";
97  }
98  return mimeType;
99  }
100 
101  void AbstractFileIO::SetReaderDescription(const std::string &description)
102  {
103  this->AbstractFileReader::SetDescription(description);
104  }
105 
107  void AbstractFileIO::SetWriterDescription(const std::string &description)
108  {
109  this->AbstractFileWriter::SetDescription(description);
110  }
111 
114  {
115  this->AbstractFileReader::SetDefaultOptions(defaultOptions);
116  }
117 
119  {
121  }
122 
124  {
125  this->AbstractFileWriter::SetDefaultOptions(defaultOptions);
126  }
127 
129  {
131  }
132 
137  IFileReader *AbstractFileIO::ReaderClone() const { return this->IOClone(); }
138  IFileWriter *AbstractFileIO::WriterClone() const { return this->IOClone(); }
139 }
const CustomMimeType * GetMimeType() const
us::Any GetOption(const std::string &name) const override
void SetOption(const std::string &name, const us::Any &value) override
us::Any GetReaderOption(const std::string &name) const
ConfidenceLevel GetReaderConfidenceLevel() const override
Options GetDefaultReaderOptions() const
void SetReaderOption(const std::string &name, const us::Any &value)
void SetWriterRanking(int ranking)
const CustomMimeType * GetMimeType() const
Options GetOptions() const override
returns a list of the supported options
std::string GetName() const
Returns the unique name for the MimeType.
void SetOptions(const Options &options) override
DataCollection - Class to facilitate loading/accessing structured data.
void SetDefaultReaderOptions(const Options &defaultOptions)
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
void SetDefaultOptions(const Options &defaultOptions)
virtual ConfidenceLevel GetWriterConfidenceLevel() const
us::Any GetWriterOption(const std::string &name) const
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
std::vector< std::string > GetExtensions() const
Returns all extensions that this MimeType can handle.
void SetReaderRanking(int ranking)
Set the service ranking for this file reader.
void SetRanking(int ranking)
Set the service ranking for this file writer.
void SetDefaultOptions(const Options &defaultOptions)
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
#define MITK_WARN
Definition: mitkLogMacros.h:19
void SetMimeType(const CustomMimeType &mimeType)
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:45
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
std::string GetReaderDescription() const
Options GetDefaultWriterOptions() const
void SetDescription(const std::string &description)
Definition: usAny.h:163
void SetReaderDescription(const std::string &description)
std::string GetWriterDescription() const
void SetWriterOption(const std::string &name, const us::Any &value)
Options GetOptions() const override
returns a list of the supported options
AbstractFileIO(const AbstractFileIO &other)
void SetRanking(int ranking)
Set the service ranking for this file reader.
void SetWriterDescription(const std::string &description)
void SetOption(const std::string &name, const us::Any &value) override
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetMimeType(const CustomMimeType &mimeType)
static std::string GetName(std::string fileName, std::string suffix)
Options GetWriterOptions() const
void SetOptions(const Options &options) override
void SetWriterOptions(const Options &options)
void SetReaderOptions(const Options &options)
virtual ConfidenceLevel GetReaderConfidenceLevel() const
ConfidenceLevel GetWriterConfidenceLevel() const override
Options GetReaderOptions() const
The common interface for all MITK file readers.
The common interface of all MITK file writers.
Abstract class for implementing a reader and writer.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.
us::Any GetOption(const std::string &name) const override
const CustomMimeType * GetMimeType() const
void SetDefaultWriterOptions(const Options &defaultOptions)