15 #ifndef __vtkMRMLScene_h 16 #define __vtkMRMLScene_h 22 #include <vtkObject.h> 23 #include <vtkSmartPointer.h> 24 #include <vtkWeakPointer.h> 38 class vtkCallbackCommand;
40 class vtkGeneralTransform;
68 void PrintSelf(ostream& os, vtkIndent indent)
override;
71 void SetURL(
const char *url);
77 void SetRootDirectory(
const char *dir);
80 const char *GetRootDirectory();
109 void Clear(
int removeSingletons=0);
131 vtkMRMLNode* CreateNodeByClass(
const char* className);
153 void RegisterNodeClass(
vtkMRMLNode* node,
const char* tagName);
168 void RegisterAbstractNodeClass(std::string className, std::string typeDisplayName);
171 const char* GetClassNameByTag(
const char *tagName);
174 const char* GetTagByClassName(
const char *className);
177 std::string GetTypeDisplayNameByClassName(std::string className);
183 vtkMRMLNode* GetDefaultNodeByClass(
const char* className);
186 void RemoveAllDefaultNodes();
189 vtkCollection* GetNodes();
220 vtkMRMLNode* AddNewNodeByClass(std::string className, std::string nodeBaseName =
"");
229 vtkMRMLNode* AddNewNodeByClassWithID(std::string className, std::string nodeBaseName, std::string nodeID);
255 void InitTraversal();
273 vtkMRMLNode *GetNextNodeByClass(
const char* className);
276 vtkCollection *GetNodesByName(
const char* name);
290 vtkMRMLNode *GetFirstNode(
const char* byName =
nullptr,
const char* byClass =
nullptr,
291 const int* byHideFromEditors =
nullptr,
292 bool exactNameMatch =
true);
300 vtkCollection *GetNodesByClassByName(
const char* className,
const char* name);
303 int GetNumberOfNodes();
309 vtkMRMLNode* GetNthNodeByClass(
int n,
const char* className );
311 vtkMRMLNode* GetFirstNodeByClass(
const char* className);
314 int GetNumberOfNodesByClass(
const char* className);
326 vtkMRMLNode* GetSingletonNode(
const char* singletonTag,
const char* className);
336 std::list<std::string> GetNodeClassesList();
340 int GetNumberOfRegisteredNodeClasses();
348 bool IsNodeClassRegistered(
const std::string& className);
351 int GetNumberOfRegisteredAbstractNodeClasses();
355 std::string GetNthRegisteredAbstractNodeClassName(
int n);
359 std::string GetNthRegisteredAbstractNodeTypeDisplayName(
int n);
364 std::string GenerateUniqueName(
const std::string& baseName);
370 const char* GetUniqueNameByString(
const char* baseName);
390 void ClearUndoStack();
393 void ClearRedoStack();
402 void SaveStateForUndo();
416 void SaveStateForUndo(vtkCollection *
nodes);
417 void SaveStateForUndo(std::vector<vtkMRMLNode *>
nodes);
425 void AddReferencedNodeID(
const char *
id,
vtkMRMLNode *refrencingNode);
426 bool IsNodeReferencingNodeID(
vtkMRMLNode* referencingNode,
const char*
id);
437 const char* GetNthReferencedID(
int n);
439 void RemoveReferencedNodeID(
const char *
id,
vtkMRMLNode *refrencingNode);
459 void UpdateNodeChangedIDs();
461 void RemoveUnusedNodeReferences();
463 bool IsReservedID(
const std::string&
id);
465 void AddReservedID(
const char *
id);
467 void RemoveReservedIDs();
471 const char* GetChangedID(
const char*
id);
487 vtkCollection* GetReferencedNodes(
vtkMRMLNode *node,
bool recursive=
true);
490 void GetReferencingNodes(
vtkMRMLNode* referencedNode, std::vector<vtkMRMLNode *> &referencingNodes);
500 int IsFilePathRelative(
const char * filepath);
508 vtkSetMacro(LoadFromXMLString,
int);
509 vtkGetMacro(LoadFromXMLString,
int);
517 vtkSetMacro(SaveToXMLString,
int);
518 vtkGetMacro(SaveToXMLString,
int);
520 vtkSetMacro(ReadDataOnLoad,
int);
521 vtkGetMacro(ReadDataOnLoad,
int);
527 void SetSceneXMLString(
const std::string &xmlString);
533 const std::string& GetSceneXMLString();
541 vtkGetObjectMacro(URIHandlerCollection, vtkCollection);
542 virtual void SetURIHandlerCollection(vtkCollection*);
593 BatchProcessState = 0x0001,
594 CloseState = 0x0002 | BatchProcessState,
595 ImportState = 0x0004 | BatchProcessState,
596 RestoreState = 0x0008 | BatchProcessState,
609 int GetStates()
const;
612 inline bool IsBatchProcessing()
const;
614 inline bool IsClosing()
const;
616 inline bool IsImporting()
const;
618 inline bool IsRestoring()
const;
620 inline bool IsUndoing()
const;
622 inline bool IsRedoing()
const;
658 void StartState(
unsigned long state,
int anticipatedMaxProgress = 0);
668 void EndState(
unsigned long state);
671 void ProgressState(
unsigned long state,
int progress = 0);
675 NodeAboutToBeAddedEvent = 0x2000,
681 NewSceneEvent = 66030,
682 MetadataAddedEvent = 66032,
692 ProgressEvent = 0x0400,
694 StartBatchProcessEvent = StateEvent | StartEvent | BatchProcessState,
695 EndBatchProcessEvent = StateEvent | EndEvent | BatchProcessState,
696 ProgressBatchProcessEvent = StateEvent | ProgressEvent | BatchProcessState,
698 StartCloseEvent = StateEvent | StartEvent | CloseState,
699 EndCloseEvent = StateEvent | EndEvent | CloseState,
700 ProgressCloseEvent = StateEvent | ProgressEvent | CloseState,
702 StartImportEvent = StateEvent | StartEvent | ImportState,
703 EndImportEvent = StateEvent | EndEvent | ImportState,
704 ProgressImportEvent = StateEvent | EndEvent | ImportState,
706 StartRestoreEvent = StateEvent | StartEvent | RestoreState,
707 EndRestoreEvent = StateEvent | EndEvent | RestoreState,
708 ProgressRestoreEvent = StateEvent | ProgressEvent | RestoreState,
710 StartSaveEvent = StateEvent | StartEvent | SaveState,
711 EndSaveEvent = StateEvent | EndEvent | SaveState,
712 ProgressSaveEvent = StateEvent | ProgressEvent | SaveState,
714 StartUndoEvent = StateEvent | StartEvent | UndoState,
715 EndUndoEvent = StateEvent | EndEvent | UndoState,
716 ProgressUndoEvent = StateEvent | ProgressEvent | UndoState,
718 StartRedoEvent = StateEvent | StartEvent | RedoState,
719 EndRedoEvent = StateEvent | EndEvent | RedoState,
720 ProgressRedoEvent = StateEvent | ProgressEvent | RedoState,
725 vtkGetStringMacro(LastLoadedVersion);
726 vtkSetStringMacro(LastLoadedVersion);
729 vtkGetStringMacro(LastLoadedExtensions);
730 vtkSetStringMacro(LastLoadedExtensions);
733 vtkGetStringMacro(Version);
734 vtkSetStringMacro(Version);
738 vtkGetStringMacro(Extensions);
739 vtkSetStringMacro(Extensions);
743 static bool ParseVersion(
const char* versionString, std::string& application,
int& major,
int& minor,
int& patch,
int& revision);
760 vtkGetMacro(StoredTime, vtkMTimeType);
768 bool GetStorableNodesModifiedSinceRead(vtkCollection* modifiedStorableNodes =
nullptr);
775 void SetStorableNodesModifiedSinceRead();
779 static void SetStorableNodesModifiedSinceRead(vtkCollection* storableNodes);
783 void SetMaximumNumberOfSavedUndoStates(
int stackSize);
784 vtkGetMacro(MaximumNumberOfSavedUndoStates,
int);
791 bool WriteToMRB(
const char* filename, vtkImageData* thumbnail=
nullptr,
vtkMRMLMessageCollection* userMessages=
nullptr);
803 static std::string UnpackSlicerDataBundle(
const char* sdbFilePath,
const char* temporaryDirectory,
vtkMRMLMessageCollection* userMessages=
nullptr);
810 bool SaveSceneToSlicerDataBundleDirectory(
const char* sdbDir, vtkImageData* thumbnail=
nullptr,
vtkMRMLMessageCollection* userMessages=
nullptr);
813 void SaveSceneScreenshot(vtkImageData* thumbnail);
824 static std::string PercentEncode(std::string s);
831 static std::string CreateUniqueFileName(
const std::string& filename,
const std::string& knownExtension =
"");
840 void PushIntoUndoStack();
841 void PushIntoRedoStack();
854 void AddReferencedNodes(
vtkMRMLNode *node, vtkCollection *refNodes,
bool recursive=
true);
857 void RemoveInvalidNodeReferences(vtkCollection* checkNodes,
const std::set<std::string> &validNodeIDs);
860 static void SceneCallback(vtkObject *caller,
unsigned long eid,
void *clientData,
void *callData);
863 std::string GenerateUniqueID(
const std::string& baseID);
864 int GetUniqueIDIndex(
const std::string& baseID);
865 std::string BuildID(
const std::string& baseID,
int idIndex)
const;
875 int GetUniqueNameIndex(
const std::string& baseName);
878 std::string BuildName(
const std::string& baseName,
int nameIndex)
const;
882 void UpdateNodeIDs();
888 void RemoveNodeID(
char *nodeID);
894 NodeReferencesType::iterator FindNodeReference(
const char* referencedId,
vtkMRMLNode* referencingNode);
897 void TrimUndoStack();
903 void GetNodeReferenceIDsFromUndoStack(std::set<std::string>& referenceIDs)
const;
906 bool IsNodeIDReservedByUndo(
const std::string
id)
const;
914 bool SaveStorableNodeToSlicerDataBundleDirectory(
vtkMRMLStorableNode* storableNode, std::string& dataDir,
949 std::map< std::string, vtkSmartPointer<vtkMRMLNode> >
NodeIDs;
966 void RemoveAllNodes(
bool removeSingletons);
989 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.
char * LastLoadedExtensions
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
std::map< std::string, std::string > RegisteredAbstractNodeClassTypeDisplayNames