Slicer 5.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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
35class vtkCallbackCommand;
36class vtkIdList;
40
55class VTK_MRML_EXPORT vtkMRMLSubjectHierarchyNode : public vtkMRMLNode
56{
57public:
58 static const vtkIdType INVALID_ITEM_ID;
59
60 // Separator characters for (de)serializing the UID and the attributes map
61 static const std::string SUBJECTHIERARCHY_SEPARATOR;
62 static const std::string SUBJECTHIERARCHY_NAME_VALUE_SEPARATOR;
63
64 // Attribute name to identify subject hierarchy 2.0 nodes in scene MRML files
66
67 enum
68 {
69 SubjectHierarchyItemAddedEvent = 62000,
93 };
94
98 {
99 vtkIdList* itemIDsToShow = nullptr;
100 vtkMRMLAbstractViewNode* viewNode = nullptr;
101 };
102
103public:
106 void PrintSelf(ostream& os, vtkIndent indent) override;
107
109
111 virtual void ReadItemFromXML(const char** atts);
113 void WriteXML(ostream& of, int indent) override;
115 void WriteNodeBodyXML(ostream& of, int indent) override;
116
118 void Copy(vtkMRMLNode *node) override;
119
121 const char* GetNodeTagName() override;
122
123// Get/Set methods
124public:
128
130 vtkIdType GetSceneItemID();
132 vtkMRMLNode* GetItemDataNode(vtkIdType itemID);
134 void SetItemName(vtkIdType itemID, std::string name);
137 std::string GetItemName(vtkIdType itemID);
139 void SetItemLevel(vtkIdType itemID, std::string level);
141 std::string GetItemLevel(vtkIdType itemID);
143 void SetItemOwnerPluginName(vtkIdType itemID, std::string ownerPluginName);
145 std::string GetItemOwnerPluginName(vtkIdType itemID);
147 void SetItemExpanded(vtkIdType itemID, bool expanded);
149 bool GetItemExpanded(vtkIdType itemID);
150
152 void SetItemUID(vtkIdType itemID, std::string uidName, std::string uidValue);
155 bool RemoveItemUID(vtkIdType itemID, std::string uidName);
158 std::string GetItemUID(vtkIdType itemID, std::string uidName);
161 std::vector<std::string> GetItemUIDNames(vtkIdType itemID);
165 bool HasItemUID(vtkIdType itemID, std::string uidName);
166
168 void SetItemAttribute(vtkIdType itemID, std::string attributeName, std::string attributeValue);
171 bool RemoveItemAttribute(vtkIdType itemID, std::string attributeName);
174 std::string GetItemAttribute(vtkIdType itemID, std::string attributeName);
177 std::vector<std::string> GetItemAttributeNames(vtkIdType itemID);
181 bool HasItemAttribute(vtkIdType itemID, std::string attributeName);
182
185 void ItemModified(vtkIdType itemID);
186
189 void RequestOwnerPluginSearch(vtkIdType itemID);
194
196 static vtkIdType GetInvalidItemID() { return INVALID_ITEM_ID; }
197
203 void SetItemDataNode(vtkIdType itemID, vtkMRMLNode* dataNode);
204
205// Hierarchy related methods
206public:
212 vtkIdType CreateItem(vtkIdType parentItemID, vtkMRMLNode* dataNode, const char* ownerPluginName=nullptr);
221 vtkIdType CreateHierarchyItem(vtkIdType parentItemID, std::string name, std::string level, int positionUnderParent = -1);
226 vtkIdType CreateSubjectItem(vtkIdType parentItemID, std::string name);
231 vtkIdType CreateStudyItem(vtkIdType parentItemID, std::string name);
236 vtkIdType CreateFolderItem(vtkIdType parentItemID, std::string name);
237
242 bool RemoveItem(vtkIdType itemID, bool removeDataNode=true, bool recursive=true);
247 bool RemoveItemChildren(vtkIdType itemID, bool removeDataNodes=true, bool recursive=true);
252 void RemoveAllItems(bool removeDataNode=false);
253
256 void SetItemParent(vtkIdType itemID, vtkIdType parentItemID, bool enableCircularCheck=true);
259 vtkIdType GetItemParent(vtkIdType itemID);
262 int GetItemPositionUnderParent(vtkIdType itemID);
265 vtkIdType GetItemByPositionUnderParent(vtkIdType parentItemID, int position);
266
271 void GetItemChildren(vtkIdType itemID, std::vector<vtkIdType>& childIDs, bool recursive=false);
273 void GetItemChildren(vtkIdType itemID, vtkIdList* childIDs, bool recursive=false);
274
277 bool ReparentItemByDataNode(vtkIdType itemID, vtkMRMLNode* newParentNode);
281 bool MoveItem(vtkIdType itemID, vtkIdType beforeItemID);
282
283// Item finder methods
284public:
289 vtkIdType GetItemByUID(const char* uidName, const char* uidValue);
290
296 vtkIdType GetItemByUIDList(const char* uidName, const char* uidValue);
297
301 vtkIdType GetItemByDataNode(vtkMRMLNode* dataNode);
302
306 vtkIdType GetItemByName(std::string name);
307
314 void GetItemsByName(std::string name, vtkIdList* foundItemIds, bool contains=false);
315
321 vtkIdType GetItemChildWithName(vtkIdType parentItemID, std::string name, bool recursive=false);
322
327 void GetDataNodesInBranch(vtkIdType itemID, vtkCollection* dataNodeCollection, const char* childClass=nullptr);
328
333 vtkMRMLNode* GetParentDataNode(vtkMRMLNode* dataNode, bool recursive=false);
334
335// Utility functions
336public:
339 void SetDisplayVisibilityForBranch(vtkIdType itemID, int visible);
343 int GetDisplayVisibilityForBranch(vtkIdType itemID);
344
348 void SetItemDisplayVisibility(vtkIdType itemID, int visible);
350 int GetItemDisplayVisibility(vtkIdType itemID);
351
355
359 bool IsItemLevel(vtkIdType itemID, std::string level);
360
364 bool IsItemVirtualBranchParent(vtkIdType itemID);
365
372 std::string GetAttributeFromItemAncestor(vtkIdType itemID, std::string attributeName, std::string level="");
373
376 vtkIdType GetItemAncestorAtLevel(vtkIdType itemID, std::string level);
377
381 bool IsAnyNodeInBranchTransformed(vtkIdType itemID, bool includeParentItem=true, vtkMRMLTransformNode* exceptionNode=nullptr);
382
384 static void DeserializeUIDList(std::string uidListString, std::vector<std::string>& deserializedUIDList);
385
390 std::vector<vtkIdType> GetItemsReferencedFromItemByDICOM(vtkIdType itemID);
393 void GetItemsReferencedFromItemByDICOM(vtkIdType itemID, vtkIdList* referencingIdList);
394
399 std::vector<vtkIdType> GetItemsReferencingItemByDICOM(vtkIdType itemID);
402 void GetItemsReferencingItemByDICOM(vtkIdType itemID, vtkIdList* referencingIdList);
403
405 std::string GenerateUniqueItemName(std::string name);
406
409
412 int GetNumberOfItemChildren(vtkIdType itemID, bool recursive=false);
413
415 void PrintItem(vtkIdType itemID, ostream& os, vtkIndent indent);
416
419
421 void ShowItemsInView(vtkIdList* itemIDs, vtkMRMLAbstractViewNode* viewNode);
422
423protected:
425 static void ItemEventCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
426
427protected:
432
433 class vtkInternal;
434 vtkInternal* Internal;
435 friend class vtkInternal;
436
438 vtkSmartPointer<vtkCallbackCommand> ItemEventCallbackCommand;
439};
440
441#endif
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D,...
Abstract class that contains graphical display properties for displayable nodes.
Abstract Superclass for all specific types of MRML nodes.
A set of MRML Nodes that supports serialization and undo/redo.
MRML node to represent a complete subject hierarchy tree.
void SetItemUID(vtkIdType itemID, std::string uidName, std::string uidValue)
Set UID to the subject hierarchy item.
vtkIdType GetItemByDataNode(vtkMRMLNode *dataNode)
std::vector< std::string > GetItemUIDNames(vtkIdType itemID)
~vtkMRMLSubjectHierarchyNode() override
static vtkMRMLSubjectHierarchyNode * New()
void WriteNodeBodyXML(ostream &of, int indent) override
Write this node's body to a MRML file in XML format.
int GetItemDisplayVisibility(vtkIdType itemID)
Get subject hierarchy item visibility.
bool HasItemAttribute(vtkIdType itemID, std::string attributeName)
bool GetItemExpanded(vtkIdType itemID)
Get expanded flag for a subject hierarchy item.
void SetItemAttribute(vtkIdType itemID, std::string attributeName, std::string attributeValue)
Add attribute to the subject hierarchy item.
vtkIdType GetItemByName(std::string name)
void SetItemLevel(vtkIdType itemID, std::string level)
Convenience function to set level attribute for a subject hierarchy item.
void SetItemParent(vtkIdType itemID, vtkIdType parentItemID, bool enableCircularCheck=true)
void operator=(const vtkMRMLSubjectHierarchyNode &)
std::string GenerateUniqueItemName(std::string name)
Generate unique item name.
static const std::string SUBJECTHIERARCHY_NAME_VALUE_SEPARATOR
void PrintItem(vtkIdType itemID, ostream &os, vtkIndent indent)
Print subject hierarchy item info on stream.
void ShowItemsInView(vtkIdList *itemIDs, vtkMRMLAbstractViewNode *viewNode)
Show items in selected view (used for drag&drop of subject hierarchy items into the viewer)
bool RemoveItemUID(vtkIdType itemID, std::string uidName)
std::string GetItemOwnerPluginName(vtkIdType itemID)
Get owner plugin name (role) for a subject hierarchy item.
vtkIdType GetItemChildWithName(vtkIdType parentItemID, std::string name, bool recursive=false)
bool HasItemUID(vtkIdType itemID, std::string uidName)
bool ReparentItemByDataNode(vtkIdType itemID, vtkMRMLNode *newParentNode)
std::string GetItemUID(vtkIdType itemID, std::string uidName)
void SetItemName(vtkIdType itemID, std::string name)
Set name for a subject hierarchy item.
static vtkMRMLSubjectHierarchyNode * ResolveSubjectHierarchy(vtkMRMLScene *scene)
Ensure the consistency and validity of the SH node in the scene.
void SetItemOwnerPluginName(vtkIdType itemID, std::string ownerPluginName)
Set owner plugin name (role) for a subject hierarchy item.
vtkSmartPointer< vtkCallbackCommand > ItemEventCallbackCommand
Command handling events from subject hierarchy items.
int GetNumberOfItems()
Get number of items under the scene, excluding the scene.
void GetItemChildren(vtkIdType itemID, vtkIdList *childIDs, bool recursive=false)
Python accessibility function to get children of a subject hierarchy item.
std::string GetAttributeFromItemAncestor(vtkIdType itemID, std::string attributeName, std::string level="")
void GetItemChildren(vtkIdType itemID, std::vector< vtkIdType > &childIDs, bool recursive=false)
vtkIdType GetSceneItemID()
Get ID of root subject hierarchy item (which can be interpreted as the scene in terms of hierarchy)
void ItemModified(vtkIdType itemID)
void RemoveAllItems(bool removeDataNode=false)
bool IsAnyNodeInBranchTransformed(vtkIdType itemID, bool includeParentItem=true, vtkMRMLTransformNode *exceptionNode=nullptr)
static vtkMRMLSubjectHierarchyNode * GetSubjectHierarchyNode(vtkMRMLScene *scene)
static void DeserializeUIDList(std::string uidListString, std::vector< std::string > &deserializedUIDList)
Deserialize a UID list string (stored in the UID map) into a vector of UID strings.
vtkIdType GetItemByUID(const char *uidName, const char *uidValue)
vtkMRMLSubjectHierarchyNode(const vtkMRMLSubjectHierarchyNode &)
void PrintSelf(ostream &os, vtkIndent indent) override
bool RemoveItem(vtkIdType itemID, bool removeDataNode=true, bool recursive=true)
vtkIdType CreateFolderItem(vtkIdType parentItemID, std::string name)
vtkMRMLNode * GetParentDataNode(vtkMRMLNode *dataNode, bool recursive=false)
vtkMRMLNode * GetItemDataNode(vtkIdType itemID)
Get data node for a subject hierarchy item.
vtkIdType GetItemByPositionUnderParent(vtkIdType parentItemID, int position)
void GetItemsByName(std::string name, vtkIdList *foundItemIds, bool contains=false)
int GetItemPositionUnderParent(vtkIdType itemID)
bool RemoveItemChildren(vtkIdType itemID, bool removeDataNodes=true, bool recursive=true)
void Copy(vtkMRMLNode *node) override
Copy the node's attributes to this object.
void WriteXML(ostream &of, int indent) override
Write this node's information to a MRML file in XML format.
void RequestOwnerPluginSearch(vtkMRMLNode *dataNode)
bool MoveItem(vtkIdType itemID, vtkIdType beforeItemID)
std::string GetItemAttribute(vtkIdType itemID, std::string attributeName)
vtkIdType GetItemByUIDList(const char *uidName, const char *uidValue)
void SetItemDataNode(vtkIdType itemID, vtkMRMLNode *dataNode)
std::string GetItemLevel(vtkIdType itemID)
Convenience function to get level attribute for a subject hierarchy item.
static void ItemEventCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
Callback function for all events from the subject hierarchy items.
std::vector< vtkIdType > GetItemsReferencedFromItemByDICOM(vtkIdType itemID)
vtkIdType GetItemAncestorAtLevel(vtkIdType itemID, std::string level)
static const std::string SUBJECTHIERARCHY_SEPARATOR
vtkIdType CreateItem(vtkIdType parentItemID, vtkMRMLNode *dataNode, const char *ownerPluginName=nullptr)
void GetItemsReferencingItemByDICOM(vtkIdType itemID, vtkIdList *referencingIdList)
static const std::string SUBJECTHIERARCHY_VERSION_ATTRIBUTE_NAME
void GetItemsReferencedFromItemByDICOM(vtkIdType itemID, vtkIdList *referencingIdList)
void GetDataNodesInBranch(vtkIdType itemID, vtkCollection *dataNodeCollection, const char *childClass=nullptr)
vtkIdType CreateStudyItem(vtkIdType parentItemID, std::string name)
bool RemoveItemAttribute(vtkIdType itemID, std::string attributeName)
std::vector< std::string > GetItemAttributeNames(vtkIdType itemID)
vtkMRMLNode * CreateNodeInstance() override
Create instance of the default node. Like New only virtual.
bool IsItemLevel(vtkIdType itemID, std::string level)
bool IsItemVirtualBranchParent(vtkIdType itemID)
vtkIdType CreateSubjectItem(vtkIdType parentItemID, std::string name)
static vtkIdType GetInvalidItemID()
Python accessor for the invalid ID.
std::vector< vtkIdType > GetItemsReferencingItemByDICOM(vtkIdType itemID)
vtkIdType GetItemParent(vtkIdType itemID)
virtual void ReadItemFromXML(const char **atts)
Read item from XML.
vtkIdType CreateHierarchyItem(vtkIdType parentItemID, std::string name, std::string level, int positionUnderParent=-1)
@ SubjectHierarchyStartResolveEvent
Event invoked when item resolving starts (e.g. after scene import)
@ SubjectHierarchyEndResolveEvent
Event invoked when item resolving finished (e.g. after scene import)
void SetItemDisplayVisibility(vtkIdType itemID, int visible)
int GetDisplayVisibilityForBranch(vtkIdType itemID)
void SetDisplayVisibilityForBranch(vtkIdType itemID, int visible)
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Contour)
int GetNumberOfItemChildren(vtkIdType itemID, bool recursive=false)
void RequestOwnerPluginSearch(vtkIdType itemID)
std::string GetItemName(vtkIdType itemID)
vtkMRMLDisplayNode * GetDisplayNodeForItem(vtkIdType itemID)
void SetItemExpanded(vtkIdType itemID, bool expanded)
Set expanded flag for a subject hierarchy item (only for internal use, do not set explicitly)
MRML node for representing a transformation between this node space and a parent node space.