Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
List of all members | Properties | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
qSlicerCoreIOManager Class Reference

#include <Base/QTCore/qSlicerCoreIOManager.h>

Inheritance diagram for qSlicerCoreIOManager:
Inheritance graph
[legend]
Collaboration diagram for qSlicerCoreIOManager:
Collaboration graph
[legend]

Properties

QString defaultSceneFileType
 

Public Slots

void setDefaultSceneFileType (QString)
 

Signals

void fileSaved (const qSlicerIO::IOProperties &savedFileParameters)
 
void newFileLoaded (const qSlicerIO::IOProperties &loadedFileParameters)
 

Public Member Functions

Q_INVOKABLE void addDefaultStorageNodes ()
 
Q_INVOKABLE QStringList allReadableFileExtensions () const
 
Q_INVOKABLE QStringList allWritableFileExtensions () const
 
Q_INVOKABLE QString completeSlicerWritableFileNameSuffix (vtkMRMLStorableNode *node) const
 
Q_INVOKABLE QString defaultSceneFileType () const
 Defines the file format that should be offered by default when the scene is saved. More...
 
Q_INVOKABLE void emitFileSaved (const QVariantMap &savedFileParameters)
 
Q_INVOKABLE void emitNewFileLoaded (const QVariantMap &loadedFileParameters)
 
Q_INVOKABLE bool examineFileInfoList (QFileInfoList &fileInfoList, QFileInfo &archetypeEntry, QString &readerDescription, qSlicerIO::IOProperties &ioProperties) const
 
Q_INVOKABLE bool exportNodes (const QList< qSlicerIO::IOProperties > &parameterMaps, bool hardenTransforms, vtkMRMLMessageCollection *userMessages=nullptr)
 
Q_INVOKABLE bool exportNodes (const QStringList &nodeIDs, const QStringList &fileNames, const qSlicerIO::IOProperties &commonParameterMap, bool hardenTransforms, vtkMRMLMessageCollection *userMessages=nullptr)
 
Q_INVOKABLE QString extractKnownExtension (const QString &fileName, vtkObject *object)
 
Q_INVOKABLE QStringList fileDescriptions (const QString &file) const
 
QStringList fileDescriptionsByType (const qSlicerIO::IOFileType fileType) const
 
qSlicerIOOptionsfileOptions (const QString &fileDescription) const
 Return the file option associated with a file type. More...
 
Q_INVOKABLE qSlicerIO::IOFileType fileType (const QString &file) const
 Return the file type associated with a file. More...
 
Q_INVOKABLE qSlicerIO::IOFileType fileTypeFromDescription (const QString &fileDescription) const
 
Q_INVOKABLE QList< qSlicerIO::IOFileTypefileTypes (const QString &file) const
 
Q_INVOKABLE QStringList fileWriterDescriptions (const qSlicerIO::IOFileType &fileType) const
 
Q_INVOKABLE QStringList fileWriterExtensions (vtkObject *object) const
 
Q_INVOKABLE qSlicerIO::IOFileType fileWriterFileType (vtkObject *object, const QString &format=QString()) const
 Return the file type associated with an VTK object. More...
 
qSlicerIOOptionsfileWriterOptions (vtkObject *object, const QString &extension) const
 
Q_INVOKABLE bool loadFile (const QString &fileName, vtkMRMLMessageCollection *userMessages=nullptr)
 
