18#ifndef __vtkMRMLFileIOManager_h
19#define __vtkMRMLFileIOManager_h
21#include "vtkMRMLLogicExport.h"
24#include <vtkSmartPointer.h>
25#include <vtkWeakPointer.h>
55 void PrintSelf(ostream& os, vtkIndent indent)
override;
98 const std::string& fileType,
99 const std::vector<std::string>& nodeClassNames,
100 bool supportUseCompression =
true);
249 vtkCollection* loadedNodes =
nullptr,
290 const std::vector<std::string>& fileNames,
292 bool hardenTransforms,
330 template <
typename HandlerType>
331 static std::vector<vtkSmartPointer<HandlerType>>
SortedByConfidence(
const std::vector<vtkSmartPointer<HandlerType>>& handlers,
332 const std::vector<double>& confidences);
340 std::vector<vtkSmartPointer<vtkMRMLFileReader>>
Readers;
341 std::vector<vtkSmartPointer<vtkMRMLFileWriter>>
Writers;
398 static void OnSceneProgress(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
bool LoadFile(const std::string &fileName, vtkMRMLMessageCollection *userMessages=nullptr)
Load a file. All the options (e.g., file type) are chosen by default.
std::vector< vtkSmartPointer< vtkMRMLFileReader > > GetReadersForFileType(const std::string &fileType)
The readers of a file type, in the order they were registered.
vtkWeakPointer< vtkMRMLApplicationLogic > ApplicationLogic
void PrintSelf(ostream &os, vtkIndent indent) override
std::string GetFileTypeForObject(vtkObject *object)
Same as GetFileWriterFileType(object).
@ OperationEndEvent
Loading or saving of files is completed. Call data: vtkMRMLOperationProgress.
@ HandlerRegisteredEvent
A reader or writer is registered. Call data: the reader or writer (vtkMRMLFileIOHandler).
@ OperationStartEvent
Loading or saving of files is started. Call data: vtkMRMLOperationProgress.
@ HandlerUnregisteredEvent
A reader or writer is unregistered. Call data: the reader or writer (vtkMRMLFileIOHandler).
@ FileSavedEvent
A file is saved. Call data: vtkMRMLIOProperties of the saved file.
ListProgress StartListProgress(const std::string &title, int numberOfFiles)
std::vector< vtkSmartPointer< vtkMRMLFileWriter > > Writers
std::vector< std::string > GetNameFiltersForFileType(const std::string &fileType, bool writers)
The name filters of every reader (or writer) of a file type: "Mimics project (*.mcs)".
virtual bool LoadNodes(const std::string &fileType, vtkMRMLIOProperties *properties, vtkCollection *loadedNodes=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
Loading.
std::string GetFileWriterFileType(vtkObject *object, const std::string &format=std::string())
The file type of the best file writer for this object, or an empty string.
bool ExportNodes(const std::vector< std::string > &nodeIDs, const std::vector< std::string > &fileNames, vtkMRMLIOProperties *commonProperties, bool hardenTransforms, vtkMRMLMessageCollection *userMessages=nullptr)
Export nodes, with the same properties for all nodes.
std::vector< std::string > GetExtensionsForFileType(const std::string &fileType, bool writers)
The extensions of every reader (or writer) of a file type: ".mcs", ".mcs.gz".
vtkWeakPointer< vtkMRMLScene > Scene
std::vector< vtkSmartPointer< vtkMRMLFileReader > > Readers
std::vector< std::string > GetAllWritableFileExtensions()
File extensions and names.
vtkMRMLFileWriter * GetWriterByClassName(const std::string &className) const
static std::string ForceFileNameValidCharacters(const std::string &filename)
Remove characters that are likely to cause problems in a filename.
std::string GetDefaultSceneFileType() const
static void OnSceneProgress(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
Forwards scene import or save progress (percent) as file progress.
void AddDefaultStorageNodes()
double MaximumProgressUpdatesPerSecond
std::vector< std::string > GetFileTypesForFile(const std::string &filePath)
All the file types that can be used for reading the file, most likely first.
void InvokeFileSavedEvent(vtkMRMLIOProperties *savedFileProperties)
Invoke FileSavedEvent. It may be used by writers that save files without the manager.
void RegisterReader(vtkMRMLFileReader *reader)
vtkMRMLNodeWriter * RegisterNodeWriter(const std::string &description, const std::string &fileType, const std::vector< std::string > &nodeClassNames, bool supportUseCompression=true)
~vtkMRMLFileIOManager() override
static vtkMRMLStorageNode * CreateAndAddDefaultStorageNode(vtkMRMLStorableNode *node)
Create and add default storage node.
double LastProgressEventTime
Time of the last invoked progress event (universal time in seconds)
vtkMRMLFileWriter * GetWriterForObject(vtkObject *object, const std::string &format=std::string())
std::string StripKnownExtension(const std::string &fileName, vtkObject *object)
std::vector< std::string > GetFileDescriptionsByType(const std::string &fileType)
Descriptions of all the readers of a file type. Usually there is only one reader for a file type.
std::vector< std::string > GetReaderFileTypes()
The file types that are registered, and what belongs to each of them.
void UnregisterHandler(vtkMRMLFileIOHandler *handler)
Remove a reader or a writer. Whoever registered a handler is responsible for unregistering it.
void EndOperationProgress(bool operationStarted, bool aborted=false)
bool LoadScene(const std::string &fileName, bool clear=true, vtkMRMLMessageCollection *userMessages=nullptr)
Load or import a scene.
virtual void SetScene(vtkMRMLScene *scene)
The scene the handlers read into and write from.
void SetDefaultSceneFileType(const std::string &fileType)
static vtkMRMLFileIOManager * New()
void StartListItemProgress(ListProgress &listProgress, int fileIndex)
Report that processing of the file at fileIndex starts.
void ReportFileProgress(double fileProgress, const std::string &text=std::string())
std::vector< vtkSmartPointer< vtkMRMLFileReader > > GetReadersForFile(const std::string &filePath)
Readers.
static std::vector< vtkSmartPointer< HandlerType > > SortedByConfidence(const std::vector< vtkSmartPointer< HandlerType > > &handlers, const std::vector< double > &confidences)
int GetNumberOfWriters() const
bool ExportNode(vtkMRMLIOProperties *properties, vtkMRMLScene *temporaryScene, bool hardenTransforms, vtkMRMLMessageCollection *userMessages)
void RegisterWriter(vtkMRMLFileWriter *writer)
bool SaveScene(const std::string &fileName, vtkImageData *screenShot=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
vtkMRMLFileReader * GetReaderByDescription(const std::string &description)
The reader that has the specified description, or nullptr.
std::vector< vtkSmartPointer< vtkMRMLFileWriter > > GetWritersForFile(const std::string &fileType, vtkMRMLIOProperties *properties, vtkMRMLScene *scene)
int GetNumberOfReaders() const
What is registered.
std::vector< vtkSmartPointer< vtkMRMLFileWriter > > GetWritersForObject(vtkObject *object)
Writers.
std::vector< std::string > GetFileWriterDescriptions(const std::string &fileType)
Descriptions of all writers of a file type.
vtkMRMLApplicationLogic * GetApplicationLogic() const
vtkMRMLFileReader * GetNthReader(int index) const
std::string GetFileTypeFromDescription(const std::string &description)
The file type of the reader that has the specified description, or an empty string.
vtkSmartPointer< vtkMRMLOperationProgress > OperationProgress
Progress of the loading or saving operation that is in progress (nullptr if no operation is in progre...
virtual bool LoadNodesFromList(vtkCollection *propertiesList, vtkCollection *loadedNodes=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
void InvokeNewFileLoadedEvent(vtkMRMLIOProperties *loadedFileProperties)
Invoke NewFileLoadedEvent. It may be used by readers that load files without the manager.
vtkMRMLFileWriter * GetNthWriter(int index) const
void EndListProgress(ListProgress &listProgress, vtkMRMLMessageCollection *userMessages, const std::string &abortedMessageFormat)
std::string ForceFileNameMaxLength(const std::string &filename, int extensionLength, int maxLength=-1)
std::string DefaultSceneFileType
bool SaveNodes(const std::string &fileType, vtkMRMLIOProperties *properties, vtkMRMLMessageCollection *userMessages=nullptr, vtkMRMLScene *scene=nullptr)
Saving.
void SetApplicationLogic(vtkMRMLApplicationLogic *applicationLogic)
vtkMRMLScene * GetScene() const
vtkMRMLNode * LoadNodesAndGetFirst(const std::string &fileType, vtkMRMLIOProperties *properties, vtkMRMLMessageCollection *userMessages=nullptr)
Load nodes and return the first loaded node.
std::vector< vtkSmartPointer< vtkMRMLFileWriter > > GetWritersForFileType(const std::string &fileType)
The writers of a file type, in the order they were registered.
bool StartOperationProgress(const std::string &title, int numberOfFiles)
std::vector< std::string > GetWriterFileTypes()
bool ProgressEventPending
True if progress changed since the last progress event.
static std::string GetFileNameValidCharactersPattern()
bool ExportNodes(vtkCollection *propertiesList, bool hardenTransforms, vtkMRMLMessageCollection *userMessages=nullptr)
std::string GetFileTypeForFile(const std::string &filePath)
The file type of the reader that is surest it can read this file ("VolumeFile"), or an empty string.
std::string ExtractKnownExtension(const std::string &fileName, vtkObject *object)
std::vector< std::string > GetAllReadableFileExtensions()
All the readable file extensions for all registered types of storage nodes. Includes the leading dot.
vtkMRMLFileReader * GetReaderForFile(const std::string &filePath)
The reader that is surest it can read this file, or nullptr.
void RegisterHandler(vtkMRMLFileIOHandler *handler)
Add a reader or a writer (calls RegisterReader() or RegisterWriter(), depending on the type of the ha...
std::string GetDescriptionForFileType(const std::string &fileType, bool writers)
What a file type is called ("Volume"), from the first handler that has a description.
bool EndListItemProgress(ListProgress &listProgress, int fileIndex)
vtkMRMLFileReader * ExamineFileList(std::vector< std::string > &fileList, vtkMRMLIOProperties *ioProperties)
bool SceneProgressObserved
True while the scene is observed for reporting its import progress.
std::vector< std::string > GetFileWriterExtensions(vtkObject *object)
Name filters of all writers that can write the object, the most confident writer's first.
int DefaultMaximumFileNameLength
std::vector< std::string > GetFileDescriptionsForFile(const std::string &filePath)
The descriptions ("Volume", "Segmentation", ...) of the readers that can read the file,...
std::string GetCompleteSlicerWritableFileNameSuffix(vtkMRMLStorableNode *node)
void InvokeProgressEvent(bool force=false)
vtkMRMLFileReader * GetReaderByClassName(const std::string &className) const
Get a registered reader or writer by its class name (exact match). Returns nullptr if not found.
Abstract Superclass for all specific types of MRML nodes.
Progress of a long operation, such as loading files.
A set of MRML Nodes that supports serialization and undo/redo.
MRML node to represent a 3D surface model.
A superclass for other storage nodes.
State of processing (loading or saving) a list of files.
bool Aborted
True if processing of the list was aborted (some files were not processed)
double RangeMinimum
Part of the overall progress range that processing of the list covers.
bool OperationStarted
True if processing of the list started an operation (it is not part of another operation)
int NumberOfProcessedFiles