# getDescendants

MainPage

Description: This method returns the descendants of node.

Constructor signature: node_descendants = MorphTreeAlpha.getDescendants(node)

Input:
• node, int, node, of which its descendants will be returned.

Output:

• node_descendants, 1d-array, int32. Array containing the descendants of node.

# C++ Aux Function

```OK
```
```OK [C/C++ extension is up-to-date]
```

# Python Implementation

``` 1 import numpy as np
2
3 def getDescendants(self, node):
4     if self._children_updated == False:
5         self.getChildren()
6     if node == 0:
7         return np.arange(self.node_array.shape[1], dtype = np.int32)
8     elif self.node_array[1,node] == 0:
9         return np.array([node],dtype = np.int32)
10     else:
11         return self.get_descendants_aux(node,self._children_list,self._cum_children_hist)
```

# Example

``` 1 from morph_tree_alpha import MorphTreeAlpha
2 import numpy as np
3
4 img = np.array([[100, 100, 100, 0,   0,   0,   0,   0],\
5                 [150, 150, 150, 150, 150, 150, 150, 150],\
6                 [150, 160, 190, 150, 200, 200, 229, 150], \
7                 [150, 185, 255, 150, 200, 230, 200, 150],\
8                 [150, 180, 200, 150, 215, 229, 200, 150],\
9                 [150, 150, 150, 150, 150, 150, 150, 150],\
10                 [50,  50,  0,   0,   0,   0,   0,   0]], dtype = np.uint8)
11
12
13 Bc = np.array([[0,1,0],\
14                [1,1,1],\
15                [0,1,0]], dtype = bool)
16
17
18 morph_tree = MorphTreeAlpha(img,Bc)
19
20
21 for i in xrange(morph_tree.node_array.shape[1]):
22   print "Descendants of node %d:" %i
23   print morph_tree.getDescendants(i)
24   print
25
26
27 g= morph_tree.generateGraph()
28 mmgraphviz(g, title='Morph-tree')
```
```Descendants of node 0:
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]

Descendants of node 1:
[ 1  2  3  5  4  6 12 11  7 13  8 14  9 10]

Descendants of node 2:
[ 2  3  5  4  6 12 11  7 13  8 14  9 10]

Descendants of node 3:
[ 3  5  4  6 12 11  7 13  8 14  9 10]

Descendants of node 4:
[ 4 12 11 13 14]

Descendants of node 5:
[ 5  6  7  8  9 10]

Descendants of node 6:
[ 6  7  8  9 10]

Descendants of node 7:
[ 7  8  9 10]

Descendants of node 8:
[ 8  9 10]

Descendants of node 9:
[ 9 10]

Descendants of node 10:
[10]

Descendants of node 11:
[11 13 14]

Descendants of node 12:
[12]

Descendants of node 13:
[13 14]

Descendants of node 14:
[14]
```