unpackLandmarks<T> function

List<List<T>> unpackLandmarks<T>(
  1. List<double> packed,
  2. List<int> counts,
  3. LandmarkBuilder<T> point
)

Splits packed into one landmark list per subject.

Implementation

List<List<T>> unpackLandmarks<T>(
  List<double> packed,
  List<int> counts,
  LandmarkBuilder<T> point,
) {
  double? optional(double value) => value.isNaN ? null : value;
  if (packed.length != counts.fold(0, (a, b) => a + b) * packedLandmarkStride) {
    throw const FormatException('Packed landmarks do not match their counts.');
  }
  final subjects = <List<T>>[];
  var at = 0;
  for (final count in counts) {
    subjects.add([
      for (var i = 0; i < count; i++, at += packedLandmarkStride)
        point(
          x: packed[at],
          y: packed[at + 1],
          z: packed[at + 2],
          visibility: optional(packed[at + 3]),
          presence: optional(packed[at + 4]),
        ),
    ]);
  }
  return subjects;
}