15 #ifndef __vtkMRMLNode_h    16 #define __vtkMRMLNode_h    21 #include "vtkIdTypeArray.h"    22 #include "vtkIntArray.h"    28 #include <vtkObject.h>    29 #include <vtkSmartPointer.h>    30 #include <vtkWeakPointer.h>    31 class vtkCallbackCommand;
    41 #ifndef vtkSetMRMLObjectMacro    42 #define vtkSetMRMLObjectMacro(node,value)  {this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) );};    46 #ifndef vtkSetAndObserveMRMLObjectMacro    47 #define vtkSetAndObserveMRMLObjectMacro(node,value)  {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value) );};    50 #ifndef vtkSetAndObserveMRMLObjectMacroNoWarning    51 #define vtkSetAndObserveMRMLObjectMacroNoWarning(node,value)  {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value), 0.0, false  );};    54 #ifndef vtkSetAndObserveMRMLObjectEventsMacro    55 #define vtkSetAndObserveMRMLObjectEventsMacro(node,value,events)  {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events));};    58 #ifndef vtkSetAndObserveMRMLObjectEventsMacroNoWarning    59 #define vtkSetAndObserveMRMLObjectEventsMacroNoWarning(node,value,events)  {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events), NULL , false );};    62 #ifndef vtkObserveMRMLObjectMacro    63 #define vtkObserveMRMLObjectMacro(node)  {this->MRMLObserverManager->ObserveObject ( (node) );};    66 #ifndef vtkObserveMRMLObjectEventsMacro    67 #define vtkObserveMRMLObjectEventsMacro(node, events)  {this->MRMLObserverManager->AddObjectEvents ( (node), (events) );};    70 #ifndef vtkUnObserveMRMLObjectMacro    71 #define vtkUnObserveMRMLObjectMacro(node)  {this->MRMLObserverManager->RemoveObjectEvents ( (node) );};    74 #ifndef vtkSetReferenceStringBodyMacro    75 #define vtkSetReferenceStringBodyMacro(name) \    76   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \    77   if ( this->name == NULL && _arg == NULL) { return;} \    78   if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \    79   std::string oldValue; \    80   if (this->name) { oldValue = this->name; delete [] this->name;  } \    83     size_t n = strlen(_arg) + 1; \    84     char *cp1 =  new char[n]; \    85     const char *cp2 = (_arg); \    87     do { *cp1++ = *cp2++; } while ( --n ); \    94   if (this->Scene && this->name) \    96     if (oldValue.size() > 0) \    98       this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \   100     this->Scene->AddReferencedNodeID(this->name, this); \   104 #ifndef vtkSetReferenceStringMacro   105 #define vtkSetReferenceStringMacro(name) \   106 virtual void Set##name (const char* _arg) \   108   vtkSetReferenceStringBodyMacro(name)\   112 #ifndef vtkCxxSetReferenceStringMacro   113 #define vtkCxxSetReferenceStringMacro(class,name)   \   114 void class::Set##name (const char* _arg)            \   116   vtkSetReferenceStringBodyMacro(name);             \   120 #ifndef vtkMRMLNodeNewMacro   121 #define vtkMRMLNodeNewMacro(newClass) \   122   vtkStandardNewMacro(newClass); \   123   vtkMRMLNode* newClass::CreateNodeInstance() \   125     return newClass::New(); \   144   void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
   189   virtual void WriteXML(ostream& of, 
int indent);
   255     return disabledModify;
   265   virtual int EndModify(
int previousDisableModifiedEventState)
   268     if (!previousDisableModifiedEventState)
   272     return this->ModifiedEventPending;
   320   virtual void ProcessMRMLEvents ( vtkObject *caller, 
unsigned long event, 
void *callData );
   336   vtkSetStringMacro(
Name);
   337   vtkGetStringMacro(
Name);
   341   vtkGetStringMacro(
ID);
   369   vtkSetStringMacro(SingletonTag);
   370   vtkGetStringMacro(SingletonTag);
   396   vtkGetMacro(DisableModifiedEvent, 
int);
   399     this->DisableModifiedEvent = onOff;
   415   vtkGetMacro(ModifiedEventPending, 
int);
   438       ++this->ModifiedEventPending;
   451     int oldModifiedEventPending = 0;
   453     if ( this->ModifiedEventPending )
   455       oldModifiedEventPending += this->ModifiedEventPending;
   456       this->ModifiedEventPending = 0;
   460     if (!this->CustomModifiedEventPending.empty())
   465       std::vector<int> customEventsToInvoke;
   466       for (std::map< int, int >::iterator it=this->CustomModifiedEventPending.begin(); it!=this->CustomModifiedEventPending.end(); ++it)
   468         oldModifiedEventPending += it->second;
   469         customEventsToInvoke.push_back(it->first);
   471       this->CustomModifiedEventPending.clear();
   472       for (std::vector<int>::iterator it=customEventsToInvoke.begin(); it!=customEventsToInvoke.end(); ++it)
   474         this->InvokeEvent(*it);
   477     return oldModifiedEventPending;
   497       this->InvokeEvent(eventId, callData);
   503       ++this->CustomModifiedEventPending[eventId];
   589   void AddNodeReferenceRole(
const char *referenceRole, 
const char *mrmlAttributeName=0, vtkIntArray *events=0);
   693                            std::vector<const char*> &referencedNodeIDs);
   728     void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) VTK_OVERRIDE {};
   731     vtkSetStringMacro(ReferenceRole);
   732     vtkGetStringMacro(ReferenceRole);
   734     vtkSetStringMacro(ReferencedNodeID);
   735     vtkGetStringMacro(ReferencedNodeID);
   742     void SetEvents(vtkIntArray* events);
   743     vtkIntArray* GetEvents() 
