29 #include <itksys/SystemTools.hxx>
36 :
std::istream(NULL), m_Stream(NULL)
41 this->init(stream->rdbuf());
46 this->init(m_Stream->rdbuf());
55 Impl(
const Impl &other) :
FileReaderWriterBase(other), m_Stream(NULL), m_PrototypeFactory(NULL) {}
56 std::string m_Location;
57 std::string m_TmpFile;
58 std::istream *m_Stream;
69 delete d->m_PrototypeFactory;
71 if (!d->m_TmpFile.empty())
73 std::remove(d->m_TmpFile.c_str());
83 d->SetMimeType(mimeType);
84 d->SetDescription(description);
91 std::vector<BaseData::Pointer> result;
96 for (DataStorage::SetOfObjects::ConstIterator iter = dataNodes->Begin(), iterEnd = dataNodes->End();
100 result.push_back(iter.Value()->GetData());
108 std::vector<BaseData::Pointer> data = this->
Read();
109 for (std::vector<BaseData::Pointer>::iterator iter = data.begin(); iter != data.end(); ++iter)
112 node->SetData(*iter);
115 result->InsertElement(result->Size(), node);
129 if (itksys::SystemTools::FileExists(this->
GetInputLocation().c_str(),
true))
141 if (d->m_PrototypeFactory)
149 d->RegisterMimeType(context);
153 MITK_WARN <<
"Not registering reader due to empty MIME type.";
172 delete us::ExtractInterface<IFileReader>(service);
176 d->m_PrototypeFactory =
new PrototypeFactory(
this);
178 d->m_Reg = context->RegisterService<
IFileReader>(d->m_PrototypeFactory, props);
186 d->m_Reg.Unregister();
188 catch (
const std::exception &)
205 return d->RegisterMimeType(context);
214 std::string localFileName;
217 if (d->m_TmpFile.empty())
220 std::string ext = itksys::SystemTools::GetFilenameExtension(this->
GetInputLocation());
221 std::ofstream tmpStream;
223 tmpStream, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary,
"XXXXXX" + ext);
224 tmpStream << d->m_Stream->rdbuf();
225 d->m_TmpFile = localFileName;
229 localFileName = d->m_TmpFile;
234 localFileName = d->m_Location;
236 return localFileName;
243 d->SetDefaultOptions(defaultOptions);
249 d->m_Location = location;
255 if (d->m_Stream != is && !d->m_TmpFile.empty())
257 std::remove(d->m_TmpFile.c_str());
258 d->m_TmpFile.clear();
260 d->m_Location = location;
276 d->RemoveProgressCallback(callback);
288 if (!filePath.empty())
297 if (nameProp.IsNull() || (strcmp(nameProp->GetValue(),
"No Name!") == 0))
302 if (baseDataNameProp.IsNull() || (strcmp(baseDataNameProp->GetValue(),
"No Name!") == 0))
virtual us::ServiceProperties GetServiceProperties() const
virtual void Add(mitk::DataNode *node, const mitk::DataStorage::SetOfObjects *parents=nullptr)=0
Adds a DataNode containing a data object to its internal storage.
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
virtual us::Any GetOption(const std::string &name) const override
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()
virtual void SetOption(const std::string &name, const us::Any &value) override
virtual 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.
virtual std::istream * GetInputStream() const override
Get the input stream.
virtual 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.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
std::string GetLocalFileName() const
Get a local file name for reading.
static std::string PROP_MIMETYPE()
Service property name for the mime-type associated with this file writer.
virtual std::vector< itk::SmartPointer< BaseData > > Read() override=0
Reads a path or stream and creates a list of BaseData objects.
itk::SmartPointer< const Self > ConstPointer
virtual void SetDefaultDataNodeProperties(DataNode *node, const std::string &filePath)
std::string GetMimeTypePrefix() const
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
void SetMimeTypePrefix(const std::string &prefix)
void SetDefaultOptions(const Options &defaultOptions)
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
std::string GetDescription() const
Options GetDefaultOptions() const
void SetDescription(const std::string &description)
MimeType GetRegisteredMimeType() const
std::string GetName() const
Returns the unique name for the MimeType.
const CustomMimeType * GetMimeType() const
virtual Options GetOptions() const override
returns a list of the supported options
virtual 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.
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)
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
virtual std::string GetInputLocation() const override
Get the current input location.
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;.
The common interface for all MITK file readers.
virtual void SetInput(const std::string &location) override
Set the input location.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
virtual void RemoveProgressCallback(const ProgressCallback &callback) override
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.