15 #ifndef __vtkMRMLScene_h 16 #define __vtkMRMLScene_h 20 #define CURRENT_MRML_VERSION "Slicer4.4.0" 26 #include <vtkObject.h> 27 #include <vtkSmartPointer.h> 28 #include <vtkWeakPointer.h> 42 class vtkCallbackCommand;
44 class vtkGeneralTransform;
72 void PrintSelf(ostream& os, vtkIndent indent)
override;
75 void SetURL(
const char *url);
81 void SetRootDirectory(
const char *dir);
84 const char *GetRootDirectory();
101 int Commit(
const char* url=
nullptr);
108 void Clear(
int removeSingletons=0);
130 vtkMRMLNode* CreateNodeByClass(
const char* className);
152 void RegisterNodeClass(
vtkMRMLNode* node,
const char* tagName);
161 const char* GetClassNameByTag(
const char *tagName);
164 const char* GetTagByClassName(
const char *className);
170 vtkMRMLNode* GetDefaultNodeByClass(
const char* className);
173 void RemoveAllDefaultNodes();
176 vtkCollection* GetNodes();
207 vtkMRMLNode* AddNewNodeByClass(std::string className, std::string nodeBaseName =
"");
216 vtkMRMLNode* AddNewNodeByClassWithID(std::string className, std::string nodeBaseName, std::string nodeID);
242 void InitTraversal();
260 vtkMRMLNode *GetNextNodeByClass(
const char* className);
263 vtkCollection *GetNodesByName(
const char* name);
277 vtkMRMLNode *GetFirstNode(
const char* byName =
nullptr,
const char* byClass =
nullptr,
278 const int* byHideFromEditors =
nullptr,
279 bool exactNameMatch =
true);
287 vtkCollection *GetNodesByClassByName(
const char* className,
const char* name);
290 int GetNumberOfNodes();
296 vtkMRMLNode* GetNthNodeByClass(
int n,
const char* className );
298 vtkMRMLNode* GetFirstNodeByClass(
const char* className);
301 int GetNumberOfNodesByClass(
const char* className);
313 vtkMRMLNode* GetSingletonNode(
const char* singletonTag,
const char* className);
323 std::list<std::string> GetNodeClassesList();
327 int GetNumberOfRegisteredNodeClasses();
335 bool IsNodeClassRegistered(
const std::string& className);
340 std::string GenerateUniqueName(
const std::string& baseName);
346 const char* GetUniqueNameByString(
const char* baseName);
366 void ClearUndoStack();
369 void ClearRedoStack();
378 void SaveStateForUndo();
392 void SaveStateForUndo(vtkCollection *
nodes);
393 void SaveStateForUndo(std::vector<vtkMRMLNode *>
nodes);
401 void AddReferencedNodeID(
const char *
id,
vtkMRMLNode *refrencingNode);
402 bool IsNodeReferencingNodeID(
vtkMRMLNode* referencingNode,
const char*
id);
413 const char* GetNthReferencedID(
int n);
415 void RemoveReferencedNodeID(
const char *
id,
vtkMRMLNode *refrencingNode);
435 void UpdateNodeChangedIDs();
437 void RemoveUnusedNodeReferences();
439 bool IsReservedID(
const std::string&
id);
441 void AddReservedID(
const char *
id);
443 void RemoveReservedIDs();
447 const char* GetChangedID(
const char*
id);
463 vtkCollection* GetReferencedNodes(
vtkMRMLNode *node,
bool recursive=
true);
466 void GetReferencingNodes(
vtkMRMLNode* referencedNode, std::vector<vtkMRMLNode *> &referencingNodes);
476 int IsFilePathRelative(
const char * filepath);
478 vtkSetMacro(ErrorCode,
unsigned long);
479 vtkGetMacro(ErrorCode,
unsigned long);
487 vtkSetMacro(LoadFromXMLString,
int);
488 vtkGetMacro(LoadFromXMLString,
int);
496 vtkSetMacro(SaveToXMLString,
int);
497 vtkGetMacro(SaveToXMLString,
int);
499 vtkSetMacro(ReadDataOnLoad,
int);
500 vtkGetMacro(ReadDataOnLoad,
int);
502 void SetErrorMessage(
const std::string &error);
503 std::string GetErrorMessage();
509 void SetSceneXMLString(
const std::string &xmlString);
515 const std::string& GetSceneXMLString();
517 void SetErrorMessage(
const char * message);
525 vtkGetObjectMacro(URIHandlerCollection, vtkCollection);
526 virtual void SetURIHandlerCollection(vtkCollection*);
577 BatchProcessState = 0x0001,
578 CloseState = 0x0002 | BatchProcessState,
579 ImportState = 0x0004 | BatchProcessState,
580 RestoreState = 0x0008 | BatchProcessState,
593 int GetStates()
const;
596 inline bool IsBatchProcessing()
const;
598 inline bool IsClosing()
const;
600 inline bool IsImporting()
const;
602 inline bool IsRestoring()
const;
604 inline bool IsUndoing()
const;
606 inline bool IsRedoing()
const;
642 void StartState(
unsigned long state,
int anticipatedMaxProgress = 0);
652 void EndState(
unsigned long state);
655 void ProgressState(
unsigned long state,
int progress = 0);
659 NodeAboutToBeAddedEvent = 0x2000,
664 NewSceneEvent = 66030,
665 MetadataAddedEvent = 66032,
675 ProgressEvent = 0x0400,
677 StartBatchProcessEvent = StateEvent | StartEvent | BatchProcessState,
678 EndBatchProcessEvent = StateEvent | EndEvent | BatchProcessState,
679 ProgressBatchProcessEvent = StateEvent | ProgressEvent | BatchProcessState,
681 StartCloseEvent = StateEvent | StartEvent | CloseState,
682 EndCloseEvent = StateEvent | EndEvent | CloseState,
683 ProgressCloseEvent = StateEvent | ProgressEvent | CloseState,
685 StartImportEvent = StateEvent | StartEvent | ImportState,
686 EndImportEvent = StateEvent | EndEvent | ImportState,
687 ProgressImportEvent = StateEvent | EndEvent | ImportState,
689 StartRestoreEvent = StateEvent | StartEvent | RestoreState,
690 EndRestoreEvent = StateEvent | EndEvent | RestoreState,
691 ProgressRestoreEvent = StateEvent | ProgressEvent | RestoreState,
693 StartSaveEvent = StateEvent | StartEvent | SaveState,
694 EndSaveEvent = StateEvent | EndEvent | SaveState,
695 ProgressSaveEvent = StateEvent | ProgressEvent | SaveState,
697 StartUndoEvent = StateEvent | StartEvent | UndoState,
698 EndUndoEvent = StateEvent | EndEvent | UndoState,
699 ProgressUndoEvent = StateEvent | ProgressEvent | UndoState,
701 StartRedoEvent = StateEvent | StartEvent | RedoState,
702 EndRedoEvent = StateEvent | EndEvent | RedoState,
703 ProgressRedoEvent = StateEvent | ProgressEvent | RedoState,
708 vtkGetStringMacro(LastLoadedVersion);
709 vtkSetStringMacro(LastLoadedVersion);
712 vtkGetStringMacro(Version);
713 vtkSetStringMacro(Version);
734 bool GetStorableNodesModifiedSinceRead(vtkCollection* modifiedStorableNodes =
nullptr);
741 void SetStorableNodesModifiedSinceRead();
745 static void SetStorableNodesModifiedSinceRead(vtkCollection* storableNodes);
749 void SetMaximumNumberOfSavedUndoStates(
int stackSize);
750 vtkGetMacro(MaximumNumberOfSavedUndoStates,
int);
757 bool WriteToMRB(
const char* filename, vtkImageData* thumbnail=
nullptr,
vtkMRMLMessageCollection* userMessages=
nullptr);
760 bool ReadFromMRB(
const char* fullName,
bool clear=
false);
765 static std::string UnpackSlicerDataBundle(
const char* sdbFilePath,
const char* temporaryDirectory);
772 bool SaveSceneToSlicerDataBundleDirectory(
const char* sdbDir, vtkImageData* thumbnail=
nullptr,
vtkMRMLMessageCollection* userMessages=
nullptr);
775 void SaveSceneScreenshot(vtkImageData* thumbnail);
786 static std::string PercentEncode(std::string s);
793 static std::string CreateUniqueFileName(
const std::string& filename,
const std::string& knownExtension =
"");
802 void PushIntoUndoStack();
803 void PushIntoRedoStack();
816 void AddReferencedNodes(
vtkMRMLNode *node, vtkCollection *refNodes,
bool recursive=
true);
819 static void SceneCallback(vtkObject *caller,
unsigned long eid,
void *clientData,
void *callData);
822 std::string GenerateUniqueID(
const std::string& baseID);
823 int GetUniqueIDIndex(
const std::string& baseID);
824 std::string BuildID(
const std::string& baseID,
int idIndex)
const;
834 int GetUniqueNameIndex(
const std::string& baseName);
837 std::string BuildName(
const std::string& baseName,
int nameIndex)
const;
841 void UpdateNodeIDs();
847 void RemoveNodeID(
char *nodeID);
853 NodeReferencesType::iterator FindNodeReference(
const char* referencedId,
vtkMRMLNode* referencingNode);
856 void TrimUndoStack();
862 void GetNodeReferenceIDsFromUndoStack(std::set<std::string>& referenceIDs)
const;
865 bool IsNodeIDReservedByUndo(
const std::string
id)
const;
873 bool SaveStorableNodeToSlicerDataBundleDirectory(
vtkMRMLStorableNode* storableNode, std::string& dataDir,
907 std::map< std::string, vtkSmartPointer<vtkMRMLNode> >
NodeIDs;
926 void RemoveAllNodes(
bool removeSingletons);
941 int LoadIntoScene(vtkCollection* scene);
943 unsigned long ErrorCode;
946 vtkTimeStamp StoredTime;
int GetNodesByClass(const char *className, std::vector< vtkMRMLNode *> &nodes)
int GetNumberOfRedoLevels()
returns number of redo steps in the history buffer
void PrintSelf(ostream &os, vtkIndent indent) override
vtkWeakPointer< vtkMRMLSubjectHierarchyNode > SubjectHierarchyNode
subject hierarchy node
vtkCallbackCommand * DeleteEventCallback
bool IsImporting() const
Return true if the scene is in Import state, false otherwise.
std::map< std::string, vtkSmartPointer< vtkMRMLNode > > NodeIDs
vtkDataIOManager * DataIOManager
void SetUndoFlag(bool flag)
int MaximumNumberOfSavedUndoStates
vtkCollection * URIHandlerCollection
std::string RootDirectory
virtual bool GetModifiedSinceRead()
std::set< std::string > ReservedIDs
std::string SceneXMLString
int GetNumberOfUndoLevels()
returns number of undo steps in the history buffer
static vtkMRMLSceneViewNode * New()
bool IsRedoing() const
Return true if the scene is in Redo state (in the process of redoing node changes), false otherwise.
MRML node to represent a complete subject hierarchy tree.
void SetUndoOn()
Set undo on/off.
virtual void UpdateNodeReferences(const char *referenceRole=nullptr)
std::map< std::string, int > UniqueIDs
MRML node to represent a 3D surface model.
vtkCacheManager * CacheManager
data i/o handling members
A set of MRML Nodes that supports serialization and undo/redo.
vtkMTimeType NodeIDsMTime
std::map< std::string, int > UniqueNames
int GetNumberOfNodeReferences(const char *referenceRole)
Return the number of node IDs for a specific reference role (and nodes as they always have the same s...
NodeReferencesType NodeReferences
std::vector< vtkMRMLNode *> RegisteredNodeClasses
A superclass for other storage nodes.
void operator=(const vtkMRMLSceneViewNode &)
std::list< vtkCollection *> UndoStack
friend class vtkMRMLScene
bool IsUndoing() const
Return true if the scene is in Undo state (in the process of undoing node changes), false otherwise.
std::map< std::string, std::string > ReferencedIDChanges
bool IsClosing() const
Return true if the scene is in Close state, false otherwise.
std::vector< std::string > RegisteredNodeTags
bool IsRestoring() const
Return true if the scene is in Restore state, false otherwise.
Abstract Superclass for all specific types of MRML nodes.
std::list< vtkCollection *> RedoStack
vtkTagTable * UserTagTable
vtkTagTable * UserTagTable
int GetStates() const
Returns the current state of the scene.
std::vector< unsigned long > States
bool IsBatchProcessing() const
Return true if the scene is in BatchProcess state, false otherwise.
std::map< std::string, vtkSmartPointer< vtkMRMLNode > > DefaultNodes
std::map< std::string, std::set< std::string > > NodeReferencesType
std::default_random_engine RandomGenerator