Exemple #1
0
def get_orientation():
    '''
  Send a POST request to this URL.

  Input: a JSON object as follows:
  {
    camera: [x, y, z]
    screenSpaceA: [x, y]
    screenSpaceB: [x, y]
    personA: [x, y, z]
    personB: [x, y, z]
    fov: [x, y]
    numTargets: 1 or 2
  }

  Returns: a JSON object as follows:
  {
    'w': w
    'x': x
    'y': y
    'z': z
  }
  '''
    parsed_json = request.get_json()
    if parsed_json is None:
        return abort(400)

    camera_list = parsed_json['camera']
    screenA_list = parsed_json['screenSpaceA']
    screenB_list = parsed_json['screenSpaceB']
    personA_list = parsed_json['personA']
    personB_list = parsed_json['personB']
    fov_list = parsed_json['fov']
    numTargets_list = parsed_json['numTargets']

    print "get_toric_trajectory: Calling trajectoryAPI now..."

    # toric interpolation

    numTargets = numTargets_list[0]
    C = toric.Vector3(camera_list[0], camera_list[1], camera_list[2])
    SA = toric.Vector2(screenA_list[0], screenA_list[1])
    PA = toric.Vector3(personA_list[0], personA_list[1], personA_list[2])
    SB = toric.Vector2(screenB_list[0], screenB_list[1])
    PB = toric.Vector3(personB_list[0], personB_list[1], personB_list[2])
    fovX = toric.RadianPi(fov_list[0])
    fovY = toric.RadianPi(fov_list[1])

    q = toricinterpolation.toric_orientation(C, SA, SB, PA, PB, fovX, fovY,
                                             numTargets)

    print "get_orientation: Response from trajectoryAPI [w: ", q[
        'w'], ", x: ", q['x'], ", y: ", q['y'], ", z: ", q['z']

    data = {'w': q['w'], 'x': q['x'], 'y': q['y'], 'z': q['z']}

    return jsonify(data)
Exemple #2
0
def get_toric_trajectory():
    '''
  Send a POST request to this URL.

  Input: a JSON object as follows:
    {
      cameraPoseN: [0, ...],
      cameraPoseE: [0, ...],
      cameraPoseD: [0, ...],
      cameraPoseT: [0, ...],
    }

  Returns: a JSON object as follows:
  {
    interpolatedSpline: [...],
  }
  '''
    parsed_json = request.get_json()
    if parsed_json is None:
        return abort(400)

    cameraPose_n_list = parsed_json['cameraPoseN']  #y
    cameraPose_e_list = parsed_json['cameraPoseE']  #x
    cameraPose_d_list = parsed_json['cameraPoseD']  #z
    cameraPose_t_list = parsed_json['cameraPoseT']
    personA_list = parsed_json['personA']
    personB_list = parsed_json['personB']

    print "get_trajectory: Calling trajectoryAPI now..."

    # toric interpolation

    # starting people positons
    PA_1 = toric.Vector3(personA_list[0], personA_list[1], personA_list[2])
    PB_1 = toric.Vector3(personB_list[0], personB_list[1], personB_list[2])

    # ending people positions: for the moment the positions are the same
    PA_2 = toric.Vector3(personA_list[0], personA_list[1], personA_list[2])
    PB_2 = toric.Vector3(personB_list[0], personB_list[1], personB_list[2])

    # Starting camera position is *outside* of PA_1:
    C_1 = toric.Vector3(cameraPose_n_list[0], cameraPose_e_list[0],
                        cameraPose_d_list[0])
    C_2 = toric.Vector3(cameraPose_n_list[1], cameraPose_e_list[1],
                        cameraPose_d_list[1])
    interpolated = toricinterpolation.toric_interpolation(
        C_1, PA_1, PB_1, C_2, PA_2, PB_2)

    print C_1
    print C_2

    P_cameraPose_new = interpolated['F']

    print "P: ", P_cameraPose_new

    P_cameraPose_new[:, 0] *= 1000.0
    P_cameraPose_new[:, 1] *= 1000.0
    P_cameraPose_new[:, 2] *= -1000.0
    T_cameraPose_new = c_[interpolated['t'], interpolated['t'],
                          interpolated['t']]

    # scale
    P_interpolatedSpline = trajectoryAPI.compute_easing_spline_trajectory(
        P_cameraPose_new, T_cameraPose_new)

    print "get_trajectory: Response from trajectoryAPI", P_interpolatedSpline

    data = {
        'interpolatedSpline': P_interpolatedSpline.tolist(),
    }
    return jsonify(data)
