在场景图形中查找 vrdGeometryNode
节点。遍历在壳几何体处停止,不会访问壳组件。
在此,我们仅明确收集 vrdGeometryNode
类型的节点。当然,可以编写类似的遍历方法,以收集其他类型或基于不同条件的节点。
def findGeosRecursive(node, geos, predicate):
""" Recursively traverses the scenegraph starting at node
and collects geometry nodes which can be filtered
with a predicate.
参数:
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)
def findGeos(root, predicate=None):
""" Wraps findGeosRecursive to return the list of geometry nodes.
"""
geos = []
findGeosRecursive(vrdNode(root), geos, predicate)
return geos
将 findGeos 与谓词函数结合使用以过滤线几何体:
def findLineGeos(root):
predicate = lambda geo : GeometryAccess.isLineType(geo.getPrimitiveType())
lines = findGeos(root, predicate)
return lines
使用 findGeos 查找 B 面几何体:
bSideGeos = findGeos(root, lambda geo : geo.isBSide())