const;
   782   static void MRMLCallback( vtkObject *caller,
   783                             unsigned long eid, 
void *clientData, 
void *callData );
   787   vtkSetStringMacro( TempURLString );
   788   vtkGetStringMacro( TempURLString );
   797   virtual const char* GetReferenceRoleFromMRMLAttributeName(
const char* attName);
   806   virtual const char* GetMRMLAttributeNameFromReferenceRole(
const char* refRole);
   811   virtual bool IsReferenceRoleGeneric(
const char* refRole);
   816   virtual void UpdateNodeReferences(
const char* referenceRole = NULL);
   822   virtual void UpdateNthNodeReference(
const char* referenceRole, 
int n);
   835   void GetUpdatedReferencedNodeEventList(
int& oldReferencedNodeUseCount, 
int& newReferencedNodeUseCount,
   836     vtkIntArray* oldConsolidatedEventList, vtkIntArray* newConsolidatedEventList,
   842   virtual void InvalidateNodeReferences();
   866   void ParseReferencesAttribute(
const char *attValue, std::map<std::string, std::string> &references);
   910   void SetID(
const char* newID);
   917   int DisableModifiedEvent;
   918   int ModifiedEventPending;
   919   std::map<int, int> CustomModifiedEventPending; 
 vtkMRMLNode * SetNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID)
Set a N-th reference from this node with specified referencedNodeID for a specific referenceRole...
 
const char * GetNthNodeReferenceID(const char *referenceRole, int n)
Return the string of the Nth node ID for a specific reference role. 
 
vtkMRMLNode * GetNodeReference(const char *referenceRole)
 
virtual void Copy(vtkMRMLNode *node) VTK_OVERRIDE
Copy the node's attributes to this object. 
 
void DisableModifiedEventOff()
 
std::vector< vtkSmartPointer< vtkMRMLNodeReference > > NodeReferenceListType
 
virtual int InvokePendingModifiedEvent()
Invokes any modified events that are pending. 
 
void AddNodeReferenceRole(const char *referenceRole, const char *mrmlAttributeName=0, vtkIntArray *events=0)
Add a referenceRole. 
 
vtkMRMLNode * SetAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=0)
Set and observe a reference node from this node for a specific referenceRole. 
 
std::map< std::string, NodeReferenceListType > NodeReferencesType
 
std::vector< std::string > GetAttributeNames()
Get all attribute names. 
 
virtual void WriteNodeBodyXML(ostream &of, int indent) VTK_OVERRIDE
Write this node's body to a MRML file in XML format. 
 
vtkWeakPointer< vtkMRMLNode > ReferencingNode
Points to this MRML node (that added the reference) 
 
virtual vtkMRMLScene * GetScene()
Only the scene can set itself to the node. 
 
virtual void Reset(vtkMRMLNode *defaultNode)
Reset node attributes to the initial state as defined in the constructor or the passed default node...
 
Manages adding and deleting of obserevers with events. 
 
void CopyWithSceneWithSingleModifiedEvent(vtkMRMLNode *node)
Copy everything (including Scene and ID) from another node of the same type. 
 
const char * GetNodeReferenceID(const char *referenceRole)
Utility function that returns the first node id for a specific referenceRole. 
 
void GetNodeReferenceRoles(std::vector< std::string > &roles)
 
void SetAttribute(const char *name, const char *value)
Set a name value pair attribute. 
 
int InMRMLCallbackFlag
Flag to avoid event loops. 
 
vtkObserverManager * MRMLObserverManager
 
virtual void OnNodeAddedToScene()
 
const char * GetNthNodeReferenceRole(int n)
 
virtual int StartModify()
Start modifying the node. Disable Modify events. 
 
virtual void ProcessMRMLEvents(vtkObject *, unsigned long, void *) VTK_OVERRIDE
alternative method to propagate events generated in Storage nodes 
 
virtual void UpdateReferences()
The method should remove all pointers and observations to all nodes that are not in the scene anymore...
 
virtual void CopyReferences(vtkMRMLNode *node)
Copy the references of the node into this. 
 