Exemple #3
0
import toric

cam = toric.Vector3(0.5, -0.5, 0)
PA = toric.Vector3(0, 0, 0)
PB = toric.Vector3(1, 0, 0)

print "CAM:(%.2f,%.2f,%.2f)" % (cam.x(), cam.y(), cam.z())
print "PA:(%.2f,%.2f,%.2f)" % (PA.x(), PA.y(), PA.z())
print "PB:(%.2f,%.2f,%.2f)" % (PB.x(), PB.y(), PB.z())

t = toric.Toric3_FromWorldPosition(cam, PA, PB)

print "Toric3: (a=%.2f, t=%.2f, p=%.2f)" % (t.getAlpha().valueDegrees(),
                                            t.getTheta().valueDegrees(),
                                            t.getPhi().valueDegrees())

cam_back = toric.Toric3_ToWorldPosition(t, PA, PB)

print "Recovering CAM:"

print "CAM_BACK:(%.2f,%.2f,%.2f)" % (cam_back.x(), cam_back.y(), cam_back.z())
Exemple #4
0
def np3_to_vector3(v):
    return toric.Vector3(v[0], v[1], v[2])
Exemple #5
0
    V = np.c_[alpha_lin, distance_A_lin, distance_B_lin, vantage_A_slerp,
              vantage_B_slerp, PA_x, PA_y, PA_z, PB_x, PB_y, PB_z]
    F = np.apply_along_axis(visualfeatures_to_world, axis=1, arr=V)

    # for different PA_1, PB_1 and PA_2, PB_2
    # compute second trajectory around PA_2 and PB_2 and combine through non-linear interpolation (p(t))

    return {'F': F, 't': t}


#
# Basic Test
#

# let's set a minimum distance of 0.9m
min_dist = 1

# starting people positons
PA_1 = toric.Vector3(0, 0, 0)
PB_1 = toric.Vector3(2, 0, 0)

# ending people positions: for the moment the positions are the same
PA_2 = toric.Vector3(0, 0, 0)
PB_2 = toric.Vector3(2, 0, 0)

# Starting camera position is *outside* of PA_1:
C_1 = toric.Vector3(-1, -0.5, 0)
C_2 = toric.Vector3(3, -1, 0)

toric_interpolation(C_1, PA_1, PB_1, C_2, PA_2, PB_2)
Exemple #6
0
def get_orientation():
  '''
  Send a POST request to this URL.

  Input: a JSON object as follows:
  {
    cameraPoseN: [0, ...],
    cameraPoseE: [0, ...],
    cameraPoseD: [0, ...],
    screenSpaceX: [0, ...],
    screenSpaceY: [0, ...],
    personN: [0, ...],
    personE: [0, ...],
    personD: [0, ...],
    fovX: [0, ...],
    fovY: [0, ...],
  }

  Returns: a JSON object as follows:
  {
    'w': w
    'x': x
    'y': y
    'z': z
  }
  '''
  parsed_json = request.get_json()
  if parsed_json is None:
    return abort(400)

  # camera_list = parsed_json['camera']
  # screenA_list = parsed_json['screenSpaceA']
  # screenB_list = parsed_json['screenSpaceB']
  # personA_list = parsed_json['personA']
  # personB_list = parsed_json['personB']
  # fov_list = parsed_json['fov']
  cameraPose_n_list = parsed_json['cameraPoseN'] #y
  cameraPose_e_list = parsed_json['cameraPoseE'] #x
  cameraPose_d_list = parsed_json['cameraPoseD'] #z
  screen_x_list = parsed_json['screenSpaceX']
  screen_y_list = parsed_json['screenSpaceY']
  person_n_list = parsed_json['personN']
  person_e_list = parsed_json['personE']
  person_d_list = parsed_json['personD']
  fov_x_list = parsed_json['fovX']
  fov_y_list = parsed_json['fovY']

  print "get_toric_trajectory: Calling trajectoryAPI now..."

  # toric interpolation
  C = toric.Vector3(cameraPose_n_list[0],cameraPose_e_list[0],cameraPose_d_list[0])
  SA = toric.Vector2(screen_x_list[0],screen_y_list[0])
  PA = toric.Vector3(person_n_list[0],person_e_list[0],person_d_list[0])
  numTargets = len(screen_x_list)
  SB = toric.Vector2(0,0)
  PB = toric.Vector3(0,0,0)
  if (numTargets > 1):
    SB = toric.Vector2(screen_x_list[1],screen_y_list[1])
    PB = toric.Vector3(person_n_list[1],person_e_list[1],person_d_list[1])
  fovX = toric.RadianPi(fov_x_list[0])
  fovY = toric.RadianPi(fov_y_list[0])

  print "numTargets", numTargets

  q = toricinterpolation.toric_orientation(C, SA, SB, PA, PB, fovX, fovY, numTargets)
  
  print "get_orientation: Response from trajectoryAPI [w: ", q['w'], ", x: ", q['x'], ", y: ", q['y'], ", z: ", q['z']

  data = {
    'w': q['w'],
    'x': q['x'],
    'y': q['y'],
    'z': q['z']
  }

  return jsonify(data)
Exemple #7
0
def get_toric_trajectory():
    '''
  Send a POST request to this URL.

  Input: a JSON object as follows:
  {
    cameraPoseN: [0, ...],
    cameraPoseE: [0, ...],
    cameraPoseD: [0, ...],
    cameraPoseT: [0, ...],
    personA: [x, y, z, ...]
    personB: [x, y, z, ...]
    screenSpaceA : [x, y, ...]
    screenSpaceB : [x, y, ...]
  }

  Returns: a JSON object as follows:
  {
    interpolatedSpline: [...],
  }
  '''
    parsed_json = request.get_json()
    if parsed_json is None:
        return abort(400)

    cameraPose_n_list = parsed_json['cameraPoseN']  #y
    cameraPose_e_list = parsed_json['cameraPoseE']  #x
    cameraPose_d_list = parsed_json['cameraPoseD']  #z
    cameraPose_t_list = parsed_json['cameraPoseT']
    personA_list = parsed_json['personA']
    personB_list = parsed_json['personB']
    screenSpaceA_list = parsed_json['screenSpaceA']
    screenSpaceB_list = parsed_json['screenSpaceB']

    print "get_toric_trajectory: Calling trajectoryAPI now..."

    # toric interpolation

    # people positons
    PA_1 = toric.Vector3(personA_list[0], personA_list[1], personA_list[2])
    PB_1 = toric.Vector3(personB_list[0], personB_list[1], personB_list[2])
    PA_2 = toric.Vector3(
        personA_list[0], personA_list[1], personA_list[2]
    )  # ending people positions: for the moment the positions are the same
    PB_2 = toric.Vector3(personB_list[0], personB_list[1], personB_list[2])

    # camera positions
    C_1 = toric.Vector3(cameraPose_n_list[0], cameraPose_e_list[0],
                        cameraPose_d_list[0])
    C_2 = toric.Vector3(cameraPose_n_list[1], cameraPose_e_list[1],
                        cameraPose_d_list[1])

    # screen space positions
    SA_1 = toric.Vector2(screenSpaceA_list[0], screenSpaceA_list[1])
    SB_1 = toric.Vector2(screenSpaceB_list[0], screenSpaceB_list[1])
    SA_2 = toric.Vector2(screenSpaceA_list[2], screenSpaceA_list[3])
    SB_2 = toric.Vector2(screenSpaceB_list[2], screenSpaceB_list[3])

    interpolated = toricinterpolation.toric_position_interpolation(
        C_1, PA_1, PB_1, C_2, PA_2, PB_2)

    print C_1
    print C_2

    P_cameraPose = interpolated['F']
    #orientInterpolated = toricinterpolation.toric_orientation_interpolation(P_cameraPose, SA_1, SB_1, SA_2, SB_2, PA_1, PB_1, PA_2, PB_2)

    print "P: ", P_cameraPose
    T_cameraPose = c_[interpolated['t'], interpolated['t'], interpolated['t']]
    P_positionSpline = trajectoryAPI.compute_easing_spline_trajectory(
        P_cameraPose, T_cameraPose)

    #print "get_toric_trajectory (position): Response from trajectoryAPI", P_positionSpline
    #print "get_toric_trajectory (orientation): Response from trajectoryAPI", P_orientationSpline

    data = {
        'positionSpline': P_positionSpline.tolist(),
        #'orientationSpline': P_orientationSpline.tolist(),
    }
    return jsonify(data)