Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkAbstractFileIO.h"
18 
19 #include "mitkCustomMimeType.h"
20 
21 namespace mitk
22 {
24  us::Any AbstractFileIO::GetReaderOption(const std::string &name) const { return AbstractFileReader::GetOption(name); }
26  {
28  }
29 
30  void AbstractFileIO::SetReaderOption(const std::string &name, const us::Any &value)
31  {
32  AbstractFileReader::SetOption(name, value);
33  }
34 
36  us::Any AbstractFileIO::GetWriterOption(const std::string &name) const { return AbstractFileWriter::GetOption(name); }
38  {
40  }
41 
42  void AbstractFileIO::SetWriterOption(const std::string &name, const us::Any &value)
43  {
44  AbstractFileWriter::SetOption(name, value);
45  }
46 
48  {
50  }
51 
53  {
55  }
56 
57  std::pair<us::ServiceRegistration<IFileReader>, us::ServiceRegistration<IFileWriter>> AbstractFileIO::RegisterService(
58  us::ModuleContext *context)
59  {
60  std::pair<us::ServiceRegistration<IFileReader>, us::ServiceRegistration<IFileWriter>> result;
61  result.first = this->AbstractFileReader::RegisterService(context);
62  const CustomMimeType *writerMimeType = this->AbstractFileWriter::GetMimeType();
63  if (writerMimeType == NULL || (writerMimeType->GetName().empty() && writerMimeType->GetExtensions().empty()))
64  {
67  }
68  result.second = this->AbstractFileWriter::RegisterService(context);
69  return result;
70  }
71 
73  {
74  }
75 
76  AbstractFileIO::AbstractFileIO(const std::string &baseDataType)
78  {
79  }
80 
81  AbstractFileIO::AbstractFileIO(const std::string &baseDataType,
82  const CustomMimeType &mimeType,
83  const std::string &description)
84  : AbstractFileIOReader(mimeType, description),
85  AbstractFileIOWriter(baseDataType, CustomMimeType(mimeType.GetName()), description)
86  {
87  }
88 
90  {
91  this->AbstractFileReader::SetMimeType(mimeType);
93  }
94 
96  {
97  const CustomMimeType *mimeType = this->AbstractFileReader::GetMimeType();
98  if (mimeType->GetName() != this->AbstractFileWriter::GetMimeType()->GetName())
99  {
100  MITK_WARN << "Reader and writer mime-tpyes are different, using the mime-type from IFileReader";
101  }
102  return mimeType;
103  }
104 
105  void AbstractFileIO::SetReaderDescription(const std::string &description)
106  {
107  this->AbstractFileReader::SetDescription(description);
108  }
109 
111  void AbstractFileIO::SetWriterDescription(const std::string &description)
112  {
113  this->AbstractFileWriter::SetDescription(description);
114  }
115 
118  {
119  this->AbstractFileReader::SetDefaultOptions(defaultOptions);
120  }
121 
123  {
125  }
126 
128  {
129  this->AbstractFileWriter::SetDefaultOptions(defaultOptions);
130  }
131 
133  {
135  }
136 
141  IFileReader *AbstractFileIO::ReaderClone() const { return this->IOClone(); }
142  IFileWriter *AbstractFileIO::WriterClone() const { return this->IOClone(); }
143 }
virtual us::Any GetOption(const std::string &name) const override
std::vector< std::string > GetExtensions() const
Returns all extensions that this MimeType can handle.
virtual void SetOption(const std::string &name, const us::Any &value) override
virtual ConfidenceLevel GetReaderConfidenceLevel() const override
void SetReaderOption(const std::string &name, const us::Any &value)
void SetWriterRanking(int ranking)
virtual Options GetOptions() const override
returns a list of the supported options
virtual void SetOptions(const Options &options) override
DataCollection - Class to facilitate loading/accessing structured data.
void SetDefaultReaderOptions(const Options &defaultOptions)
Options GetReaderOptions() const
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
void SetDefaultOptions(const Options &defaultOptions)
const CustomMimeType * GetMimeType() const
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
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:23
void SetMimeType(const CustomMimeType &mimeType)
std::string GetDescription() const
std::pair< us::ServiceRegistration< IFileReader >, us::ServiceRegistration< IFileWriter > > RegisterService(us::ModuleContext *context=us::GetModuleContext())
void SetDescription(const std::string &description)
Definition: usAny.h:163
void SetReaderDescription(const std::string &description)
std::string GetName() const
Returns the unique name for the MimeType.
void SetWriterOption(const std::string &name, const us::Any &value)
const CustomMimeType * GetMimeType() const
virtual 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)
Options GetDefaultReaderOptions() const
const CustomMimeType * GetMimeType() const
virtual void SetOption(const std::string &name, const us::Any &value) override
us::Any GetReaderOption(const std::string &name) const
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
virtual ConfidenceLevel GetReaderConfidenceLevel() const
void SetMimeType(const CustomMimeType &mimeType)
us::Any GetWriterOption(const std::string &name) const
static std::string GetName(std::string fileName, std::string suffix)
virtual void SetOptions(const Options &options) override
std::string GetWriterDescription() const
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
void SetWriterOptions(const Options &options)
void SetReaderOptions(const Options &options)
virtual ConfidenceLevel GetWriterConfidenceLevel() const override
Options GetWriterOptions() const
The common interface for all MITK file readers.
Abstract class for implementing a reader and writer.
void SetDescription(const std::string &description)
Sets a human readable description of this writer.
virtual us::Any GetOption(const std::string &name) const override
std::string GetReaderDescription() const
virtual ConfidenceLevel GetWriterConfidenceLevel() const
void SetDefaultWriterOptions(const Options &defaultOptions)
Options GetDefaultWriterOptions() const
std::string GetDescription() const