std::map< std::string, vtkSmartPointer< vtkIntArray > > NodeReferenceEventsType
 
void SetDisableModifiedEvent(int onOff)
 
virtual int GetDisableModifiedEvent()
Turn on/off generating InvokeEvent for set macros. 
 
virtual void UpdateReferenceID(const char *oldID, const char *newID)
Update the stored reference to another node in the scene. 
 
std::map< std::string, std::string > NodeReferenceMRMLAttributeNames
 
const char * GetAttribute(const char *name)
Get value of a name value pair attribute. 
 
bool HasNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Return true if referencedNodeID is in the node ID list for a specific referenceRole. 
 
virtual void OnNodeReferenceModified(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is modified. 
 
virtual char * GetSingletonTag()
 
NodeReferenceEventsType NodeReferenceEvents
 
void GetNodeReferenceIDs(const char *referenceRole, std::vector< const char *> &referencedNodeIDs)
Return a list of the referenced node IDs. 
 
vtkSmartPointer< vtkMRMLNode > ReferencedNode
The referenced node that is actually observed now. 
 
void SetAddToSceneNoModify(int value)
 
virtual void SetSceneReferences()
Update the references of the node to the scene. 
 
void RemoveAttribute(const char *name)
Remove attribute with the specified name. 
 
A set of MRML Nodes that supports serialization and undo/redo. 
 
virtual const char * GetNodeTagName() VTK_OVERRIDE
Get node XML tag name (like Volume, Model) 
 
vtkSmartPointer< vtkIntArray > Events
 
vtkMRMLNode * AddNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Convenience method that adds a referencedNodeID at the end of the list. 
 
virtual int EndModify(int previousDisableModifiedEventState)
End modifying the node. 
 
void RemoveNthNodeReferenceID(const char *referenceRole, int n)
Convenience method that removes the Nth node ID from the list. 
 
virtual void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is removed (set to NULL). 
 
vtkMRMLNode * AddAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=0)
Add and observe a reference node from this node for a specific referenceRole. 
 
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...
 
virtual void ProcessChildNode(vtkMRMLNode *)
Set dependencies between this node and a child node when parsing XML file. 
 
virtual void SetScene(vtkMRMLScene *scene)
 
void PrintSelf(ostream &vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) VTK_OVERRIDE
 
const char * URLDecodeString(const char *inString)
Decode a URL string. 
 
char * ReferenceRole
Name of the reference role. 
 
AttributesType Attributes
 
vtkMRMLNode * SetAndObserveNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID, vtkIntArray *events=0)
Set and observe the Nth node ID for a specific reference role. 
 
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
 
virtual void WriteXML(ostream &of, int indent) VTK_OVERRIDE
Write this node's information to a MRML file in XML format. 
 
vtkMRMLNode * GetNthNodeReference(const char *referenceRole, int n)
Get referenced MRML node for a specific referenceRole. 
 
std::map< std::string, std::string > AttributesType
 
void CopyWithSingleModifiedEvent(vtkMRMLNode *node)
 
void RemoveNodeReferenceIDs(const char *referenceRole)
Remove all node IDs and associated nodes for a specific referenceRole. 
 
void CopyWithoutModifiedEvent(vtkMRMLNode *node)
 
vtkCallbackCommand * MRMLCallbackCommand
Holders for MRML callbacks. 
 
vtkWeakPointer< vtkMRMLScene > Scene
 
virtual void InvokeCustomModifiedEvent(int eventId, void *callData=NULL)
This method allows the node to compress events. 
 
virtual vtkMRMLNode * CreateNodeInstance() VTK_OVERRIDE
MRMLNode methods. 
 
vtkMRMLNode * SetNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Set a reference to a node with specified nodeID from this node for a specific referenceRole. 
 
virtual void OnNodeReferenceAdded(vtkMRMLNodeReference *reference)
 
virtual void UpdateNodeReferences(const char *referenceRole=NULL)
 
void GetNodeReferences(const char *referenceRole, std::vector< vtkMRMLNode *> &nodes)
Return a list of the referenced nodes. 
 
void SetInMRMLCallbackFlag(int flag)
 
virtual void Modified() VTK_OVERRIDE
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent. 
 
void CopyWithScene(vtkMRMLNode *node)
Copy everything (including Scene and ID) from another node of the same type. 
 
Abstract Superclass for all specific types of MRML nodes. 
 
Class to hold information about a node reference. 
 
const char * URLEncodeString(const char *inString)
Encode a URL string. 
 
NodeReferencesType NodeReferences
 
virtual void SetSingletonTag(const char *)
Tag that make this node a singleton in the scene. 
 
void DisableModifiedEventOn()
 
int GetNumberOfNodeReferenceRoles()
 
virtual void UpdateScene(vtkMRMLScene *)
 
virtual void ReadXMLAttributes(const char **atts) VTK_OVERRIDE
Read node attributes from XML file.