Esempio n. 1
0
def markersToUINodes(mkr_list):
    """
    Convert a list of markers into a hierarchy to show the user.
    """
    root = object_nodes.ObjectNode('root')
    cam_nodes_store = {}
    for mkr in mkr_list:
        mkr_name = mkr.get_node()
        mkr_name = mkr_name.rpartition('|')[-1]
        cam = mkr.get_camera()
        bnd = mkr.get_bundle()

        # Get camera
        cam_shp_node = cam.get_shape_node()
        cam_name = cam.get_shape_node()
        cam_name = cam_name.rpartition('|')[-1]
        cam_node = None
        if cam_shp_node not in cam_nodes_store:
            data = {
                'marker': mkr,
                'camera': cam,
            }
            cam_node = object_nodes.CameraNode(cam_name,
                                               data=data,
                                               parent=root)
            cam_nodes_store[cam_shp_node] = cam_node
        else:
            cam_node = cam_nodes_store[cam_shp_node]
        assert cam_node is not None

        # The marker.
        data = {
            'marker': mkr,
            'camera': cam,
        }
        mkr_node = object_nodes.MarkerNode(mkr_name,
                                           data=data,
                                           parent=cam_node)

        # Get Bundle under marker.
        if bnd is None:
            continue
        bnd_name = bnd.get_node()
        bnd_name = bnd_name.rpartition('|')[-1]
        data = {
            'marker': mkr,
            'bundle': bnd,
            'camera': cam,
        }
        assert mkr_node is not None
        bnd_node = object_nodes.BundleNode(bnd_name,
                                           data=data,
                                           parent=mkr_node)
    return root
Esempio n. 2
0
def markersToUINodes(mkr_list, show_cam, show_mkr, show_bnd):
    """
    Convert a list of markers into a hierarchy to show the user.

    :param mkr_list: List of Marker objects to convert into UI nodes.
    :type mkr_list: [Marker, ..]

    :param show_cam: Should we show cameras?
    :type show_cam: bool

    :param show_mkr: Should we show markers?
    :type show_mkr: bool

    :param show_bnd: Should we show bundles?
    :type show_bnd: bool

    :return: A list of UI MarkerNode objects.
    :rtype: [MarkerNode, ..]
    """
    assert isinstance(show_cam, bool)
    assert isinstance(show_mkr, bool)
    assert isinstance(show_bnd, bool)
    root = object_nodes.ObjectNode('root')
    cam_nodes_store = {}
    for mkr in mkr_list:
        mkr_name = mkr.get_node()
        mkr_name = mkr_name.rpartition('|')[-1]
        cam = mkr.get_camera()
        bnd = mkr.get_bundle()

        # Get camera
        if show_cam is False:
            cam_node = root
        else:
            cam_tfm_node = cam.get_transform_node()
            cam_name = cam.get_transform_node()
            cam_name = cam_name.rpartition('|')[-1]
            cam_node = None
            if cam_tfm_node not in cam_nodes_store:
                cam_uuid = cam.get_transform_uid()
                data = {
                    'uuid': cam_uuid,
                    'marker': mkr,
                    'camera': cam,
                }
                cam_node = object_nodes.CameraNode(cam_name, data=data, parent=root)
                cam_nodes_store[cam_tfm_node] = cam_node
            else:
                cam_node = cam_nodes_store[cam_tfm_node]
        assert cam_node is not None

        # The marker.
        mkr_node = cam_node
        if show_mkr is True:
            mkr_uuid = mkr.get_node_uid()
            data = {
                'uuid': mkr_uuid,
                'marker': mkr,
                'camera': cam,
            }
            mkr_node = object_nodes.MarkerNode(mkr_name, data=data, parent=cam_node)

        # Get Bundle under marker.
        if bnd is None:
            continue
        if show_bnd is False:
            continue
        bnd_name = bnd.get_node()
        bnd_name = bnd_name.rpartition('|')[-1]
        bnd_uuid = bnd.get_node_uid()
        data = {
            'marker': mkr,
            'bundle': bnd,
            'camera': cam,
            'uuid': bnd_uuid,
        }
        assert mkr_node is not None
        bnd_node = object_nodes.BundleNode(bnd_name, data=data, parent=mkr_node)
    return root