Commit 5577c3a3 authored by finetjul's avatar finetjul
Browse files

ENH: Add utility method vtkMRMLDisplayableNode::GetNthDisplayNodeByClass

This new method can be handy because displayable nodes can have multiple
display nodes (e.g. vtkMRMLScalarVolumeNode can have
vtkMRMLScalarVolumeDisplayNode and
vtkMRMLGPURayCastVolumeRenderingDisplayNode at the same time. Annotations
have also typically more than 1 display node: textDisplayNode,
controlPointsDisplayNode...).

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21537 3bd1e089-480b-0410-8dfb-8563597acbee
parent 656c2126
......@@ -238,6 +238,21 @@ vtkMRMLDisplayNode* vtkMRMLDisplayableNode::GetNthDisplayNode(int n)
return node;
}
//----------------------------------------------------------------------------
vtkMRMLDisplayNode* vtkMRMLDisplayableNode
::GetNthDisplayNodeByClass(int n, const char* className)
{
for (int i = 0; i < this->GetNumberOfDisplayNodes(); ++i)
{
vtkMRMLDisplayNode* displayNode = this->GetNthDisplayNode(i);
if (displayNode->IsA(className) && (n-- == 0))
{
return displayNode;
}
}
return 0;
}
//-----------------------------------------------------------
void vtkMRMLDisplayableNode::UpdateDisplayNodes()
{
......
......@@ -147,8 +147,9 @@ public:
/// If not cached, it tnternally scans (slow) the scene to search for the
/// associated display node ID.
/// If the displayable node is no longer in the scene (GetScene() == 0), it
/// happens after the node is removed from hte scene (scene->RemoveNode(dn),
/// happens after the node is removed from the scene (scene->RemoveNode(dn),
/// the returned display node is 0.
/// \sa GetNthDisplayNodeByClass()
vtkMRMLDisplayNode* GetNthDisplayNode(int n);
///
......@@ -156,6 +157,10 @@ public:
/// \sa GetNthDisplayNode(int), GetDisplayNodeID()
inline vtkMRMLDisplayNode* GetDisplayNode();
/// Return the nth display node that is of class \a className.
/// \sa GetNthDisplayNode()
vtkMRMLDisplayNode* GetNthDisplayNodeByClass(int n, const char* className);
///
/// Return a copy of the list of the display nodes. Some nodes can be 0
/// when the scene is in a temporary state.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment