Beispiel #1
0
def globe_coordinates(latitude, longitude, delta = 0.0):
    globe_radius = 50
    radLatitude = latitude * math.pi / 180.0;
    radLongitude = longitude * math.pi / 180.0;

    return [
        (globe_radius + delta) * math.cos(radLatitude) * math.cos(radLongitude),
        (globe_radius + delta) * math.sin(radLatitude),
        - (globe_radius + delta) * math.cos(radLatitude) * math.sin(radLongitude)
    ]
Beispiel #2
0
def sphere_layout(radius):
    ids = graphiti.get_node_ids()
    for nid in ids:
        r1 = random.random() * 2 * math.pi
        r2 = random.random() * 2 * math.pi
        r3 = 0.9 + 0.1 * random.random()

        pos = [
            radius * r3 * math.sin(r1) * math.cos(r2),
            radius * r3 * math.cos(r1),
            radius * r3 * math.sin(r1) * math.sin(r2)
        ]

        graphiti.set_node_attribute(nid, "graphiti:space:position", "vec3", std.vec3_to_str(pos))
Beispiel #3
0
def seed_circle_layout():
    radius = 100.0

    ids = graphiti.get_node_ids()
    zeros = []
    for id in ids:
        attribute = graphiti.get_node_attribute(id, "depth")
        if attribute == None:
            continue
        else:
            if attribute == 0:
                zeros.append(id)

    count = 0
    if len(zeros) == 1:
        radius = 0.0
    for id in zeros:
        angle = 2.0 * math.pi * float(count) / float(len(zeros))

        x = radius * math.cos(angle)
        y = 0.0
        z = radius * math.sin(angle)

        graphiti.set_node_attribute(id, "graphiti:space:position", "vec3", str(x) + " " + str(y) + " " + str(z))
        graphiti.set_node_attribute(id, "graphiti:space:locked", "bool", "True")
        graphiti.set_node_attribute(id, "graphiti:space:activity", "float", "2.0")
        graphiti.set_node_attribute(id, "og:space:mark", "int", "2")
        count += 1
Beispiel #4
0
def conic_layout():
    graph = std.load_nx_graph()

    graphiti.set_attribute("graphiti:space:linkmode", "string", "node_color")

    sorted_degrees = sorted(nx.degree(graph).values())
    max_degree = sorted_degrees[-1]

    degree_nodes = {}
    for n in graph.nodes(data = True):
        degree = nx.degree(graph, n[0])
        if degree in degree_nodes:
            degree_nodes[degree].append(n[0])
        else:
            degree_nodes[degree] = [n[0]]

    max_radius = 30.0
    max_height = 20
    for n in graph.nodes(data = True):
        degree = nx.degree(graph, n[0])

        nodes = degree_nodes[degree]

        radius = 1.0 + max_radius * float(1.0 - float(degree) / float(max_degree))
        alpha = 2.0 * math.pi * random.random() #float(nodes.index(n[0])) / float(len(nodes)) 
        # 3D
        # beta = 2.0 * math.pi * random.random() #float(nodes.index(n[0])) / float(len(nodes)) 

        x = radius * math.cos(alpha)
        y = max_height * float(degree) / float(max_degree)
        z = radius * math.sin(alpha)
        # 3D
        # x = radius * math.sin(alpha) * math.cos(beta)
        # y = radius * math.sin(alpha) * math.sin(beta)
        # z = radius * math.cos(alpha)

        graphiti.set_node_attribute(n[0], "graphiti:space:position", "vec3", str(x) + " " + str(y) + " " + str(z))
