# Converts pose + hands + face landmarks to a render data vector.

type: "HolisticTrackingToRenderData"

# Image size. (std::pair<int, int>)
input_stream: "IMAGE_SIZE:image_size"
# Pose landmarks. (NormalizedLandmarkList)
input_stream: "POSE_LANDMARKS:landmarks"
# Region of interest calculated based on pose landmarks. (NormalizedRect)
input_stream: "POSE_ROI:roi"
# Left hand landmarks. (NormalizedLandmarkList)
input_stream: "LEFT_HAND_LANDMARKS:left_hand_landmarks"
# Right hand landmarks. (NormalizedLandmarkList)
input_stream: "RIGHT_HAND_LANDMARKS:right_hand_landmarks"
# Face landmarks. (NormalizedLandmarkList)
input_stream: "FACE_LANDMARKS:face_landmarks"

# Render data vector. (std::vector<RenderData>)
output_stream: "RENDER_DATA_VECTOR:render_data_vector"

# --------------------------------------------------------------------------- #
# ------------------ Calculates scale for render objects -------------------- #
# --------------------------------------------------------------------------- #

# Calculates rendering scale based on the pose bounding box.
node {
  calculator: "RectToRenderScaleCalculator"
  input_stream: "NORM_RECT:roi"
  input_stream: "IMAGE_SIZE:image_size"
  output_stream: "RENDER_SCALE:render_scale"
  node_options: {
    [type.googleapis.com/mediapipe.RectToRenderScaleCalculatorOptions] {
      multiplier: 0.0008
    }
  }
}

# --------------------------------------------------------------------------- #
# --------------- Combines pose and hands into pose skeleton ---------------- #
# --------------------------------------------------------------------------- #

# Gets pose landmarks before wrists.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks"
  output_stream: "landmarks_before_wrist"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 11 end: 15 }
    }
  }
}

# Gets pose left wrist landmark.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks"
  output_stream: "landmarks_left_wrist"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 15 end: 16 }
    }
  }
}

# Gets pose right wrist landmark.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks"
  output_stream: "landmarks_right_wrist"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 16 end: 17 }
    }
  }
}

# Gets pose landmarks after wrists.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks"
  output_stream: "landmarks_after_wrist"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 23 end: 33 }
    }
  }
}

# Gets left hand wrist landmark.
node {
  calculator: "HandWristForPose"
  input_stream: "HAND_LANDMARKS:left_hand_landmarks"
  output_stream: "WRIST_LANDMARK:left_hand_wrist_landmark"
}

# Gets left hand wrist landmark or keep pose wrist landmark if hand was not
# predicted.
node {
  calculator: "MergeCalculator"
  input_stream: "left_hand_wrist_landmark"
  input_stream: "landmarks_left_wrist"
  output_stream: "merged_left_hand_wrist_landmark"
}

# Gets right hand wrist landmark.
node {
  calculator: "HandWristForPose"
  input_stream: "HAND_LANDMARKS:right_hand_landmarks"
  output_stream: "WRIST_LANDMARK:right_hand_wrist_landmark"
}

# Gets right hand wrist landmark or keep pose wrist landmark if hand was not
# predicted.
node {
  calculator: "MergeCalculator"
  input_stream: "right_hand_wrist_landmark"
  input_stream: "landmarks_right_wrist"
  output_stream: "merged_right_hand_wrist_landmark"
}

# Combines pose landmarks all together.
node {
  calculator: "ConcatenateNormalizedLandmarkListCalculator"
  input_stream: "landmarks_before_wrist"
  input_stream: "merged_left_hand_wrist_landmark"
  input_stream: "merged_right_hand_wrist_landmark"
  input_stream: "landmarks_after_wrist"
  output_stream: "landmarks_merged"
  node_options: {
    [type.googleapis.com/mediapipe.ConcatenateVectorCalculatorOptions] {
      only_emit_if_all_present: true
    }
  }
}

