25 #include <itksys/SystemTools.hxx> 32 :
std::istream(nullptr), m_Stream(nullptr)
37 this->init(stream->rdbuf());
42 this->init(m_Stream->rdbuf());
51 Impl(
const Impl &other) :
FileReaderWriterBase(other), m_Stream(
nullptr), m_PrototypeFactory(
nullptr) {}
52 std::string m_Location;
53 std::string m_TmpFile;
54 std::istream *m_Stream;
65 delete d->m_PrototypeFactory;
67 if (!d->m_TmpFile.empty())
69 std::remove(d->m_TmpFile.c_str());
79 d->SetMimeType(mimeType);
80 d->SetDescription(description);
87 std::vector<BaseData::Pointer> result;
91 DataStorage::SetOfObjects::ConstPointer dataNodes = ds->GetAll();
92 for (DataStorage::SetOfObjects::ConstIterator iter = dataNodes->Begin(), iterEnd = dataNodes->End();
96 result.push_back(iter.Value()->GetData());
103 DataStorage::SetOfObjects::Pointer result = DataStorage::SetOfObjects::New();
104 std::vector<BaseData::Pointer> data = this->
Read();
105 for (
auto iter = data.begin(); iter != data.end(); ++iter)
108 node->SetData(*iter);
111 result->InsertElement(result->Size(), node);
125 if (itksys::SystemTools::FileExists(this->
GetInputLocation().c_str(),
true))
137 if (d->m_PrototypeFactory)
140 if (context ==
nullptr)
145 d->RegisterMimeType(context);
149 MITK_WARN <<
"Not registering reader due to empty MIME type.";
168 delete us::ExtractInterface<IFileReader>(service);
172 d->m_PrototypeFactory =
new PrototypeFactory(
this);
174 d->m_Reg = context->RegisterService<
IFileReader>(d->m_PrototypeFactory, props);
182 d->m_Reg.Unregister();
184 catch (
const std::exception &)
201 return d->RegisterMimeType(context);
212 std::string localFileName;
215 if (d->m_TmpFile.empty())
218 std::string ext = itksys::SystemTools::GetFilenameExtension(this->
GetInputLocation());
219 std::ofstream tmpStream;
221 tmpStream, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary,
"XXXXXX" + ext);
222 tmpStream << d->m_Stream->rdbuf();
223 d->m_TmpFile = localFileName;
227 localFileName = d->m_TmpFile;
232 localFileName = d->m_Location;
234 return localFileName;
241 d->SetDefaultOptions(defaultOptions);
247 d->m_Location = location;
248 d->m_Stream =
nullptr;
253 if (d->m_Stream != is && !d->m_TmpFile.empty())
255 std::remove(d->m_TmpFile.c_str());
256 d->m_TmpFile.clear();
258 d->m_Location = location;
274 d->RemoveProgressCallback(callback);
286 if (!filePath.empty())
const CustomMimeType * GetMimeType() const
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr, bool fallBackOnDataProperties=true) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
Data management class that handles 'was created by' relations.
MimeType GetRegisteredMimeType() const
us::Any GetOption(const std::string &name) const override
virtual us::ServiceProperties GetServiceProperties() const
void SetVisibility(bool visible, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="visible")
Convenience method for setting visibility properties (instances of BoolProperty)
US_Core_EXPORT const std::string & SERVICE_RANKING()
void SetOption(const std::string &name, const us::Any &value) override
ConfidenceLevel GetConfidenceLevel() const override
The confidence level of the reader or writer implementation.
std::map< std::string, void * > InterfaceMap
static std::string PROP_DESCRIPTION()
Service property name for a description.
std::istream * GetInputStream() const override
Get the input stream.
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.
std::map< std::string, us::Any > Options
Options for reading or writing data.
std::string GetDescription() const
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
static std::string PROP_MIMETYPE()
Service property name for the mime-type associated with this file writer.
std::vector< itk::SmartPointer< BaseData > > Read() override=0
Reads a path or stream and creates a list of BaseData objects.
virtual void Add(DataNode *node, const DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
std::vector< std::string > m_ReadFiles
virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath)
static std::string NO_NAME_VALUE()
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
std::string GetLocalFileName() const
Get a local file name for reading.
void SetMimeTypePrefix(const std::string &prefix)
void SetDefaultOptions(const Options &defaultOptions)
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
~AbstractFileReader() override
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
void SetDescription(const std::string &description)
Options GetDefaultOptions() const
Options GetOptions() const override
returns a list of the supported options
void AddProgressCallback(const ProgressCallback &callback) override
virtual std::istream * GetInputStream() const =0
Get the input stream.
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
void SetRanking(int ranking)
Set the service ranking for this file reader.
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
std::vector< std::string > GetReadFiles() override
Base class for creating mitk::BaseData objects from files or streams.
static std::string CreateTemporaryFile(std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
virtual std::string GetInputLocation() const =0
Get the current input location.
static std::string GetName(std::string fileName, std::string suffix)
std::string GetInputLocation() const override
Get the current input location.
The common interface for all MITK file readers.
void SetInput(const std::string &location) override
Set the input location.
std::string GetMimeTypePrefix() const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
void RemoveProgressCallback(const ProgressCallback &callback) override
Class for nodes of the DataTree.