Beispiel #5
0
def on_idle():

    global radius
    global radius_speed

    global alpha
    global alpha_speed

    global beta
    global beta_speed

    hand_position = None
    hand_direction = None
    hand_velocity = None
    box = None
    confidence = None
    grab = None

    mutex.acquire()
    try:
        if "position" in leap_context:
            hand_position = leap_context["position"]
        if "direction" in leap_context:
            hand_direction = leap_context["direction"]
        if "velocity" in leap_context:
            hand_velocity = leap_context["velocity"]
        if "box" in leap_context:
            box = leap_context["box"]
        if "confidence" in leap_context:
            confidence = leap_context["confidence"]
        if "grab" in leap_context:
            grab = leap_context["grab"]
    finally:
        mutex.release()

    camera_position = graphiti.get_attribute("og:space:camera:position")

    cam_pos = Leap.Vector()
    cam_pos.x = camera_position[0]
    cam_pos.y = camera_position[1]
    cam_pos.z = camera_position[2]

    alpha_acceleration = 0.0
    beta_acceleration = 0.0
    radius_acceleration = 0.0
    action = ""
    x_action = ""
    y_action = ""
    z_action = ""
    if not (hand_position is None or hand_direction is None or hand_velocity is None or box is None or confidence < 0.1):

        hand_position = box.normalize_point(hand_position)
        hand_velocity = box.normalize_point(hand_velocity)

        hand_pos = Leap.Vector()
        hand_pos.x = 2.0 * hand_position.z - 1.0
        hand_pos.y = -(2.0 * hand_position.y - 1.0)
        hand_pos.z = 2.0 * hand_position.x - 1.0

        if hand_pos.z > 0.0:
            z_action = "Right "
            z_sign = 1.0
        elif hand_pos.z < -0.0:
            z_action = "Left "
            z_sign = -1.0
        else:
            z_sign = 0.0

        if hand_pos.y > 0.0:
            y_action = "Down "
            y_sign = 1.0
        elif hand_pos.y < -0.0:
            y_sign = -1.0
            y_action = "Up "
        else:
            y_sign = 0.0

        if hand_pos.x > 0.0:
            x_action = " Back"
            x_sign = 1.0
        elif hand_pos.x < -0.0:
            x_action = " Front"
            x_sign = -1.0
        else:
            x_sign = 0.0

        threshold = 0.45
        if abs(hand_pos.z) >= threshold:
            action += z_action
            hand_pos.z = (1.0 / threshold) * (hand_pos.z - z_sign * threshold)
            alpha_acceleration = z_sign * (abs(hand_pos.z * hand_pos.z)) / 300

        threshold = 0.3
        if abs(hand_pos.y) >= threshold:
            action += y_action
            hand_pos.y = (1.0 / threshold) * (hand_pos.y - y_sign * threshold)
            beta_acceleration = -y_sign * 0.1

        if abs(hand_pos.x) >= threshold:
            action += x_action
            hand_pos.x = (1.0 / threshold) * (hand_pos.x - x_sign * threshold)
            radius_acceleration = x_sign *  0.1

        if len(action) == 0:
            action += "Neutral"

    if grab == 1.0:
        alpha_speed = 0.0
        beta_speed = 0.0
        radius_speed = 0.0
        alpha_acceleration = 0.0
        beta_acceleration = 0.0
        radius_acceleration = 0.0
        graphiti.set_attribute("og:space:title", "string", "Freeze")
        return

    alpha_speed += alpha_acceleration
    alpha += alpha_speed

    beta_speed += beta_acceleration
    beta += beta_speed 

    radius_speed += radius_acceleration
    radius += radius_speed

    max_beta = 100.0
    min_beta = - 100.0
    if beta > max_beta:
        beta = max_beta
    if beta < min_beta:
        beta = min_beta

    max_radius = 200
    min_radius = 10
    if radius > max_radius:
        radius = max_radius
    if radius < min_radius:
        radius = min_radius

    cam_pos.x = radius * math.cos(alpha)
    cam_pos.y = beta
    cam_pos.z = radius * math.sin(alpha)

    graphiti.set_attribute("og:space:camera:position", "vec3", "{0} {1} {2}".format(cam_pos.x, cam_pos.y, cam_pos.z))
    graphiti.set_attribute("og:space:title", "string", action)
    graphiti.set_attribute("og:space:camera:target", "vec3", "0.0 {0} 0.0".format(cam_pos.y))

    alpha_speed = alpha_speed * 0.8
    beta_speed = beta_speed * 0.8
    radius_speed = radius_speed * 0.8
