예제 #1
0
def flythrough(simulation, targets, duration=10, **kwargs):
    """Return a camera path of a flythrough of a cell target.

    This function will load the simulation config file given and all the neurons
    associated with the target specification. The camera position is
    computed based only on the soma positions and corresponds to a front
    view of the circuit. The path duration must be in seconds.

    The targets parameter can be:

    - A cell GID (as integer)
    - An iterable of GIDs
    - A target labels (as a string)
    - A list of any of the above

    The optional keyword arguments are:

    - samples: Number of keyframes to generate
    - speedup: From 1 to inf, this parameter specifies a speed up for
      the initial camera speed. Use 1 for a linear camera path, if higher
      that one the camera will start faster and will decrease its speed
      non-linearly and monotonically. Recommended values are between 1
      and 3.
      The default value is 1.
    """
    options = _CommonOptions(**kwargs)
    try:
        samples = kwargs['samples']
        assert(samples > 1)
    except KeyError:
        samples = 100
    try:
        norm = float(kwargs['speedup'])
        assert(norm >= 1)
    except KeyError:
        norm = 1

    simulation = _brain.Simulation(simulation)
    circuit = simulation.open_circuit()
    positions = circuit.positions(
        _rtneuron.util.targets_to_gids(targets, simulation))

    top = positions.max(0)
    bottom = positions.min(0)
    center = (top + bottom) * 0.5
    start = _compute_eye_position(positions, options)
    end = center
    end[2] = bottom[2] - (top[2] - bottom[2]) / 5.0

    path = _rtneuron.CameraPath()

    for i in range(samples):
        i = 1 / (samples - 1.0) * i
        time = duration * i
        a = (1 - (1 - i) ** norm) ** (1 / norm)
        position = start * (1 - a) + end * a
        path.addKeyFrame(time, path.KeyFrame(position, ([1, 0, 0], 0), 1))

    return path
예제 #2
0
def create_camera_path(keyframes) :
    path = rtneuron.CameraPath()
    for time, position, orientation in keyframes :
        key = rtneuron.CameraPath.KeyFrame()
        key.position = position
        key.orientation = orientation
        key.stereo_correction = 1
        path.addKeyFrame(time, key)
    return path
예제 #3
0
def _neurons_front_view(gids, circuit, **kwargs):
    options = _CommonOptions(**kwargs)

    points = options.fit_point_generator(gids, circuit)
    eye = _compute_eye_position(points, options)

    path = _rtneuron.CameraPath()
    path.addKeyFrame(0, path.KeyFrame(eye, ([1, 0, 0], 0), 1))

    return path
예제 #4
0
def _neurons_top_view(gids, circuit, **kwargs):
    options = _CommonOptions(**kwargs)

    points = options.fit_point_generator(gids, circuit)
    points = points[:,[0, 2, 1]]

    eye = _compute_eye_position(points, options)
    eye[1], eye[2] = eye[2], eye[1]

    path = _rtneuron.CameraPath()
    path.addKeyFrame(0, path.KeyFrame(eye, ([1, 0, 0], -90), 1))

    return path
예제 #5
0
def rotation(look_at, axis, start, angle, up=[0, 1, 0], duration=10, **kwargs):
    """Return a camera path of a rotation around an arbitrary axis with a
    fixation point.

    The parameters are:

    - look_at: The point at which the camera will look. The rotation axis
      is also placed at this point.
    - axis: A normalized vector used as rotation axis. The rotation sense
      is defined applying the right-hand rule to this vector.
    - start: The initial camera position. The distance of this point to center
      is preserved.
    - angle: The rotation angle of the final position in radians.
    - up: A normalized vector or one of the strings "axis" or "tangent".
      This parameter defines the vector to which the y axis of the camera is
      aligned. If a normalized vector is given, that direction is used.  For
      "axis", the axis direction is used. For "tangent", the up direction lies
      on the rotation plane and is tangent to the circular trajectory.

    The optional keyword arguments are:

    - samples: Number of keyframes to generate
    - timing: A [0..1]->[0..1] function used to map sample timestamps
      from a uniform distribution to any user given distribution.
    """

    path = _rtneuron.CameraPath()

    try:
        samples = kwargs['samples']
        assert(samples > 1)
    except KeyError:
        samples = 100
    try:
        timing = kwargs['timing']
    except KeyError:
        timing = lambda x : x

    look_at = _numpy.array(look_at)
    start = _numpy.array(start)
    axis = _numpy.array(axis)
    if type(up) is str and up == "axis":
        up = axis
    else:
        up = _numpy.array(up)

    center = look_at + axis * _numpy.dot(axis, start - look_at)
    x = start - center
    distance = _numpy.linalg.norm(x)
    if distance == 0:
        print("Warning: start point lies on rotation axis. "
              "No rotation performed")
        return
    x /= distance
    y = _numpy.cross(axis, x)

    for i in range(samples):
        # Computing the normalized sample position
        i = 1 / (samples - 1.0) * i
        # Camera position
        phi = angle * timing(i)
        position = center + x * _math.cos(phi) * distance + \
                            y * _math.sin(phi) * distance

        camera_z = position - look_at
        camera_z /= _numpy.linalg.norm(camera_z)
        if type(up) is str and up == "tangent":
            orientation = _compute_orientation(
                camera_z, _numpy.cross(position - center, axis))
        else:
            orientation = _compute_orientation(camera_z, up)

        time = duration * i
        path.addKeyFrame(time, path.KeyFrame(position, orientation, 1))

    return path