Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLFileIOManager.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware Inc.
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16==============================================================================*/
17
18#ifndef __vtkMRMLFileIOManager_h
19#define __vtkMRMLFileIOManager_h
20
21#include "vtkMRMLLogicExport.h"
22
23#include <vtkObject.h>
24#include <vtkSmartPointer.h>
25#include <vtkWeakPointer.h>
26
27#include <string>
28#include <vector>
29
30class vtkCollection;
31class vtkImageData;
33class vtkMRMLNode;
34class vtkMRMLScene;
43
49class VTK_MRML_LOGIC_EXPORT vtkMRMLFileIOManager : public vtkObject
50{
51public:
53 vtkTypeMacro(vtkMRMLFileIOManager, vtkObject);
54 void PrintSelf(ostream& os, vtkIndent indent) override;
55
59 enum
60 {
65 };
66
68 virtual void SetScene(vtkMRMLScene* scene);
70
75
77
89 vtkMRMLNodeWriter* RegisterNodeWriter(const std::string& description,
90 const std::string& fileType,
91 const std::vector<std::string>& nodeClassNames,
92 bool supportUseCompression = true);
96
98
99 vtkMRMLFileReader* GetReaderByClassName(const std::string& className) const;
100 vtkMRMLFileWriter* GetWriterByClassName(const std::string& className) const;
102
104
110
112
113
116 std::vector<vtkSmartPointer<vtkMRMLFileReader>> GetReadersForFile(const std::string& filePath);
118 vtkMRMLFileReader* GetReaderForFile(const std::string& filePath);
120 std::string GetFileTypeForFile(const std::string& filePath);
122 std::vector<std::string> GetFileTypesForFile(const std::string& filePath);
124 std::vector<std::string> GetFileDescriptionsForFile(const std::string& filePath);
125
127 vtkMRMLFileReader* GetReaderByDescription(const std::string& description);
129 std::string GetFileTypeFromDescription(const std::string& description);
131 std::vector<std::string> GetFileDescriptionsByType(const std::string& fileType);
132
143 vtkMRMLFileReader* ExamineFileList(std::vector<std::string>& fileList, vtkMRMLIOProperties* ioProperties);
145
147
148
150 std::vector<vtkSmartPointer<vtkMRMLFileWriter>> GetWritersForObject(vtkObject* object);
156 vtkMRMLFileWriter* GetWriterForObject(vtkObject* object, const std::string& format = std::string());
158 std::string GetFileWriterFileType(vtkObject* object, const std::string& format = std::string());
160 std::string GetFileTypeForObject(vtkObject* object);
162 std::vector<std::string> GetFileWriterDescriptions(const std::string& fileType);
164 std::vector<std::string> GetFileWriterExtensions(vtkObject* object);
166
168
169 std::vector<std::string> GetReaderFileTypes();
170 std::vector<std::string> GetWriterFileTypes();
172 std::vector<std::string> GetExtensionsForFileType(const std::string& fileType, bool writers);
174 std::vector<std::string> GetNameFiltersForFileType(const std::string& fileType, bool writers);
176 std::string GetDescriptionForFileType(const std::string& fileType, bool writers);
178 std::vector<vtkSmartPointer<vtkMRMLFileReader>> GetReadersForFileType(const std::string& fileType);
180 std::vector<vtkSmartPointer<vtkMRMLFileWriter>> GetWritersForFileType(const std::string& fileType);
182
184
185
187 std::vector<std::string> GetAllWritableFileExtensions();
189 std::vector<std::string> GetAllReadableFileExtensions();
190
195
199
201 static std::string ForceFileNameValidCharacters(const std::string& filename);
202
207 std::string ForceFileNameMaxLength(const std::string& filename, int extensionLength, int maxLength = -1);
208
213
218 std::string ExtractKnownExtension(const std::string& fileName, vtkObject* object);
219
224 std::string StripKnownExtension(const std::string& fileName, vtkObject* object);
226
228
229
236 virtual bool LoadNodes(const std::string& fileType, //
237 vtkMRMLIOProperties* properties,
238 vtkCollection* loadedNodes = nullptr,
239 vtkMRMLMessageCollection* userMessages = nullptr);
240
243 virtual bool LoadNodesFromList(vtkCollection* propertiesList, vtkCollection* loadedNodes = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
244
246 vtkMRMLNode* LoadNodesAndGetFirst(const std::string& fileType, vtkMRMLIOProperties* properties, vtkMRMLMessageCollection* userMessages = nullptr);
247
249 bool LoadScene(const std::string& fileName, bool clear = true, vtkMRMLMessageCollection* userMessages = nullptr);
250
252 bool LoadFile(const std::string& fileName, vtkMRMLMessageCollection* userMessages = nullptr);
254
256
257
262 bool SaveNodes(const std::string& fileType, vtkMRMLIOProperties* properties, vtkMRMLMessageCollection* userMessages = nullptr, vtkMRMLScene* scene = nullptr);
263
270 bool ExportNodes(vtkCollection* propertiesList, bool hardenTransforms, vtkMRMLMessageCollection* userMessages = nullptr);
271
273 bool ExportNodes(const std::vector<std::string>& nodeIDs,
274 const std::vector<std::string>& fileNames,
275 vtkMRMLIOProperties* commonProperties,
276 bool hardenTransforms,
277 vtkMRMLMessageCollection* userMessages = nullptr);
278
281 bool SaveScene(const std::string& fileName, vtkImageData* screenShot = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
282
286
290
294 void InvokeFileSavedEvent(vtkMRMLIOProperties* savedFileProperties);
295
299 std::string GetDefaultSceneFileType() const;
300 void SetDefaultSceneFileType(const std::string& fileType);
301
302protected:
305
308 template <typename HandlerType>
309 static std::vector<vtkSmartPointer<HandlerType>> SortedByConfidence(const std::vector<vtkSmartPointer<HandlerType>>& handlers, //
310 const std::vector<double>& confidences);
311
314 std::vector<vtkSmartPointer<vtkMRMLFileWriter>> GetWritersForFile(const std::string& fileType, vtkMRMLIOProperties* properties, vtkMRMLScene* scene);
315
316 vtkWeakPointer<vtkMRMLScene> Scene;
317 vtkWeakPointer<vtkMRMLApplicationLogic> ApplicationLogic;
318 std::vector<vtkSmartPointer<vtkMRMLFileReader>> Readers;
319 std::vector<vtkSmartPointer<vtkMRMLFileWriter>> Writers;
320
323
324private:
326 void operator=(const vtkMRMLFileIOManager&) = delete;
327};
328
329#endif
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).
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
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.
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.
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()
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
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.
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
std::string ForceFileNameMaxLength(const std::string &filename, int extensionLength, int maxLength=-1)
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.
std::vector< std::string > GetWriterFileTypes()
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)
std::string GetDescriptionForFileType(const std::string &fileType, bool writers)
What a file type is called ("Volume"), from the first handler that has a description.
vtkMRMLFileReader * ExamineFileList(std::vector< std::string > &fileList, vtkMRMLIOProperties *ioProperties)
std::vector< std::string > GetFileWriterExtensions(vtkObject *object)
Name filters of all writers that can write the object, the most confident writer's first.
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)
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.
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.