vtkMRMLScene.h

Go to the documentation of this file.
00001 /*=auto=========================================================================
00002 
00003 Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
00004 
00005 See Doc/copyright/copyright.txt
00006 or http://www.slicer.org/copyright/copyright.txt for details.
00007 
00008 Program:   3D Slicer
00009 Module:    $RCSfile: vtkMRMLScene.h,v $
00010 Date:      $Date: 2006/03/17 15:10:09 $
00011 Version:   $Revision: 1.18 $
00012 
00013 =========================================================================auto=*/
00014 //
00015 //
00020 //
00023 
00024 #ifndef __vtkMRMLScene_h
00025 #define __vtkMRMLScene_h
00026 
00027 #include <list>
00028 #include <map>
00029 #include <vector>
00030 #include <string>
00031 
00032 #include "vtkCollection.h"
00033 #include "vtkObjectFactory.h"
00034 
00035 #include "vtkMRML.h"
00036 //#include "vtkMRMLNode.h"
00037 class vtkMRMLNode;
00038 #include "vtkCacheManager.h"
00039 #include "vtkDataIOManager.h"
00040 #include "vtkTagTable.h"
00041 
00042 class vtkCallbackCommand;
00043 class vtkGeneralTransform;
00044 class vtkURIHandler;
00045 
00046 class VTK_MRML_EXPORT vtkMRMLScene : public vtkCollection
00047 {
00048 public:
00049   static vtkMRMLScene *New();
00050   vtkTypeMacro(vtkMRMLScene,vtkCollection);
00051   void PrintSelf(ostream& os, vtkIndent indent);
00052 
00055   void SetURL(const char *url) {
00056     this->URL = std::string(url); 
00057   };
00058   
00061   const char *GetURL() {
00062     return this->URL.c_str();
00063   };
00064   
00067   void SetRootDirectory(const char *dir) {
00068     this->RootDirectory = std::string(dir); 
00069   };
00070   
00073   const char *GetRootDirectory() {
00074     return this->RootDirectory.c_str();
00075   };
00076   
00079   int Connect();
00080   
00083   int Import();
00084 
00087   int Commit(const char* url=NULL);
00088 
00091   void Clear(int removeSingletons);
00092 
00095   void ResetNodes();
00096   
00099   vtkMRMLNode* CreateNodeByClass(const char* className);
00100 
00106   void RegisterNodeClass(vtkMRMLNode* node);
00107   
00110   const char* GetClassNameByTag(const char *tagName);
00111 
00114   const char* GetTagByClassName(const char *className);
00115 
00118   vtkCollection* GetCurrentScene()
00119     {
00120     return this->CurrentScene;
00121     };
00122 
00128   void RequestNodeID(vtkMRMLNode *node, const char *ID);
00129   
00132   vtkMRMLNode* AddNode(vtkMRMLNode *n);
00133 
00136   vtkMRMLNode* CopyNode(vtkMRMLNode *n);
00137 
00140   vtkMRMLNode* AddNodeNoNotify(vtkMRMLNode *n);
00141 
00144   void NodeAdded(vtkMRMLNode *n);
00145   void NodeAdded() {this->NodeAdded(NULL);};
00146   
00149   void RemoveNode(vtkMRMLNode *n); 
00150 
00155   void RemoveNodeNoNotify(vtkMRMLNode *n); 
00156   
00160   int IsNodePresent(vtkMRMLNode *n) {
00161     return this->CurrentScene->vtkCollection::IsItemPresent((vtkObject *)n);};
00162 
00165   void InitTraversal() { 
00166     if (this && this->CurrentScene) 
00167       {
00168       this->CurrentScene->InitTraversal(); 
00169       }
00170   };
00171   
00174   vtkMRMLNode *GetNextNode() {
00175     return (vtkMRMLNode *)(this->CurrentScene->GetNextItemAsObject());};
00176   
00179   vtkMRMLNode *GetNextNodeByClass(const char* className);
00180 
00183   vtkCollection *GetNodesByName(const char* name);
00184 
00187   vtkMRMLNode *GetNodeByID(const char* name);
00188   //BTX
00189   vtkMRMLNode *GetNodeByID(std::string name);
00190   //ETX
00191   
00194   vtkCollection *GetNodesByClassByName(const char* className, const char* name);
00195   
00198   int GetNumberOfNodes () { return this->CurrentScene->GetNumberOfItems(); };
00199 
00202   vtkMRMLNode* GetNthNode(int n);
00203   
00206   vtkMRMLNode* GetNthNodeByClass(int n, const char* className );
00207   
00210   int GetNumberOfNodesByClass(const char* className);
00211   
00214   //BTX
00215   int GetNodesByClass(const char *className, std::vector<vtkMRMLNode *> &nodes);
00216   //ETX
00217   
00218   //BTX
00219   std::list<std::string> GetNodeClassesList();
00220   //ETX
00221   
00224   const char* GetNodeClasses();
00225   
00229   int GetNumberOfRegisteredNodeClasses();
00233   vtkMRMLNode * GetNthRegisteredNodeClass(int n);
00234 
00235   const char* GetUniqueNameByString(const char* className);
00239   int GetUniqueIDIndexByClass(const char* className);
00243   int GetUniqueIDIndexByClassFromIndex(const char* className, int hint);
00244   
00247   void InsertAfterNode( vtkMRMLNode *item, vtkMRMLNode *newItem);
00250   void InsertBeforeNode( vtkMRMLNode *item, vtkMRMLNode *newItem);
00251   
00254   int GetTransformBetweenNodes( vtkMRMLNode *node1, vtkMRMLNode *node2, 
00255                                 vtkGeneralTransform *xform );
00256 
00259   void SetUndoOn() {UndoFlag=true;};
00260   void SetUndoOff() {UndoFlag=false;};
00261   bool GetUndoFlag() {return UndoFlag;};
00262   void SetUndoFlag(bool flag) {UndoFlag = flag;};
00263 
00266   void Undo();
00267   
00270   void Redo();
00271 
00274   void ClearUndoStack();
00275   
00278   void ClearRedoStack();
00279 
00282   int GetNumberOfUndoLevels() { return (int)this->UndoStack.size();};
00283   
00286   int GetNumberOfRedoLevels() { return (int)this->RedoStack.size();};
00287 
00290   void SaveStateForUndo();
00293   void SaveStateForUndo(vtkMRMLNode *node);
00296   void SaveStateForUndo(vtkCollection *nodes);
00297   //BTX
00298   void SaveStateForUndo(std::vector<vtkMRMLNode *> nodes);
00299   //ETX
00300 
00304   void AddReferencedNodeID(const char *id, vtkMRMLNode *refrencingNode)
00305   {
00306     if (id && refrencingNode && refrencingNode->GetScene() && refrencingNode->GetID()) 
00307       {
00308       this->ReferencedIDs.push_back(id);
00309       this->ReferencingNodes.push_back(refrencingNode);
00310       }
00311   };
00312 
00316   void ClearReferencedNodeID()
00317   {
00318     this->ReferencedIDs.clear();
00319     this->ReferencingNodes.clear();
00320     this->ReferencedIDChanges.clear();
00321   };
00322 
00326   void RemoveReferencedNodeID(const char *id, vtkMRMLNode *refrencingNode);
00327 
00331   void RemoveNodeReferences(vtkMRMLNode *node);
00332 
00336   void RemoveReferencesToNode(vtkMRMLNode *node);
00337 
00341   void UpdateNodeReferences();
00342 
00346   void UpdateNodeReferences(vtkCollection* chekNodes);
00347 
00351   void CopyNodeReferences(vtkMRMLScene *scene);
00352 
00356   void UpdateNodeChangedIDs();
00357 
00361   void RemoveUnusedNodeReferences();
00362 
00365   void AddReservedID(const char *id);
00366 
00369   void RemoveReservedIDs() {
00370     this->ReservedIDs.clear();
00371   };
00372 
00376   const char* GetChangedID(const char* id);
00377 
00380   vtkCollection* GetReferencedNodes(vtkMRMLNode *node);
00381 
00385   void GetReferencedSubScene(vtkMRMLNode *node, vtkMRMLScene* newScene);
00386 
00387 
00388 //BTX
00391   static void SetActiveScene(vtkMRMLScene *);
00392   static vtkMRMLScene *GetActiveScene();
00393 //ETX
00394 
00395 //BTX
00398   enum
00399     {
00400       NodeAddedEvent = 66000,
00401       NodeRemovedEvent = 66001,
00402       NewSceneEvent = 66002,
00403       SceneCloseEvent = 66003,
00404       SceneClosingEvent = 66004,
00405       SceneLoadingErrorEvent = 66005,
00406       SceneEditedEvent = 66006,
00407       MetadataAddedEvent = 66007,
00408       LoadProgressFeedbackEvent = 66008,
00409       SaveProgressFeedbackEvent = 66009,
00410       SceneLoadStartEvent = 66010,
00411       SceneLoadEndEvent = 66011,
00412       SceneRestoredEvent = 66008,
00413       NodeAboutToBeAddedEvent = 66012,
00414       NodeAboutToBeRemovedEvent = 66013
00415     };
00416 //ETX
00417 
00420   int IsFilePathRelative(const char * filepath);
00421 
00424   vtkSetMacro(ErrorCode,unsigned long);
00425   vtkGetMacro(ErrorCode,unsigned long);
00426 
00429   vtkSetMacro(LoadFromXMLString,int);
00430   vtkGetMacro(LoadFromXMLString,int);
00431 
00434   vtkSetMacro(SaveToXMLString,int);
00435   vtkGetMacro(SaveToXMLString,int);
00436 
00437 //BTX
00440   void SetSceneXMLString(const std::string &xmlString) {
00441     this->SceneXMLString = xmlString;
00442   };
00443 
00446   std::string GetSceneXMLString() {
00447     return this->SceneXMLString;
00448   };
00449 //ETX
00450 
00453   vtkSetMacro(ReadDataOnLoad,int);
00454   vtkGetMacro(ReadDataOnLoad,int);
00455 
00456 //BTX
00459   void SetErrorMessage(const std::string &error) {
00460     this->ErrorMessage = error;
00461   };
00462 
00465   std::string GetErrorMessage() {
00466     return this->ErrorMessage;
00467   };
00468 //ETX
00469 
00472   void SetErrorMessage(const char * message)
00473     {
00474     this->SetErrorMessage(std::string(message));
00475     }
00476 
00479   const char *GetErrorMessagePointer()
00480     {
00481     return (this->GetErrorMessage().c_str());
00482     }
00483 
00486   unsigned long GetSceneModifiedTime()
00487     {
00488     if (this->CurrentScene && this->CurrentScene->GetMTime() > this->SceneModifiedTime)
00489       {
00490       this->SceneModifiedTime = this->CurrentScene->GetMTime();
00491       }
00492     return this->SceneModifiedTime;
00493     };
00494     
00497   void IncrementSceneModifiedTime()
00498     {
00499     this->SceneModifiedTime ++;
00500     };
00501 
00504   void Edited()
00505     {
00506     this->InvokeEvent( vtkMRMLScene::SceneEditedEvent );
00507     }
00508 
00509 
00512   vtkGetObjectMacro ( CacheManager, vtkCacheManager );
00513   vtkSetObjectMacro ( CacheManager, vtkCacheManager );
00516   vtkGetObjectMacro ( DataIOManager, vtkDataIOManager );
00517   vtkSetObjectMacro ( DataIOManager, vtkDataIOManager );
00520   vtkGetObjectMacro ( URIHandlerCollection, vtkCollection );
00521   vtkSetObjectMacro ( URIHandlerCollection, vtkCollection );
00524   vtkGetObjectMacro ( UserTagTable, vtkTagTable);
00525   vtkSetObjectMacro ( UserTagTable, vtkTagTable);  
00526 
00530   vtkURIHandler *FindURIHandler(const char *URI);
00533   vtkURIHandler *FindURIHandlerByName ( const char *name );
00536   void AddURIHandler(vtkURIHandler *handler);
00537 
00542   vtkGetMacro( IsClosed, int );
00543   vtkSetMacro( IsClosed, int );
00544   
00547   vtkGetStringMacro(LastLoadedVersion);
00548   vtkSetStringMacro(LastLoadedVersion);
00549 
00552   vtkGetStringMacro(Version);
00553   vtkSetStringMacro(Version);
00554 
00557   int IsModifiedSinceRead();
00558 
00561   void CopyRegisteredNodesToScene(vtkMRMLScene *scene);
00562 
00563 protected:
00564   vtkMRMLScene();
00565   ~vtkMRMLScene();
00566   vtkMRMLScene(const vtkMRMLScene&);
00567   void operator=(const vtkMRMLScene&);
00568   
00569   void PushIntoUndoStack();
00570   void PushIntoRedoStack();
00571 
00572   void CopyNodeInUndoStack(vtkMRMLNode *node);
00573   void CopyNodeInRedoStack(vtkMRMLNode *node);
00574 
00575   void AddReferencedNodes(vtkMRMLNode *node, vtkCollection *refNodes);
00576 
00579   static void SceneCallback( vtkObject *caller, unsigned long eid, 
00580                              void *clientData, void *callData );
00581   vtkCollection* CurrentScene;
00582   
00584   vtkCacheManager *CacheManager;
00585   vtkDataIOManager *DataIOManager;
00586   vtkCollection *URIHandlerCollection;
00587   vtkTagTable *UserTagTable;
00588 
00589   unsigned long SceneModifiedTime;
00590   
00591   int UndoStackSize;
00592   bool UndoFlag;
00593   
00594   bool InUndo;
00595 
00596   //BTX
00597   std::list< vtkCollection* >  UndoStack;
00598   std::list< vtkCollection* >  RedoStack;
00599   //ETX
00600   
00601   //BTX
00602   std::string         URL;
00603   std::map< std::string, int> UniqueIDByClass;
00604   std::vector< std::string >  UniqueIDs;
00605   std::vector< vtkMRMLNode* > RegisteredNodeClasses;
00606   std::vector< std::string >  RegisteredNodeTags;
00607   std::string          RootDirectory;
00608 
00609   std::vector< std::string > ReferencedIDs;
00610   std::vector< vtkMRMLNode* > ReferencingNodes;
00611   std::map< std::string, std::string> ReferencedIDChanges;
00612   
00613   //vtksys::hash_map<const char*, vtkMRMLNode*> NodeIDs;
00614   std::map<std::string, vtkMRMLNode*> NodeIDs;
00615   std::map<std::string, int> ReservedIDs;
00616 
00617   std::string ErrorMessage;
00618 
00619   std::string SceneXMLString;
00620   //ETX
00621   
00622   int LoadFromXMLString;
00623 
00624   int SaveToXMLString;
00625 
00626   int ReadDataOnLoad;
00627 
00628   void UpdateNodeIDs();
00629 
00630   unsigned long NodeIDsMTime;
00631 
00632   void RemoveAllNodesExceptSingletons();
00633 
00634   vtkSetStringMacro(ClassNameList);
00635   vtkGetStringMacro(ClassNameList);
00636 
00637   char *Version;
00638 
00639   char *LastLoadedVersion;
00640   vtkCallbackCommand *DeleteEventCallback;
00641   
00642 private:
00644   void AddItem(vtkObject *o) { this->CurrentScene->vtkCollection::AddItem(o); this->Modified();};
00645   void RemoveItem(vtkObject *o) { this->CurrentScene->vtkCollection::RemoveItem(o); this->Modified();};
00646   void RemoveItem(int i) { this->CurrentScene->vtkCollection::RemoveItem(i); this->Modified();};
00647   int  IsItemPresent(vtkObject *o) { return this->CurrentScene->vtkCollection::IsItemPresent(o);};
00648   
00649   int LoadIntoScene(vtkCollection* scene);
00650 
00651   unsigned long ErrorCode;
00652 
00653   char* ClassNameList;
00654 
00655   static vtkMRMLScene *ActiveScene;
00656 
00657   int IsClosed;
00658 };
00659 
00660 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1