# Takes left pose landmarks.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks_merged"
  output_stream: "landmarks_left_side"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 0 end: 1 }
      ranges: { begin: 2 end: 3 }
      ranges: { begin: 4 end: 5 }
      ranges: { begin: 6 end: 7 }
      ranges: { begin: 8 end: 9 }
      ranges: { begin: 10 end: 11 }
      ranges: { begin: 12 end: 13 }
      ranges: { begin: 14 end: 15 }
      combine_outputs: true
    }
  }
}

# Takes right pose landmarks.
node {
  calculator: "SplitNormalizedLandmarkListCalculator"
  input_stream: "landmarks_merged"
  output_stream: "landmarks_right_side"
  node_options: {
    [type.googleapis.com/mediapipe.SplitVectorCalculatorOptions] {
      ranges: { begin: 1 end: 2 }
      ranges: { begin: 3 end: 4 }
      ranges: { begin: 5 end: 6 }
      ranges: { begin: 7 end: 8 }
      ranges: { begin: 9 end: 10 }
      ranges: { begin: 11 end: 12 }
      ranges: { begin: 13 end: 14 }
      ranges: { begin: 15 end: 16 }
      combine_outputs: true
    }
  }
}

# --------------------------------------------------------------------------- #
# ---------------------------------- Pose ----------------------------------- #
# --------------------------------------------------------------------------- #

# Converts pose connections to white lines.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:landmarks_merged"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:landmarks_render_data"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_connections: 0
      landmark_connections: 1
      landmark_connections: 0
      landmark_connections: 2
      landmark_connections: 2
      landmark_connections: 4
      landmark_connections: 1
      landmark_connections: 3
      landmark_connections: 3
      landmark_connections: 5
      landmark_connections: 0
      landmark_connections: 6
      landmark_connections: 1
      landmark_connections: 7
      landmark_connections: 6
      landmark_connections: 7
      landmark_connections: 6
      landmark_connections: 8
      landmark_connections: 7
      landmark_connections: 9
      landmark_connections: 8
      landmark_connections: 10
      landmark_connections: 9
      landmark_connections: 11
      landmark_connections: 10
      landmark_connections: 12
      landmark_connections: 11
      landmark_connections: 13
      landmark_connections: 12
      landmark_connections: 14
      landmark_connections: 13
      landmark_connections: 15
      landmark_connections: 10
      landmark_connections: 14
      landmark_connections: 11
      landmark_connections: 15

      landmark_color { r: 255 g: 255 b: 255 }
      connection_color { r: 255 g: 255 b: 255 }
      thickness: 3.0
      visualize_landmark_depth: false
      utilize_visibility: true
      visibility_threshold: 0.1
    }
  }
}

# Converts pose joints to big white circles.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:landmarks_merged"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:landmarks_background_joints_render_data"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 255 g: 255 b: 255 }
      connection_color { r: 255 g: 255 b: 255 }
      thickness: 5.0
      visualize_landmark_depth: false
      utilize_visibility: true
      visibility_threshold: 0.5
    }
  }
}

# Converts pose left side joints to orange circles (inside white ones).
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:landmarks_left_side"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:landmarks_left_joints_render_data"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 255 g: 138 b: 0 }
      connection_color { r: 255 g: 138 b: 0 }
      thickness: 3.0
      visualize_landmark_depth: false
      utilize_visibility: true
      visibility_threshold: 0.5
    }
  }
}

# Converts pose right side joints to cyan circles (inside white ones).
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:landmarks_right_side"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:landmarks_right_joints_render_data"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 0 g: 217 b: 231 }
      connection_color { r: 0 g: 217 b: 231 }
      thickness: 3.0
      visualize_landmark_depth: false
      utilize_visibility: true
      visibility_threshold: 0.5
    }
  }
}

# --------------------------------------------------------------------------- #
# ------------------------------- Left hand --------------------------------- #
# --------------------------------------------------------------------------- #

# Converts left hand connections to white lines.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:left_hand_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:left_hand_landmarks_connections_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_connections: 0
      landmark_connections: 1
      landmark_connections: 1
      landmark_connections: 2
      landmark_connections: 2
      landmark_connections: 3
      landmark_connections: 3
      landmark_connections: 4
      landmark_connections: 0
      landmark_connections: 5
      landmark_connections: 5
      landmark_connections: 6
      landmark_connections: 6
      landmark_connections: 7
      landmark_connections: 7
      landmark_connections: 8
      landmark_connections: 5
      landmark_connections: 9
      landmark_connections: 9
      landmark_connections: 10
      landmark_connections: 10
      landmark_connections: 11
      landmark_connections: 11
      landmark_connections: 12
      landmark_connections: 9
      landmark_connections: 13
      landmark_connections: 13
      landmark_connections: 14
      landmark_connections: 14
      landmark_connections: 15
      landmark_connections: 15
      landmark_connections: 16
      landmark_connections: 13
      landmark_connections: 17
      landmark_connections: 0
      landmark_connections: 17
      landmark_connections: 17
      landmark_connections: 18
      landmark_connections: 18
      landmark_connections: 19
      landmark_connections: 19
      landmark_connections: 20
      landmark_color { r: 255 g: 255 b: 255 }
      connection_color { r: 255 g: 255 b: 255 }
      thickness: 4.0
      visualize_landmark_depth: false
    }
  }
}

# Converts left hand color joints.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:left_hand_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:left_hand_landmarks_joints_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 255 g: 138 b: 0 }
      connection_color { r: 255 g: 138 b: 0 }
      thickness: 3.0
      visualize_landmark_depth: false
    }
  }
}

# --------------------------------------------------------------------------- #
# -------------------------------- Right hand ------------------------------- #
# --------------------------------------------------------------------------- #

# Converts right hand connections to white lines.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:right_hand_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:right_hand_landmarks_connections_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_connections: 0
      landmark_connections: 1
      landmark_connections: 1
      landmark_connections: 2
      landmark_connections: 2
      landmark_connections: 3
      landmark_connections: 3
      landmark_connections: 4
      landmark_connections: 0
      landmark_connections: 5
      landmark_connections: 5
      landmark_connections: 6
      landmark_connections: 6
      landmark_connections: 7
      landmark_connections: 7
      landmark_connections: 8
      landmark_connections: 5
      landmark_connections: 9
      landmark_connections: 9
      landmark_connections: 10
      landmark_connections: 10
      landmark_connections: 11
      landmark_connections: 11
      landmark_connections: 12
      landmark_connections: 9
      landmark_connections: 13
      landmark_connections: 13
      landmark_connections: 14
      landmark_connections: 14
      landmark_connections: 15
      landmark_connections: 15
      landmark_connections: 16
      landmark_connections: 13
      landmark_connections: 17
      landmark_connections: 0
      landmark_connections: 17
      landmark_connections: 17
      landmark_connections: 18
      landmark_connections: 18
      landmark_connections: 19
      landmark_connections: 19
      landmark_connections: 20
      landmark_color { r: 255 g: 255 b: 255 }
      connection_color { r: 255 g: 255 b: 255 }
      thickness: 4.0
      visualize_landmark_depth: false
    }
  }
}

# Converts right hand color joints.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:right_hand_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:right_hand_landmarks_joints_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 0 g: 217 b: 231 }
      connection_color { r: 0 g: 217 b: 231 }
      thickness: 3.0
      visualize_landmark_depth: false
    }
  }
}

# --------------------------------------------------------------------------- #
# ---------------------------------- Face ----------------------------------- #
# --------------------------------------------------------------------------- #

