Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLSubjectHierarchyNode.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
6  Queen's University, Kingston, ON, Canada. All Rights Reserved.
7 
8  See COPYRIGHT.txt
9  or http://www.slicer.org/copyright/copyright.txt for details.
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16 
17  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
18  and was supported through the Applied Cancer Research Unit program of Cancer Care
19  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
20 
21 ==============================================================================*/
22 
23 // .NAME vtkMRMLSubjectHierarchyNode
24 // .SECTION Description
25 // MRML node to represent subject hierarchy tree
26 //
27 
28 #ifndef __vtkMRMLSubjectHierarchyNode_h
29 #define __vtkMRMLSubjectHierarchyNode_h
30 
31 // MRML includes
32 #include <vtkMRMLNode.h>
34 
35 class vtkCallbackCommand;
36 class vtkIdList;
37 class vtkMRMLDisplayNode;
40 
56 class VTK_MRML_EXPORT vtkMRMLSubjectHierarchyNode : public vtkMRMLNode
57 {
58 public:
59  static const vtkIdType INVALID_ITEM_ID;
60 
61  // Separator characters for (de)serializing the UID and the attributes map
62  static const std::string SUBJECTHIERARCHY_SEPARATOR;
63  static const std::string SUBJECTHIERARCHY_NAME_VALUE_SEPARATOR;
64 
65  // Attribute name to identify subject hierarchy 2.0 nodes in scene MRML files
66  static const std::string SUBJECTHIERARCHY_VERSION_ATTRIBUTE_NAME;
67 
68  enum
69  {
70  SubjectHierarchyItemAddedEvent = 62000,
94  };
95 
99  {
100  vtkIdList* itemIDsToShow = nullptr;
101  vtkMRMLAbstractViewNode* viewNode = nullptr;
102  };
103 
104 public:
105  static vtkMRMLSubjectHierarchyNode *New();
107  void PrintSelf(ostream& os, vtkIndent indent) override;
108 
109  vtkMRMLNode* CreateNodeInstance() override;
110 
112  virtual void ReadItemFromXML(const char** atts);
114  void WriteXML(ostream& of, int indent) override;
116  void WriteNodeBodyXML(ostream& of, int indent) override;
117 
119  void Copy(vtkMRMLNode *node) override;
120 
122  const char* GetNodeTagName() override;
123 
124 // Get/Set methods
125 public:
128  static vtkMRMLSubjectHierarchyNode* GetSubjectHierarchyNode(vtkMRMLScene* scene);
129 
131  vtkIdType GetSceneItemID();
133  vtkMRMLNode* GetItemDataNode(vtkIdType itemID);
135  void SetItemName(vtkIdType itemID, std::string name);
138  std::string GetItemName(vtkIdType itemID);
140  void SetItemLevel(vtkIdType itemID, std::string level);
142  std::string GetItemLevel(vtkIdType itemID);
144  void SetItemOwnerPluginName(vtkIdType itemID, std::string ownerPluginName);
146  std::string GetItemOwnerPluginName(vtkIdType itemID);
148  void SetItemExpanded(vtkIdType itemID, bool expanded);
150  bool GetItemExpanded(vtkIdType itemID);
151 
153  void SetItemUID(vtkIdType itemID, std::string uidName, std::string uidValue);
156  std::string GetItemUID(vtkIdType itemID, std::string uidName);
157 
159  void SetItemAttribute(vtkIdType itemID, std::string attributeName, std::string attributeValue);
162  bool RemoveItemAttribute(vtkIdType itemID, std::string attributeName);
165  std::string GetItemAttribute(vtkIdType itemID, std::string attributeName);
168  std::vector<std::string> GetItemAttributeNames(vtkIdType itemID);
172  bool HasItemAttribute(vtkIdType itemID, std::string attributeName);
173 
176  void ItemModified(vtkIdType itemID);
177 
180  void RequestOwnerPluginSearch(vtkIdType itemID);
184  void RequestOwnerPluginSearch(vtkMRMLNode* dataNode);
185 
187  static vtkIdType GetInvalidItemID() { return INVALID_ITEM_ID; }
188 
194  void SetItemDataNode(vtkIdType itemID, vtkMRMLNode* dataNode);
195 
196 // Hierarchy related methods
197 public:
203  vtkIdType CreateItem(vtkIdType parentItemID, vtkMRMLNode* dataNode, const char* ownerPluginName=nullptr);
212  vtkIdType CreateHierarchyItem(vtkIdType parentItemID, std::string name, std::string level, int positionUnderParent = -1);
217  vtkIdType CreateSubjectItem(vtkIdType parentItemID, std::string name);
222  vtkIdType CreateStudyItem(vtkIdType parentItemID, std::string name);
227  vtkIdType CreateFolderItem(vtkIdType parentItemID, std::string name);
228 
233  bool RemoveItem(vtkIdType itemID, bool removeDataNode=true, bool recursive=true);
238  bool RemoveItemChildren(vtkIdType itemID, bool removeDataNodes=true, bool recursive=true);
243  void RemoveAllItems(bool removeDataNode=false);
244 
247  void SetItemParent(vtkIdType itemID, vtkIdType parentItemID, bool enableCircularCheck=true);
250  vtkIdType GetItemParent(vtkIdType itemID);
253  int GetItemPositionUnderParent(vtkIdType itemID);
256  vtkIdType GetItemByPositionUnderParent(vtkIdType parentItemID, int position);
257 
262  void GetItemChildren(vtkIdType itemID, std::vector<vtkIdType>& childIDs, bool recursive=false);
264  void GetItemChildren(vtkIdType itemID, vtkIdList* childIDs, bool recursive=false);
265 
268  bool ReparentItemByDataNode(vtkIdType itemID, vtkMRMLNode* newParentNode);
272  bool MoveItem(vtkIdType itemID, vtkIdType beforeItemID);
273 
274 // Item finder methods
275 public:
280  vtkIdType GetItemByUID(const char* uidName, const char* uidValue);
281 
287  vtkIdType GetItemByUIDList(const char* uidName, const char* uidValue);
288 
292  vtkIdType GetItemByDataNode(vtkMRMLNode* dataNode);
293 
297  vtkIdType GetItemByName(std::string name);
298 
305  void GetItemsByName(std::string name, vtkIdList* foundItemIds, bool contains=false);
306 
312  vtkIdType GetItemChildWithName(vtkIdType parentItemID, std::string name, bool recursive=false);
313 
318  void GetDataNodesInBranch(vtkIdType itemID, vtkCollection* dataNodeCollection, const char* childClass=nullptr);
319 
324  vtkMRMLNode* GetParentDataNode(vtkMRMLNode* dataNode, bool recursive=false);
325 
326 // Utility functions
327 public:
330  void SetDisplayVisibilityForBranch(vtkIdType itemID, int visible);
334  int GetDisplayVisibilityForBranch(vtkIdType itemID);
335 
339  void SetItemDisplayVisibility(vtkIdType itemID, int visible);
341  int GetItemDisplayVisibility(vtkIdType itemID);
342 
345  vtkMRMLDisplayNode* GetDisplayNodeForItem(vtkIdType itemID);
346 
350  bool IsItemLevel(vtkIdType itemID, std::string level);
351 
355  bool IsItemVirtualBranchParent(vtkIdType itemID);
356 
363  std::string GetAttributeFromItemAncestor(vtkIdType itemID, std::string attributeName, std::string level="");
364 
367  vtkIdType GetItemAncestorAtLevel(vtkIdType itemID, std::string level);
368 
372  bool IsAnyNodeInBranchTransformed(vtkIdType itemID, bool includeParentItem=true, vtkMRMLTransformNode* exceptionNode=nullptr);
373 
375  static void DeserializeUIDList(std::string uidListString, std::vector<std::string>& deserializedUIDList);
376 
381  std::vector<vtkIdType> GetItemsReferencedFromItemByDICOM(vtkIdType itemID);
384  void GetItemsReferencedFromItemByDICOM(vtkIdType itemID, vtkIdList* referencingIdList);
385 
390  std::vector<vtkIdType> GetItemsReferencingItemByDICOM(vtkIdType itemID);
393  void GetItemsReferencingItemByDICOM(vtkIdType itemID, vtkIdList* referencingIdList);
394 
396  std::string GenerateUniqueItemName(std::string name);
397 
399  int GetNumberOfItems();
400 
403  int GetNumberOfItemChildren(vtkIdType itemID, bool recursive=false);
404 
406  void PrintItem(vtkIdType itemID, ostream& os, vtkIndent indent);
407 
409  static vtkMRMLSubjectHierarchyNode* ResolveSubjectHierarchy(vtkMRMLScene* scene);
410 
412  void ShowItemsInView(vtkIdList* itemIDs, vtkMRMLAbstractViewNode* viewNode);
413 
414 protected:
416  static void ItemEventCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
417 
418 protected:
420  ~vtkMRMLSubjectHierarchyNode() override;
423 
424  class vtkInternal;
425  vtkInternal* Internal;
426  friend class vtkInternal;
427 
429  vtkSmartPointer<vtkCallbackCommand> ItemEventCallbackCommand;
430 };
431 
432 #endif
virtual void WriteNodeBodyXML(ostream &of, int indent)
Write this node&#39;s body to a MRML file in XML format.
Event invoked when item resolving starts (e.g. after scene import)
static const std::string SUBJECTHIERARCHY_VERSION_ATTRIBUTE_NAME
MRML node for representing a transformation between this node space and a parent node space...
vtkSmartPointer< vtkCallbackCommand > ItemEventCallbackCommand
Command handling events from subject hierarchy items.
Event invoked when item resolving finished (e.g. after scene import)
void operator=(const vtkMRMLNode &)
virtual vtkMRMLNode * CreateNodeInstance()=0
Create instance of the default node. Like New only virtual.
MRML node to represent a complete subject hierarchy tree.
virtual void Copy(vtkMRMLNode *node)
Copy node contents from another node of the same type. Does not copy node ID and Scene. Performs deep copy - an independent copy is created from all data, including bulk data.
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D...
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
static const std::string SUBJECTHIERARCHY_NAME_VALUE_SEPARATOR
virtual void WriteXML(ostream &of, int indent)
static vtkIdType GetInvalidItemID()
Python accessor for the invalid ID.
static const std::string SUBJECTHIERARCHY_SEPARATOR
void PrintSelf(ostream &os, vtkIndent indent) override
Abstract class that contains graphical display properties for displayable nodes.
virtual const char * GetNodeTagName()=0
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167