Beispiel #6
0
def on_idle():

    global radius
    global radius_speed

    global alpha
    global alpha_speed

    global beta
    global beta_speed

    hand_position = None
    hand_direction = None
    hand_velocity = None
    box = None
    confidence = None
    grab = None

    mutex.acquire()
    try:
        if "position" in leap_context:
            hand_position = leap_context["position"]
        if "direction" in leap_context:
            hand_direction = leap_context["direction"]
        if "velocity" in leap_context:
            hand_velocity = leap_context["velocity"]
        if "box" in leap_context:
            box = leap_context["box"]
        if "confidence" in leap_context:
            confidence = leap_context["confidence"]
        if "grab" in leap_context:
            grab = leap_context["grab"]
    finally:
        mutex.release()

    camera_position = graphiti.get_attribute("og:space:camera:position")

    cam_pos = Leap.Vector()
    cam_pos.x = camera_position[0]
    cam_pos.y = camera_position[1]
    cam_pos.z = camera_position[2]

    alpha_acceleration = 0.0
    beta_acceleration = 0.0
    radius_acceleration = 0.0
    action = ""
    x_action = ""
    y_action = ""
    z_action = ""
    if not (hand_position is None or hand_direction is None
            or hand_velocity is None or box is None or confidence < 0.1):

        hand_position = box.normalize_point(hand_position)
        hand_velocity = box.normalize_point(hand_velocity)

        hand_pos = Leap.Vector()
        hand_pos.x = 2.0 * hand_position.z - 1.0
        hand_pos.y = -(2.0 * hand_position.y - 1.0)
        hand_pos.z = 2.0 * hand_position.x - 1.0

        if hand_pos.z > 0.0:
            z_action = "Right "
            z_sign = 1.0
        elif hand_pos.z < -0.0:
            z_action = "Left "
            z_sign = -1.0
        else:
            z_sign = 0.0

        if hand_pos.y > 0.0:
            y_action = "Down "
            y_sign = 1.0
        elif hand_pos.y < -0.0:
            y_sign = -1.0
            y_action = "Up "
        else:
            y_sign = 0.0

        if hand_pos.x > 0.0:
            x_action = " Back"
            x_sign = 1.0
        elif hand_pos.x < -0.0:
            x_action = " Front"
            x_sign = -1.0
        else:
            x_sign = 0.0

        threshold = 0.45
        if abs(hand_pos.z) >= threshold:
            action += z_action
            hand_pos.z = (1.0 / threshold) * (hand_pos.z - z_sign * threshold)
            alpha_acceleration = z_sign * (abs(hand_pos.z * hand_pos.z)) / 300

        threshold = 0.3
        if abs(hand_pos.y) >= threshold:
            action += y_action
            hand_pos.y = (1.0 / threshold) * (hand_pos.y - y_sign * threshold)
            beta_acceleration = -y_sign * 0.1

        if abs(hand_pos.x) >= threshold:
            action += x_action
            hand_pos.x = (1.0 / threshold) * (hand_pos.x - x_sign * threshold)
            radius_acceleration = x_sign * 0.1

        if len(action) == 0:
            action += "Neutral"

    if grab == 1.0:
        alpha_speed = 0.0
        beta_speed = 0.0
        radius_speed = 0.0
        alpha_acceleration = 0.0
        beta_acceleration = 0.0
        radius_acceleration = 0.0
        graphiti.set_attribute("og:space:title", "string", "Freeze")
        return

    alpha_speed += alpha_acceleration
    alpha += alpha_speed

    beta_speed += beta_acceleration
    beta += beta_speed

    radius_speed += radius_acceleration
    radius += radius_speed

    max_beta = 100.0
    min_beta = -100.0
    if beta > max_beta:
        beta = max_beta
    if beta < min_beta:
        beta = min_beta

    max_radius = 200
    min_radius = 10
    if radius > max_radius:
        radius = max_radius
    if radius < min_radius:
        radius = min_radius

    cam_pos.x = radius * math.cos(alpha)
    cam_pos.y = beta
    cam_pos.z = radius * math.sin(alpha)

    graphiti.set_attribute(
        "og:space:camera:position", "vec3",
        "{0} {1} {2}".format(cam_pos.x, cam_pos.y, cam_pos.z))
    graphiti.set_attribute("og:space:title", "string", action)
    graphiti.set_attribute("og:space:camera:target", "vec3",
                           "0.0 {0} 0.0".format(cam_pos.y))

    alpha_speed = alpha_speed * 0.8
    beta_speed = beta_speed * 0.8
    radius_speed = radius_speed * 0.8