# Converts face connections to white lines.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:face_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:face_landmarks_connections_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      # Lips.
      landmark_connections: 61
      landmark_connections: 146
      landmark_connections: 146
      landmark_connections: 91
      landmark_connections: 91
      landmark_connections: 181
      landmark_connections: 181
      landmark_connections: 84
      landmark_connections: 84
      landmark_connections: 17
      landmark_connections: 17
      landmark_connections: 314
      landmark_connections: 314
      landmark_connections: 405
      landmark_connections: 405
      landmark_connections: 321
      landmark_connections: 321
      landmark_connections: 375
      landmark_connections: 375
      landmark_connections: 291
      landmark_connections: 61
      landmark_connections: 185
      landmark_connections: 185
      landmark_connections: 40
      landmark_connections: 40
      landmark_connections: 39
      landmark_connections: 39
      landmark_connections: 37
      landmark_connections: 37
      landmark_connections: 0
      landmark_connections: 0
      landmark_connections: 267
      landmark_connections: 267
      landmark_connections: 269
      landmark_connections: 269
      landmark_connections: 270
      landmark_connections: 270
      landmark_connections: 409
      landmark_connections: 409
      landmark_connections: 291
      landmark_connections: 78
      landmark_connections: 95
      landmark_connections: 95
      landmark_connections: 88
      landmark_connections: 88
      landmark_connections: 178
      landmark_connections: 178
      landmark_connections: 87
      landmark_connections: 87
      landmark_connections: 14
      landmark_connections: 14
      landmark_connections: 317
      landmark_connections: 317
      landmark_connections: 402
      landmark_connections: 402
      landmark_connections: 318
      landmark_connections: 318
      landmark_connections: 324
      landmark_connections: 324
      landmark_connections: 308
      landmark_connections: 78
      landmark_connections: 191
      landmark_connections: 191
      landmark_connections: 80
      landmark_connections: 80
      landmark_connections: 81
      landmark_connections: 81
      landmark_connections: 82
      landmark_connections: 82
      landmark_connections: 13
      landmark_connections: 13
      landmark_connections: 312
      landmark_connections: 312
      landmark_connections: 311
      landmark_connections: 311
      landmark_connections: 310
      landmark_connections: 310
      landmark_connections: 415
      landmark_connections: 415
      landmark_connections: 308
      # Left eye.
      landmark_connections: 33
      landmark_connections: 7
      landmark_connections: 7
      landmark_connections: 163
      landmark_connections: 163
      landmark_connections: 144
      landmark_connections: 144
      landmark_connections: 145
      landmark_connections: 145
      landmark_connections: 153
      landmark_connections: 153
      landmark_connections: 154
      landmark_connections: 154
      landmark_connections: 155
      landmark_connections: 155
      landmark_connections: 133
      landmark_connections: 33
      landmark_connections: 246
      landmark_connections: 246
      landmark_connections: 161
      landmark_connections: 161
      landmark_connections: 160
      landmark_connections: 160
      landmark_connections: 159
      landmark_connections: 159
      landmark_connections: 158
      landmark_connections: 158
      landmark_connections: 157
      landmark_connections: 157
      landmark_connections: 173
      landmark_connections: 173
      landmark_connections: 133
      # Left eyebrow.
      landmark_connections: 46
      landmark_connections: 53
      landmark_connections: 53
      landmark_connections: 52
      landmark_connections: 52
      landmark_connections: 65
      landmark_connections: 65
      landmark_connections: 55
      landmark_connections: 70
      landmark_connections: 63
      landmark_connections: 63
      landmark_connections: 105
      landmark_connections: 105
      landmark_connections: 66
      landmark_connections: 66
      landmark_connections: 107
      # Right eye.
      landmark_connections: 263
      landmark_connections: 249
      landmark_connections: 249
      landmark_connections: 390
      landmark_connections: 390
      landmark_connections: 373
      landmark_connections: 373
      landmark_connections: 374
      landmark_connections: 374
      landmark_connections: 380
      landmark_connections: 380
      landmark_connections: 381
      landmark_connections: 381
      landmark_connections: 382
      landmark_connections: 382
      landmark_connections: 362
      landmark_connections: 263
      landmark_connections: 466
      landmark_connections: 466
      landmark_connections: 388
      landmark_connections: 388
      landmark_connections: 387
      landmark_connections: 387
      landmark_connections: 386
      landmark_connections: 386
      landmark_connections: 385
      landmark_connections: 385
      landmark_connections: 384
      landmark_connections: 384
      landmark_connections: 398
      landmark_connections: 398
      landmark_connections: 362
      # Right eyebrow.
      landmark_connections: 276
      landmark_connections: 283
      landmark_connections: 283
      landmark_connections: 282
      landmark_connections: 282
      landmark_connections: 295
      landmark_connections: 295
      landmark_connections: 285
      landmark_connections: 300
      landmark_connections: 293
      landmark_connections: 293
      landmark_connections: 334
      landmark_connections: 334
      landmark_connections: 296
      landmark_connections: 296
      landmark_connections: 336
      # Face oval.
      landmark_connections: 10
      landmark_connections: 338
      landmark_connections: 338
      landmark_connections: 297
      landmark_connections: 297
      landmark_connections: 332
      landmark_connections: 332
      landmark_connections: 284
      landmark_connections: 284
      landmark_connections: 251
      landmark_connections: 251
      landmark_connections: 389
      landmark_connections: 389
      landmark_connections: 356
      landmark_connections: 356
      landmark_connections: 454
      landmark_connections: 454
      landmark_connections: 323
      landmark_connections: 323
      landmark_connections: 361
      landmark_connections: 361
      landmark_connections: 288
      landmark_connections: 288
      landmark_connections: 397
      landmark_connections: 397
      landmark_connections: 365
      landmark_connections: 365
      landmark_connections: 379
      landmark_connections: 379
      landmark_connections: 378
      landmark_connections: 378
      landmark_connections: 400
      landmark_connections: 400
      landmark_connections: 377
      landmark_connections: 377
      landmark_connections: 152
      landmark_connections: 152
      landmark_connections: 148
      landmark_connections: 148
      landmark_connections: 176
      landmark_connections: 176
      landmark_connections: 149
      landmark_connections: 149
      landmark_connections: 150
      landmark_connections: 150
      landmark_connections: 136
      landmark_connections: 136
      landmark_connections: 172
      landmark_connections: 172
      landmark_connections: 58
      landmark_connections: 58
      landmark_connections: 132
      landmark_connections: 132
      landmark_connections: 93
      landmark_connections: 93
      landmark_connections: 234
      landmark_connections: 234
      landmark_connections: 127
      landmark_connections: 127
      landmark_connections: 162
      landmark_connections: 162
      landmark_connections: 21
      landmark_connections: 21
      landmark_connections: 54
      landmark_connections: 54
      landmark_connections: 103
      landmark_connections: 103
      landmark_connections: 67
      landmark_connections: 67
      landmark_connections: 109
      landmark_connections: 109
      landmark_connections: 10
      landmark_color { r: 255 g: 255 b: 255 }
      connection_color { r: 255 g: 255 b: 255 }
      thickness: 0.5
      visualize_landmark_depth: false
    }
  }
}