virtual Q_INVOKABLE bool loadNodes (const qSlicerIO::IOFileType &fileType, const qSlicerIO::IOProperties &parameters, vtkCollection *loadedNodes=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
 
virtual bool loadNodes (const QList< qSlicerIO::IOProperties > &files, vtkCollection *loadedNodes=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
 
vtkMRMLNodeloadNodesAndGetFirst (qSlicerIO::IOFileType fileType, const qSlicerIO::IOProperties &parameters, vtkMRMLMessageCollection *userMessages=nullptr)
 
Q_INVOKABLE bool loadScene (const QString &fileName, bool clear=true, vtkMRMLMessageCollection *userMessages=nullptr)
 
 qSlicerCoreIOManager (QObject *parent=nullptr)
 
void registerIO (qSlicerIO *io)
 
Q_INVOKABLE bool saveNodes (qSlicerIO::IOFileType fileType, const qSlicerIO::IOProperties &parameters, vtkMRMLMessageCollection *userMessages=nullptr, vtkMRMLScene *scene=nullptr)
 
Q_INVOKABLE bool saveScene (const QString &fileName, QImage screenShot, vtkMRMLMessageCollection *userMessages=nullptr)
 
Q_INVOKABLE QString stripKnownExtension (const QString &fileName, vtkObject *object)
 
 ~qSlicerCoreIOManager () override
 

Static Public Member Functions

static Q_INVOKABLE vtkMRMLStorageNodecreateAndAddDefaultStorageNode (vtkMRMLStorableNode *node)
 Create and add default storage node. More...
 
static Q_INVOKABLE QRegExp fileNameRegExp (const QString &extension=QString())
 
static Q_INVOKABLE QString forceFileNameValidCharacters (const QString &filename)
 Remove characters that are likely to cause problems in a filename. More...
 

Protected Member Functions

qSlicerFileReaderreader (const QString &ioDescription) const
 
const QList< qSlicerFileReader * > & readers () const
 Returns the list of registered readers. More...
 
QList< qSlicerFileReader * > readers (const qSlicerIO::IOFileType &fileType) const
 Returns the list of registered readers or writers associated with fileType. More...
 
const QList< qSlicerFileWriter * > & writers () const
 Returns the list of registered writers. More...
 
QList< qSlicerFileWriter * > writers (const qSlicerIO::IOFileType &fileType) const
 Returns the list of registered writers for a given fileType. More...
 

Protected Attributes

QScopedPointer< qSlicerCoreIOManagerPrivate > d_ptr
 

Detailed Description

Definition at line 49 of file qSlicerCoreIOManager.h.

Property Documentation

◆ defaultSceneFileType

QString qSlicerCoreIOManager::defaultSceneFileType
readwrite

Definition at line 51 of file qSlicerCoreIOManager.h.

Constructor & Destructor Documentation

◆ qSlicerCoreIOManager()

qSlicerCoreIOManager::qSlicerCoreIOManager ( QObject *  parent = nullptr)

◆ ~qSlicerCoreIOManager()

qSlicerCoreIOManager::~qSlicerCoreIOManager ( )
override

Member Function Documentation

◆ addDefaultStorageNodes()

Q_INVOKABLE void qSlicerCoreIOManager::addDefaultStorageNodes ( )

Create default storage nodes for all storable nodes that are to be saved with the scene and do not have a storage node already File name is set based on node name, using use default file extension, with special characters in the node name percent-encoded. This method can be used to ensure a storage node exists before writing a storable node to file by calling storableNode->GetStorageNode()->WriteData(storableNode).

◆ allReadableFileExtensions()

Q_INVOKABLE QStringList qSlicerCoreIOManager::allReadableFileExtensions ( ) const

Return a string list of all the readable file extensions for all registered types of storage nodes. Includes the leading dot.

◆ allWritableFileExtensions()

Q_INVOKABLE QStringList qSlicerCoreIOManager::allWritableFileExtensions ( ) const

Return a string list of all the writable file extensions for all registered types of storage nodes. Includes the leading dot.

◆ completeSlicerWritableFileNameSuffix()

Q_INVOKABLE QString qSlicerCoreIOManager::completeSlicerWritableFileNameSuffix ( vtkMRMLStorableNode node) const

Returns a full extension for this storable node that is recognised by Slicer IO. Consults the storage node for a list of known suffixes, if no match is found and the .* extension exists, return the Qt completeSuffix string. If .* is not in the complete list of known suffixes, returns an empty suffix. Always includes the leading dot.

◆ createAndAddDefaultStorageNode()

static Q_INVOKABLE vtkMRMLStorageNode* qSlicerCoreIOManager::createAndAddDefaultStorageNode ( vtkMRMLStorableNode node)
static

Create and add default storage node.

◆ defaultSceneFileType()

Q_INVOKABLE QString qSlicerCoreIOManager::defaultSceneFileType ( ) const

Defines the file format that should be offered by default when the scene is saved.

◆ emitFileSaved()

Q_INVOKABLE void qSlicerCoreIOManager::emitFileSaved ( const QVariantMap savedFileParameters)

This function should be used from python scripted module willing to interface with the qSlicerCoreIOManager. It will emit the signal fileSaved().

See also
fileSaved()

◆ emitNewFileLoaded()

Q_INVOKABLE void qSlicerCoreIOManager::emitNewFileLoaded ( const QVariantMap loadedFileParameters)

This function should be used from python scripted module willing to interface with the qSlicerCoreIOManager. It will emit the signal newFileLoaded().

See also
newFileLoaded()

◆ examineFileInfoList()

Q_INVOKABLE bool qSlicerCoreIOManager::examineFileInfoList ( QFileInfoList &  fileInfoList,
QFileInfo &  archetypeEntry,
QString &  readerDescription,
qSlicerIO::IOProperties ioProperties 
) const

Iterates through readers looking at the fileInfoList to see if there is an entry that can serve as an archetype for loading multiple fileInfos. If so, the reader removes the recognized fileInfos from the list and sets the ioProperties so that the corresponding loader will read these files. The archetypeEntry will contain the fileInfo for the archetype and the method returns true. If no pattern is recognized the method returns false. The specific motivating use case is when the file list contains a set of related files, such as a list of image files that are recognized as a volume. But other cases could also make sense, such as when a file format has a set or related files such as textures or material files for a surface model.

See also
qSlicerDataDialog
qSlicerFileReader

◆ exportNodes() [1/2]

Q_INVOKABLE bool qSlicerCoreIOManager::exportNodes ( const QList< qSlicerIO::IOProperties > &  parameterMaps,
bool  hardenTransforms,
vtkMRMLMessageCollection userMessages = nullptr 
)

Export nodes using the registered writers. Return true on success, false otherwise. Unlike saveNodes(), this function creates a temporary scene while saving, in order to to avoid modifying storage nodes in the current scene. The list parameterMaps should consist of maps that each specify a "nodeID" (ID of a node in the main scene), a "fileName" (an absolute file path), a "fileFormat" (e.g. "NRRD (.nrrd)"), and any other options that the associated writer may end up using.

Parameters
parameterMapsFor each node to exported, a map of parameters that will get passed to qSlicerCoreIOManager::saveNodes.
hardenTransformsWhether to temporarily apply transform hardening before export.
userMessagesIf a valid pointer is passed, then error messages may be returned in it.
See also
qSlicerNodeWriter, qSlicerIO::IOProperties, qSlicerIO::IOFileType, vtkMRMLStorageNode, saveNodes().

◆ exportNodes() [2/2]

Q_INVOKABLE bool qSlicerCoreIOManager::exportNodes ( const QStringList &  nodeIDs,
const QStringList &  fileNames,
const qSlicerIO::IOProperties commonParameterMap,
bool  hardenTransforms,
vtkMRMLMessageCollection userMessages = nullptr 
)

Export nodes using the registered writers with an API that is usable from Python. It only allows exporting all nodes with the same parameters. Return true on success, false otherwise.

See also
exportNodes().

◆ extractKnownExtension()

Q_INVOKABLE QString qSlicerCoreIOManager::extractKnownExtension ( const QString &  fileName,
vtkObject *  object 
)

If fileName ends with an extension that is associated with object, then return that extension. Otherwise return an empty string. If there are multiple candidates (such as for "something.seg.nrrd" both ".nrrd" and ".seg.nrrd" extensions match) then the longest is returned.

◆ fileDescriptions()

Q_INVOKABLE QStringList qSlicerCoreIOManager::fileDescriptions ( const QString &  file) const

Return the file description associated with a file Usually the description is a short text of one or two words e.g. Volume, Model, ...

◆ fileDescriptionsByType()

QStringList qSlicerCoreIOManager::fileDescriptionsByType ( const qSlicerIO::IOFileType  fileType) const

◆ fileNameRegExp()

static Q_INVOKABLE QRegExp qSlicerCoreIOManager::fileNameRegExp ( const QString &  extension = QString())
static

Generate a regular expression that can ensure a filename has a valid extension. Example of supported extensions: "", "*", ".*", ".jpg", ".png" ".tar.gz"... An empty extension or "*" means any filename (or directory) is valid

◆ fileOptions()

qSlicerIOOptions* qSlicerCoreIOManager::fileOptions ( const QString &  fileDescription) const

Return the file option associated with a file type.

◆ fileSaved

void qSlicerCoreIOManager::fileSaved ( const qSlicerIO::IOProperties savedFileParameters)
signal

This signal is emitted each time a file is saved using saveNodes() The savedFileParameters QVariant map contains the parameters passed to the writer.

See also
saveNodes()

◆ fileType()

Q_INVOKABLE qSlicerIO::IOFileType qSlicerCoreIOManager::fileType ( const QString &  file) const

Return the file type associated with a file.

◆ fileTypeFromDescription()

Q_INVOKABLE qSlicerIO::IOFileType qSlicerCoreIOManager::fileTypeFromDescription ( const QString &  fileDescription) const

◆ fileTypes()

Q_INVOKABLE QList<qSlicerIO::IOFileType> qSlicerCoreIOManager::fileTypes ( const QString &  file) const

◆ fileWriterDescriptions()

Q_INVOKABLE QStringList qSlicerCoreIOManager::fileWriterDescriptions ( const qSlicerIO::IOFileType fileType) const

◆ fileWriterExtensions()

Q_INVOKABLE QStringList qSlicerCoreIOManager::fileWriterExtensions ( vtkObject *  object) const

◆ fileWriterFileType()

Q_INVOKABLE qSlicerIO::IOFileType qSlicerCoreIOManager::fileWriterFileType ( vtkObject *  object,
const QString &  format = QString() 
) const

Return the file type associated with an VTK object.

◆ fileWriterOptions()

qSlicerIOOptions* qSlicerCoreIOManager::fileWriterOptions ( vtkObject *  object,
const QString &  extension 
) const

◆ forceFileNameValidCharacters()

static Q_INVOKABLE QString qSlicerCoreIOManager::forceFileNameValidCharacters ( const QString &  filename)
static

Remove characters that are likely to cause problems in a filename.

◆ loadFile()

Q_INVOKABLE bool qSlicerCoreIOManager::loadFile ( const QString &  fileName,
vtkMRMLMessageCollection userMessages = nullptr 
)

Convenient function to load a file. All the options (e.g. filetype) are chosen by default. If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

◆ loadNodes() [1/2]

virtual Q_INVOKABLE bool qSlicerCoreIOManager::loadNodes ( const qSlicerIO::IOFileType fileType,
const qSlicerIO::IOProperties parameters,
vtkCollection *  loadedNodes = nullptr,
vtkMRMLMessageCollection userMessages = nullptr 
)
virtual

Load a list of nodes corresponding to fileType. A given fileType corresponds to a specific reader qSlicerIO. A map of qvariant allows to specify which parameters should be passed to the reader. The function return 0 if it fails. The map associated with most of the fileType should contains either fileName (QString or QStringList) or fileNames (QStringList). More specific parameters could also be set. For example, the volume reader qSlicerVolumesIO could also be called with the following parameters: LabelMap (bool), Center (bool) If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

Note
Make also sure the case of parameter name is respected
See also
qSlicerIO::IOProperties, qSlicerIO::IOFileType, saveNodes()

Reimplemented in qSlicerIOManager.

◆ loadNodes() [2/2]

virtual bool qSlicerCoreIOManager::loadNodes ( const QList< qSlicerIO::IOProperties > &  files,
vtkCollection *  loadedNodes = nullptr,
vtkMRMLMessageCollection userMessages = nullptr 
)
virtual

Utility function that loads a bunch of files. The "fileType" attribute should in the parameter map for each node to load. If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

Reimplemented in qSlicerIOManager.

◆ loadNodesAndGetFirst()

vtkMRMLNode* qSlicerCoreIOManager::loadNodesAndGetFirst ( qSlicerIO::IOFileType  fileType,
const qSlicerIO::IOProperties parameters,
vtkMRMLMessageCollection userMessages = nullptr 
)

Load a list of node corresponding to fileType and return the first loaded node. This function is provided for convenience and is equivalent to call loadNodes with a vtkCollection parameter and retrieve the first element. If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

◆ loadScene()

Q_INVOKABLE bool qSlicerCoreIOManager::loadScene ( const QString &  fileName,
bool  clear = true,
vtkMRMLMessageCollection userMessages = nullptr 
)

Load/import a scene corresponding to fileName This function is provided for convenience and is equivalent to call loadNodes function with QString("SceneFile"). If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

◆ newFileLoaded

void qSlicerCoreIOManager::newFileLoaded ( const qSlicerIO::IOProperties loadedFileParameters)
signal

This signal is emitted each time a file is loaded using loadNodes() The loadedFileParameters QVariant map contains the parameters passed to the reader and also the fileType and nodeIDs keys respectively associated with a QString and a QStringList.

See also
loadNodes(const qSlicerIO::IOFileType&, const qSlicerIO::IOProperties&, vtkCollection*)

◆ reader()

qSlicerFileReader* qSlicerCoreIOManager::reader ( const QString &  ioDescription) const
protected

◆ readers() [1/2]

const QList<qSlicerFileReader*>& qSlicerCoreIOManager::readers ( ) const
protected

Returns the list of registered readers.

◆ readers() [2/2]

QList<qSlicerFileReader*> qSlicerCoreIOManager::readers ( const qSlicerIO::IOFileType fileType) const
protected

Returns the list of registered readers or writers associated with fileType.

◆ registerIO()

void qSlicerCoreIOManager::registerIO ( qSlicerIO io)

Register the reader/writer io Note also that the IOManager takes ownership of io

◆ saveNodes()

Q_INVOKABLE bool qSlicerCoreIOManager::saveNodes ( qSlicerIO::IOFileType  fileType,
const qSlicerIO::IOProperties parameters,
vtkMRMLMessageCollection userMessages = nullptr,
vtkMRMLScene scene = nullptr 
)

Save nodes (or scene) using the registered writers. Return true on success, false otherwise. Attributes are typically: For all: QString fileName (or QStringList fileNames) For nodes: QString nodeID, bool useCompression If a valid pointer is passed to userMessages additional error or warning information may be returned in it. If a valid pointer is passed to scene, writers will be told to use that scene instead of the current scene.

See also
qSlicerNodeWriter, qSlicerIO::IOProperties, qSlicerIO::IOFileType, loadNodes(), exportNodes()

◆ saveScene()

Q_INVOKABLE bool qSlicerCoreIOManager::saveScene ( const QString &  fileName,
QImage  screenShot,
vtkMRMLMessageCollection userMessages = nullptr 
)

Save a scene corresponding to fileName This function is provided for convenience and is equivalent to call saveNodes function with QString("SceneFile") with the fileName and screenShot set as properties. If a valid pointer is passed to userMessages additional error or warning information may be returned in it.

◆ setDefaultSceneFileType

void qSlicerCoreIOManager::setDefaultSceneFileType ( QString  )
slot

Defines the file format that should be offered by default when the scene is saved. Valid options are defined in qSlicerSceneWriter (for example, "MRML Scene (.mrml)" or "Medical Reality Bundle (.mrb)").

◆ stripKnownExtension()

Q_INVOKABLE QString qSlicerCoreIOManager::stripKnownExtension ( const QString &  fileName,
vtkObject *  object 
)

If fileName ends with an extension that is associated with object, then return a stripped version of fileName, where that extension has been chopped off. If the extension is duplicated in the tail of fileName, then all duplicates are stripped away.

◆ writers() [1/2]

const QList<qSlicerFileWriter*>& qSlicerCoreIOManager::writers ( ) const
protected

Returns the list of registered writers.

◆ writers() [2/2]

QList<qSlicerFileWriter*> qSlicerCoreIOManager::writers ( const qSlicerIO::IOFileType fileType) const
protected

Returns the list of registered writers for a given fileType.

Member Data Documentation

◆ d_ptr

QScopedPointer<qSlicerCoreIOManagerPrivate> qSlicerCoreIOManager::d_ptr
protected

Definition at line 285 of file qSlicerCoreIOManager.h.


The documentation for this class was generated from the following file: