Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLScene.h
Go to the documentation of this file.
1/*=auto=========================================================================
2
3Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5See COPYRIGHT.txt
6or http://www.slicer.org/copyright/copyright.txt for details.
7
8Program: 3D Slicer
9Module: $RCSfile: vtkMRMLScene.h,v $
10Date: $Date: 2006/03/17 15:10:09 $
11Version: $Revision: 1.18 $
12
13=========================================================================auto=*/
14
15#ifndef __vtkMRMLScene_h
16#define __vtkMRMLScene_h
17
18// MRML includes
19#include "vtkMRML.h"
20class vtkCacheManager;
23class vtkMRMLNode;
29class vtkTagTable;
30class vtkURIHandler;
31
32// VTK includes
33#include <vtkObject.h>
34#include <vtkSmartPointer.h>
35#include <vtkWeakPointer.h>
36class vtkCallbackCommand;
37class vtkCollection;
38class vtkGeneralTransform;
39class vtkImageData;
40
41// STD includes
42#include <list>
43#include <map>
44#include <random>
45#include <set>
46#include <string>
47#include <vector>
48
53//
56class VTK_MRML_EXPORT vtkMRMLScene : public vtkObject
57{
63
64public:
65 static vtkMRMLScene* New();
66 vtkTypeMacro(vtkMRMLScene, vtkObject);
67 void PrintSelf(ostream& os, vtkIndent indent) override;
68
70 void SetURL(const char* url);
71 void SetURL(const std::string& url) { return this->SetURL(url.c_str()); };
72
74 const char* GetURL();
75
77 void SetRootDirectory(const char* dir);
78
80 const char* GetRootDirectory();
81
86 int Connect(vtkMRMLMessageCollection* userMessages = nullptr);
87
96 int Import(vtkMRMLMessageCollection* userMessages = nullptr);
97
104 int Commit(const char* url = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
105
111 void Clear(int removeSingletons = 0);
112
115
133 vtkMRMLNode* CreateNodeByClass(const char* className);
134
138
142
163 void RegisterNodeClass(vtkMRMLNode* node, const char* tagName);
164
170
178 void RegisterAbstractNodeClass(std::string className, std::string typeDisplayName);
179
181 const char* GetClassNameByTag(const char* tagName);
182
184 const char* GetTagByClassName(const char* className);
185
187 std::string GetTypeDisplayNameByClassName(std::string className);
188
193 vtkMRMLNode* GetDefaultNodeByClass(const char* className);
194
197
199 vtkCollection* GetNodes();
200
214
230 vtkMRMLNode* AddNewNodeByClass(std::string className, std::string nodeBaseName = "");
231
239 vtkMRMLNode* AddNewNodeByClassWithID(std::string className, std::string nodeBaseName, std::string nodeID);
240
243
248 void NodeAdded() { this->NodeAdded(nullptr); }
249
252
257
266
275
283 vtkMRMLNode* GetNextNodeByClass(const char* className);
284
286 vtkCollection* GetNodesByName(const char* name);
287 vtkMRMLNode* GetFirstNodeByName(const char* name);
288
300 vtkMRMLNode* GetFirstNode(const char* byName = nullptr, const char* byClass = nullptr, const int* byHideFromEditors = nullptr, bool exactNameMatch = true);
301
303 vtkMRMLNode* GetNodeByID(const char* name);
304 vtkMRMLNode* GetNodeByID(std::string name);
305
308 vtkCollection* GetNodesByClassByName(const char* className, const char* name);
309
312
315
317 vtkMRMLNode* GetNthNodeByClass(int n, const char* className);
319 vtkMRMLNode* GetFirstNodeByClass(const char* className);
320
322 int GetNumberOfNodesByClass(const char* className);
323
325 int GetNodesByClass(const char* className, std::vector<vtkMRMLNode*>& nodes);
326
328 vtkCollection* GetNodesByClass(const char* className);
329
334 vtkMRMLNode* GetSingletonNode(const char* singletonTag, const char* className);
335
343
344 std::list<std::string> GetNodeClassesList();
345
352
356 bool IsNodeClassRegistered(const std::string& className);
357
360
364
368
372 std::string GenerateUniqueName(const std::string& baseName);
373
378 const char* GetUniqueNameByString(const char* baseName);
379
384
386 void SetUndoOn() { UndoFlag = true; }
387 void SetUndoOff() { UndoFlag = false; }
388 bool GetUndoFlag() { return UndoFlag; }
389 void SetUndoFlag(bool flag) { UndoFlag = flag; }
390
392 void Undo();
393
395 void Redo();
396
399
402
404 int GetNumberOfUndoLevels() { return static_cast<int>(this->UndoStack.size()); }
405
407 int GetNumberOfRedoLevels() { return static_cast<int>(this->RedoStack.size()); }
408
411
418
424 void SaveStateForUndo(vtkCollection* nodes);
425 void SaveStateForUndo(std::vector<vtkMRMLNode*> nodes);
426
433 void AddReferencedNodeID(const char* id, vtkMRMLNode* refrencingNode);
434 bool IsNodeReferencingNodeID(vtkMRMLNode* referencingNode, const char* id);
435
445 const char* GetNthReferencedID(int n);
446
447 void RemoveReferencedNodeID(const char* id, vtkMRMLNode* refrencingNode);
448
450
452
460 void UpdateNodeReferences(vtkCollection* checkNodes = nullptr);
461
463
465
468
470
480
490
491 bool IsReservedID(const std::string& id);
492
493 void AddReservedID(const char* id);
494
496
499 const char* GetChangedID(const char* id);
500
515 vtkCollection* GetReferencedNodes(vtkMRMLNode* node, bool recursive = true);
516
518 void GetReferencingNodes(vtkMRMLNode* referencedNode, std::vector<vtkMRMLNode*>& referencingNodes);
519
527
528 int IsFilePathRelative(const char* filepath);
529
536 vtkSetMacro(LoadFromXMLString, int);
537 vtkGetMacro(LoadFromXMLString, int);
538
545 vtkSetMacro(SaveToXMLString, int);
546 vtkGetMacro(SaveToXMLString, int);
547
548 vtkSetMacro(ReadDataOnLoad, int);
549 vtkGetMacro(ReadDataOnLoad, int);
550
555 void SetSceneXMLString(const std::string& xmlString);
556
561 const std::string& GetSceneXMLString();
562
564
565 vtkGetObjectMacro(CacheManager, vtkCacheManager);
567 vtkGetObjectMacro(DataIOManager, vtkDataIOManager);
569 vtkGetObjectMacro(URIHandlerCollection, vtkCollection);
570 virtual void SetURIHandlerCollection(vtkCollection*);
571 vtkGetObjectMacro(UserTagTable, vtkTagTable);
573
578 vtkURIHandler* FindURIHandler(const char* URI);
583
629
637 int GetStates() const;
638
640 inline bool IsBatchProcessing() const;
642 inline bool IsClosing() const;
644 inline bool IsImporting() const;
646 inline bool IsRestoring() const;
648 inline bool IsUndoing() const;
650 inline bool IsRedoing() const;
651
689 void StartState(unsigned long state, int anticipatedMaxProgress = 0);
690
699 void EndState(unsigned long state);
700
705 void ProgressState(unsigned long state, double progress = 0.0);
706
708 {
714
716 MetadataAddedEvent = 66032, // ### Slicer 4.5: Simplify - Do not explicitly set for backward compat. See issue #3472
719
723 StateEvent = 0x2000,
724 StartEvent = 0x0100,
725 EndEvent = 0x0200,
727
731
735
742
746
752
756
760 };
761
763 vtkGetStringMacro(LastLoadedVersion);
764 vtkSetStringMacro(LastLoadedVersion);
765
767 vtkGetStringMacro(LastLoadedExtensions);
768 vtkSetStringMacro(LastLoadedExtensions);
769
771 vtkGetStringMacro(Version);
772 vtkSetStringMacro(Version);
773
776 vtkGetStringMacro(Extensions);
777 vtkSetStringMacro(Extensions);
778
781 static bool ParseVersion(const char* versionString, std::string& application, int& major, int& minor, int& patch, int& revision);
782
786
789
792
796 bool GetModifiedSinceRead(vtkCollection* modifiedNodes = nullptr);
797
799 vtkGetMacro(StoredTime, vtkMTimeType);
800
807 bool GetStorableNodesModifiedSinceRead(vtkCollection* modifiedStorableNodes = nullptr);
808
814 bool GetPrivateStorableNodesModifiedSinceRead(vtkCollection* modifiedStorableNodes = nullptr);
815
822
825 static void SetStorableNodesModifiedSinceRead(vtkCollection* storableNodes);
826
831
835
842 bool WriteToMRB(const char* filename, vtkImageData* thumbnail = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
843
847 bool ReadFromMRB(const char* fullName, bool clear = false, vtkMRMLMessageCollection* userMessages = nullptr);
848
854 static std::string UnpackSlicerDataBundle(const char* sdbFilePath, const char* temporaryDirectory, vtkMRMLMessageCollection* userMessages = nullptr);
855
862 bool SaveSceneToSlicerDataBundleDirectory(const char* sdbDir, vtkImageData* thumbnail = nullptr, vtkMRMLMessageCollection* userMessages = nullptr);
863
865 void SaveSceneScreenshot(vtkImageData* thumbnail);
866
876 static std::string PercentEncode(std::string s);
877
883 static std::string CreateUniqueFileName(const std::string& filename, const std::string& knownExtension = "");
884
885protected:
886 typedef std::map<std::string, std::set<std::string>> NodeReferencesType;
887
889 ~vtkMRMLScene() override;
890
893
896
901
905 void AddReferencedNodes(vtkMRMLNode* node, vtkCollection* refNodes, bool recursive = true);
906
908 void RemoveInvalidNodeReferences(vtkCollection* checkNodes, const std::set<std::string>& validNodeIDs);
909
911 static void SceneCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
912 static void NodeFactoryEventCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
913
914 std::string GenerateUniqueID(vtkMRMLNode* node);
915 std::string GenerateUniqueID(const std::string& baseID);
916 int GetUniqueIDIndex(const std::string& baseID);
917 std::string BuildID(const std::string& baseID, int idIndex) const;
918
920 std::string GenerateUniqueName(vtkMRMLNode* node);
921
927 int GetUniqueNameIndex(const std::string& baseName);
928
930 std::string BuildName(const std::string& baseName, int nameIndex) const;
931
935
938
940 void RemoveNodeID(char* nodeID);
941
944
946 NodeReferencesType::iterator FindNodeReference(const char* referencedId, vtkMRMLNode* referencingNode);
947
950
953
955 void GetNodeReferenceIDsFromUndoStack(std::set<std::string>& referenceIDs) const;
956
958 bool IsNodeIDReservedByUndo(const std::string id) const;
959
961
968 void UpdateNodeReferences(vtkCollection* checkNodes, double progressRangeStart, double progressRangeEnd, double& lastReportedProgress);
969
972 bool WriteToMRBInternal(const char* filename, vtkImageData* thumbnail, vtkMRMLMessageCollection* userMessages);
974 vtkImageData* screenShot,
975 vtkMRMLMessageCollection* userMessages,
976 double progressRangeStart,
977 double progressRangeEnd);
978
980 std::string& dataDir,
981 std::map<vtkMRMLStorageNode*, std::vector<std::string>>& originalStorageNodeFileNames,
982 vtkMRMLMessageCollection* userMessages);
983
994 bool GetPrivateStorableNodesDirectory(const std::string& url, std::string& privateDir);
995
1006 bool SavePrivateStorableNodes(const std::string& url, vtkMRMLMessageCollection* userMessages = nullptr);
1007
1008 vtkCollection* Nodes;
1009
1011 vtkWeakPointer<vtkMRMLSubjectHierarchyNode> SubjectHierarchyNode;
1012
1016 vtkCollection* URIHandlerCollection;
1018
1019 std::vector<unsigned long> States;
1020
1023
1024 std::list<vtkCollection*> UndoStack;
1025 std::list<vtkCollection*> RedoStack;
1026
1027 std::string URL;
1028 std::string RootDirectory;
1029
1030 std::map<std::string, int> UniqueIDs;
1031 std::map<std::string, int> UniqueNames;
1032 std::set<std::string> ReservedIDs;
1033
1035 vtkSmartPointer<vtkMRMLNodeFactory> NodeFactory;
1037 vtkSmartPointer<vtkCallbackCommand> NodeFactoryCallback;
1038
1039 NodeReferencesType NodeReferences; // ReferencedIDs (string), ReferencingNodes (node pointer)
1040 std::map<std::string, std::string> ReferencedIDChanges;
1041 std::map<std::string, vtkSmartPointer<vtkMRMLNode>> NodeIDs;
1042
1043 // Stores default nodes. If a class is created or reset (using CreateNodeByClass or Clear) and
1044 // a default node is defined for it then the content of the default node will be used to initialize
1045 // the class. It is useful for overriding default values that are set in a node's constructor.
1046 std::map<std::string, vtkSmartPointer<vtkMRMLNode>> DefaultNodes;
1047
1048 std::string SceneXMLString;
1049
1051
1053
1055
1056 vtkMTimeType NodeIDsMTime;
1057
1058 void RemoveAllNodes(bool removeSingletons);
1059
1060 char* Version;
1062
1065
1066 vtkCallbackCommand* DeleteEventCallback;
1067
1068 std::default_random_engine RandomGenerator;
1069
1070private:
1071 vtkMRMLScene(const vtkMRMLScene&); // Not implemented
1072 void operator=(const vtkMRMLScene&); // Not implemented
1073
1077 int LoadIntoScene(vtkCollection* scene, vtkMRMLMessageCollection* userMessages = nullptr);
1078
1080 vtkTimeStamp StoredTime;
1081};
1082
1083//------------------------------------------------------------------------------
1088
1089//------------------------------------------------------------------------------
1091{
1093}
1094
1095//------------------------------------------------------------------------------
1100
1101//------------------------------------------------------------------------------
1106
1107//------------------------------------------------------------------------------
1109{
1111}
1112
1113//------------------------------------------------------------------------------
1115{
1117}
1118
1119#endif
Manages the on-disk remote cache used by MRML storage.
Registered MRML node classes of a scene.
Abstract Superclass for all specific types of MRML nodes.
void RegisterAbstractNodeClass(std::string className, std::string typeDisplayName)
Register abstract node type display name.
int GetStates() const
Returns the current state of the scene.
vtkWeakPointer< vtkMRMLSubjectHierarchyNode > SubjectHierarchyNode
subject hierarchy node
vtkCollection * URIHandlerCollection
void GetNodeReferenceIDsFromUndoStack(std::set< std::string > &referenceIDs) const
Returns all unique node reference IDs that are referenced within the undo stack.
bool IsNodeIDReservedByUndo(const std::string id) const
Returns true if a node is not referenced within the scene, but is referenced within the Undo stack.
bool ReadFromMRB(const char *fullName, bool clear=false, vtkMRMLMessageCollection *userMessages=nullptr)
Read the scene from a MRML scene bundle (.mrb) file If userMessages is not nullptr then the method ma...
static void SetStorableNodesModifiedSinceRead(vtkCollection *storableNodes)
Given a collection of storable nodes, iterate through and call StorableModified() on them.
char * LastLoadedVersion
void SetUndoOff()
void SetUndoFlag(bool flag)
static void NodeFactoryEventCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
std::map< std::string, std::string > ReferencedIDChanges
void CopyRegisteredNodesToScene(vtkMRMLScene *scene)
void ReserveNodeReferenceIDs(vtkMRMLNode *node)
Reserve all node reference ids for a node.
void SaveSceneScreenshot(vtkImageData *thumbnail)
Utility function to write the scene thumbnail to a file in the scene's root folder.
static std::string PercentEncode(std::string s)
vtkMRMLNode * GetNthReferencingNode(int n)
vtkMRMLNode * CreateNodeByClass(const char *className)
Create node with a given class.
std::map< std::string, vtkSmartPointer< vtkMRMLNode > > NodeIDs
void StartState(unsigned long state, int anticipatedMaxProgress=0)
Flag the scene as being in a state mode.
const char * GetURL()
Get URL (file name) of the scene.
void ClearUndoStack()
clear Undo stack, delete undo history
int MaximumNumberOfSavedUndoStates
bool WriteToMRB(const char *filename, vtkImageData *thumbnail=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
Write the scene to a MRML scene bundle (.mrb) file. If thumbnail image is provided then it is saved i...
const char * GetNthReferencedID(int n)
void RemoveUnreferencedStorageNodes()
Remove all vtkMRMLStorageNode instances not referenced by any vtkMRMLStorableNode.
vtkMRMLNode * GetNthNode(int n)
Get n-th node in the scene.
void UpdateNodeReferences(vtkCollection *checkNodes, double progressRangeStart, double progressRangeEnd, double &lastReportedProgress)
void EndState(unsigned long state)
Unflag the scene as being in a state mode.
vtkTagTable * UserTagTable
std::string GenerateUniqueID(const std::string &baseID)
void AddNodeID(vtkMRMLNode *node)
Add node to NodeIDs map used to speedup GetByID() method.
const char * GetClassNameByTag(const char *tagName)
Add a path to the list.
void RemoveNodeReferences(vtkMRMLNode *node)
int Commit(const char *url=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
void SaveStateForUndo(std::vector< vtkMRMLNode * > nodes)
void ProgressState(unsigned long state, double progress=0.0)
bool IsNodeClassRegistered(const std::string &className)
Return True if className is a registered node.
static bool ParseVersion(const char *versionString, std::string &application, int &major, int &minor, int &patch, int &revision)
void RemoveInvalidNodeReferences(vtkCollection *checkNodes, const std::set< std::string > &validNodeIDs)
Remove invalid node references after scene import.
vtkMRMLNode * GetNodeByID(std::string name)
void RemoveReferencesToNode(vtkMRMLNode *node)
std::map< std::string, std::set< std::string > > NodeReferencesType
void CopyNodeChangedIDs(vtkMRMLScene *scene)
vtkMRMLNode * CopyNode(vtkMRMLNode *n)
Add a copy of a node to the scene.
vtkMRMLNode * GetFirstNode(const char *byName=nullptr, const char *byClass=nullptr, const int *byHideFromEditors=nullptr, bool exactNameMatch=true)
Return the first node in the scene that matches the filtering criteria if specified.
vtkURIHandler * FindURIHandlerByName(const char *name)
Returns a URIHandler of a specific type if its name is known.
bool SaveSceneToSlicerDataBundleDirectory(const char *sdbDir, vtkImageData *thumbnail=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
Save the scene into a self contained directory, sdbDir If thumbnail image is provided then it is save...
std::string GetNthRegisteredAbstractNodeClassName(int n)
void RemoveUnreferencedDisplayNodes()
Remove all vtkMRMLDisplayNode instances not referenced by any vtkMRMLDisplayableNode.
int Connect(vtkMRMLMessageCollection *userMessages=nullptr)
Create new scene from URL If userMessages is not nullptr then the method may add messages to it about...
vtkSmartPointer< vtkCallbackCommand > NodeFactoryCallback
Forwards NodeClassRegisteredEvent of the node factory to the scene observers.
vtkMRMLNode * GetSingletonNode(vtkMRMLNode *n)
Search and return a matching singleton in the scene that the input singleton node will overwrite if i...
void RemoveAllNodes(bool removeSingletons)
void Clear(int removeSingletons=0)
friend class vtkMRMLSceneViewNode
std::string RootDirectory
vtkCollection * GetNodesByClassByName(const char *className, const char *name)
int GetNumberOfUndoLevels()
returns number of undo steps in the history buffer
std::set< std::string > ReservedIDs
static std::string CreateUniqueFileName(const std::string &filename, const std::string &knownExtension="")
bool IsBatchProcessing() const
Return true if the scene is in BatchProcess state, false otherwise.
vtkCallbackCommand * DeleteEventCallback
void SetStorableNodesModifiedSinceRead()
Search the scene for storable nodes that are not "ModifiedSinceRead".
vtkMRMLNode * AddNewNodeByClass(std::string className, std::string nodeBaseName="")
Instantiate and add a node to the scene.
void PushIntoUndoStack()
void CopyDefaultNodesToScene(vtkMRMLScene *scene)
Copies all default nodes into the parameter scene. Does not remove existing default nodes.
virtual void SetUserTagTable(vtkTagTable *)
vtkMRMLNode * GetNodeByID(const char *name)
Get node given a unique ID.
void Undo()
undo, set the scene to previous state
std::string GenerateUniqueName(vtkMRMLNode *node)
Return a unique name for a MRML node. It uses the node tag as the base.
void ResetNodes()
Reset all nodes to their constructor's state.
void SetNodeFactory(vtkMRMLNodeFactory *factory)
std::map< std::string, int > UniqueIDs
vtkMRMLNodeFactory * GetNodeFactory()
vtkMRMLNode * GetDefaultNodeByClass(const char *className)
void RegisterNodeClass(vtkMRMLNode *node)
Utility function to RegisterNodeClass(), the node tag name is used when registering the node.
bool GetUndoFlag()
NodeReferencesType::iterator FindNodeReference(const char *referencedId, vtkMRMLNode *referencingNode)
Get a NodeReferences iterator for a node reference.
void AddReferencedNodes(vtkMRMLNode *node, vtkCollection *refNodes, bool recursive=true)
int Import(vtkMRMLMessageCollection *userMessages=nullptr)
Add the scene into the existing scene (no clear) from URL file or from.
bool SaveStorableNodeToSlicerDataBundleDirectory(vtkMRMLStorableNode *storableNode, std::string &dataDir, std::map< vtkMRMLStorageNode *, std::vector< std::string > > &originalStorageNodeFileNames, vtkMRMLMessageCollection *userMessages)
const char * GetUniqueNameByString(const char *baseName)
vtkMRMLNode * GetNthNodeByClass(int n, const char *className)
Get n-th node of a specified class in the scene.
static void SceneCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
Handle vtkMRMLScene::DeleteEvent: clear the scene.
std::list< vtkCollection * > UndoStack
void SaveStateForUndo()
Save current state in the undo buffer.
void UpdateNodeIDs()
Synchronize NodeIDs map used to speedup GetByID() method with the Nodes collection.
void ClearNodeIDs()
Clear NodeIDs map used to speedup GetByID() method.
void RemoveReservedIDs()
std::map< std::string, vtkSmartPointer< vtkMRMLNode > > DefaultNodes
void RemoveNodeID(char *nodeID)
Remove node from NodeIDs map used to speedup GetByID() method.
int IsFilePathRelative(const char *filepath)
~vtkMRMLScene() override
std::string GenerateUniqueID(vtkMRMLNode *node)
std::map< std::string, int > UniqueNames
void TrimUndoStack()
Clean up elements of the undo/redo stack beyond the maximum size.
static vtkMRMLScene * New()
vtkMRMLNode * AddNode(vtkMRMLNode *nodeToAdd)
Add a node to the scene and send vtkMRMLScene::NodeAboutToBeAddedEvent, vtkMRMLScene::NodeAddedEvent ...
void NodeAdded(vtkMRMLNode *n)
Invoke a vtkMRMLScene::NodeAddedEvent.
const char * GetChangedID(const char *id)
int GetNodesByClass(const char *className, std::vector< vtkMRMLNode * > &nodes)
Get vector of nodes of a specified class in the scene.
int IsNodePresent(vtkMRMLNode *n)
Determine whether a particular node is present.
int GetNumberOfRegisteredNodeClasses()
bool WriteToMRBInternal(const char *filename, vtkImageData *thumbnail, vtkMRMLMessageCollection *userMessages)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void SetSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode *)
void GetReferencingNodes(vtkMRMLNode *referencedNode, std::vector< vtkMRMLNode * > &referencingNodes)
Get vector of nodes containing references to an input node.
@ NodeAboutToBeRemovedEvent
@ ProgressBatchProcessEvent
@ SaveProgressFeedbackEvent
@ StateEvent
1024 (decimal)
@ ImportProgressFeedbackEvent
void SetURL(const std::string &url)
int GetUniqueIDIndex(const std::string &baseID)
void AddReservedID(const char *id)
virtual void SetCacheManager(vtkCacheManager *)
int GetNumberOfRedoLevels()
returns number of redo steps in the history buffer
std::string BuildName(const std::string &baseName, int nameIndex) const
Combine a basename and an index to produce a full name.
void UpdateNodeReferences(vtkCollection *checkNodes=nullptr)
Notify nodes about node ID changes.
vtkSmartPointer< vtkMRMLNodeFactory > NodeFactory
Registry of node classes (created on first use if not set explicitly)
void RegisterNodeClass(vtkMRMLNode *node, const char *tagName)
Register a node class to the scene so that the scene can later create the same node type from a tag o...
void RemoveUnusedNodeReferences()
void GetReferencedSubScene(vtkMRMLNode *node, vtkMRMLScene *newScene)
Get a sub-scene containing all nodes directly or indirectly referenced by the input node.
vtkCollection * GetNodesByClass(const char *className)
bool IsNodeReferencingNodeID(vtkMRMLNode *referencingNode, const char *id)
void SaveStateForUndo(vtkMRMLNode *node)
vtkCollection * GetNodesByName(const char *name)
Get nodes having the specified name.
void CopyNodeInUndoStack(vtkMRMLNode *node)
void AddURIHandler(vtkURIHandler *handler)
Add a URI handler to the collection.
const char * GetTagByClassName(const char *className)
Add a path to the list.
vtkMRMLNode * GetNextNodeByClass(const char *className)
vtkMRMLNode * GetFirstNodeByClass(const char *className)
Convenience function for getting 0-th node of a specified class in the scene.
std::string BuildID(const std::string &baseID, int idIndex) const
int GetNumberOfNodesByClass(const char *className)
Get number of nodes of a specified class in the scene.
void RemoveAllDefaultNodes()
Deletes all default node values from the scene.
std::string URL
void CopyNodeReferences(vtkMRMLScene *scene)
vtkMRMLNode * InsertBeforeNode(vtkMRMLNode *item, vtkMRMLNode *newItem)
insert a node in the scene before a specified node
vtkURIHandler * FindURIHandler(const char *URI)
Find a URI handler in the collection that can work on the passed URI.
int GetUniqueNameIndex(const std::string &baseName)
Returns a unique index for a given baseName.
vtkMRMLNode * InsertAfterNode(vtkMRMLNode *item, vtkMRMLNode *newItem)
insert a node in the scene after a specified node
const char * GetRootDirectory()
Get Root directory, where URL is pointing.
vtkMRMLNode * GetNthRegisteredNodeClass(int n)
int GetNumberOfRegisteredAbstractNodeClasses()
Get the number of registered abstract node classes.
void AddReferencedNodeID(const char *id, vtkMRMLNode *refrencingNode)
vtkCollection * GetNodes()
Return collection of nodes.
void CopySingletonNodesToScene(vtkMRMLScene *scene)
Copies all singleton nodes into the parameter scene.
std::default_random_engine RandomGenerator
const std::string & GetSceneXMLString()
Returns the saved scene with an XML format if SaveToXMLString is true and Commit() was called prior.
int GetNumberOfNodes()
Get number of nodes in the scene.
bool SaveSceneToSlicerDataBundleDirectoryInternal(const char *sdbDir, vtkImageData *screenShot, vtkMRMLMessageCollection *userMessages, double progressRangeStart, double progressRangeEnd)
std::vector< unsigned long > States
vtkMRMLNode * AddNewNodeByClassWithID(std::string className, std::string nodeBaseName, std::string nodeID)
Instantiates and adds a new node to the scene with the specified ID.
vtkCollection * Nodes
void SetMaximumNumberOfSavedUndoStates(int stackSize)
Sets the maximum number of saved undo states and removes the oldest saved states so that the number o...
std::string GetTemporaryBundleDirectory()
Returns a string for the temporary directory to use for saving/reading scene files....
vtkMRMLNode * GetFirstNodeByName(const char *name)
std::list< vtkCollection * > RedoStack
void CopyNodeInRedoStack(vtkMRMLNode *node)
vtkCollection * GetReferencedNodes(vtkMRMLNode *node, bool recursive=true)
Return collection of all nodes referenced directly or indirectly by node.
NodeReferencesType NodeReferences
void SetUndoOn()
Set undo on/off.
bool IsRestoring() const
Return true if the scene is in Restore state, false otherwise.
char * LastLoadedExtensions
void ClearRedoStack()
clear Redo stack, delete redo history
void RemoveReferencedNodeID(const char *id, vtkMRMLNode *refrencingNode)
bool IsUndoing() const
Return true if the scene is in Undo state (in the process of undoing node changes),...
void SetRootDirectory(const char *dir)
Set Root directory, where URL is pointing.
vtkMTimeType NodeIDsMTime
void SetSceneXMLString(const std::string &xmlString)
Set the XML string to read from by Import() if GetLoadFromXMLString() is true.
static std::string UnpackSlicerDataBundle(const char *sdbFilePath, const char *temporaryDirectory, vtkMRMLMessageCollection *userMessages=nullptr)
Unpack the file into a temp directory and return the scene file inside. Note that the first mrml file...
void SaveStateForUndo(vtkCollection *nodes)
void SetURL(const char *url)
Set URL (file name) of the scene.
bool GetPrivateStorableNodesDirectory(const std::string &url, std::string &privateDir)
Computes the "<SceneFileName>_Private" subfolder path for url, where SceneFileName is the scene file ...
void PushIntoRedoStack()
bool SavePrivateStorableNodes(const std::string &url, vtkMRMLMessageCollection *userMessages=nullptr)
bool GetStorableNodesModifiedSinceRead(vtkCollection *modifiedStorableNodes=nullptr)
Search the scene for storable nodes that are "ModifiedSinceRead".
void AddDefaultNode(vtkMRMLNode *node)
bool IsImporting() const
Return true if the scene is in Import state, false otherwise.
std::string SceneXMLString
vtkMRMLNode * GetNextNode()
bool IsReservedID(const std::string &id)
bool GetModifiedSinceRead(vtkCollection *modifiedNodes=nullptr)
Returns true if the scene has been "significantly" modified since the last saved state....
std::string GetNthRegisteredAbstractNodeTypeDisplayName(int n)
vtkMRMLSubjectHierarchyNode * GetSubjectHierarchyNode()
bool GetPrivateStorableNodesModifiedSinceRead(vtkCollection *modifiedStorableNodes=nullptr)
Search the scene for private storable nodes (i.e., storable nodes with HideFromEditors enabled) that ...
bool IsRedoing() const
Return true if the scene is in Redo state (in the process of redoing node changes),...
vtkDataIOManager * DataIOManager
std::list< std::string > GetNodeClassesList()
virtual void SetDataIOManager(vtkDataIOManager *)
vtkCacheManager * CacheManager
data i/o handling members
void InitTraversal()
void RemoveNode(vtkMRMLNode *n)
Remove a path from the list.
std::string GetTypeDisplayNameByClassName(std::string className)
Get type display name which is shown in the GUI.
void Redo()
redo, set the scene to previously undone
vtkMRMLNode * AddNodeNoNotify(vtkMRMLNode *n)
int GetNumberOfNodeReferences()
Get the total number of node references (number of ReferencedID-ReferencingNode pairs).
virtual void SetURIHandlerCollection(vtkCollection *)
std::string GenerateUniqueName(const std::string &baseName)
Generate a node name that is unique in the scene. Calling this function successively with the same ba...
vtkMRMLNode * GetSingletonNode(const char *singletonTag, const char *className)
Search and return the singleton of type className with a singletonTag tag.
bool IsClosing() const
Return true if the scene is in Close state, false otherwise.
void UpdateNodeChangedIDs()
Change node IDs based on the ReferencedIDChanges list.
MRML node to represent a 3D surface model.
A superclass for other storage nodes.
MRML node to represent a complete subject hierarchy tree.