# Converts face joints to cyan circles.
node {
  calculator: "LandmarksToRenderDataCalculator"
  input_stream: "NORM_LANDMARKS:face_landmarks"
  input_stream: "RENDER_SCALE:render_scale"
  output_stream: "RENDER_DATA:face_landmarks_joints_rd"
  node_options: {
    [type.googleapis.com/mediapipe.LandmarksToRenderDataCalculatorOptions] {
      landmark_color { r: 0 g: 217 b: 231 }
      connection_color { r: 0 g: 217 b: 231 }
      thickness: 0.5
      visualize_landmark_depth: false
    }
  }
}

# Concatenates all render data.
node {
  calculator: "ConcatenateRenderDataVectorCalculator"
  input_stream: "landmarks_render_data"
  input_stream: "landmarks_background_joints_render_data"
  input_stream: "landmarks_left_joints_render_data"
  input_stream: "landmarks_right_joints_render_data"

  # Left hand.
  input_stream: "left_hand_landmarks_connections_rd"
  input_stream: "left_hand_landmarks_joints_rd"

  # Right hand.
  input_stream: "right_hand_landmarks_connections_rd"
  input_stream: "right_hand_landmarks_joints_rd"

  # Face.
  input_stream: "face_landmarks_connections_rd"
  input_stream: "face_landmarks_joints_rd"

  output_stream: "render_data_vector"
}
