Find geometry nodes

Finding vrdGeometryNode nodes in the scenegraph. The traversal stops at shell geometries, shell components are not visited.

Here, we explicitly collect only nodes of type vrdGeometryNode. Of course, a similar traversal method can be written that collects other types of nodes or nodes based on a different criterion.

findGeosRecursive in lineGeometry-texCoords.py

def findGeosRecursive(node, geos, predicate):
    """ Recursively traverses the scenegraph starting at node
        and collects geometry nodes which can be filtered 
        with a predicate.
        Args:
            node (vrdNode): Currently traversed node
            geos (list of vrdGeometryNode): List of collected geometry nodes
            predicate (function): None or predicate(vrdGeometryNode)->bool
    """
    geo = vrdGeometryNode(node)
    if geo.isValid():
        if predicate is None or predicate(geo):
            geos.append(geo)
        # stop traversing the tree
    else:
        # traverse the children
        for child in node.getChildren():
            findGeosRecursive(child, geos, predicate)

findGeos in lineGeometry-texCoords.py

def findGeos(root, predicate=None):
    """ Wraps findGeosRecursive to return the list of geometry nodes.
    """
    geos = []
    findGeosRecursive(vrdNode(root), geos, predicate)
    return geos

Using findGeos with predicate function to filter for line geometries:

findLineGeos in lineGeometry-texCoords.py

def findLineGeos(root):
    predicate = lambda geo : GeometryAccess.isLineType(geo.getPrimitiveType())
    lines = findGeos(root, predicate)
    return lines

Using findGeos to find B-side geometries:

bSideGeos = findGeos(root, lambda geo : geo.isBSide())